Many IDEs have a "variables" pane where you can add/remove variables to watch. These variables value are updated every time you step the code.
Is there such an option in GDB?
If you want a graphical version of GDB, then you can look at DDD. It has the exact option you're looking for.
GDB - not being graphical - cannot deliver the kind of functionality in a pane, but you can use the display
command to show a variable after each step.
I think the most practical way to achieve this (and what I do in practice) is to use watch
. From the prompt: watch varname
will break whenever a variable is written to. For global variables, sometimes it's best to get the address of the variable with print &varname
and then set a watch on the address watch (int)0xDEADBEEF
, replacing DEADBEEF with the output of the print command, and using something other than int if it isn't an int.
There is also GDB's TUI mode. I don't believe you can tell it to watch a specific variable, but you can have it display the registers (or the source code, or other things) as you step through. In the prompt (after launching gdb -tui
) enter: tui reg general
. This will show the variable after each step while it is in a register. More TUI options.
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