-
Notifications
You must be signed in to change notification settings - Fork 88
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 debugger when entering/returning from function #78
Comments
Hmm. Not sure off the top of my head, but I'm guessing it's because my debugger uses hooks internally and they conflict with yours. An alternative you can try is to patch the function instead. Something like this: dbg = require 'debugger'
function dbgfun(fun, env)
env = env or _G
local f = env[fun]
env[fun] = function(...)
dbg()
f(...)
end
end
function dostuff()
print("about to do stuff")
local a = "" + 3 -- oops a bug
end
dbgfun("dostuff")
dostuff() This should also be much much faster too as it doesn't leave a debug hook set all the time. Does that solve your problem, or do you need the hooks to work for some other reason? |
I agree that your solution is fine for most cases and much faster than installing a hook triggered at each call, but it does not give access to local functions inside modules, which was my initial intention, and it's also tricky to wrap methods and metamethods with your approach. Wouldn't be possible to make your hooks compatible with the proposed approach, or to provide some dbgfun(funname, funline) working like a kind of breakpoint? Of course, this would assume that there is not much code to run between the set point and the hook. I modified slightly your proposal to disable the wrap: local function dbgfun (fun, env, f_)
env = env or _G
local f = assert(env[fun], "invalid function name or environment")
env[fun] = f_ or function(...)
dbg()
f(...)
end
return f
end
|
update: calling |
It might be possible, but I remember debug hooks having a bunch of limitations and just being painfully slow in general. I haven't touched that part of the code in a few years, so I don't know off the top of my head. |
I have tried to run the debugger at the entry of a function with the given name, using the following (slow) code. This works with
debug.debug()
but not withdbg()
. Is there a recommended way to do this? Note that callingdbg()
withindebug.debug()
does not work either (assumingdbg()
is visible).The text was updated successfully, but these errors were encountered: