GDB Quick Reference: Essential GDB Commands and Usage, Study notes of Algorithms and Programming

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

Pre 2010

Uploaded on 08/31/2009

koofers-user-acw
koofers-user-acw 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GDB QUICK REFERENCE
GDB Version 4
Essential Commands
gdb
program
[
core
]
debug
program
[
using coredump
core
]
b
[
le
:
]
function
set breakpointat
function
[
in
le
]
run
[
arglist
]
start your program
[
with
arglist
]
bt
backtrace: display 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
Starting GDB
gdb
start GDB, with no debugging les
gdb
program
begin debugging
program
gdb
program core
debug coredump
core
produced by
program
gdb --help
describe command line options
Stopping GDB
quit
exit GDB; also
q
or
EOF
(eg
C-d
)
INTERRUPT
(eg
C-c
) terminate current command, or
send to running process
Getting Help
help
list classes of commands
help
class
one-line descriptions for commands in
class
help
command
describe
command
Executing your Program
run
arglist
start your program with
arglist
run
start your program with current argument
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
specify
arglist
for next
run
set args
specify empty argument list
show args
display argument list
show environment
show all environmentvariables
show env
var
showvalue of environmentvariable
var
set env
var string
set environmentvariable
var
unset env
var
remove
var
from environment
Shell Commands
cd
dir
change working directory to
dir
pwd
Printworking directory
make
:::
call \
make
"
shell
cmd
execute arbitrary shell command string
[]
surround optional arguments
:::
show one or more arguments
c
1991, 1992 Free Software Foundation, Inc. Permissions on back
Breakpoints and Watchpoints
break
[
le
:
]
line
b
[
le
:
]
line
set breakpointat
line
number
[
in
le
]
eg:
break main.c:37
break
[
le
:
]
function
set breakpointat
function
[
in
le
]
break +
oset
break -
oset
set break at
oset
lines from current stop
break *
addr
set breakpoint at address
addr
break
set breakpoint at next instruction
break
:::
if
expr
break conditionally on nonzero
expr
cond
n
[
expr
]
new conditional expression on breakpoint
n
; make unconditional if no
expr
tbreak
:::
temporary break; disable when reached
rbreak
regex
break on all functions matching
regex
watch
expr
set a watchpoint for expression
expr
catch
x
break at C++ handler for exception
x
info break
show dened breakpoints
info watch
show dened watchpoints
clear
delete breakpoints at next instruction
clear
[
le
:
]
fun
delete breakpoints at entry to
fun
()
clear
[
le
:
]
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 reached
enable del
[
n
]
enable breakpoints
[
or breakpoint
n
]
;
delete when reached
ignore
ncount
ignore breakpoint
n
,
count
times
commands
n
[
silent
]
command-list
execute GDB
command-list
every time
breakpoint
n
is reached.
[
silent
suppresses default display
]
end
end of
command-list
Program Stack
backtrace
[
n
]
bt
[
n
]
print trace of all frames in stack; or of
n
frames|innermost if
n
>0
, outermost if
n
<0
frame
[
n
]
select frame number
n
or frame at
address
n
;ifno
n
, display current frame
up
n
select frame
n
frames up
down
n
select frame
n
frames down
info frame
[
addr
]
describe selected frame, or frame at
addr
info args
arguments of selected frame
info locals
local variables of selected frame
info reg
[
rn
]
:::
info all-reg
[
rn
]
register values
[
for regs
rn
]
in selected
frame;
all-reg
includes oating point
info catch
exception handlers active in selected
frame
Execution Control
continue
[
count
]
c
[
count
]
continue running; if
count
specied,
ignore this breakpoint next
count
times
step
[
count
]
s
[
count
]
execute until another line reached; repeat
count
times if specied
stepi
[
count
]
si
[
count
]
step by machine instructions rather than
source lines
next
[
count
]
n
[
count
]
execute next line, including any function
calls
nexti
[
count
]
ni
[
count
]
next machine instruction rather than
source line
until
[
location
]
run until next instruction (or
location
)
finish
run until selected stack frame returns
return
[
expr
]
pop selected stack frame without
executing
[
setting return value
]
signal
num
resume execution with signal
s
(none if
0
)
jump
line
jump *
address
resume execution at specied
line
number
or
address
set var=
expr
evaluate
expr
without displaying it; use
for altering program variables
Display
print
[
/
f
][
expr
]
p
[
/
f
][
expr
]
showvalue of
expr
[
or last value
$
]
according to format
f
:
x
hexadecimal
d
signed decimal
u
unsigned decimal
o
octal
t
binary
a
address, absolute and relative
c
character
f
oating point
call
[
/
f
]
expr
like
print
but does not display
void
x
[
/
Nuf
]
expr
examine memory at address
expr
;
optional format spec follows slash
N
countofhow many units to display
u
unit size; one of
b
individual bytes
h
halfwords (twobytes)
w
words (four bytes)
g
giantwords (eightbytes)
f
printing format. Any
print
format, or
s
null-terminated string
i
machine instructions
disassem
[
addr
]
display memory as machine instructions
Automatic Display
display
[
/
f
]
expr
showvalue of
expr
each time program
stops
[
according to format
f
]
display
display all enabled expressions on list
undisplay
n
removenumber(s)
n
from list of
automatically displayed expressions
disable disp
n
disable display for expression(s) number
n
enable disp
n
enable display for expression(s) number
n
info display
numbered list of display expressions
pf2

Partial preview of the text

Download GDB Quick Reference: Essential GDB Commands and Usage and more Study notes Algorithms and Programming in PDF only on Docsity!

GDB^ QUICK

REFERENCE

GDB^ Version^

4

Essential^ Commands gdb^ program^ [cor

e]^ debug^ progr

am^ [using^ coredump

core]

b^ [^ le:]function

set^ breakp

oint^ at^ function

[in^ le]

run^ [arglist]^

start^ your^ program

[with^ arglist]

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

Starting^ GDB gdb^

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

Stopping^ GDB quit^

exit^ GDB;^ also^

q^ or^ EOF^ (eg^ C-d

INTERRUPT^

(eg^ C-c)^ terminate

current^ command,

or send^ to^ running

pro^ cess

Getting^ Help help^

list^ classes^ of^ commands help^ class^

one-line^ descriptions

for^ commands^

in class help^ command^

describ^ e^ command

Executing^ y

our^ Program

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

Shell^ Commands cd^ dir^

change^ working^

directory^ to^ dir pwd^

Print^ working^ directory make^ :^ :^ :^

call^ \make" shell^ cmd^

execute^ arbitrary

shell^ command^

string

[^ ]^ surround^ optional

arguments^

:^ :^ :^ show^ one^ or^

more^ arguments

c^ 1991,^1992 Free

Software^ Foundation,

Inc.^ Permissions

Breakp on back

oints^ and^ W

atchp^ oints

break^ [^ le:]line b^ [^ le:]line

set^ breakp^ oint^ at

line^ numb^ er^ [in

le]

eg:^ break^ main.c:

break^ [^ le:]function

set^ breakp^ oint^

at^ function^ [in^

le]

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

cond^ n^ [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

clear^ [^ le:]fun

delete^ breakp

oints^ at^ entry^ to

fun()

clear^ [^ le:]line

delete^ breakp

oints^ on^ source^

line

delete^ [n]^

delete^ breakp^ oin

ts^ [or^ breakp^ oin

t^ n]

disable^ [n]^

disable^ breakp^ oin

ts^ [or^ breakp^ oin

t^ n]

enable^ [n]^

enable^ breakp^ oin

ts^ [or^ breakp^ oin

t^ n]

enable^ once^ [n

]^ enable^ breakp

oints^ [or^ breakp

oint^ n];

disable^ again^ when

reached

enable^ del^ [n]^

enable^ breakp^ oin

ts^ [or^ breakp^ oin

t^ n];

delete^ when^ reac

hed ignore^ n^ count

ignore^ breakp

oint^ n,^ count^ times

commands^ n^ [silent]^ command-list

execute^ GDB^ command-list

every^ time breakp^ oint^ n^ is^

reached.^ [silent

suppresses^ default

display]

end^

end^ of^ command-list

Program^ Stac

k

backtrace^ [n] bt^ [n]

print^ trace^ of^ all

frames^ in^ stack;

or^ of^ n frames|innermost

if^ n>0,^ outermost

if n<

frame^ [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

info^ frame^ [addr

]^ describ^ e^ selected

frame,^ or^ frame

at^ addr

info^ args^

arguments^ of^ selected

frame info^ locals^

lo^ cal^ variables^ of

selected^ frame

info^ reg^ [rn]:^ :

:

info^ all-reg^ [

register^ v rn]

alues^ [for^ regs^ rn

]^ in^ selected

frame;^ all-reg

includes^ oating

p^ oint

info^ catch^

exception^ handlers

active^ in^ selected frame

Execution^ Con

trol

continue^ [count

]

c^ [count]

continue^ running;

if^ count^ sp^ eci^

ed, ignore^ this^ breakp

oint^ next^ count^

times

step^ [count] s^ [count]

execute^ until^ another

line^ reached;^ rep

eat count^ times^ if^ sp

eci^ ed

stepi^ [count] si^ [count]

step^ by^ machine

instructions^ rather

than source^ lines

next^ [count] n^ [count]

execute^ next^ line,

including^ any^ function calls

nexti^ [count] ni^ [count]

next^ machine^ instruction

rather^ than source^ line

until^ [location

]^ run^ until^

next^ instruction

(or^ location)

finish^

run^ until^ selected

stack^ frame^ returns

return^ [expr]^

p^ op^ selected^ stac

k^ frame^ withoutexecuting [setting^ return^ value]

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

Display print^ [/f^ ]^ [expr

]

p^ [/f^ ]^ [expr]

show^ value^ of^ expr

[or^ last^ value^ $

]

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

call^ [/f^ ]^ expr^

like^ print^ but^ do

es^ not^ display^ void

x^ [/Nuf^ ]^ expr^

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

disassem^ [addr

]^ display^ memory

as^ machine^ instructions

Automatic^

Display

display^ [/f^ ]^ expr

show^ value^ of

expr^ each^ time^

program

stops^ [according

to^ format^ f^ ]

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

Expressions expr^

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

Symb^ ol^ Table info^ address^ s

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

GDB^ Scripts source^ script^

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

Signals handle^ signal^ act

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

Debugging^

Targets

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

Controlling

GDB

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

Source^ Files dir^ names^

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^

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

GDB^ under

GNU^ Emacs

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

GDB^ License show^ copying^

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.