Is it possible to have gdb log something to the terminal instead of breaking on it? For example I would like to set a 'breakpoint' on some method and have gdb print self as well as the parameters each time the method is invoked. Basically I want to insert print statements into arbitrary places without actually recompiling.
thanks for any suggestions
This is what i have so far after these helpful comments:
define logFoo
b fooMethod
commands
po self
end
end
GDB doesn't seem to like the nested end statements though. any thoughts?
To skip a breakpoint a certain number of times, we use the ignore command. The ignore command takes two arguments: the breakpoint number to skip, and the number of times to skip it. (gdb) ignore 2 5 Will ignore next 5 crossings of breakpoint 2.
To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.
To save breakpoint definitions to a file use the save breakpoints command. This command saves all current breakpoint definitions together with their commands and ignore counts, into a file filename suitable for use in a later debugging session.
Setting watchpoints. You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. Depending on your system, watchpoints may be implemented in software or hardware.
You can use Breakpoint Command Lists. There is an example how to do it.
For example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.
break foo if x>0 commands silent printf "x is %d\n",x cont end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With