Reputation: 4350
In gdb
, when it hits a breakpoint, I need to manually investigate the variable values, one by one, with print
or print/x
functions.
Is there any easier way to list all selected variable's values whenever it hits a breakpoint, commonly known as a "watch window" of a GUI debugger?
Upvotes: 0
Views: 750
Reputation: 7582
Commands can be executed on breakpoints.
From docs:
break foo
commands
printf "x is %d\n",x
end
Or add commands to some existing breakpoint (breakpoint number 3 in this case):
commands 3
print x
print y
end
Or make a command that adds prints to a breakpoint:
define addwatch
commands $arg0
print x
print y
end
end
Then use:
addwatch 3
Or make a command that sets a breakpoint and adds prints to it.
Scripts can be stored in .gdbinit
, so they'll load automatically. The language is either this GDB syntax or Python.
P.S. Some people do tracing with this by adding continue
at the end of the command list: that way the variables are printed, but the application doesn't stop on the breakpoint.
Upvotes: 2