]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/refcard.tex
(1) Improvements from B Chassell.
[thirdparty/binutils-gdb.git] / gdb / doc / refcard.tex
CommitLineData
bca43169 1%This file is TeX source for a reference card describing GDB, the GNU debugger.
98088880 2%$Id$
bca43169
RP
3%Copyright (C) 1991 Free Software Foundation, Inc.
4%Permission is granted to make and distribute verbatim copies of
5%this reference provided the copyright notices and permission notices
6%are preserved on all copies.
7%
8%TeX markup is a programming language; accordingly this file is source
9%for a program to generate a reference.
10%
11%This program is free software; you can redistribute it and/or modify
12%it under the terms of the GNU General Public License as published by
13%the Free Software Foundation; either version 1, or (at your option)
14%any later version.
15%
16%This program is distributed in the hope that it will be useful, but
17%WITHOUT ANY WARRANTY; without even the implied warranty of
18%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19%General Public License for more details.
20%
21%You can find a copy of the GNU General Public License in the GDB
22%manual; or write to the Free Software Foundation, Inc.,
23%675 Mass Ave, Cambridge, MA 02139, USA.
24%
25%You can contact the author as: pesch@cygnus.com
26%
27% Roland Pesch
28% Cygnus Support
29% 814 University Ave.
30% Palo Alto, CA 94301 USA
31%
32% +1 415 322 3811
33%
34% Cygnus Support is an organization devoted to commercial
35% support of free software. For general information
36% contact ``info@cygnus.com''
37%
98088880
RP
38% NOTE ON INTENTIONAL OMISSIONS: This reference card includes most GDB
39% commands, but due to space constraints there are some things I chose
d54bd32d
RP
40% to omit. In general, not all synonyms for commands are covered, nor
41% all variations of a command.
98088880
RP
42% The GDB-under-Emacs section omits gdb-mode functions without default
43% keybindings. GDB startup options are not described.
d9800dbb 44% set print sevenbit-strings, set symbol-reloading omitted.
d54bd32d
RP
45% printsyms, printpsyms, omitted since they're for GDB maintenance primarily
46% share omitted due to obsolescence
d9800dbb 47% set check range/type omitted at least til code is in GDB.
98088880 48%
bca43169
RP
49{%
50\def\$#1${{#1}}% Kluge: collect RCS revision info without $...$
51\xdef\manvers{\$Revision$}%
d9800dbb
RP
52}%
53\input threecol
54\input rcfonts
55%
bca43169 56\vsize=8in
98088880 57\hyphenpenalty=5000\tolerance=2000\raggedright\raggedbottom
bca43169
RP
58\normalbaselineskip=9pt\baselineskip=9pt
59%
60\parindent=0pt
61\parskip=0pt
62\footline={\vbox to0pt{\hss}}
63%
64\def\ctl#1{{\tt C-#1}}
65\def\opt#1{{\brm[{\rm #1}]}}
66\def\xtra#1{\noalign{\smallskip{\tt#1}}}
67%
68\long\def\sec#1;#2\endsec{\vskip 1pc
69\halign{%
70%COL 1 (of halign):
d9800dbb
RP
71\vtop{\hsize=1.1in\tt
72##\par\vskip 2pt }\hfil
bca43169
RP
73%COL 2 (of halign):
74&\vtop{\hsize=2.1in\hangafter=1\hangindent=0.5em
75\rm ##\par\vskip 2pt}\cr
76%Tail of \long\def fills in halign body with \sec args:
77\noalign{{\bbf #1}\vskip 2pt}
78#2
79}
80}
81
d54bd32d 82{\vbbf GDB QUICK REFERENCE}\hfil{\smrm GDB Version 4}\qquad
98088880
RP
83
84\sec Essential Commands;
85gdb {\it program} \opt{{\it core}}&debug {\it program} \opt{using
86coredump {\it core}}\cr
98088880
RP
87b \opt{\it file\tt:}{\it function}&set breakpoint at {\it function} \opt{in \it file}\cr
88run \opt{{\it arglist}}&start your program \opt{with {\it arglist}}\cr
d9800dbb 89bt& backtrace: display program stack\cr
98088880
RP
90p {\it expr}&display the value of an expression\cr
91c &continue running your program\cr
d9800dbb
RP
92n &next line, stepping over function calls\cr
93s &next line, stepping into function calls\cr
98088880 94\endsec
bca43169
RP
95
96\sec Starting GDB;
d54bd32d 97gdb&start GDB, with no debugging files\cr
bca43169 98gdb {\it program}&begin debugging {\it program}\cr
d54bd32d
RP
99gdb {\it program core}&debug coredump {\it core} produced by {\it
100program}\cr
101gdb -help&describe command line options\cr
bca43169
RP
102\endsec
103
104\sec Stopping GDB;
98088880
RP
105quit&exit GDB; also {\tt q} or {\tt EOF} (eg \ctl{d})\cr
106INTERRUPT&(eg \ctl{c}) terminate current command, or send to running process\cr
bca43169
RP
107\endsec
108
109\sec Getting Help;
98088880
RP
110help&list classes of commands\cr
111help {\it class}&one-line descriptions for commands in {\it class}\cr
112help {\it command}&describe {\it command}\cr
bca43169
RP
113\endsec
114
115\sec Executing your Program;
116run {\it arglist}&start your program with {\it arglist}\cr
117run&start your program with current argument list\cr
d54bd32d 118run $\ldots$ <{\it inf} >{\it outf}&start your program with input, output
bca43169
RP
119redirected\cr
120\cr
98088880 121kill&kill running program\cr
bca43169 122\cr
98088880 123tty {\it dev}&use {\it dev} as stdin and stdout for next {\tt run}\cr
bca43169
RP
124set args {\it arglist}&specify {\it arglist} for next
125{\tt run}\cr
126set args&specify empty argument list\cr
127show args&display argument list\cr
128\cr
129show environment&show all environment variables\cr
130show env {\it var}&show value of environment variable {\it var}\cr
98088880
RP
131set env {\it var} {\it string}&set environment variable {\it var}\cr
132unset env {\it var}&remove {\it var} from environment\cr
bca43169
RP
133\endsec
134
135\sec Shell Commands;
98088880 136cd {\it dir}&change working directory to {\it dir}\cr
bca43169 137pwd&Print working directory\cr
98088880
RP
138make $\ldots$&call ``{\tt make}''\cr
139shell {\it cmd}&execute arbitrary shell command string\cr
bca43169
RP
140\endsec
141
142\vfill
d54bd32d
RP
143\line{\smrm \opt{ } surround optional arguments \hfil $\ldots$ show
144one or more arguments\rm\qquad}
145
146\centerline{\smrm \copyright 1991, 1992 Free Software Foundation, Inc.\qquad Permissions on back}
bca43169
RP
147\eject
148\sec Breakpoints and Watchpoints;
98088880
RP
149break \opt{\it file\tt:}{\it line}\par
150b \opt{\it file\tt:}{\it line}&set breakpoint at {\it line} number \opt{in \it file}\par
bca43169 151eg:\quad{\tt break main.c:37}\quad\cr
98088880
RP
152break \opt{\it file\tt:}{\it function}&set breakpoint at {\it
153function} \opt{in \it file}\cr
bca43169 154break +{\it offset}\par
98088880
RP
155break -{\it offset}&set break at {\it offset} lines from current stop\cr
156break *{\it addr}&set breakpoint at address {\it addr}\cr
157break&set breakpoint at next instruction\cr
158break $\ldots$ if {\it expr}&break conditionally on nonzero {\it expr}\cr
159cond {\it n} \opt{\it expr}&new conditional expression on breakpoint
160{\it n}; make unconditional if no {\it expr}\cr
161tbreak $\ldots$&temporary break; disable when reached\cr
162rbreak {\it regex}&break on all functions matching {\it regex}\cr
163watch {\it expr}&set a watchpoint for expression {\it expr}\cr
164catch {\it x}&break at C++ handler for exception {\it x}\cr
bca43169 165\cr
98088880
RP
166info break&show defined breakpoints\cr
167info watch&show defined watchpoints\cr
bca43169 168\cr
98088880
RP
169clear&delete breakpoints at next instruction\cr
170clear \opt{\it file\tt:}{\it fun}&delete breakpoints at entry to {\it fun}()\cr
171clear \opt{\it file\tt:}{\it line}&delete breakpoints on source line \cr
d54bd32d
RP
172delete \opt{{\it n}}&delete breakpoints
173\opt{or breakpoint {\it n}}\cr
174\cr
175disable \opt{{\it n}}&disable breakpoints
176\opt{or breakpoint {\it n}}
177\cr
178enable \opt{{\it n}}&enable breakpoints
179\opt{or breakpoint {\it n}}
180\cr
181enable once \opt{{\it n}}&enable breakpoints \opt{or breakpoint {\it n}};
182disable again when reached
183\cr
184enable del \opt{{\it n}}&enable breakpoints \opt{or breakpoint {\it n}};
185delete when reached
bca43169 186\cr
bca43169 187\cr
98088880 188ignore {\it n} {\it count}&ignore breakpoint {\it n}, {\it count}
bca43169
RP
189times\cr
190\cr
98088880 191commands {\it n}\par
d54bd32d
RP
192\qquad \opt{\tt silent}\par
193\qquad {\it command-list}&execute GDB {\it command-list} every time breakpoint {\it n} is reached. \opt{{\tt silent} suppresses default
194display}\cr
195end&end of {\it command-list}\cr
bca43169
RP
196\endsec
197
98088880
RP
198\sec Program Stack;
199backtrace \opt{\it n}\par
200bt \opt{\it n}&print trace of all frames in stack; or of {\it n}
201frames---innermost if {\it n}{\tt >0}, outermost if {\it n}{\tt <0}\cr
202frame \opt{\it n}&select frame number {\it n} or frame at address {\it
203n}; if no {\it n}, display current frame\cr
204up {\it n}&select frame {\it n} frames up\cr
205down {\it n}&select frame {\it n} frames down\cr
206info frame \opt{\it addr}&describe selected frame, or frame at
207{\it addr}\cr
208info args&arguments of selected frame\cr
209info locals&local variables of selected frame\cr
d54bd32d
RP
210info reg \opt{\it rn}\par
211info all-reg \opt{\it rn}&register values \opt{for reg {\it rn\/}} in
212selected frame; {\tt all-reg} includes floating point\cr
98088880 213info catch&exception handlers active in selected frame\cr
bca43169
RP
214\endsec
215
216\vfill\eject
217\sec Execution Control;
218continue \opt{\it count}\par
98088880 219c \opt{\it count}&continue running; if {\it count} specified, ignore
bca43169
RP
220this breakpoint next {\it count} times\cr
221\cr
222step \opt{\it count}\par
98088880 223s \opt{\it count}&execute until another line reached; repeat {\it count} times if
bca43169 224specified\cr
bca43169 225stepi \opt{\it count}\par
98088880 226si \opt{\it count}&step by machine instructions rather than source
bca43169
RP
227lines\cr
228\cr
229next \opt{\it count}\par
98088880 230n \opt{\it count}&execute next line, including any function calls\cr
bca43169 231nexti \opt{\it count}\par
98088880 232ni \opt{\it count}&next machine instruction rather than source
bca43169
RP
233line\cr
234\cr
98088880
RP
235until \opt{\it location}&run until next instruction (or {\it
236location})\cr
237finish&run until selected stack frame returns\cr
238return \opt{\it expr}&pop selected stack frame without executing
239\opt{setting return value}\cr
240signal {\it num}&resume execution with signal {\it s} (none if {\tt 0})\cr
bca43169 241jump {\it line}\par
98088880 242jump *{\it address}&resume execution at specified {\it line} number or
bca43169 243{\it address}\cr
98088880 244set var={\it expr}&evaluate {\it expr} without displaying it; use for
bca43169
RP
245altering program variables\cr
246\endsec
247
98088880 248\sec Display;
d54bd32d
RP
249print \opt{\tt/{\it f}\/} \opt{\it expr}\par
250p \opt{\tt/{\it f}\/} \opt{\it expr}&show value of {\it expr} \opt{or
251last value \tt \$} according to format {\it f}:\cr
bca43169
RP
252\qquad x&hexadecimal\cr
253\qquad d&signed decimal\cr
254\qquad u&unsigned decimal\cr
255\qquad o&octal\cr
d54bd32d 256\qquad t&binary\cr
bca43169 257\qquad a&address, absolute and relative\cr
98088880 258\qquad c&character\cr
bca43169 259\qquad f&floating point\cr
98088880 260call \opt{\tt /{\it f}\/} {\it expr}&like {\tt print} but does not display
bca43169 261{\tt void}\cr
98088880
RP
262x \opt{\tt/{\it Nuf}\/} {\it expr}&examine memory at address {\it expr};
263optional format spec follows slash\cr
264\quad {\it N}&count of how many units to display\cr
265\quad {\it u}&unit size; one of\cr
bca43169
RP
266&{\tt\qquad b}\ individual bytes\cr
267&{\tt\qquad h}\ halfwords (two bytes)\cr
268&{\tt\qquad w}\ words (four bytes)\cr
269&{\tt\qquad g}\ giant words (eight bytes)\cr
98088880
RP
270\quad {\it f}&printing format. Any {\tt print} format, or\cr
271&{\tt\qquad s}\ null-terminated string\cr
272&{\tt\qquad i}\ machine instructions\cr
d9800dbb 273disassem \opt{\it addr}&display memory as machine instructions\cr
bca43169
RP
274\endsec
275
276\sec Automatic Display;
98088880 277display \opt{\tt/\it f\/} {\it expr}&show value of {\it expr} each time
bca43169 278program stops \opt{according to format {\it f}\/}\cr
98088880
RP
279display&display all enabled expressions on list\cr
280undisplay {\it n}&remove number(s) {\it n} from list of
bca43169 281automatically displayed expressions\cr
d9800dbb 282disable disp {\it n}&disable display for expression(s) number {\it
98088880 283n}\cr
d9800dbb 284enable disp {\it n}&enable display for expression(s) number {\it
98088880
RP
285n}\cr
286info display&numbered list of display expressions\cr
bca43169
RP
287\endsec
288
98088880
RP
289\vfill\eject
290
291\sec Expressions;
d9800dbb 292{\it expr}&an expression in C, C++, or Modula-2 (including function calls), or:\cr
98088880
RP
293{\it addr\/}@{\it len}&an array of {\it len} elements beginning at {\it
294addr}\cr
295{\it file}::{\it nm}&a variable or function {\it nm} defined in {\it
296file}\cr
297$\tt\{${\it type}$\tt\}${\it addr}&read memory at {\it addr} as specified
298{\it type}\cr
299\$&most recent displayed value\cr
300\${\it n}&{\it n}th displayed value\cr
301\$\$&displayed value previous to \$\cr
302\$\${\it n}&{\it n}th displayed value back from \$\cr
303\$\_&last address examined with {\tt x}\cr
304\$\_\_&value at address \$\_\cr
305\${\it var}&convenience variable; assign any value\cr
306\cr
307show values \opt{{\it n}}&show last 10 values \opt{or surrounding
308\${\it n}}\cr
309show convenience&display all convenience variables\cr
bca43169
RP
310\endsec
311
312\sec Symbol Table;
98088880
RP
313info address {\it s}&show where symbol {\it s} is stored\cr
314info func \opt{\it regex}&show names, types of defined functions
bca43169 315(all, or matching {\it regex})\cr
98088880 316info var \opt{\it regex}&show names, types of global variables (all,
bca43169 317or matching {\it regex})\cr
d54bd32d
RP
318whatis \opt{\it expr}\par
319ptype \opt{\it expr}&show data type of {\it expr} \opt{or \tt \$}
320without evaluating; {\tt ptype} gives more detail\cr
98088880
RP
321ptype {\it type}&describe type, struct, union, or enum\cr
322\endsec
323
324\sec GDB Scripts;
325source {\it script}&read, execute GDB commands from file {\it
326script}\cr
327\cr
328define {\it cmd}\par
d54bd32d
RP
329\qquad {\it command-list}&create new GDB command {\it cmd};
330execute script defined by {\it command-list}\cr
331end&end of {\it command-list}\cr
98088880 332document {\it cmd}\par
d54bd32d
RP
333\qquad {\it help-text}&create online documentation
334for new GDB command {\it cmd}\cr
335end&end of {\it help-text}\cr
98088880
RP
336\endsec
337
338\sec Signals;
d9800dbb
RP
339handle {\it signal} {\it act}&specify GDB actions for {\it signal}:\cr
340\quad print&announce signal\cr
341\quad noprint&be silent for signal\cr
98088880
RP
342\quad stop&halt execution on signal\cr
343\quad nostop&do not halt execution\cr
344\quad pass&allow your program to handle signal\cr
345\quad nopass&do not allow your program to see signal\cr
346info signals&show table of signals, GDB action for each\cr
347\endsec
348
349\sec Debugging Targets;
350target {\it type} {\it param}&connect to target machine, process, or file\cr
351help target&display available targets\cr
352attach {\it param}&connect to another process\cr
353detach&release target from GDB control\cr
bca43169
RP
354\endsec
355
356\vfill\eject
357\sec Controlling GDB;
d9800dbb 358set {\it param} {\it value}&set one of GDB's internal parameters\cr
d54bd32d 359show {\it param}&display current setting of parameter\cr
bca43169 360\xtra{\rm Parameters understood by {\tt set} and {\tt show}:}
98088880
RP
361\quad complaints {\it limit}&number of messages on unusual symbols\cr
362\quad confirm {\it on/off}&enable or disable cautionary queries\cr
363\quad editing {\it on/off}&control {\tt readline} command-line editing\cr
d9800dbb
RP
364\quad height {\it lpp}&number of lines before pause in display\cr
365\quad language {\it lang}&Language for GDB expressions ({\tt auto}, {\tt c} or
366{\tt modula-2})\cr
367\quad listsize {\it n}&number of lines shown by {\tt list}\cr
98088880
RP
368\quad prompt {\it str}&use {\it str} as GDB prompt\cr
369\quad radix {\it base}&octal, decimal, or hex number representation\cr
370\quad verbose {\it on/off}&control messages when loading
d54bd32d 371symbols\cr
98088880 372\quad width {\it cpl}&number of characters before line folded\cr
d9800dbb
RP
373\quad write {\it on/off}&Allow or forbid patching binary, core files
374(when reopened with {\tt exec} or {\tt core})
98088880 375\cr
d54bd32d
RP
376\quad history $\ldots$\par
377\quad h $\ldots$&groups with the following options:\cr
378\quad h exp {\it off/on}&disable/enable {\tt readline} history expansion\cr
98088880
RP
379\quad h file {\it filename}&file for recording GDB command history\cr
380\quad h size {\it size}&number of commands kept in history list\cr
381\quad h save {\it off/on}&control use of external file for
382command history\cr
383\cr
d54bd32d
RP
384\quad print $\ldots$\par
385\quad p $\ldots$&groups with the following options:\cr
98088880
RP
386\quad p address {\it on/off}&print memory addresses in stacks,
387values\cr
388\quad p array {\it off/on}&compact or attractive format for
389arrays\cr
d9800dbb 390\quad p demangl {\it on/off}&source (demangled) or internal form for C++
98088880
RP
391symbols\cr
392\quad p asm-dem {\it on/off}&demangle C++ symbols in
393machine-instruction output\cr
d54bd32d 394\quad p elements {\it limit}&number of array elements to display\cr
98088880
RP
395\quad p object {\it on/off}&print C++ derived types for objects\cr
396\quad p pretty {\it off/on}&struct display: compact or indented\cr
d54bd32d 397\quad p union {\it on/off}&display of union members\cr
98088880
RP
398\quad p vtbl {\it off/on}&display of C++ virtual function
399tables\cr
400\cr
401show commands&show last 10 commands\cr
402show commands {\it n}&show 10 commands around number {\it n}\cr
403show commands +&show next 10 commands\cr
bca43169
RP
404\endsec
405
406\sec Working Files;
d54bd32d
RP
407file \opt{\it file}&use {\it file} for both symbols and executable;
408with no arg, discard both\cr
409core \opt{\it file}&read {\it file} as coredump; or discard\cr
410exec \opt{\it file}&use {\it file} as executable only; or discard\cr
411symbol \opt{\it file}&use symbol table from {\it file}; or discard\cr
98088880
RP
412load {\it file}&dynamically link {\it file\/} and add its symbols\cr
413add-sym {\it file} {\it addr}&read additional symbols from {\it file},
bca43169 414dynamically loaded at {\it addr}\cr
98088880
RP
415info files&display working files and targets in use\cr
416path {\it dirs}&add {\it dirs} to front of path searched for
417executable and symbol files\cr
d9800dbb 418show path&display executable and symbol file path\cr
98088880 419info share&list names of shared libraries currently loaded\cr
bca43169
RP
420\endsec
421
422\vfill\eject
423\sec Source Files;
98088880
RP
424dir {\it names}&add directory {\it names} to front of source path\cr
425dir&clear source path\cr
426show dir&show current source path\cr
bca43169 427\cr
98088880
RP
428list&show next ten lines of source\cr
429list -&show previous ten lines\cr
430list {\it lines}&display source centered around {\it lines},
bca43169 431specified as one of:\cr
98088880
RP
432\quad{\opt{\it file\tt:}\it num}&line number \opt{in named file}\cr
433\quad{\opt{\it file\tt:}\it function}&beginning of function \opt{in
bca43169
RP
434named file}\cr
435\quad{\tt +\it off}&{\it off} lines after last printed\cr
436\quad{\tt -\it off}&{\it off} lines previous to last printed\cr
98088880 437\quad{\tt*\it address}&line containing {\it address}\cr
bca43169 438list {\it f},{\it l}&from line {\it f} to line {\it l}\cr
98088880 439info line {\it num}&show starting, ending addresses of compiled code for
bca43169 440source line {\it num}\cr
98088880
RP
441info source&show name of current source file\cr
442info sources&list all source files in use\cr
443forw {\it regex}&search following source lines for {\it regex}\cr
444rev {\it regex}&search preceding source lines for {\it regex}\cr
bca43169
RP
445\endsec
446
447\sec GDB under GNU Emacs;
98088880
RP
448M-x gdb&run GDB under Emacs\cr
449\ctl{h} m&describe GDB mode\cr
450M-s&step one line ({\tt step})\cr
451M-n&next line ({\tt next})\cr
452M-i&step one instruction ({\tt stepi})\cr
453\ctl{c} \ctl{f}&finish current stack frame ({\tt finish})\cr
454M-c&continue ({\tt cont})\cr
455M-u&up {\it arg} frames ({\tt up})\cr
456M-d&down {\it arg} frames ({\tt down})\cr
457\ctl{x} \&&copy number from point, insert at end\cr
bca43169
RP
458\ctl{x} SPC&(in source file) set break at point\cr
459\endsec
460
d9800dbb 461\sec GDB License;
d54bd32d
RP
462show copying&Display GNU General Public License\cr
463show warranty&There is NO WARRANTY for GDB. Display full no-warranty
d9800dbb
RP
464statement.\cr
465\endsec
466
bca43169
RP
467
468\vfill
469{\smrm\parskip=6pt
d54bd32d
RP
470\centerline{Copyright \copyright 1991, 1992 Free Software Foundation, Inc.}
471\centerline{Roland Pesch (pesch@cygnus.com), January 1992---\manvers}
98088880 472\centerline{The author assumes no responsibility for any errors on this card.}
bca43169
RP
473
474This card may be freely distributed under the terms of the GNU
475General Public License.
476
d9800dbb
RP
477\centerline{Please contribute to development of this card by
478annotating it.}
479
480GDB itself is free software; you are welcome to distribute copies of
481it under the terms of the GNU General Public License. There is
482absolutely no warranty for GDB.
98088880 483}
bca43169 484\end