Datasheet
546
Exploring the Software-Development Tools in Linux
Table 1-4 (continued)
info var
Displays all global and static variable
names.
kill
Ends the program you’re debugging.
list
Lists a section of the source code.
make Runs the make utility to rebuild the execut-
able without leaving gdb.
next
Advances one line of source code in the
current function without stepping into other
functions.
print EXPR Shows the value of the expression EXPR.
quit Quits gdb.
run
Starts running the executable that is cur-
rently running.
set variable
VAR=VALUE
Sets the value of the variable VAR to
VALUE.
shell CMD Executes the UNIX command CMD, without
leaving gdb.
step
Advances one line in the current function,
stepping into other functions, if any.
watch VAR Shows the value of the variable named VAR
whenever the value changes.
where
Displays the call sequence. Use this com-
mand to locate where your program died.
x/F ADDR
Examines the contents of the memory loca-
tion at address ADDR in the format speci-
fied by the letter F, which can be o (octal),
x (hex), d (decimal), u (unsigned decimal),
t (binary), f (float), a (address), i (instruc-
tion), c (char), or s (string). You can append
a letter indicating the size of data type to
the format letter. Size letters are b (byte), h
(halfword, 2 bytes), w (word, 4 bytes), and g
(giant, 8 bytes). Typically, ADDR is the name
of a variable or pointer.
Finding bugs by using gdb
To understand how you can find bugs by using gdb, you need to see an
example. The procedure is easiest to show with a simple example, so the fol-
lowing, dbgtst.c, is a contrived program that contains a typical bug.
42_770191-bk08ch01.indd 54642_770191-bk08ch01.indd 546 8/6/10 9:51 AM8/6/10 9:51 AM