1 .\" Copyright (C) 1991-2013 Free Software Foundation, Inc.
2 .\" See section COPYING for conditions for redistribution
4 .TH gdb 1 "22may2002" "GNU Tools" "GNU Tools"
6 gdb \- The GNU Debugger
11 .RB "[\|" \-help "\|]"
15 .RB "[\|" \-batch "\|]"
48 .IR core \||\| procID\c
52 The purpose of a debugger such as GDB is to allow you to see what is
53 going on ``inside'' another program while it executes\(em\&or what another
54 program was doing at the moment it crashed.
56 GDB can do four main kinds of things (plus other things in support of
57 these) to help you catch bugs in the act:
61 Start your program, specifying anything that might affect its behavior.
65 Make your program stop on specified conditions.
69 Examine what has happened, when your program has stopped.
73 Change things in your program, so you can experiment with correcting the
74 effects of one bug and go on to learn about another.
77 You can use GDB to debug programs written in C, C++, and Modula-2.
78 Fortran support will be added when a GNU Fortran compiler is ready.
80 GDB is invoked with the shell command \c
82 \&. Once started, it reads
83 commands from the terminal until you tell it to exit with the GDB
86 \&. You can get online help from \c
89 by using the command \c
95 \& with no arguments or options; but the most
96 usual way to start GDB is with one argument or two, specifying an
97 executable program as the argument:
104 You can also start with both an executable program and a core file specified:
111 You can, instead, specify a process ID as a second argument, if you want
112 to debug a running process:
119 would attach GDB to process \c
121 \& (unless you also have a file
124 \&\|'; GDB does check for a core file first).
126 Here are some of the most frequently needed GDB commands:
128 .B break \fR[\|\fIfile\fB:\fR\|]\fIfunction
130 Set a breakpoint at \c
136 .B run \fR[\|\fIarglist\fR\|]
137 Start your program (with \c
142 Backtrace: display the program stack.
146 Display the value of an expression.
149 Continue running your program (after stopping, e.g. at a breakpoint).
152 Execute next program line (after stopping); step \c
155 function calls in the line.
157 .B edit \fR[\|\fIfile\fB:\fR\|]\fIfunction
158 look at the program line where it is presently stopped.
160 .B list \fR[\|\fIfile\fB:\fR\|]\fIfunction
161 type the text of the program in the vicinity of where it is presently stopped.
164 Execute next program line (after stopping); step \c
167 function calls in the line.
169 .B help \fR[\|\fIname\fR\|]
170 Show information about GDB command \c
172 \&, or general information
178 For full details on GDB, see \c
180 Using GDB: A Guide to the GNU Source-Level Debugger\c
181 \&, by Richard M. Stallman and Roland H. Pesch. The same text is available online
188 Any arguments other than options specify an executable
189 file and core file (or process ID); that is, the first argument
191 associated option flag is equivalent to a `\|\c
193 \&\|' option, and the
194 second, if any, is equivalent to a `\|\c
196 \&\|' option if it's the name of a file. Many options have
197 both long and short forms; both are shown here. The long forms are also
198 recognized if you truncate them, so long as enough of the option is
199 present to be unambiguous. (If you prefer, you can flag option
202 \&\|' rather than `\|\c
204 \&\|', though we illustrate the
205 more usual convention.)
207 All the options and command line arguments you give are processed
208 in sequential order. The order makes a difference when the
211 \&\|' option is used.
217 List all options, with brief explanations.
220 .BI "\-symbols=" "file"\c
224 Read symbol table from file \c
230 Enable writing into executable and core files.
233 .BI "\-exec=" "file"\c
239 \& as the executable file to execute when
240 appropriate, and for examining pure data in conjunction with a core
246 Read symbol table from file \c
248 \& and use it as the executable
252 .BI "\-core=" "file"\c
258 \& as a core dump to examine.
261 .BI "\-command=" "file"\c
265 Execute GDB commands from file \c
270 .BI "\-ex " "command"\c
277 .BI "\-directory=" "directory"\c
279 .BI "\-d " "directory"\c
283 \& to the path to search for source files.
288 Do not execute commands from ~/.gdbinit.
294 Do not execute commands from any `\|\c
296 \&\|' initialization files.
303 ``Quiet''. Do not print the introductory and copyright messages. These
304 messages are also suppressed in batch mode.
308 Run in batch mode. Exit with status \c
310 \& after processing all the command
311 files specified with `\|\c
315 \&\|', if not inhibited).
316 Exit with nonzero status if an error occurs in executing the GDB
317 commands in the command files.
319 Batch mode may be useful for running GDB as a filter, for example to
320 download and run a program on another computer; in order to make this
321 more useful, the message
324 Program\ exited\ normally.
328 (which is ordinarily issued whenever a program running under GDB control
329 terminates) is not issued when running in batch mode.
332 .BI "\-cd=" "directory"\c
336 \& as its working directory,
337 instead of the current directory.
343 Emacs sets this option when it runs GDB as a subprocess. It tells GDB
344 to output the full file name and line number in a standard,
345 recognizable fashion each time a stack frame is displayed (which
346 includes each time the program stops). This recognizable format looks
349 \&\|' characters, followed by the file name, line number
350 and character position separated by colons, and a newline. The
351 Emacs-to-GDB interface program uses the two `\|\c
354 a signal to display the source code for the frame.
359 Set the line speed (baud rate or bits per second) of any serial
360 interface used by GDB for remote debugging.
363 .BI "\-tty=" "device"\c
367 \& for your program's standard input and output.
371 The full documentation for
373 is maintained as a Texinfo manual. If the
377 programs and GDB's Texinfo documentation are properly installed at
378 your site, the command
382 should give you access to the complete manual.
385 Using GDB: A Guide to the GNU Source-Level Debugger\c
386 , Richard M. Stallman and Roland H. Pesch, July 1991.
388 Copyright (c) 1991, 2010 Free Software Foundation, Inc.
390 Permission is granted to make and distribute verbatim copies of
391 this manual provided the copyright notice and this permission notice
392 are preserved on all copies.
394 Permission is granted to copy and distribute modified versions of this
395 manual under the conditions for verbatim copying, provided that the
396 entire resulting derived work is distributed under the terms of a
397 permission notice identical to this one.
399 Permission is granted to copy and distribute translations of this
400 manual into another language, under the above conditions for modified
401 versions, except that this permission notice may be included in
402 translations approved by the Free Software Foundation instead of in
403 the original English.