Vous êtes sur la page 1sur 2

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

1998,2000 Free Software Foundation, Inc. Permissions on back


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

Vous aimerez peut-être aussi