

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A quick reference for essential gdb (gnu debugger) commands and usage. It covers topics such as setting breakpoints, running and debugging programs, examining memory, and using shell commands. Useful for both beginners and experienced users who need a refresher on gdb commands.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


GDB^ Version^
4
set^ breakp
oint^ at^ function
start^ your^ program
bt^
backtrace:^ displa
y^ program^ stack p^ expr^
display^ the^ value
of^ an^ expression c^
continue^ running
your^ program n^
next^ line,^ stepping
over^ function^ calls s^
next^ line,^ stepping
into^ function^ calls
start^ GDB,^ with
no^ debugging^
les
gdb^ program^
b^ egin^ debugging
program gdb^ program^ cor
e^ debug^ coredump
core^ pro^ duced^
by program gdb^ --help^
describ^ e^ command
line^ options
exit^ GDB;^ also^
q^ or^ EOF^ (eg^ C-d
(eg^ C-c)^ terminate
current^ command,
or send^ to^ running
pro^ cess
list^ classes^ of^ commands help^ class^
one-line^ descriptions
for^ commands^
in class help^ command^
describ^ e^ command
run^ arglist^
start^ your^ program
with^ arglist run^
start^ your^ program
with^ current^ argumen
t list run^ :^ :^ :^ <inf^ >outf
start^ your^ program
with^ input,^ output redirected kill^
kill^ running^ program tty^ dev^
use^ dev^ as^ stdin
and^ stdout^ for^
next^ run
set^ args^ arglist
sp^ ecify^ arglist
for^ next^ run set^ args^
sp^ ecify^ empty^ argumen
t^ list show^ args^
display^ argumen
t^ list show^ environment
show^ all^ environmen
t^ variables show^ env^ var^
show^ value^ of^ en
vironment^ variable
var
set^ env^ var^ string
set^ environmen
t^ variable^ var unset^ env^ var^
remove^ var^ from
environment
change^ working^
directory^ to^ dir pwd^
Print^ working^ directory make^ :^ :^ :^
call^ \make" shell^ cmd^
execute^ arbitrary
shell^ command^
string
arguments^
:^ :^ :^ show^ one^ or^
more^ arguments
c^ 1991,^1992 Free
Software^ Foundation,
Inc.^ Permissions
set^ breakp^ oint^ at
eg:^ break^ main.c:
set^ breakp^ oint^
break^ +o^ set break^ - o^ set
set^ break^ at^ o^
set^ lines^ from^ curren
t^ stop
break^ *addr^
set^ breakp^ oint^ at
address^ addr break^
set^ breakp^ oint^ at
next^ instruction break^ :^ :^ :^ if^ expr
break^ conditionally
on^ nonzero^ expr
new^ conditional
expression^ on^ breakp
oint n;^ make^ unconditional
if^ no^ expr tbreak^ :^ :^ :^
temp^ orary^ break;
disable^ when^ reac
hed
rbreak^ regex^
break^ on^ all^ functions
matching^ regex watch^ expr^
set^ a^ watchp^ oin
t^ for^ expression^
expr
catch^ x^
break^ at^ C++^ handler
for^ exception^ x info^ break^
show^ de^ ned^ breakp
oints info^ watch^
show^ de^ ned^ watc
hp^ oints clear^
delete^ breakp^ oin
ts^ at^ next^ instruction
delete^ breakp
oints^ at^ entry^ to
fun()
delete^ breakp
oints^ on^ source^
line
delete^ breakp^ oin
disable^ breakp^ oin
enable^ breakp^ oin
disable^ again^ when
reached
enable^ breakp^ oin
delete^ when^ reac
hed ignore^ n^ count
ignore^ breakp
oint^ n,^ count^ times
execute^ GDB^ command-list
every^ time breakp^ oint^ n^ is^
suppresses^ default
end^
end^ of^ command-list
print^ trace^ of^ all
frames^ in^ stack;
or^ of^ n frames|innermost
if^ n>0,^ outermost
if n<
select^ frame^ num
b^ er^ n^ or^ frame^
at address^ n;^ if^ no
n,^ display^ curren
t^ frame
up^ n^
select^ frame^ n^ frames
up down^ n^
select^ frame^ n^ frames
down
frame,^ or^ frame
at^ addr
info^ args^
arguments^ of^ selected
frame info^ locals^
lo^ cal^ variables^ of
selected^ frame
:
frame;^ all-reg
includes^ oating
p^ oint
info^ catch^
exception^ handlers
active^ in^ selected frame
continue^ running;
if^ count^ sp^ eci^
ed, ignore^ this^ breakp
oint^ next^ count^
times
execute^ until^ another
line^ reached;^ rep
eat count^ times^ if^ sp
eci^ ed
step^ by^ machine
instructions^ rather
than source^ lines
execute^ next^ line,
including^ any^ function calls
next^ machine^ instruction
rather^ than source^ line
next^ instruction
(or^ location)
finish^
run^ until^ selected
stack^ frame^ returns
p^ op^ selected^ stac
signal^ num^
resume^ execution
with^ signal^ s^ (none
if^0 )
jump^ line jump^ *address
resume^ execution
at^ sp^ eci^ ed^ line
numb^ er or^ address set^ var=expr^
evaluate^ expr^ without
displaying^ it;^ use for^ altering^ program
variables
show^ value^ of^ expr
according^ to^ format
f: x^
hexadecimal d^
signed^ decimal u^
unsigned^ decimal o^
o^ ctal t^
binary a^
address,^ absolute
and^ relative c^
character f^
oating^ p^ oint
like^ print^ but^ do
es^ not^ display^ void
examine^ memory
at^ address^ expr
optional^ format^
sp^ ec^ follows^ slash N^
count^ of^ how^ man
y^ units^ to^ displa
y
u^
unit^ size;^ one^ of^ b^ individual
bytes h halfwords (two^ bytes) w words (four^ bytes) g giant words^ (eight^ bytes) f^
printing^ format.
Any^ print^ format,
or s^ null-terminated
string i^ machine^ instructions
as^ machine^ instructions
show^ value^ of
expr^ each^ time^
program
display^
display^ all^ enabled
expressions^ on^
list
undisplay^ n^
remove^ numb^ er(s)
n^ from^ list^ of automatically^ displa
yed^ expressions disable^ disp^ n
disable^ displa
y^ for^ expression(s)
numb^ er^ n
enable^ disp^ n^
enable^ display^ for
expression(s)^ n
umb^ er^ n
info^ display^
numb^ ered^ list^ of
display^ expressions
an^ expression^ in
C,^ C++,^ or^ Mo
dula- (including^ function
calls),^ or: addr^ @len^
an^ array^ of^ len^
elements^ b^ eginning
at addr le::nm^
a^ variable^ or^ function
nm^ de^ ned^ in^
le
ftypegaddr^
read^ memory^ at
addr^ as^ sp^ eci^ ed
type
$^
most^ recent^ displa
yed^ value $n^
nth^ displayed^ value $$^
displayed^ value^
previous^ to^ $ $$n^
nth^ displayed^ value
back^ from^ $ $^
last^ address^ examined
with^ x $^
value^ at^ address
$var^
convenience^ variable;
assign^ any^ value show^ values^ [n
]^ show^ last
10 values^ [or^ surrounding
$n]
show^ convenience
display^ all^ con
venience^ variables
show^ where
symb^ ol^ s^ is^ stored info^ func^ [regex
]^ show^ names,
typ^ es^ of^ de^ ned
functions (all,^ or^ matching
regex) info^ var^ [regex
]^ show^ names,
typ^ es^ of^ global
variables^ (all, or^ matching^ regex
whatis^ [expr] ptype^ [expr]
show^ data^ typ^ e^
of^ expr^ [or^ $]^ withoutevaluating; ptype^ gives^ more^ detail ptype^ type^
describ^ e^ typ^ e,^ struct,
union,^ or^ enum
read,^ execute^ GDB
commands^ from
le script define^ cmdcommand-list
create^ new^ GDB
command^ cmd;
execute script^ de^ ned^ by
command-list end^
end^ of^ command-list document^ cmdhelp-text
create^ online^ do
cumentation^ for
new^ GDB command^ cmd end^
end^ of^ help-text
sp^ ecify^ GDB
actions^ for^ signal
print^
announce^ signal noprint^
b^ e^ silent^ for^ signal stop^
halt^ execution^ on
signal nostop^
do^ not^ halt^ execution pass^
allow^ your^ program
to^ handle^ signal nopass^
do^ not^ allow^ your
program^ to^ see
signal
info^ signals^
show^ table^ of^ signals,
GDB^ action^ for each
target^ type^ par
am^ connect^ to
target^ machine,
pro^ cess,^ or^ le
help^ target^
display^ available
targets attach^ param^
connect^ to^ another
pro^ cess detach^
release^ target^ from
GDB^ control
set^ param^ value
set^ one^ of^
GDB's^ internal^
parameters
show^ param^
display^ current^
setting^ of^ parameter Parameters^ understo
o^ d^ by^ set^ and^
show: complaints^ limit
numb^ er^ of^ messages
on^ unusual^ sym
b^ ols
confirm^ on/o^
enable^ or^ disable
cautionary^ queries editing^ on/o^
control^ readline
command-line^ editing height^ lpp^
numb^ er^ of^ lines^
b^ efore^ pause^ in^
display
language^ lang^
Language^ for^ GDB
expressions^ (auto
,^ c or^ modula-2) listsize^ n^
numb^ er^ of^ lines^
shown^ by^ list prompt^ str^
use^ str^ as^ GDB
prompt radix^ base^
o^ ctal,^ decimal,^ or
hex^ numb^ er representation verbose^ on/o^
control^ messages
when^ loading^ sym
b^ ols
width^ cpl^
numb^ er^ of^ characters
b^ efore^ line^ folded write^ on/o^
Allow^ or^ forbid^
patching^ binary,
core^ les (when^ reop^ ened
with^ exec^ or^ core
history^ :^ :^ : h^ :^ :^ :
groups^ with^ the
following^ options: h^ exp^ o^ /on^
disable/enable^ readline
history expansion h^ file^ lename
le^ for^ recording
GDB^ command
history
h^ size^ size^
numb^ er^ of^ commands
kept^ in^ history
list
h^ save^ o^ /on^
control^ use^ of^ external
le^ for^ command history print^ :^ :^ : p^ :^ :^ :
groups^ with^ the
following^ options: p^ address^ on/o
print^ memory
addresses^ in^ stac
ks,^ values
p^ array^ o^ /on^
compact^ or^ attractiv
e^ format^ for^ arra
ys
p^ demangl^ on/o
source^ (demangled)
or^ internal^ form
for C++^ symb^ ols p^ asm-dem^ on/o
demangle^ C++
symb^ ols^ in^ mac
hine- instruction^ output p^ elements^ limit
numb^ er^ of^ arra
y^ elements^ to^ displa
y
p^ object^ on/o^
print^ C++^ deriv
ed^ typ^ es^ for^ ob^ jects p^ pretty^ o^ /on
struct^ displa
y:^ compact^ or^ inden
ted
p^ union^ on/o^
display^ of^ union
memb^ ers p^ vtbl^ o^ /on^
display^ of^ C++
virtual^ function
tables
show^ commands^
show^ last^10 commands show^ commands^
n^ show^10 commands
around^ numb^ er
n
show^ commands^
+^ show^ next
10 commands Working^ Files file^ [^ le]^
use^ le^ for^ b^ oth
symb^ ols^ and^ executable;with no arg, discard^ b^ oth core^ [^ le]^
read^ le^ as^ coredump;
or^ discard exec^ [^ le]^
use^ le^ as^ executable
only;^ or^ discard symbol^ [^ le]^
use^ symb^ ol^ table
from^ le;^ or^ discard load^ le^
dynamically^ link
le^ and^ add^ its
symb^ ols
add-sym^ le^ addr
read^ additional
symb^ ols^ from^
le, dynamically^ loaded
at^ addr info^ files^
display^ working
les^ and^ targets
in^ use
path^ dirs^
add^ dirs^ to^ fron
t^ of^ path^ searched
for executable^ and^
symb^ ol^ les show^ path^
display^ executable
and^ symb^ ol^ le
path
info^ share^
list^ names^ of^ shared
libraries^ curren
tly loaded
add^ directory^ names
to^ front^ of^ source path dir^
clear^ source^ path show^ dir^
show^ current^ source
path list^
show^ next^ ten^ lines
of^ source list^ -^
show^ previous^ ten
lines list^ lines^
display^ source^ surrounding
lines,^ sp^ eci^ ed as: [^ le:]num^
line^ numb^ er^ [in^
named^ le] [^ le:]function^
b^ eginning^ of^ function
[in^ named^ le] +o^
o^ lines^ after^ last
printed
o^ lines^ previous
to^ last^ printed *address^
line^ containing^ addr
ess list^ f,l^
from^ line^ f^ to^ line
l info^ line^ num
show^ starting,
ending^ addresses
of compiled^ co^ de^ for
source^ line^ num info^ source^
show^ name^ of^ curren
t^ source^ le info^ sources^
list^ all^ source^ les
in^ use forw^ regex^
search^ following^
source^ lines^ for^
regex
rev^ regex^
search^ preceding
source^ lines^ for
regex
M-x^ gdb^
run^ GDB^ under^
Emacs C-h^ m^
describ^ e^ GDB^ mo
de M-s^
step^ one^ line^ (step
M-n^
next^ line^ (next) M-i^
step^ one^ instruction
(stepi) C-c^ C-f^
nish^ current^ stac
k^ frame^ (finish
M-c^
continue^ (cont) M-u^
up^ arg^ frames^ (up
M-d^
down^ arg^ frames
(down) C-x^ &^
copy^ numb^ er^ from
p^ oint,^ insert^ at
end
C-x^ SPC^
(in^ source^ le)^ set
break^ at^ p^ oint
Display^ GNU^ General
Public^ License show^ warranty^
There^ is^ NO^ WARRANTY
for^ GDB. Display^ full^ no-w
arranty^ statemen
t.
Copyright^ c^ 1991,
1992 Free^ Softw
are^ Foundation,^ Inc. Roland^ Pesch^ (p^ esc
[email protected]),^ Jan
uary^ 1992|Revision:
The^ author^ assumes
no^ resp^ onsibility
for^ any^ errors^ on
this^ card.
This^ card^ may^ b
e^ freely^ distributed
under^ the^ terms
of^ the^ GNU
General^ Public^ License.Please^ contribute
to^ development^
of^ this^ card^ by^ annotating
it.
GDB^ itself^ is^ free
software;^ you^ are
welcome^ to^ distribute
copies^ of
it^ under^ the^ terms
of^ the^ GNU^ General
Public^ License.^
There^ is
absolutely^ no^ warran
ty^ for^ GDB.