1 .\" Copyright (C) 1991, 1999 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 "\|]"
44 .IR core \||\| procID\c
48 The purpose of a debugger such as GDB is to allow you to see what is
49 going on ``inside'' another program while it executes\(em\&or what another
50 program was doing at the moment it crashed.
52 GDB can do four main kinds of things (plus other things in support of
53 these) to help you catch bugs in the act:
57 Start your program, specifying anything that might affect its behavior.
61 Make your program stop on specified conditions.
65 Examine what has happened, when your program has stopped.
69 Change things in your program, so you can experiment with correcting the
70 effects of one bug and go on to learn about another.
73 You can use GDB to debug programs written in C, C++, and Modula-2.
74 Fortran support will be added when a GNU Fortran compiler is ready.
76 GDB is invoked with the shell command \c
78 \&. Once started, it reads
79 commands from the terminal until you tell it to exit with the GDB
82 \&. You can get online help from \c
85 by using the command \c
91 \& with no arguments or options; but the most
92 usual way to start GDB is with one argument or two, specifying an
93 executable program as the argument:
100 You can also start with both an executable program and a core file specified:
107 You can, instead, specify a process ID as a second argument, if you want
108 to debug a running process:
115 would attach GDB to process \c
117 \& (unless you also have a file
120 \&\|'; GDB does check for a core file first).
122 Here are some of the most frequently needed GDB commands:
124 .B break \fR[\|\fIfile\fB:\fR\|]\fIfunction
126 Set a breakpoint at \c
132 .B run \fR[\|\fIarglist\fR\|]
133 Start your program (with \c
138 Backtrace: display the program stack.
142 Display the value of an expression.
145 Continue running your program (after stopping, e.g. at a breakpoint).
148 Execute next program line (after stopping); step \c
151 function calls in the line.
153 .B edit \fR[\|\fIfile\fB:\fR\|]\fIfunction
154 look at the program line where it is presently stopped.
156 .B list \fR[\|\fIfile\fB:\fR\|]\fIfunction
157 type the text of the program in the vicinity of where it is presently stopped.
160 Execute next program line (after stopping); step \c
163 function calls in the line.
165 .B help \fR[\|\fIname\fR\|]
166 Show information about GDB command \c
168 \&, or general information
174 For full details on GDB, see \c
176 Using GDB: A Guide to the GNU Source-Level Debugger\c
177 \&, by Richard M. Stallman and Roland H. Pesch. The same text is available online
184 Any arguments other than options specify an executable
185 file and core file (or process ID); that is, the first argument
187 associated option flag is equivalent to a `\|\c
189 \&\|' option, and the
190 second, if any, is equivalent to a `\|\c
192 \&\|' option if it's the name of a file. Many options have
193 both long and short forms; both are shown here. The long forms are also
194 recognized if you truncate them, so long as enough of the option is
195 present to be unambiguous. (If you prefer, you can flag option
198 \&\|' rather than `\|\c
200 \&\|', though we illustrate the
201 more usual convention.)
203 All the options and command line arguments you give are processed
204 in sequential order. The order makes a difference when the
207 \&\|' option is used.
213 List all options, with brief explanations.
216 .BI "\-symbols=" "file"\c
220 Read symbol table from file \c
226 Enable writing into executable and core files.
229 .BI "\-exec=" "file"\c
235 \& as the executable file to execute when
236 appropriate, and for examining pure data in conjunction with a core
242 Read symbol table from file \c
244 \& and use it as the executable
248 .BI "\-core=" "file"\c
254 \& as a core dump to examine.
257 .BI "\-command=" "file"\c
261 Execute GDB commands from file \c
266 .BI "\-directory=" "directory"\c
268 .BI "\-d " "directory"\c
272 \& to the path to search for source files.
279 Do not execute commands from any `\|\c
281 \&\|' initialization files.
282 Normally, the commands in these files are executed after all the
283 command options and arguments have been processed.
290 ``Quiet''. Do not print the introductory and copyright messages. These
291 messages are also suppressed in batch mode.
295 Run in batch mode. Exit with status \c
297 \& after processing all the command
298 files specified with `\|\c
302 \&\|', if not inhibited).
303 Exit with nonzero status if an error occurs in executing the GDB
304 commands in the command files.
306 Batch mode may be useful for running GDB as a filter, for example to
307 download and run a program on another computer; in order to make this
308 more useful, the message
311 Program\ exited\ normally.
315 (which is ordinarily issued whenever a program running under GDB control
316 terminates) is not issued when running in batch mode.
319 .BI "\-cd=" "directory"\c
323 \& as its working directory,
324 instead of the current directory.
330 Emacs sets this option when it runs GDB as a subprocess. It tells GDB
331 to output the full file name and line number in a standard,
332 recognizable fashion each time a stack frame is displayed (which
333 includes each time the program stops). This recognizable format looks
336 \&\|' characters, followed by the file name, line number
337 and character position separated by colons, and a newline. The
338 Emacs-to-GDB interface program uses the two `\|\c
341 a signal to display the source code for the frame.
346 Set the line speed (baud rate or bits per second) of any serial
347 interface used by GDB for remote debugging.
350 .BI "\-tty=" "device"\c
354 \& for your program's standard input and output.
363 Using GDB: A Guide to the GNU Source-Level Debugger\c
364 , Richard M. Stallman and Roland H. Pesch, July 1991.
366 Copyright (c) 1991 Free Software Foundation, Inc.
368 Permission is granted to make and distribute verbatim copies of
369 this manual provided the copyright notice and this permission notice
370 are preserved on all copies.
372 Permission is granted to copy and distribute modified versions of this
373 manual under the conditions for verbatim copying, provided that the
374 entire resulting derived work is distributed under the terms of a
375 permission notice identical to this one.
377 Permission is granted to copy and distribute translations of this
378 manual into another language, under the above conditions for modified
379 versions, except that this permission notice may be included in
380 translations approved by the Free Software Foundation instead of in
381 the original English.