GDB

Gdb

Commands

M-x gdb
invoke gdb from emacs
C-c
interrupt, return control to gdb
q
quit gdb
run
start program from beginning
kill
cancel the running program
cont
continue execution (from breakpoint, etc.)
fin
finish this function and break on return
ret value
return immediately from this function with value
s
continue and break at next statement
n
continue and break at next statement in this function
break function
set breakpoint at entry to function function
clear function
clear any breakpoint set at entry to function function
M-x gdb-break
set breakpoint at source line containing emacs cursor
info break
display list of breakpoints
delete bnum
clear breakpoint specified by bnum
frame 0
display source, etc., for innermost stack frame
frame n
for n>0, display source, etc., for caller of frame n-1
bt
display backtrace of function calls.
p exp
evaluate exp in the context of current frame and print its value in the format implied by its type.
p/letter exp
evaluate exp in context of current frame and print its value in the format specified by letter.
x/letter exp
similar to p, but exp is treated as an address and the memory contents at that address are displayed.

Formats

Format letters for p and p commands.

a address
c character
d signed decimal
f floating point
i instruction (assembler syntax)
o octal
s string
u unsigned decimal
x hexadecimal

Convenience Variables

$
most recent value printed
$$
next to most recent value printed
$n
nth value printed
$r0, $r1, ..., $r15
registers r0, r1, ..., r15
$pc, $ap, ...
registers pc, ap, ...
$ps
process status longword

Helpful Hints

To change the value of a program (or convenience) variable, use and assignment as exp in a p command; e.g., p x=1 sets the variable x to 1.

To debug a function, try setting a breakpoint at the function, and using p commands to call the function, e.g., p f(5,s) calls f with arguments 5 and s and, if a breakpoint has been set, breaks immediately on entering the function. You can then step through the function, examine variables, etc.

It is often useful to set a breakpoint at main before running the program.

After giving an x command, subsequent returns (i.e., the RETURN key) are intepreted as x commands with the same format and applied to the memory address following the one just examined.


Sun May 29 16:30:03 EDT 1994