summaryrefslogtreecommitdiff
path: root/share/doc/gdb/gdb-man.html
blob: a26f3b4bd0d6a64050ec8ce837f77f64cb14f3e4 (plain)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 Free Software Foundation, Inc.

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.

(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." -->
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: gdb man</title>

<meta name="description" content="Debugging with GDB: gdb man">
<meta name="keywords" content="Debugging with GDB: gdb man">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Man-Pages.html#Man-Pages" rel="up" title="Man Pages">
<link href="gdbserver-man.html#gdbserver-man" rel="next" title="gdbserver man">
<link href="Man-Pages.html#Man-Pages" rel="previous" title="Man Pages">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="gdb-man"></a>
<div class="header">
<p>
Next: <a href="gdbserver-man.html#gdbserver-man" accesskey="n" rel="next">gdbserver man</a>, Up: <a href="Man-Pages.html#Man-Pages" accesskey="u" rel="up">Man Pages</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="node-heading">gdb man</h4>
<a name="gdb-man-1"></a>
<h3 class="heading">gdb man</h3>


<p>gdb [OPTIONS] [<var>prog</var>|<var>prog</var> <var>procID</var>|<var>prog</var> <var>core</var>]
</p>
<p>The purpose of a debugger such as <small>GDB</small> is to allow you to see what is
going on &ldquo;inside&rdquo; another program while it executes &ndash; or what another
program was doing at the moment it crashed.
</p>
<p><small>GDB</small> can do four main kinds of things (plus other things in support of
these) to help you catch bugs in the act:
</p>
<ul>
<li> Start your program, specifying anything that might affect its behavior.

</li><li> Make your program stop on specified conditions.

</li><li> Examine what has happened, when your program has stopped.

</li><li> Change things in your program, so you can experiment with correcting the
effects of one bug and go on to learn about another.
</li></ul>

<p>You can use <small>GDB</small> to debug programs written in C, C<tt>++</tt>, Fortran and
Modula-2.
</p>
<p><small>GDB</small> is invoked with the shell command <code>gdb</code>.  Once started, it reads
commands from the terminal until you tell it to exit with the <small>GDB</small>
command <code>quit</code> or <code>exit</code>.  You can get online help from <small>GDB</small> itself
by using the command <code>help</code>.
</p>
<p>You can run <code>gdb</code> with no arguments or options; but the most
usual way to start <small>GDB</small> is with one argument or two, specifying an
executable program as the argument:
</p>
<div class="smallexample">
<pre class="smallexample">gdb program
</pre></div>

<p>You can also start with both an executable program and a core file specified:
</p>
<div class="smallexample">
<pre class="smallexample">gdb program core
</pre></div>

<p>You can, instead, specify a process ID as a second argument or use option
<code>-p</code>, if you want to debug a running process:
</p>
<div class="smallexample">
<pre class="smallexample">gdb program 1234
gdb -p 1234
</pre></div>

<p>would attach <small>GDB</small> to process <code>1234</code>.  With option <samp>-p</samp> you
can omit the <var>program</var> filename.
</p>
<p>Here are some of the most frequently needed <small>GDB</small> commands:
</p>
<dl compact="compact">
<dt><code>break [<var>file</var>:][<var>function</var>|<var>line</var>]</code></dt>
<dd><p>Set a breakpoint at <var>function</var> or <var>line</var> (in <var>file</var>).
</p>
</dd>
<dt><code>run [<var>arglist</var>]</code></dt>
<dd><p>Start your program (with <var>arglist</var>, if specified).
</p>
</dd>
<dt><code>bt</code></dt>
<dd><p>Backtrace: display the program stack.
</p>
</dd>
<dt><code>print <var>expr</var></code></dt>
<dd><p>Display the value of an expression.
</p>
</dd>
<dt><code>c</code></dt>
<dd><p>Continue running your program (after stopping, e.g. at a breakpoint).
</p>
</dd>
<dt><code>next</code></dt>
<dd><p>Execute next program line (after stopping); step <em>over</em> any
function calls in the line.
</p>
</dd>
<dt><code>edit [<var>file</var>:]<var>function</var></code></dt>
<dd><p>look at the program line where it is presently stopped.
</p>
</dd>
<dt><code>list [<var>file</var>:]<var>function</var></code></dt>
<dd><p>type the text of the program in the vicinity of where it is presently stopped.
</p>
</dd>
<dt><code>step</code></dt>
<dd><p>Execute next program line (after stopping); step <em>into</em> any
function calls in the line.
</p>
</dd>
<dt><code>help [<var>name</var>]</code></dt>
<dd><p>Show information about <small>GDB</small> command <var>name</var>, or general information
about using <small>GDB</small>.
</p>
</dd>
<dt><code>quit</code></dt>
<dt><code>exit</code></dt>
<dd><p>Exit from <small>GDB</small>.
</p></dd>
</dl>


<p>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 <samp>--se</samp> option, and the second,
if any, is equivalent to a <samp>-c</samp> option if it&rsquo;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.
</p>
<p>The abbreviated forms are shown here with &lsquo;<samp>-</samp>&rsquo; and long forms are shown
with &lsquo;<samp>--</samp>&rsquo; to reflect how they are shown in <samp>--help</samp>. However,
<small>GDB</small> recognizes all of the following conventions for most options:
</p>
<dl compact="compact">
<dt><code>--option=<var>value</var></code></dt>
<dt><code>--option <var>value</var></code></dt>
<dt><code>-option=<var>value</var></code></dt>
<dt><code>-option <var>value</var></code></dt>
<dt><code>--o=<var>value</var></code></dt>
<dt><code>--o <var>value</var></code></dt>
<dt><code>-o=<var>value</var></code></dt>
<dt><code>-o <var>value</var></code></dt>
</dl>

<p>All the options and command line arguments you give are processed
in sequential order.  The order makes a difference when the <samp>-x</samp>
option is used.
</p>
<dl compact="compact">
<dt><code>--help</code></dt>
<dt><code>-h</code></dt>
<dd><p>List all options, with brief explanations.
</p>
</dd>
<dt><code>--symbols=<var>file</var></code></dt>
<dt><code>-s <var>file</var></code></dt>
<dd><p>Read symbol table from <var>file</var>.
</p>
</dd>
<dt><code>--write</code></dt>
<dd><p>Enable writing into executable and core files.
</p>
</dd>
<dt><code>--exec=<var>file</var></code></dt>
<dt><code>-e <var>file</var></code></dt>
<dd><p>Use <var>file</var> as the executable file to execute when
appropriate, and for examining pure data in conjunction with a core
dump.
</p>
</dd>
<dt><code>--se=<var>file</var></code></dt>
<dd><p>Read symbol table from <var>file</var> and use it as the executable
file.
</p>
</dd>
<dt><code>--core=<var>file</var></code></dt>
<dt><code>-c <var>file</var></code></dt>
<dd><p>Use <var>file</var> as a core dump to examine.
</p>
</dd>
<dt><code>--command=<var>file</var></code></dt>
<dt><code>-x <var>file</var></code></dt>
<dd><p>Execute <small>GDB</small> commands from <var>file</var>.
</p>
</dd>
<dt><code>--eval-command=<var>command</var></code></dt>
<dt><code>-ex <var>command</var></code></dt>
<dd><p>Execute given <small>GDB</small> <var>command</var>.
</p>
</dd>
<dt><code>--init-eval-command=<var>command</var></code></dt>
<dt><code>-iex</code></dt>
<dd><p>Execute <small>GDB</small> <var>command</var> before loading the inferior.
</p>
</dd>
<dt><code>--directory=<var>directory</var></code></dt>
<dt><code>-d <var>directory</var></code></dt>
<dd><p>Add <var>directory</var> to the path to search for source files.
</p>
</dd>
<dt><code>--nh</code></dt>
<dd><p>Do not execute commands from <samp>~/.config/gdb/gdbinit</samp>,
<samp>~/.gdbinit</samp>, <samp>~/.config/gdb/gdbearlyinit</samp>, or
<samp>~/.gdbearlyinit</samp>
</p>
</dd>
<dt><code>--nx</code></dt>
<dt><code>-n</code></dt>
<dd><p>Do not execute commands from any <samp>.gdbinit</samp> or
<samp>.gdbearlyinit</samp> initialization files.
</p>
</dd>
<dt><code>--quiet</code></dt>
<dt><code>--silent</code></dt>
<dt><code>-q</code></dt>
<dd><p>&ldquo;Quiet&rdquo;.  Do not print the introductory and copyright messages.  These
messages are also suppressed in batch mode.
</p>
</dd>
<dt><code>--batch</code></dt>
<dd><p>Run in batch mode.  Exit with status <code>0</code> after processing all the command
files specified with <samp>-x</samp> (and <samp>.gdbinit</samp>, if not inhibited).
Exit with nonzero status if an error occurs in executing the <small>GDB</small>
commands in the command files.
</p>
<p>Batch mode may be useful for running <small>GDB</small> as a filter, for example to
download and run a program on another computer; in order to make this
more useful, the message
</p>
<div class="smallexample">
<pre class="smallexample">Program exited normally.
</pre></div>

<p>(which is ordinarily issued whenever a program running under <small>GDB</small> control
terminates) is not issued when running in batch mode.
</p>
</dd>
<dt><code>--batch-silent</code></dt>
<dd><p>Run in batch mode, just like <samp>--batch</samp>, but totally silent.  All <small>GDB</small>
output is supressed (stderr is unaffected).  This is much quieter than
<samp>--silent</samp> and would be useless for an interactive session.
</p>
<p>This is particularly useful when using targets that give &lsquo;<samp>Loading section</samp>&rsquo;
messages, for example.
</p>
<p>Note that targets that give their output via <small>GDB</small>, as opposed to writing
directly to <code>stdout</code>, will also be made silent.
</p>
</dd>
<dt><code>--args <var>prog</var> [<var>arglist</var>]</code></dt>
<dd><p>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:
</p>
<div class="smallexample">
<pre class="smallexample">gdb ./a.out -q
</pre></div>

<p>It would start <small>GDB</small> with <samp>-q</samp>, not printing the introductory message.  On
the other hand, using:
</p>
<div class="smallexample">
<pre class="smallexample">gdb --args ./a.out -q
</pre></div>

<p>starts <small>GDB</small> with the introductory message, and passes the option to the inferior.
</p>
</dd>
<dt><code>--pid=<var>pid</var></code></dt>
<dd><p>Attach <small>GDB</small> to an already running program, with the PID <var>pid</var>.
</p>
</dd>
<dt><code>--tui</code></dt>
<dd><p>Open the terminal user interface.
</p>
</dd>
<dt><code>--readnow</code></dt>
<dd><p>Read all symbols from the given symfile on the first access.
</p>
</dd>
<dt><code>--readnever</code></dt>
<dd><p>Do not read symbol files.
</p>
</dd>
<dt><code>--return-child-result</code></dt>
<dd><p><small>GDB</small>&rsquo;s exit code will be the same as the child&rsquo;s exit code.
</p>
</dd>
<dt><code>--configuration</code></dt>
<dd><p>Print details about GDB configuration and then exit.
</p>
</dd>
<dt><code>--version</code></dt>
<dd><p>Print version information and then exit.
</p>
</dd>
<dt><code>--cd=<var>directory</var></code></dt>
<dd><p>Run <small>GDB</small> using <var>directory</var> as its working directory,
instead of the current directory.
</p>
</dd>
<dt><code>--data-directory=<var>directory</var></code></dt>
<dt><code>-D</code></dt>
<dd><p>Run <small>GDB</small> using <var>directory</var> as its data directory.  The data
directory is where <small>GDB</small> searches for its auxiliary files.
</p>
</dd>
<dt><code>--fullname</code></dt>
<dt><code>-f</code></dt>
<dd><p>Emacs sets this option when it runs <small>GDB</small> as a subprocess.  It tells
<small>GDB</small> 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 &lsquo;<samp>\032</samp>&rsquo; characters, followed by the file name, line number
and character position separated by colons, and a newline.  The
Emacs-to-<small>GDB</small> interface program uses the two &lsquo;<samp>\032</samp>&rsquo;
characters as a signal to display the source code for the frame.
</p>
</dd>
<dt><code>-b <var>baudrate</var></code></dt>
<dd><p>Set the line speed (baud rate or bits per second) of any serial
interface used by <small>GDB</small> for remote debugging.
</p>
</dd>
<dt><code>-l <var>timeout</var></code></dt>
<dd><p>Set timeout, in seconds, for remote debugging.
</p>
</dd>
<dt><code>--tty=<var>device</var></code></dt>
<dd><p>Run using <var>device</var> for your program&rsquo;s standard input and output.
</p></dd>
</dl>


<hr>
<div class="header">
<p>
Next: <a href="gdbserver-man.html#gdbserver-man" accesskey="n" rel="next">gdbserver man</a>, Up: <a href="Man-Pages.html#Man-Pages" accesskey="u" rel="up">Man Pages</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>