1 .\" Copyright (C) 1991, 1999, 2010-2012 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 "\|]"
14 .RB "[\|" \-batch "\|]"
47 .IR core \||\| procID\c
51 The purpose of a debugger such as GDB is to allow you to see what is
52 going on ``inside'' another program while it executes\(em\&or what another
53 program was doing at the moment it crashed.
55 GDB can do four main kinds of things (plus other things in support of
56 these) to help you catch bugs in the act:
60 Start your program, specifying anything that might affect its behavior.
64 Make your program stop on specified conditions.
68 Examine what has happened, when your program has stopped.
72 Change things in your program, so you can experiment with correcting the
73 effects of one bug and go on to learn about another.
76 You can use GDB to debug programs written in C, C++, and Modula-2.
77 Fortran support will be added when a GNU Fortran compiler is ready.
79 GDB is invoked with the shell command \c
81 \&. Once started, it reads
82 commands from the terminal until you tell it to exit with the GDB
85 \&. You can get online help from \c
88 by using the command \c
94 \& with no arguments or options; but the most
95 usual way to start GDB is with one argument or two, specifying an
96 executable program as the argument:
103 You can also start with both an executable program and a core file specified:
110 You can, instead, specify a process ID as a second argument, if you want
111 to debug a running process:
118 would attach GDB to process \c
120 \& (unless you also have a file
123 \&\|'; GDB does check for a core file first).
125 Here are some of the most frequently needed GDB commands:
127 .B break \fR[\|\fIfile\fB:\fR\|]\fIfunction
129 Set a breakpoint at \c
135 .B run \fR[\|\fIarglist\fR\|]
136 Start your program (with \c
141 Backtrace: display the program stack.
145 Display the value of an expression.
148 Continue running your program (after stopping, e.g. at a breakpoint).
151 Execute next program line (after stopping); step \c
154 function calls in the line.
156 .B edit \fR[\|\fIfile\fB:\fR\|]\fIfunction
157 look at the program line where it is presently stopped.
159 .B list \fR[\|\fIfile\fB:\fR\|]\fIfunction
160 type the text of the program in the vicinity of where it is presently stopped.
163 Execute next program line (after stopping); step \c
166 function calls in the line.
168 .B help \fR[\|\fIname\fR\|]
169 Show information about GDB command \c
171 \&, or general information
177 For full details on GDB, see \c
179 Using GDB: A Guide to the GNU Source-Level Debugger\c
180 \&, by Richard M. Stallman and Roland H. Pesch. The same text is available online
187 Any arguments other than options specify an executable
188 file and core file (or process ID); that is, the first argument
190 associated option flag is equivalent to a `\|\c
192 \&\|' option, and the
193 second, if any, is equivalent to a `\|\c
195 \&\|' option if it's the name of a file. Many options have
196 both long and short forms; both are shown here. The long forms are also
197 recognized if you truncate them, so long as enough of the option is
198 present to be unambiguous. (If you prefer, you can flag option
201 \&\|' rather than `\|\c
203 \&\|', though we illustrate the
204 more usual convention.)
206 All the options and command line arguments you give are processed
207 in sequential order. The order makes a difference when the
210 \&\|' option is used.
216 List all options, with brief explanations.
219 .BI "\-symbols=" "file"\c
223 Read symbol table from file \c
229 Enable writing into executable and core files.
232 .BI "\-exec=" "file"\c
238 \& as the executable file to execute when
239 appropriate, and for examining pure data in conjunction with a core
245 Read symbol table from file \c
247 \& and use it as the executable
251 .BI "\-core=" "file"\c
257 \& as a core dump to examine.
260 .BI "\-command=" "file"\c
264 Execute GDB commands from file \c
269 .BI "\-ex " "command"\c
276 .BI "\-directory=" "directory"\c
278 .BI "\-d " "directory"\c
282 \& to the path to search for source files.
289 Do not execute commands from any `\|\c
291 \&\|' initialization files.
292 Normally, the commands in these files are executed after all the
293 command options and arguments have been processed.
300 ``Quiet''. Do not print the introductory and copyright messages. These
301 messages are also suppressed in batch mode.
305 Run in batch mode. Exit with status \c
307 \& after processing all the command
308 files specified with `\|\c
312 \&\|', if not inhibited).
313 Exit with nonzero status if an error occurs in executing the GDB
314 commands in the command files.
316 Batch mode may be useful for running GDB as a filter, for example to
317 download and run a program on another computer; in order to make this
318 more useful, the message
321 Program\ exited\ normally.
325 (which is ordinarily issued whenever a program running under GDB control
326 terminates) is not issued when running in batch mode.
329 .BI "\-cd=" "directory"\c
333 \& as its working directory,
334 instead of the current directory.
340 Emacs sets this option when it runs GDB as a subprocess. It tells GDB
341 to output the full file name and line number in a standard,
342 recognizable fashion each time a stack frame is displayed (which
343 includes each time the program stops). This recognizable format looks
346 \&\|' characters, followed by the file name, line number
347 and character position separated by colons, and a newline. The
348 Emacs-to-GDB interface program uses the two `\|\c
351 a signal to display the source code for the frame.
356 Set the line speed (baud rate or bits per second) of any serial
357 interface used by GDB for remote debugging.
360 .BI "\-tty=" "device"\c
364 \& for your program's standard input and output.
373 Using GDB: A Guide to the GNU Source-Level Debugger\c
374 , Richard M. Stallman and Roland H. Pesch, July 1991.
376 Copyright (c) 1991, 2010 Free Software Foundation, Inc.
378 Permission is granted to make and distribute verbatim copies of
379 this manual provided the copyright notice and this permission notice
380 are preserved on all copies.
382 Permission is granted to copy and distribute modified versions of this
383 manual under the conditions for verbatim copying, provided that the
384 entire resulting derived work is distributed under the terms of a
385 permission notice identical to this one.
387 Permission is granted to copy and distribute translations of this
388 manual into another language, under the above conditions for modified
389 versions, except that this permission notice may be included in
390 translations approved by the Free Software Foundation instead of in
391 the original English.