1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "GDB 1"
.TH GDB 1 2024-02-27 gdb- "GNU Development Tools"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
gdb \- The GNU Debugger
.SH SYNOPSIS
.IX Header "SYNOPSIS"
gdb [OPTIONS] [\fIprog\fR|\fIprog\fR \fIprocID\fR|\fIprog\fR \fIcore\fR]
.SH DESCRIPTION
.IX Header "DESCRIPTION"
The purpose of a debugger such as GDB is to allow you to see what is
going on "inside" another program while it executes \-\- or what another
program was doing at the moment it crashed.
.PP
GDB can do four main kinds of things (plus other things in support of
these) to help you catch bugs in the act:
.IP \(bu 4
Start your program, specifying anything that might affect its behavior.
.IP \(bu 4
Make your program stop on specified conditions.
.IP \(bu 4
Examine what has happened, when your program has stopped.
.IP \(bu 4
Change things in your program, so you can experiment with correcting the
effects of one bug and go on to learn about another.
.PP
You can use GDB to debug programs written in C, C++, Fortran and
Modula\-2.
.PP
GDB is invoked with the shell command \f(CW\*(C`gdb\*(C'\fR. Once started, it reads
commands from the terminal until you tell it to exit with the GDB
command \f(CW\*(C`quit\*(C'\fR or \f(CW\*(C`exit\*(C'\fR. You can get online help from GDB itself
by using the command \f(CW\*(C`help\*(C'\fR.
.PP
You can run \f(CW\*(C`gdb\*(C'\fR with no arguments or options; but the most
usual way to start GDB is with one argument or two, specifying an
executable program as the argument:
.PP
.Vb 1
\& gdb program
.Ve
.PP
You can also start with both an executable program and a core file specified:
.PP
.Vb 1
\& gdb program core
.Ve
.PP
You can, instead, specify a process ID as a second argument or use option
\&\f(CW\*(C`\-p\*(C'\fR, if you want to debug a running process:
.PP
.Vb 2
\& gdb program 1234
\& gdb \-p 1234
.Ve
.PP
would attach GDB to process \f(CW1234\fR. With option \fB\-p\fR you
can omit the \fIprogram\fR filename.
.PP
Here are some of the most frequently needed GDB commands:
.IP "\fBbreak [\fR\fIfile\fR\fB:][\fR\fIfunction\fR\fB|\fR\fIline\fR\fB]\fR" 4
.IX Item "break [file:][function|line]"
Set a breakpoint at \fIfunction\fR or \fIline\fR (in \fIfile\fR).
.IP "\fBrun [\fR\fIarglist\fR\fB]\fR" 4
.IX Item "run [arglist]"
Start your program (with \fIarglist\fR, if specified).
.IP \fBbt\fR 4
.IX Item "bt"
Backtrace: display the program stack.
.IP "\fBprint\fR \fIexpr\fR" 4
.IX Item "print expr"
Display the value of an expression.
.IP \fBc\fR 4
.IX Item "c"
Continue running your program (after stopping, e.g. at a breakpoint).
.IP \fBnext\fR 4
.IX Item "next"
Execute next program line (after stopping); step \fIover\fR any
function calls in the line.
.IP "\fBedit [\fR\fIfile\fR\fB:]\fR\fIfunction\fR" 4
.IX Item "edit [file:]function"
look at the program line where it is presently stopped.
.IP "\fBlist [\fR\fIfile\fR\fB:]\fR\fIfunction\fR" 4
.IX Item "list [file:]function"
type the text of the program in the vicinity of where it is presently stopped.
.IP \fBstep\fR 4
.IX Item "step"
Execute next program line (after stopping); step \fIinto\fR any
function calls in the line.
.IP "\fBhelp [\fR\fIname\fR\fB]\fR" 4
.IX Item "help [name]"
Show information about GDB command \fIname\fR, or general information
about using GDB.
.IP \fBquit\fR 4
.IX Item "quit"
.PD 0
.IP \fBexit\fR 4
.IX Item "exit"
.PD
Exit from GDB.
.PP
For full details on GDB,
see \fIUsing GDB: A Guide to the GNU Source-Level Debugger\fR,
by Richard M. Stallman and Roland H. Pesch. The same text is available online
as the \f(CW\*(C`gdb\*(C'\fR entry in the \f(CW\*(C`info\*(C'\fR program.
.SH OPTIONS
.IX Header "OPTIONS"
Any arguments other than options specify an executable
file and core file (or process ID); that is, the first argument
encountered with no
associated option flag is equivalent to a \fB\-\-se\fR option, and the second,
if any, is equivalent to a \fB\-c\fR option if it's the name of a file.
Many options have
both long and abbreviated forms; both are shown here. The long forms are also
recognized if you truncate them, so long as enough of the option is
present to be unambiguous.
.PP
The abbreviated forms are shown here with \fB\-\fR and long forms are shown
with \fB\-\-\fR to reflect how they are shown in \fB\-\-help\fR. However,
GDB recognizes all of the following conventions for most options:
.ie n .IP """\-\-option=\fIvalue\fR""" 4
.el .IP \f(CW\-\-option=\fR\f(CIvalue\fR\f(CW\fR 4
.IX Item "--option=value"
.PD 0
.ie n .IP """\-\-option \fIvalue\fR""" 4
.el .IP "\f(CW\-\-option \fR\f(CIvalue\fR\f(CW\fR" 4
.IX Item "--option value"
.ie n .IP """\-option=\fIvalue\fR""" 4
.el .IP \f(CW\-option=\fR\f(CIvalue\fR\f(CW\fR 4
.IX Item "-option=value"
.ie n .IP """\-option \fIvalue\fR""" 4
.el .IP "\f(CW\-option \fR\f(CIvalue\fR\f(CW\fR" 4
.IX Item "-option value"
.ie n .IP """\-\-o=\fIvalue\fR""" 4
.el .IP \f(CW\-\-o=\fR\f(CIvalue\fR\f(CW\fR 4
.IX Item "--o=value"
.ie n .IP """\-\-o \fIvalue\fR""" 4
.el .IP "\f(CW\-\-o \fR\f(CIvalue\fR\f(CW\fR" 4
.IX Item "--o value"
.ie n .IP """\-o=\fIvalue\fR""" 4
.el .IP \f(CW\-o=\fR\f(CIvalue\fR\f(CW\fR 4
.IX Item "-o=value"
.ie n .IP """\-o \fIvalue\fR""" 4
.el .IP "\f(CW\-o \fR\f(CIvalue\fR\f(CW\fR" 4
.IX Item "-o value"
.PD
.PP
All the options and command line arguments you give are processed
in sequential order. The order makes a difference when the \fB\-x\fR
option is used.
.IP \fB\-\-help\fR 4
.IX Item "--help"
.PD 0
.IP \fB\-h\fR 4
.IX Item "-h"
.PD
List all options, with brief explanations.
.IP \fB\-\-symbols=\fR\fIfile\fR 4
.IX Item "--symbols=file"
.PD 0
.IP "\fB\-s\fR \fIfile\fR" 4
.IX Item "-s file"
.PD
Read symbol table from \fIfile\fR.
.IP \fB\-\-write\fR 4
.IX Item "--write"
Enable writing into executable and core files.
.IP \fB\-\-exec=\fR\fIfile\fR 4
.IX Item "--exec=file"
.PD 0
.IP "\fB\-e\fR \fIfile\fR" 4
.IX Item "-e file"
.PD
Use \fIfile\fR as the executable file to execute when
appropriate, and for examining pure data in conjunction with a core
dump.
.IP \fB\-\-se=\fR\fIfile\fR 4
.IX Item "--se=file"
Read symbol table from \fIfile\fR and use it as the executable
file.
.IP \fB\-\-core=\fR\fIfile\fR 4
.IX Item "--core=file"
.PD 0
.IP "\fB\-c\fR \fIfile\fR" 4
.IX Item "-c file"
.PD
Use \fIfile\fR as a core dump to examine.
.IP \fB\-\-command=\fR\fIfile\fR 4
.IX Item "--command=file"
.PD 0
.IP "\fB\-x\fR \fIfile\fR" 4
.IX Item "-x file"
.PD
Execute GDB commands from \fIfile\fR.
.IP \fB\-\-eval\-command=\fR\fIcommand\fR 4
.IX Item "--eval-command=command"
.PD 0
.IP "\fB\-ex\fR \fIcommand\fR" 4
.IX Item "-ex command"
.PD
Execute given GDB \fIcommand\fR.
.IP \fB\-\-init\-eval\-command=\fR\fIcommand\fR 4
.IX Item "--init-eval-command=command"
.PD 0
.IP \fB\-iex\fR 4
.IX Item "-iex"
.PD
Execute GDB \fIcommand\fR before loading the inferior.
.IP \fB\-\-directory=\fR\fIdirectory\fR 4
.IX Item "--directory=directory"
.PD 0
.IP "\fB\-d\fR \fIdirectory\fR" 4
.IX Item "-d directory"
.PD
Add \fIdirectory\fR to the path to search for source files.
.IP \fB\-\-nh\fR 4
.IX Item "--nh"
Do not execute commands from \fI~/.config/gdb/gdbinit\fR,
\&\fI~/.gdbinit\fR, \fI~/.config/gdb/gdbearlyinit\fR, or
\&\fI~/.gdbearlyinit\fR
.IP \fB\-\-nx\fR 4
.IX Item "--nx"
.PD 0
.IP \fB\-n\fR 4
.IX Item "-n"
.PD
Do not execute commands from any \fI.gdbinit\fR or
\&\fI.gdbearlyinit\fR initialization files.
.IP \fB\-\-quiet\fR 4
.IX Item "--quiet"
.PD 0
.IP \fB\-\-silent\fR 4
.IX Item "--silent"
.IP \fB\-q\fR 4
.IX Item "-q"
.PD
"Quiet". Do not print the introductory and copyright messages. These
messages are also suppressed in batch mode.
.IP \fB\-\-batch\fR 4
.IX Item "--batch"
Run in batch mode. Exit with status \f(CW0\fR after processing all the command
files specified with \fB\-x\fR (and \fI.gdbinit\fR, if not inhibited).
Exit with nonzero status if an error occurs in executing the GDB
commands in the command files.
.Sp
Batch mode may be useful for running GDB as a filter, for example to
download and run a program on another computer; in order to make this
more useful, the message
.Sp
.Vb 1
\& Program exited normally.
.Ve
.Sp
(which is ordinarily issued whenever a program running under GDB control
terminates) is not issued when running in batch mode.
.IP \fB\-\-batch\-silent\fR 4
.IX Item "--batch-silent"
Run in batch mode, just like \fB\-\-batch\fR, but totally silent. All GDB
output is supressed (stderr is unaffected). This is much quieter than
\&\fB\-\-silent\fR and would be useless for an interactive session.
.Sp
This is particularly useful when using targets that give \fBLoading section\fR
messages, for example.
.Sp
Note that targets that give their output via GDB, as opposed to writing
directly to \f(CW\*(C`stdout\*(C'\fR, will also be made silent.
.IP "\fB\-\-args\fR \fIprog\fR \fB[\fR\fIarglist\fR\fB]\fR" 4
.IX Item "--args prog [arglist]"
Change interpretation of command line so that arguments following this
option are passed as arguments to the inferior. As an example, take
the following command:
.Sp
.Vb 1
\& gdb ./a.out \-q
.Ve
.Sp
It would start GDB with \fB\-q\fR, not printing the introductory message. On
the other hand, using:
.Sp
.Vb 1
\& gdb \-\-args ./a.out \-q
.Ve
.Sp
starts GDB with the introductory message, and passes the option to the inferior.
.IP \fB\-\-pid=\fR\fIpid\fR 4
.IX Item "--pid=pid"
Attach GDB to an already running program, with the PID \fIpid\fR.
.IP \fB\-\-tui\fR 4
.IX Item "--tui"
Open the terminal user interface.
.IP \fB\-\-readnow\fR 4
.IX Item "--readnow"
Read all symbols from the given symfile on the first access.
.IP \fB\-\-readnever\fR 4
.IX Item "--readnever"
Do not read symbol files.
.IP \fB\-\-return\-child\-result\fR 4
.IX Item "--return-child-result"
GDB's exit code will be the same as the child's exit code.
.IP \fB\-\-configuration\fR 4
.IX Item "--configuration"
Print details about GDB configuration and then exit.
.IP \fB\-\-version\fR 4
.IX Item "--version"
Print version information and then exit.
.IP \fB\-\-cd=\fR\fIdirectory\fR 4
.IX Item "--cd=directory"
Run GDB using \fIdirectory\fR as its working directory,
instead of the current directory.
.IP \fB\-\-data\-directory=\fR\fIdirectory\fR 4
.IX Item "--data-directory=directory"
.PD 0
.IP \fB\-D\fR 4
.IX Item "-D"
.PD
Run GDB using \fIdirectory\fR as its data directory. The data
directory is where GDB searches for its auxiliary files.
.IP \fB\-\-fullname\fR 4
.IX Item "--fullname"
.PD 0
.IP \fB\-f\fR 4
.IX Item "-f"
.PD
Emacs sets this option when it runs GDB as a subprocess. It tells
GDB to output the full file name and line number in a standard,
recognizable fashion each time a stack frame is displayed (which
includes each time the program stops). This recognizable format looks
like two \fB\e032\fR characters, followed by the file name, line number
and character position separated by colons, and a newline. The
Emacs-to-GDB interface program uses the two \fB\e032\fR
characters as a signal to display the source code for the frame.
.IP "\fB\-b\fR \fIbaudrate\fR" 4
.IX Item "-b baudrate"
Set the line speed (baud rate or bits per second) of any serial
interface used by GDB for remote debugging.
.IP "\fB\-l\fR \fItimeout\fR" 4
.IX Item "-l timeout"
Set timeout, in seconds, for remote debugging.
.IP \fB\-\-tty=\fR\fIdevice\fR 4
.IX Item "--tty=device"
Run using \fIdevice\fR for your program's standard input and output.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
The full documentation for GDB is maintained as a Texinfo manual.
If the \f(CW\*(C`info\*(C'\fR and \f(CW\*(C`gdb\*(C'\fR programs and GDB's Texinfo
documentation are properly installed at your site, the command
.PP
.Vb 1
\& info gdb
.Ve
.PP
should give you access to the complete manual.
.PP
\&\fIUsing GDB: A Guide to the GNU Source-Level Debugger\fR,
Richard M. Stallman and Roland H. Pesch, July 1991.
.SH COPYRIGHT
.IX Header "COPYRIGHT"
Copyright (c) 1988\-2023 Free Software Foundation, Inc.
.PP
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.
.PP
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom."
|