You are on page 1of 2

GDB QUICK REFERENCE GDB Version 4 Breakpoints and Watchpoints Execution Control

break [file:]line set breakpoint at line number [in file] continue [count] continue running; if count specified, ignore
Essential Commands b [file:]line eg: break main.c:37 c [count] this breakpoint next count times
gdb program [core] debug program [using coredump core] break [file:]func set breakpoint at func [in file] step [count] execute until another line reached; repeat
b [file:]function set breakpoint at function [in file] break +offset set break at offset lines from current stop s [count] count times if specified
run [arglist] start your program [with arglist] break -offset
break *addr set breakpoint at address addr stepi [count] step by machine instructions rather than
bt backtrace: display program stack si [count] source lines
break set breakpoint at next instruction
p expr display the value of an expression
break . . . if expr break conditionally on nonzero expr
c continue running your program next [count] execute next line, including any function
n next line, stepping over function calls cond n [expr] new conditional expression on breakpoint
n; make unconditional if no expr
n [count] calls
s next line, stepping into function calls
tbreak . . . temporary break; disable when reached nexti [count] next machine instruction rather than
rbreak regex break on all functions matching regex ni [count] source line
Starting GDB watch expr set a watchpoint for expression expr
gdb start GDB, with no debugging files catch event break at event, which may be catch, until [location] run until next instruction (or location)
gdb program begin debugging program throw, exec, fork, vfork, load, or finish run until selected stack frame returns
gdb program core debug coredump core produced by unload. return [expr] pop selected stack frame without
program info break show defined breakpoints executing [setting return value]
gdb --help describe command line options info watch show defined watchpoints signal num resume execution with signal s (none if 0)
jump line resume execution at specified line number
Stopping GDB clear delete breakpoints at next instruction jump *address or address
quit exit GDB; also q or EOF (eg C-d) clear [file:]fun delete breakpoints at entry to fun() set var=expr evaluate expr without displaying it; use
for altering program variables
INTERRUPT (eg C-c) terminate current command, or clear [file:]line delete breakpoints on source line
send to running process
delete [n] delete breakpoints [or breakpoint n]
Getting Help disable [n] disable breakpoints [or breakpoint n] print [/f ] [expr] show value of expr [or last value $]
help list classes of commands enable [n] enable breakpoints [or breakpoint n] p [/f ] [expr] according to format f:
help class one-line descriptions for commands in x hexadecimal
class enable once [n] enable breakpoints [or breakpoint n]; d signed decimal
help command describe command disable again when reached u unsigned decimal
enable del [n] enable breakpoints [or breakpoint n]; o octal
Executing your Program delete when reached t binary
ignore n count ignore breakpoint n, count times a address, absolute and relative
run arglist start your program with arglist c character
run start your program with current argument f floating point
list commands n execute GDB command-list every time
run ... <inf >outf start your program with input, output [silent] breakpoint n is reached. [silent call [/f ] expr like print but does not display void
redirected command-list suppresses default display] x [/Nuf ] expr examine memory at address expr; optional
kill kill running program end end of command-list format spec follows slash
N count of how many units to display
tty dev use dev as stdin and stdout for next run Program Stack u unit size; one of
set args arglist specify arglist for next run b individual bytes
set args specify empty argument list backtrace [n] print trace of all frames in stack; or of n h halfwords (two bytes)
show args display argument list bt [n] frames—innermost if n>0, outermost if w words (four bytes)
n<0 g giant words (eight bytes)
show env show all environment variables frame [n] select frame number n or frame at address f printing format. Any print format, or
show env var show value of environment variable var n; if no n, display current frame s null-terminated string
set env var string set environment variable var up n select frame n frames up i machine instructions
unset env var remove var from environment down n select frame n frames down disassem [addr] display memory as machine instructions
info frame [addr] describe selected frame, or frame at addr
Shell Commands info args arguments of selected frame
info locals local variables of selected frame Automatic Display
cd dir change working directory to dir
pwd Print working directory info reg [rn]. . . register values [for regs rn ] in selected display [/f ] expr show value of expr each time program
make . . . call “make” info all-reg [rn] frame; all-reg includes floating point stops [according to format f ]
shell cmd execute arbitrary shell command string display display all enabled expressions on list
undisplay n remove number(s) n from list of
automatically displayed expressions
[] surround optional arguments ... show one or more arguments disable disp n disable display for expression(s) number n
enable disp n enable display for expression(s) number n

c 1998 Free Software Foundation, Inc. Permissions on back info display numbered list of display expressions
Expressions Controlling GDB Source Files
expr an expression in C, C++, or Modula-2 set param value set one of GDB’s internal parameters dir names add directory names to front of source
(including function calls), or: show param display current setting of parameter path
addr @len an array of len elements beginning at Parameters understood by set and show: dir clear source path
addr complaint limit number of messages on unusual symbols show dir show current source path
file::nm a variable or function nm defined in file
confirm on/off enable or disable cautionary queries
{type}addr read memory at addr as specified type editing on/off control readline command-line editing list show next ten lines of source
height lpp number of lines before pause in display
list - show previous ten lines
$ most recent displayed value
list lines display source surrounding lines, specified
$n nth displayed value language lang Language for GDB expressions (auto, c or
$$ displayed value previous to $ modula-2)
$$n nth displayed value back from $ listsize n number of lines shown by list
[file:]num line number [in named file]
$ last address examined with x prompt str use str as GDB prompt [file:]function beginning of function [in named file]
$ value at address $ radix base octal, decimal, or hex number +off off lines after last printed
$var convenience variable; assign any value representation -off off lines previous to last printed
verbose on/off control messages when loading symbols *address line containing address
show values [n] show last 10 values [or surrounding $n] width cpl number of characters before line folded list f,l from line f to line l
show conv display all convenience variables write on/off Allow or forbid patching binary, core files info line num show starting, ending addresses of
(when reopened with exec or core) compiled code for source line num
history . . . groups with the following options: info source show name of current source file
Symbol Table h ... info sources list all source files in use
info address s show where symbol s is stored h exp off/on disable/enable readline history expansion forw regex search following source lines for regex
info func [regex] show names, types of defined functions h file filename file for recording GDB command history rev regex search preceding source lines for regex
(all, or matching regex) h size size number of commands kept in history list
h save off/on control use of external file for command
info var [regex] show names, types of global variables (all, history GDB under GNU Emacs
or matching regex) M-x gdb run GDB under Emacs
print . . . groups with the following options:
whatis [expr] show data type of expr [or $] without C-h m describe GDB mode
p ...
ptype [expr] evaluating; ptype gives more detail M-s step one line (step)
p address on/off print memory addresses in stacks, values
ptype type describe type, struct, union, or enum M-n next line (next)
p array off/on compact or attractive format for arrays M-i step one instruction (stepi)
p demangl on/off source (demangled) or internal form for C-c C-f finish current stack frame (finish)
GDB Scripts C++ symbols M-c continue (cont)
source script read, execute GDB commands from file p asm-dem on/off demangle C++ symbols in machine- M-u up arg frames (up)
script instruction output M-d down arg frames (down)
p elements limit number of array elements to display C-x & copy number from point, insert at end
define cmd create new GDB command cmd; execute p object on/off print C++ derived types for objects
command-list script defined by command-list
C-x SPC (in source file) set break at point
p pretty off/on struct display: compact or indented
end end of command-list
document cmd create online documentation for new GDB
p union on/off display of union members
p vtbl off/on display of C++ virtual function tables
GDB License
help-text command cmd
show copying Display GNU General Public License
end end of help-text show warranty There is NO WARRANTY for GDB.
show commands show last 10 commands
show commands n show 10 commands around number n Display full no-warranty statement.
Signals show commands + show next 10 commands
handle signal act specify GDB actions for signal:
print announce signal Working Files
noprint be silent for signal
file [file] use file for both symbols and executable;
stop halt execution on signal
with no arg, discard both
c 1991, ’92, ’93, ’98 Free Software Foundation, Inc.
nostop do not halt execution Roland H. Pesch
pass allow your program to handle signal core [file] read file as coredump; or discard The author assumes no responsibility for any errors on this card.
nopass do not allow your program to see signal exec [file] use file as executable only; or discard
info signals show table of signals, GDB action for each This card may be freely distributed under the terms of the GNU
symbol [file] use symbol table from file; or discard General Public License.
load file dynamically link file and add its symbols
Debugging Targets add-sym file addr read additional symbols from file,
Please contribute to development of this card by annotating it.
Improvements can be sent to
target type param connect to target machine, process, or file dynamically loaded at addr
help target display available targets info files display working files and targets in use GDB itself is free software; you are welcome to distribute copies of
attach param connect to another process path dirs add dirs to front of path searched for it under the terms of the GNU General Public License. There is
detach release target from GDB control executable and symbol files absolutely no warranty for GDB.
show path display executable and symbol file path
info share list names of shared libraries currently