Closed jsalzbergedu closed 4 years ago
A: a breakpoint on a function call so that I can see where a function is called and what values it is called with
You can set a breakpoint on the first statement in the function and it will break when the function is called.
To get the values it's called with, you can use the STACK command to retrieve the content of the stack, which will include all parameters and upvalues.
B: the ability to pop backwards a stack frame so I can retry the function with different arguments.
You can use "stepout" command, but you won't be able to re-enter the function with different parameters, as Lua doesn't support changing the control pointer outside of a normal control flow. You can wrap a function in a loop or wait for the next call to that function to tweak the parameters.
You can change the values the function is called with before the function is executed (or change the parameter values when the control is inside the function), but that's it.
Thank you!
You can change the values the function is called with before the function is executed
Ok so that's what I meant for break on function call. Like if I have a function F at address P, before the function F at address P is called the debugger breaks. Is this possible via the Lua debugger?
Thank you.
if I have a function F at address P, before the function F at address P is called the debugger breaks. Is this possible via the Lua debugger?
No, the debugger doesn't know anything about addresses; it only "knows" about line numbers. Functions don't really have names, as they are anonymous values that can be assigned to different variables, so you can't really say "break at function a". What you can do is to figure our where the function starts (either because you have access to the source code or because the function has been created and you can access its linedefined
field from the debug interface) and set a breakpoint there.
This means that if you do have a function "pointer" func
, you can interrogate it with debug.getinfo(func, "S").linedefined
(or similarly with lua_getinfo
) to get the line number where a breakpoint can be set to be triggered on the function entry.
Often, when I am debugging, I want to have either
A: a breakpoint on a function call so that I can see where a function is called and what values it is called with
or
B: the ability to pop backwards a stack frame so I can retry the function with different arguments.
Are either of these possible, and if so, do you have any advice as to how they might be implemented? Thank you.