GDB Refcard

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

GDB QUICK REFERENCE

GDB Version 4

Essential Commands

program [core] debug program [using coredump core]


set breakpoint at 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
gdb

b [ le:]function

Starting GDB

gdb
gdb
gdb

program
program core

gdb --help

Stopping GDB
quit
INTERRUPT

Getting Help
help
help

class
help command

start GDB, with no debugging les


begin debugging program
debug coredump core produced by
program
describe command line options
exit GDB; also q or EOF (eg C-d)
(eg C-c) terminate current command, or
send to running process
list classes of commands
one-line descriptions for commands in
class
describe command

Executing your Program


arglist

kill
tty dev
set args arglist
set args
show args

use dev as stdin and stdout for next


specify arglist for next run
specify empty argument list
display argument list

show environment
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 environment

run : : : <inf >outf

run

Shell Commands

cd dir
pwd
make : : :
shell cmd

[ ]

change working directory to dir


Print working directory
call \make"
execute arbitrary shell command string

surround optional arguments

break [ le:]line

set breakpoint at line number [in le]


eg: break main.c:37
b [ le:]line
break [ le:]function set breakpoint at function [in le]
break +o set
set break at o set lines from current stop
break -o set
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
info watch

show de ned breakpoints


show de ned watchpoints

clear

delete
delete
delete
delete

clear [ le:]fun

clear [ le:]line

delete [n]

disable [n]

enable [n]

enable once [n]

enable del [n]


ignore

start your program with arglist


start your program with current argument
list
start your program with input, output
redirected
kill running program

run
run

Breakpoints and Watchpoints

:::

show one or more arguments

c 1991, 1992 Free Software Foundation, Inc.

Permissions on back

n count

commands n
[silent]

command-list

end

Program Stack

backtrace [n]
bt [n]
frame [n]
up n
down
info
info
info
info
info
info

frame [addr]
args
locals
reg [rn]: : :
all-reg [rn]
catch

breakpoints
breakpoints
breakpoints
breakpoints

at next instruction
at entry to fun()
on source line
[or breakpoint n]

disable breakpoints [or breakpoint n]


enable breakpoints [or breakpoint n]
enable breakpoints [or breakpoint n];
disable again when reached
enable breakpoints [or breakpoint n];
delete when reached
ignore breakpoint n, count times
execute GDB command-list every time
breakpoint n is reached. [silent
suppresses default display]
end of command-list
print trace of all frames in stack; or of n
frames|innermost if n>0, outermost if
n<0
select frame number n or frame at
address n; if no n, display current frame
select frame n frames up
select frame n frames down
describe selected frame, or frame at addr
arguments of selected frame
local variables of selected frame
register values [for regs rn ] in selected
frame; all-reg includes oating point
exception handlers active in selected
frame

Execution Control
continue [count]

continue running; if count speci ed,


ignore this breakpoint next count times

step [count]

execute until another line reached; repeat


count times if speci ed
step by machine instructions rather than
source lines

c [count]
s [count]

stepi [count]

si [count]

next [count]

execute next line, including any function


calls
next machine instruction rather than
source line

n [count]

nexti [count]
ni [count]
until [location]
finish
return [expr]
signal num
jump line
jump *address
set var=expr

Display

print [/f ] [expr]


p [/f ] [expr]
x
d
u
o
t
a
c
f

call [/f ]

expr
x [/Nuf ] expr
N
u

f
disassem [addr]

run until next instruction (or location)


run until selected stack frame returns
pop selected stack frame without
executing [setting return value]
resume execution with signal s (none if 0)
resume execution at speci ed line number
or address
evaluate expr without displaying it; use
for altering program variables
show value of expr [or last value $]
according to format f:
hexadecimal
signed decimal
unsigned decimal
octal
binary
address, absolute and relative
character
oating point
like print but does not display void
examine memory at address expr;
optional format spec follows slash
count of how many units to display
unit size; one of
b individual bytes
h halfwords (two bytes)
w words (four bytes)
g giant words (eight bytes)
printing format. Any print format, or
s null-terminated string
i machine instructions
display memory as machine instructions

Automatic Display
display [/f ]
display
undisplay

expr

disable disp n
enable disp n
info display

show value of expr each time program


stops [according to format f ]
display all enabled expressions on list
remove number(s) n from list of
automatically displayed expressions
disable display for expression(s) number n
enable display for expression(s) number n
numbered list of display expressions

Expressions
expr

$
$n
$$
$$n
$
$
$var

an expression in C, C++, or Modula-2


(including function calls), or:
an array of len elements beginning at
addr
a variable or function nm de ned in le
read memory at addr as speci ed type
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 convenience

show last 10 values [or surrounding $n]


display all convenience variables

addr @len
le::nm
type addr

f g

Symbol Table
info address

info func [regex]


info var [regex]
whatis [expr]

ptype [expr]
ptype type

GDB Scripts
source

script

cmd
command-list

define

end
document
end

cmd
help-text

Signals

handle signal
print
noprint
stop
nostop
pass
nopass
info signals

act

show where symbol s is stored


show names, types of de ned functions
(all, or matching regex)
show names, types of global variables (all,
or matching regex)
show data type of expr [or $] without
evaluating; ptype gives more detail
describe type, struct, union, or enum
read, execute GDB commands from le
script
create new GDB command cmd; execute
script de ned by command-list
end of command-list
create online documentation for new GDB
command cmd
end of help-text
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
detach

connect to target machine, process, or le


display available targets
connect to another process
release target from GDB control

Controlling GDB
set param value
show param

set one of GDB's internal parameters


display current setting of parameter
Parameters understood by set and show:
complaints limit number of messages on unusual symbols
confirm on/o
enable or disable cautionary queries
editing on/o
control readline command-line editing
height lpp
number of lines before pause in display
language lang
Language for GDB expressions (auto, c
or modula-2)
listsize n
number of lines shown by list
prompt str
use str as GDB prompt
radix base
octal, decimal, or hex number
representation
verbose on/o
control messages when loading symbols
width cpl
number of characters before line folded
write on/o
Allow or forbid patching binary, core les
(when reopened with exec or core)
history : : :
groups with the following options:
h :::
h exp

o /on

h file
h size
h save

lename
size
o /on

print : : :
p :::
p address on/o
p array o /on
p demangl on/o
p
p
p
p
p
p

disable/enable readline history


expansion
le for recording GDB command history
number of commands kept in history list
control use of external le for command
history
groups with the following options:

print memory addresses in stacks, values


compact or attractive format for arrays
source (demangled) or internal form for
C++ symbols
asm-dem on/o demangle C++ symbols in machineinstruction output
elements limit number of array elements to display
object on/o
print C++ derived types for objects
pretty o /on
struct display: compact or indented
union on/o
display of union members
vtbl o /on
display of C++ virtual function tables

show commands
show commands n
show commands +

Working Files
file [ le]

core [ le]

exec [ le]

symbol [ le]
load le
add-sym le addr
info files
path dirs
show path
info share

show last 10 commands


show 10 commands around number n
show next 10 commands
use le for both symbols and executable;
with no arg, discard both
read le as coredump; or discard
use le as executable only; or discard
use symbol table from le; or discard
dynamically link le and add its symbols
read additional symbols from le,
dynamically loaded at addr
display working les and targets in use
add dirs to front of path searched for
executable and symbol les
display executable and symbol le path
list names of shared libraries currently
loaded

Source Files
dir

names

add directory names to front of source


path
clear source path
show current source path

dir
show dir

show next ten lines of source


show previous ten lines
display source surrounding lines, speci ed
as:
line number [in named le]
beginning of function [in named le]
o lines after last printed
o lines previous to last printed
line containing address
from line f to line l
show starting, ending addresses of
compiled code for source line num
show name of current source le
list all source les in use
search following source lines for regex
search preceding source lines for regex

list
list list lines

le:]num
le:]function
+o
-o
*address
list f,l
info line num
[

info source
info sources
forw regex
rev regex

GDB under GNU Emacs

M-x
C-h
M-s
M-n
M-i
C-c
M-c
M-u
M-d
C-x
C-x

run GDB under Emacs


describe GDB mode
step one line (step)
next line (next)
step one instruction (stepi)
nish current stack frame (finish)
continue (cont)
up arg frames (up)
down arg frames (down)
copy number from point, insert at end
(in source le) set break at point

gdb
m

C-f

&
SPC

GDB License
show copying
show warranty

Display GNU General Public License


There is NO WARRANTY for GDB.
Display full no-warranty statement.

Copyright c 1991, 1992 Free Software Foundation, Inc.


Roland Pesch ([email protected]), January 1992|Revision: 1.99
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.
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 warranty for GDB.

You might also like