1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Invoking GDB</title>
18
19<meta name="description" content="Debugging with GDB: Invoking GDB">
20<meta name="keywords" content="Debugging with GDB: Invoking GDB">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Invocation.html#Invocation" rel="up" title="Invocation">
29<link href="File-Options.html#File-Options" rel="next" title="File Options">
30<link href="Invocation.html#Invocation" rel="previous" title="Invocation">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Invoking-GDB"></a>
65<div class="header">
66<p>
67Next: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="n" rel="next">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</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>
68</div>
69<hr>
70<a name="Invoking-GDB-1"></a>
71<h3 class="section">2.1 Invoking <small>GDB</small></h3>
72
73<p>Invoke <small>GDB</small> by running the program <code>gdb</code>.  Once started,
74<small>GDB</small> reads commands from the terminal until you tell it to exit.
75</p>
76<p>You can also run <code>gdb</code> with a variety of arguments and options,
77to specify more of your debugging environment at the outset.
78</p>
79<p>The command-line options described here are designed
80to cover a variety of situations; in some environments, some of these
81options may effectively be unavailable.
82</p>
83<p>The most usual way to start <small>GDB</small> is with one argument,
84specifying an executable program:
85</p>
86<div class="smallexample">
87<pre class="smallexample">gdb <var>program</var>
88</pre></div>
89
90<p>You can also start with both an executable program and a core file
91specified:
92</p>
93<div class="smallexample">
94<pre class="smallexample">gdb <var>program</var> <var>core</var>
95</pre></div>
96
97<p>You can, instead, specify a process ID as a second argument or use option
98<code>-p</code>, if you want to debug a running process:
99</p>
100<div class="smallexample">
101<pre class="smallexample">gdb <var>program</var> 1234
102gdb -p 1234
103</pre></div>
104
105<p>would attach <small>GDB</small> to process <code>1234</code>.  With option <samp>-p</samp> you
106can omit the <var>program</var> filename.
107</p>
108<p>Taking advantage of the second command-line argument requires a fairly
109complete operating system; when you use <small>GDB</small> as a remote
110debugger attached to a bare board, there may not be any notion of
111&ldquo;process&rdquo;, and there is often no way to get a core dump.  <small>GDB</small>
112will warn you if it is unable to attach or to read core dumps.
113</p>
114<p>You can optionally have <code>gdb</code> pass any arguments after the
115executable file to the inferior using <code>--args</code>.  This option stops
116option processing.
117</p><div class="smallexample">
118<pre class="smallexample">gdb --args gcc -O2 -c foo.c
119</pre></div>
120<p>This will cause <code>gdb</code> to debug <code>gcc</code>, and to set
121<code>gcc</code>&rsquo;s command-line arguments (see <a href="Arguments.html#Arguments">Arguments</a>) to &lsquo;<samp>-O2 -c foo.c</samp>&rsquo;.
122</p>
123<p>You can run <code>gdb</code> without printing the front material, which describes
124<small>GDB</small>&rsquo;s non-warranty, by specifying <code>--silent</code>
125(or <code>-q</code>/<code>--quiet</code>):
126</p>
127<div class="smallexample">
128<pre class="smallexample">gdb --silent
129</pre></div>
130
131<p>You can further control how <small>GDB</small> starts up by using command-line
132options.  <small>GDB</small> itself can remind you of the options available.
133</p>
134<p>Type
135</p>
136<div class="smallexample">
137<pre class="smallexample">gdb -help
138</pre></div>
139
140<p>to display all available options and briefly describe their use
141(&lsquo;<samp>gdb -h</samp>&rsquo; is a shorter equivalent).
142</p>
143<p>All options and command line arguments you give are processed
144in sequential order.  The order makes a difference when the
145&lsquo;<samp>-x</samp>&rsquo; option is used.
146</p>
147
148<table class="menu" border="0" cellspacing="0">
149<tr><td align="left" valign="top">&bull; <a href="File-Options.html#File-Options" accesskey="1">File Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Choosing files
150</td></tr>
151<tr><td align="left" valign="top">&bull; <a href="Mode-Options.html#Mode-Options" accesskey="2">Mode Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Choosing modes
152</td></tr>
153<tr><td align="left" valign="top">&bull; <a href="Startup.html#Startup" accesskey="3">Startup</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">What <small>GDB</small> does during startup
154</td></tr>
155</table>
156
157<hr>
158<div class="header">
159<p>
160Next: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="n" rel="next">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</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>
161</div>
162
163
164
165</body>
166</html>
167