154Chapter5 • Working with GNU Debugger
(gdb) n
13 printf("\nThe sum is : %d\n", total);
2: total = 70
1: num1 = 3
(gdb) n
The sum is : 70
14}
2: total = 70
1: num1 = 3
(gdb) n
Program exited with code 021.
(gdb)
You can use the following commands to control the display of variables and get informa-
tion about variables that are being displayed.
•The
undisplay
command removes a variable from the list of displayed items.
•The
disable display
command keeps the variable in the display list but disables
its continuous display.
•The
enable display
command enables display of a variable that was previously
disabled.
•The
info display
command displays a list of expressions or variables currently in
the display list.
5.5.3Displaying Environment Variables
Environment variables play a significant role in debugging a program. They are used to
locate files and other tasks related to the file system as well as shell command execution. The
following command displays the value of the
PATH
variable:
(gdb) show path
Executable and object file path: /usr/kerberos/bin:/bin:/usr/
bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin
The following command shows the current directory:
(gdb) pwd
Working directory /home/rr/5.
All environment variables can be displayed using the following command:
(gdb) show environment
PWD=/home/rr/5
HOSTNAME=conformix.conformix.net
PVM_RSH=/usr/bin/rsh
QTDIR=/usr/lib/qt-2.3.0
LESSOPEN=|/usr/bin/lesspipe.sh %s