Reputation: 21
If a C program is something like:
void main ()
{
int a, b, c;
a = 1;
b = a + 1;
c = b + 1;
}
while running gdb, and single stepping:
How do I display the variable that got updated by that single step? Of course this is a highly simplified example, the idea being trace the execution. Something like:
(gdb) step
a=1
(gdb) step
b=2
(gdb) step
c=3
Thanks
Upvotes: 1
Views: 387
Reputation: 2513
The closest thing that gdb has to this is setting a watch for a variable. GDB will break every time a watched variable is changed. GDB: Watch a variable in a given scope for example
Upvotes: 0
Reputation: 5566
gdb has an option that causes it to display 6 panels.
The upper right panel displays locals or registers.
(gdb) step
a=1
With this display, the line a=1 is the next line to be executed.
How do I display the variable that got updated by that single step?
In the 6 panel display, the variable a is displayed, (and since you did not initialize it, any value might show prior to the step) and when you step, the 'a' value is updated.
In emacs, the command is (setq gdb-many-windows t), and I am confident the gdb manual can identify the command line equivalent.
--- might be related to "layout regs"
Upvotes: 1
Reputation: 33854
This cannot be done automaticly, imagine a line where you step that loks like this:
int a = someFunction(b++, c--);
a
, b
, and c
change (along with any number of global or static variables affected by someFunction
). How would GDB
know what to print? You can use the print
command to show a variables value.
Upvotes: 0