I use the gdb command commands
to create "printf" statements on the fly. Just make sure the last command is continue.
#assume two breakpoints, 1 and 2
commands 1
silent
echo calling baz\n
set $print_foobar=1
continue
end
commands 2
silent
echo calling foobar\n
if $print_foobar
set $print_foobar=0
backtrace
end
continue
end
I've recently fallen in love with this technique as it lets me create printf()
statement for code that is already running. Plus GDB scripting though limited lets you do quite a bit when deciding what to print. I've yet to find a situation where a commands section wasn't as good or better than a printf()
.