pkulchenko / MobDebug

Remote debugger for Lua.
Other
885 stars 192 forks source link

Start and off method #37

Open moteus opened 6 years ago

moteus commented 6 years ago

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 commented 5 years ago

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 commented 4 years ago

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