Displaying Variables153
5.5.2Automatic Displaying Variables with Each Command
The
display
command displays the value of a variable and keeps a record of the vari-
able so that its value is displayed after each command. The following session shows how this
feature works. This is an easy way to closely watch the value of variables with the execution of
each line of code. It is especially useful when you are tracing through a loop where you need to
know the values of some variables in each cycle.
[rr@conformix 5]$ gdb sum
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public
License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty"
for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) break main
Breakpoint 1 at 0x8048496: file sum.c, line 6.
(gdb) run
Starting program: /home/rr/5/sum
Breakpoint 1, main () at sum.c:6
6 printf("Enter first number : ");
(gdb) display num1
1: num1 = 134518424
(gdb) disp total
2: total = 134513777
(gdb) n
7 scanf("%d", &num1);
2: total = 134513777
1: num1 = 134518424
(gdb) n
Enter first number : 3
8 printf("Enter second number : ");
2: total = 134513777
1: num1 = 3
(gdb) n
9 scanf("%d", &num2);
2: total = 134513777
1: num1 = 3
(gdb) n
Enter second number : 67
11 total = num1 + num2;
2: total = 134513777
1: num1 = 3
Next Page >>
<< Previous Page
Back to the Table of Contents