]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdb.1
gdb/
[thirdparty/binutils-gdb.git] / gdb / gdb.1
CommitLineData
0b302171 1.\" Copyright (C) 1991, 1999, 2010-2012 Free Software Foundation, Inc.
c906108c
SS
2.\" See section COPYING for conditions for redistribution
3.\" $Id$
87885426 4.TH gdb 1 "22may2002" "GNU Tools" "GNU Tools"
c906108c
SS
5.SH NAME
6gdb \- The GNU Debugger
7.SH SYNOPSIS
8.na
9.TP
10.B gdb
11.RB "[\|" \-help "\|]"
07540c15 12.RB "[\|" \-nh "\|]"
c906108c
SS
13.RB "[\|" \-nx "\|]"
14.RB "[\|" \-q "\|]"
15.RB "[\|" \-batch "\|]"
16.RB "[\|" \-cd=\c
17.I dir\c
18\|]
19.RB "[\|" \-f "\|]"
20.RB "[\|" "\-b\ "\c
21.IR bps "\|]"
22.RB "[\|" "\-tty="\c
23.IR dev "\|]"
24.RB "[\|" "\-s "\c
25.I symfile\c
26\&\|]
27.RB "[\|" "\-e "\c
28.I prog\c
29\&\|]
30.RB "[\|" "\-se "\c
31.I prog\c
32\&\|]
33.RB "[\|" "\-c "\c
34.I core\c
35\&\|]
36.RB "[\|" "\-x "\c
3d16a105
FCE
37.I file\c
38\&\|]
39.RB "[\|" "\-ex "\c
40.I cmd\c
c906108c
SS
41\&\|]
42.RB "[\|" "\-d "\c
43.I dir\c
44\&\|]
45.RB "[\|" \c
46.I prog\c
47.RB "[\|" \c
48.IR core \||\| procID\c
49\&\|]\&\|]
50.ad b
51.SH DESCRIPTION
52The purpose of a debugger such as GDB is to allow you to see what is
53going on ``inside'' another program while it executes\(em\&or what another
54program was doing at the moment it crashed.
55
56GDB can do four main kinds of things (plus other things in support of
57these) to help you catch bugs in the act:
58
59.TP
60\ \ \ \(bu
61Start your program, specifying anything that might affect its behavior.
62
63.TP
64\ \ \ \(bu
65Make your program stop on specified conditions.
66
67.TP
68\ \ \ \(bu
69Examine what has happened, when your program has stopped.
70
71.TP
72\ \ \ \(bu
73Change things in your program, so you can experiment with correcting the
74effects of one bug and go on to learn about another.
75.PP
76
77You can use GDB to debug programs written in C, C++, and Modula-2.
78Fortran support will be added when a GNU Fortran compiler is ready.
79
80GDB is invoked with the shell command \c
81.B gdb\c
82\&. Once started, it reads
83commands from the terminal until you tell it to exit with the GDB
84command \c
85.B quit\c
86\&. You can get online help from \c
87.B gdb\c
88\& itself
89by using the command \c
90.B help\c
91\&.
92
93You can run \c
94.B gdb\c
95\& with no arguments or options; but the most
96usual way to start GDB is with one argument or two, specifying an
97executable program as the argument:
98.sp
99.br
100gdb\ program
101.br
102.sp
103
104You can also start with both an executable program and a core file specified:
105.sp
106.br
107gdb\ program\ core
108.br
109.sp
110
111You can, instead, specify a process ID as a second argument, if you want
112to debug a running process:
113.sp
114.br
115gdb\ program\ 1234
116.br
117.sp
118
119would attach GDB to process \c
120.B 1234\c
121\& (unless you also have a file
122named `\|\c
123.B 1234\c
124\&\|'; GDB does check for a core file first).
125
126Here are some of the most frequently needed GDB commands:
127.TP
128.B break \fR[\|\fIfile\fB:\fR\|]\fIfunction
129\&
130Set a breakpoint at \c
131.I function\c
132\& (in \c
133.I file\c
134\&).
135.TP
136.B run \fR[\|\fIarglist\fR\|]
137Start your program (with \c
138.I arglist\c
139\&, if specified).
140.TP
141.B bt
142Backtrace: display the program stack.
143.TP
144.BI print " expr"\c
145\&
146Display the value of an expression.
147.TP
148.B c
149Continue running your program (after stopping, e.g. at a breakpoint).
150.TP
151.B next
152Execute next program line (after stopping); step \c
153.I over\c
154\& any
155function calls in the line.
156.TP
87885426
FN
157.B edit \fR[\|\fIfile\fB:\fR\|]\fIfunction
158look at the program line where it is presently stopped.
159.TP
160.B list \fR[\|\fIfile\fB:\fR\|]\fIfunction
161type the text of the program in the vicinity of where it is presently stopped.
162.TP
c906108c
SS
163.B step
164Execute next program line (after stopping); step \c
165.I into\c
166\& any
167function calls in the line.
168.TP
169.B help \fR[\|\fIname\fR\|]
170Show information about GDB command \c
171.I name\c
172\&, or general information
173about using GDB.
174.TP
175.B quit
176Exit from GDB.
177.PP
178For full details on GDB, see \c
179.I
180Using 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
182as the \c
183.B gdb\c
184\& entry in the \c
185.B info\c
186\& program.
187.SH OPTIONS
188Any arguments other than options specify an executable
189file and core file (or process ID); that is, the first argument
190encountered with no
191associated option flag is equivalent to a `\|\c
192.B \-se\c
193\&\|' option, and the
194second, if any, is equivalent to a `\|\c
195.B \-c\c
196\&\|' option if it's the name of a file. Many options have
197both long and short forms; both are shown here. The long forms are also
198recognized if you truncate them, so long as enough of the option is
199present to be unambiguous. (If you prefer, you can flag option
200arguments with `\|\c
201.B +\c
202\&\|' rather than `\|\c
203.B \-\c
204\&\|', though we illustrate the
205more usual convention.)
206
207All the options and command line arguments you give are processed
208in sequential order. The order makes a difference when the
209`\|\c
210.B \-x\c
211\&\|' option is used.
212
213.TP
214.B \-help
215.TP
216.B \-h
217List all options, with brief explanations.
218
219.TP
220.BI "\-symbols=" "file"\c
221.TP
222.BI "\-s " "file"\c
223\&
224Read symbol table from file \c
225.I file\c
226\&.
227
228.TP
229.B \-write
230Enable writing into executable and core files.
231
232.TP
233.BI "\-exec=" "file"\c
234.TP
235.BI "\-e " "file"\c
236\&
237Use file \c
238.I file\c
239\& as the executable file to execute when
240appropriate, and for examining pure data in conjunction with a core
241dump.
242
243.TP
244.BI "\-se=" "file"\c
245\&
246Read symbol table from file \c
247.I file\c
248\& and use it as the executable
249file.
250
251.TP
252.BI "\-core=" "file"\c
253.TP
254.BI "\-c " "file"\c
255\&
256Use file \c
257.I file\c
258\& as a core dump to examine.
259
260.TP
261.BI "\-command=" "file"\c
262.TP
263.BI "\-x " "file"\c
264\&
265Execute GDB commands from file \c
266.I file\c
267\&.
268
3d16a105
FCE
269.TP
270.BI "\-ex " "command"\c
271\&
272Execute given GDB \c
273.I command\c
274\&.
275
c906108c
SS
276.TP
277.BI "\-directory=" "directory"\c
278.TP
279.BI "\-d " "directory"\c
280\&
281Add \c
282.I directory\c
283\& to the path to search for source files.
284.PP
285
07540c15
DE
286.TP
287.B \-nh
288Do not execute commands from ~/.gdbinit.
289
c906108c
SS
290.TP
291.B \-nx
292.TP
293.B \-n
294Do not execute commands from any `\|\c
295.B .gdbinit\c
296\&\|' initialization files.
c906108c
SS
297
298
299.TP
300.B \-quiet
301.TP
302.B \-q
303``Quiet''. Do not print the introductory and copyright messages. These
304messages are also suppressed in batch mode.
305
306.TP
307.B \-batch
308Run in batch mode. Exit with status \c
309.B 0\c
310\& after processing all the command
311files specified with `\|\c
312.B \-x\c
313\&\|' (and `\|\c
314.B .gdbinit\c
315\&\|', if not inhibited).
316Exit with nonzero status if an error occurs in executing the GDB
317commands in the command files.
318
319Batch mode may be useful for running GDB as a filter, for example to
320download and run a program on another computer; in order to make this
321more useful, the message
322.sp
323.br
324Program\ exited\ normally.
325.br
326.sp
327
328(which is ordinarily issued whenever a program running under GDB control
329terminates) is not issued when running in batch mode.
330
331.TP
332.BI "\-cd=" "directory"\c
333\&
334Run GDB using \c
335.I directory\c
336\& as its working directory,
337instead of the current directory.
338
339.TP
340.B \-fullname
341.TP
342.B \-f
343Emacs sets this option when it runs GDB as a subprocess. It tells GDB
344to output the full file name and line number in a standard,
345recognizable fashion each time a stack frame is displayed (which
346includes each time the program stops). This recognizable format looks
347like two `\|\c
348.B \032\c
349\&\|' characters, followed by the file name, line number
350and character position separated by colons, and a newline. The
351Emacs-to-GDB interface program uses the two `\|\c
352.B \032\c
353\&\|' characters as
354a signal to display the source code for the frame.
355
356.TP
357.BI "\-b " "bps"\c
358\&
359Set the line speed (baud rate or bits per second) of any serial
360interface used by GDB for remote debugging.
361
362.TP
363.BI "\-tty=" "device"\c
364\&
365Run using \c
366.I device\c
367\& for your program's standard input and output.
368.PP
369
370.SH "SEE ALSO"
f4045bcb
PA
371The full documentation for
372.B gdb
373is maintained as a Texinfo manual. If the
374.B info
375and
376.B gdb
377programs and GDB's Texinfo documentation are properly installed at
378your site, the command
379.IP
380.B info gdb
381.PP
382should give you access to the complete manual.
383
c906108c
SS
384.I
385Using GDB: A Guide to the GNU Source-Level Debugger\c
386, Richard M. Stallman and Roland H. Pesch, July 1991.
387.SH COPYING
abd775ce 388Copyright (c) 1991, 2010 Free Software Foundation, Inc.
c906108c
SS
389.PP
390Permission is granted to make and distribute verbatim copies of
391this manual provided the copyright notice and this permission notice
392are preserved on all copies.
393.PP
394Permission is granted to copy and distribute modified versions of this
395manual under the conditions for verbatim copying, provided that the
396entire resulting derived work is distributed under the terms of a
397permission notice identical to this one.
398.PP
399Permission is granted to copy and distribute translations of this
400manual into another language, under the above conditions for modified
401versions, except that this permission notice may be included in
402translations approved by the Free Software Foundation instead of in
403the original English.