Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start and off method #37

Open
moteus opened this issue Dec 20, 2017 · 2 comments
Open

Start and off method #37

moteus opened this issue Dec 20, 2017 · 2 comments
Assignees

Comments

@moteus
Copy link
Contributor

moteus commented Dec 20, 2017

My use case now is work with server which creates separate coroutine for each request.
So code looks like this

mobdebug.coro()
mobdebug.start()
mobdebug.off()
function handler() -- this function calls in coro
  mobdebug.on()
  .... 
  mobdebug.off()
end

In this case I have small inconvenience.
Debugger interrupt execution of main thread just after mobdebug.start() returns.
But I really do not need this. I just need only connect to debugger and then
just turn on debugger in some functions.
So I suggest add one more argument to start
In my system i implement it just like if off then mobdebug.off() end before return true
inside start function and use it like

mobdebug.coro()
mobdebug.start(nil, nil, true)
function handler()
  mobdebug.on()
  .... 
  mobdebug.off()
end
@mdurn
Copy link

mdurn commented May 16, 2019

Any updates on this (or any other way to do this)? Specifically on skipping the first debugger pause from start()? My use case is debugging in openresty and using a mobdebug listener from my shell. I would rather only break at my pause statements.

@pkulchenko pkulchenko self-assigned this Jul 24, 2020
@pkulchenko
Copy link
Owner

@moteus, coming back to this, three years later. I'd prefer to provide a table with options instead of adding a third parameter. Here is a patch against a current master; it adds runonstart option you can set to false to disable stopping:

diff --git a/src/mobdebug.lua b/src/mobdebug.lua
index dc4ea68..364c696 100644
--- a/src/mobdebug.lua
+++ b/src/mobdebug.lua
@@ -1056,8 +1056,11 @@ local function start(controller_host, controller_port)
   -- only one debugging session can be run (as there is only one debug hook)
   if isrunning() then return end
 
-  lasthost = controller_host or lasthost
-  lastport = controller_port or lastport
+  local opt = (type(controller_host) == "table" and controller_host
+    or {hostname = controller_host, port = controller_port})
+
+  lasthost = opt.hostname or lasthost
+  lastport = opt.port or lastport
 
   controller_host = lasthost or "localhost"
   controller_port = lastport or mobdebug.port
@@ -1101,7 +1104,7 @@ local function start(controller_host, controller_port)
     coro_debugger = corocreate(debugger_loop)
     debug.sethook(debug_hook, HOOKMASK)
     seen_hook = nil -- reset in case the last start() call was refused
-    step_into = true -- start with step command
+    if opt.runonstart ~= false then step_into = true end -- start with step command
     return true
   else
     print(("Could not connect to %s:%s: %s")

Let me know how it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants