MobDebug icon indicating copy to clipboard operation
MobDebug copied to clipboard

Start and off method

Open moteus opened this issue 8 years ago • 2 comments

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

moteus avatar Dec 20 '17 16:12 moteus

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.

mdurn avatar May 16 '19 19:05 mdurn

@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.

pkulchenko avatar Jul 24 '20 04:07 pkulchenko