GDB QUICK REFERENCE GDB Version 5
Essential Commands
gdb program [core] debug program [using coredump core]b [file:]function
set breakpoint at function [in file]run [arglist]
start your program [with arglist]
btp expr
cns

backtrace: display program stackdisplay the value of an expression
continue running your program
next line, stepping over function calls
next line, stepping into function calls

Starting GDBBreakpoints and Watchpoints
break [file:]line
set breakpoint at line number [in file]eg: break main.c:37
b [file:]linebreak [file:]func
set breakpoint at func [in file]
break +offset
break -offset
break *addr
break
break . . . if expr
cond n [expr]

set break at offset lines from current stop
set breakpoint at address addr
set breakpoint at next instruction
break conditionally on nonzero expr
new conditional expression on breakpointn; make unconditional if no expr
temporary break; disable when reachedtbreak . . .
rbreak [file:]regex break on all functions matching regex [inwatch expr
catch event

file]
set a watchpoint for expression expr
break at event, which may be catch,throw, exec, fork, vfork, load, orunload.

info breakinfo watch

show defined breakpoints
show defined watchpoints

clear
clear [file:]fundelete breakpoints at next instruction

clear [file:]line

delete breakpoints on source line

delete [n]delete breakpoints [or breakpoint n]disable [n]disable breakpoints [or breakpoint n]enable [n]enable breakpoints [or breakpoint n]enable once [n]enable breakpoints [or breakpoint n];disable again when reachedExecuting your Program

enable del [n]run arglist
run

enable breakpoints [or breakpoint n];delete when reachedignore n countignore breakpoint n, count times

commands n[silent]

execute GDB command-list every timebreakpoint n is reached. [silentgdb
gdb program
gdb program coregdb --help

start GDB, with no debugging files
begin debugging program
debug coredump core produced byprogram
describe command line options

Stopping GDB
quit
INTERRUPT

exit GDB; also q or EOF (eg C-d)(eg C-c) terminate current command, orsend to running process

Getting Help
help
help classhelp command

run . . . <inf >outf

list classes of commands
one-line descriptions for commands inclassdescribe command

start your program with arglist
start your program with current argument
list
start your program with input, output
redirectedkill

kill running program

tty dev
set args arglist
set args
show args

use dev as stdin and stdout for next run
specify arglist for next run
specify empty argument list
display argument list

show env
show env var
set env var string
unset env var

show all environment variables
show value of environment variable var
set environment variable var
remove var from environmentcommand-list

Shell Commands
cd dirpwd
make . . .
shell cmd

change working directory to dir
Print working directory
call “make”
execute arbitrary shell command string[ ] surround optional arguments. . . show one or more arguments

c 1998-2024 Free Software Foundation, Inc.

Permissions on backend

suppresses default display]end of command-list

n<0up ndown ninfo frame [addr]
info args
info locals
info reg [rn]. . .
info all-reg [rn]step [count]s [count]

execute until another line reached; repeat
count times if specified

stepi [count]si [count]

step by machine instructions rather thansource lines

next [count]n [count]

execute next line, including any function
calls

nexti [count]ni [count]next machine instruction rather thansource line

until [location]finishreturn [expr]

run until next instruction (or location)
run until selected stack frame returns
pop selected stack frame without
executing [setting return value]

signal num
jump line
jump *address
set var=expr

resume execution with signal s (none if 0)
resume execution at specified line numberor address
evaluate expr without displaying it; usefor altering program variables

delete breakpoints at entry to fun()

Program Stackbacktrace [n]print trace of all frames in stack; or of nframes—innermost if n>0, outermost if
bt [n]
frame [n]Execution Control
continue [count]continue running; if count specified, ignore
this breakpoint next count times
c [count]

Display
print [/f ] [expr]
p [/f ] [expr]

show value of expr [or last value $]according to format f:

xduot
acf
call [/f ] expr

hexadecimal
signed decimal
unsigned decimaloctalbinaryaddress, absolute and relative
characterfloating point

x [/Nuf ] expr

examine memory at address expr; optional
format spec follows slash
count of how many units to display
unit size; one ofb individual bytes
h halfwords (two bytes)
w words (four bytes)
g giant words (eight bytes)
printing format. Any print format, ors null-terminated stringi machine instructions

Nuf

like print but does not display void

select frame number n or frame at addressn; if no n, display current frame
select frame n frames up
select frame n frames downdisassem [addr]

describe selected frame, or frame at addr
arguments of selected frame
local variables of selected frame

Automatic Display
display [/f ] expr show value of expr each time program
stops [according to format f ]register values [for regs rn ] in selectedframe; all-reg includes floating point

display
undisplay ndisable disp nenable disp n
info display

display memory as machine instructions

display all enabled expressions on list
remove number(s) n from list ofautomatically displayed expressions
disable display for expression(s) number nenable display for expression(s) number nnumbered list of display expressions

Expressions
expr

file::nman expression in C, C++, or Modula-2(including function calls), or:an array of len elements beginning ataddr
a variable or function nm defined in file{type}addr

read memory at addr as specified type$$n$$$$n$$$var

most recent displayed value
nth displayed value
displayed value previous to $nth displayed value back from $last address examined with x
value at address $convenience variable; assign any value

show values [n]show conv

show last 10 values [or surrounding $n]
display all convenience variables

addr @len

Symbol Table
info address s
info func [regex]

show where symbol s is storedinfo var [regex]

show names, types of global variables (all,or matching regex)

whatis [expr]
ptype [expr]
ptype typeshow data type of expr [or $] without
evaluating; ptype gives more detailshow names, types of defined functions(all, or matching regex)

describe type, struct, union, or enum

Controlling GDB

Source Filesset param value
show param

dir names

Parameters understood by set and show:complaint limit number of messages on unusual symbols
confirm on/off enable or disable cautionary queries
editing on/off control readline command-line editingheight lpp
number of lines before pause in display
language lang
Language for GDB expressions (auto, c ormodula-2)
listsize nnumber of lines shown by list
prompt str
use str as GDB prompt
radix baseoctal, decimal, or hex number
representation
verbose on/off control messages when loading symbols
width cpl
number of characters before line folded
write on/off
Allow or forbid patching binary, core files(when reopened with exec or core)
history . . .
groups with the following options:h ...
h exp off/on
h file filename
h size size
h save off/on

define cmd
command-list

end
document cmd
help-textend

C++ symbols
read, execute GDB commands from file
scriptcreate new GDB command cmd; execute
script defined by command-list
end of command-list
create online documentation for new GDB
command cmd
end of help-text

Signals
handle signal act
print
noprint
stop
nostoppass
nopassinfo signals

specify GDB actions for signal:announce signal
be silent for signal
halt execution on signal
do not halt execution
allow your program to handle signal
do not allow your program to see signal
show table of signals, GDB action for each

Debugging Targets
target type param
help target
attach param
detachdisable/enable readline history expansion
file for recording GDB command history
number of commands kept in history list
control use of external file for command
history

print . . .
groups with the following options:p ...
p address on/off print memory addresses in stacks, values
p array off/on compact or attractive format for arraysp demangl on/off source (demangled) or internal form for

GDB Scripts
source script

set one of GDB’s internal parametersdisplay current setting of parameter

connect to target machine, process, or filedisplay available targets
connect to another process
release target from GDB control

p asm-dem on/off demangle C++ symbols in machineinstruction output

p elements limit number of array elements to display
p object on/off print C++ derived types for objects
p pretty off/on struct display: compact or indented
p union on/off display of union members
p vtbl off/on
display of C++ virtual function tables
show commands
show commands nshow commands +show last 10 commands
show 10 commands around number nshow next 10 commands

Working Files
file [file]use file for both symbols and executable;with no arg, discard bothcore [file]

read file as coredump; or discard

exec [file]use file as executable only; or discard

symbol [file]load fileadd-sym file addr

use symbol table from file; or discard
dynamically link file and add its symbols
read additional symbols from file,
dynamically loaded at addr
display working files and targets in use
add dirs to front of path searched forexecutable and symbol files
display executable and symbol file path
list names of shared libraries currently
loadedinfo files
path dirs
show pathinfo sharedir
show dirlist
list list lines[file:]num[file:]function+off-off*address
list f,linfo line num
info source
info sources
forw regex
rev regex

add directory names to front of source
pathclear source pathshow current source pathshow next ten lines of sourceshow previous ten lines
display source surrounding lines, specified
as:line number [in named file]
beginning of function [in named file]
off lines after last printed
off lines previous to last printed
line containing addressfrom line f to line lshow starting, ending addresses ofcompiled code for source line num
show name of current source file
list all source files in use
search following source lines for regex
search preceding source lines for regex

GDB under GNU Emacs
M-x gdb
C-h m
M-s
M-n
M-i
C-c C-f
M-c
M-u
M-d
C-x &C-x SPC

run GDB under Emacs
describe GDB mode
step one line (step)
next line (next)
step one instruction (stepi)
finish current stack frame (finish)continue (cont)up arg frames (up)down arg frames (down)
copy number from point, insert at end(in source file) set break at pointGDB Licenseshow copying
show warranty

Copyright

Display GNU General Public License
There is NO WARRANTY for GDB.
Display full no-warranty statement.

c 1991-2024 Free Software Foundation, Inc. Author:

Roland H. Pesch
The author assumes no responsibility for any errors on this card.
This card may be freely distributed under the terms of the GNU
General Public License.
Please contribute to development of this card by annotating it.
Improvements can be sent to bug-gdb@gnu.org.
GDB itself is free software; you are welcome to distribute copies of
it under the terms of the GNU General Public License. There isabsolutely no warranty for GDB.