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: Target Commands</title>
18
19<meta name="description" content="Debugging with GDB: Target Commands">
20<meta name="keywords" content="Debugging with GDB: Target Commands">
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="Targets.html#Targets" rel="up" title="Targets">
29<link href="Byte-Order.html#Byte-Order" rel="next" title="Byte Order">
30<link href="Active-Targets.html#Active-Targets" rel="previous" title="Active Targets">
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="Target-Commands"></a>
65<div class="header">
66<p>
67Next: <a href="Byte-Order.html#Byte-Order" accesskey="n" rel="next">Byte Order</a>, Previous: <a href="Active-Targets.html#Active-Targets" accesskey="p" rel="previous">Active Targets</a>, Up: <a href="Targets.html#Targets" accesskey="u" rel="up">Targets</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="Commands-for-Managing-Targets"></a>
71<h3 class="section">19.2 Commands for Managing Targets</h3>
72
73<dl compact="compact">
74<dt><code>target <var>type</var> <var>parameters</var></code></dt>
75<dd><p>Connects the <small>GDB</small> host environment to a target machine or
76process.  A target is typically a protocol for talking to debugging
77facilities.  You use the argument <var>type</var> to specify the type or
78protocol of the target machine.
79</p>
80<p>Further <var>parameters</var> are interpreted by the target protocol, but
81typically include things like device names or host names to connect
82with, process numbers, and baud rates.
83</p>
84<p>The <code>target</code> command does not repeat if you press <tt class="key">RET</tt> again
85after executing the command.
86</p>
87<a name="index-help-target"></a>
88</dd>
89<dt><code>help target</code></dt>
90<dd><p>Displays the names of all targets available.  To display targets
91currently selected, use either <code>info target</code> or <code>info files</code>
92(see <a href="Files.html#Files">Commands to Specify Files</a>).
93</p>
94</dd>
95<dt><code>help target <var>name</var></code></dt>
96<dd><p>Describe a particular target, including any parameters necessary to
97select it.
98</p>
99<a name="index-set-gnutarget"></a>
100</dd>
101<dt><code>set gnutarget <var>args</var></code></dt>
102<dd><p><small>GDB</small> uses its own library BFD to read your files.  <small>GDB</small>
103knows whether it is reading an <em>executable</em>,
104a <em>core</em>, or a <em>.o</em> file; however, you can specify the file format
105with the <code>set gnutarget</code> command.  Unlike most <code>target</code> commands,
106with <code>gnutarget</code> the <code>target</code> refers to a program, not a machine.
107</p>
108<blockquote>
109<p><em>Warning:</em> To specify a file format with <code>set gnutarget</code>,
110you must know the actual BFD name.
111</p></blockquote>
112
113<p>See <a href="Files.html#Files">Commands to Specify Files</a>.
114</p>
115<a name="index-show-gnutarget"></a>
116</dd>
117<dt><code>show gnutarget</code></dt>
118<dd><p>Use the <code>show gnutarget</code> command to display what file format
119<code>gnutarget</code> is set to read.  If you have not set <code>gnutarget</code>,
120<small>GDB</small> will determine the file format for each file automatically,
121and <code>show gnutarget</code> displays &lsquo;<samp>The current BFD target is &quot;auto&quot;</samp>&rsquo;.
122</p></dd>
123</dl>
124
125<a name="index-common-targets"></a>
126<p>Here are some common targets (available, or not, depending on the GDB
127configuration):
128</p>
129<dl compact="compact">
130<dd><a name="index-target"></a>
131</dd>
132<dt><code>target exec <var>program</var></code></dt>
133<dd><a name="index-executable-file-target"></a>
134<p>An executable file.  &lsquo;<samp>target exec <var>program</var></samp>&rsquo; is the same as
135&lsquo;<samp>exec-file <var>program</var></samp>&rsquo;.
136</p>
137</dd>
138<dt><code>target core <var>filename</var></code></dt>
139<dd><a name="index-core-dump-file-target"></a>
140<p>A core dump file.  &lsquo;<samp>target core <var>filename</var></samp>&rsquo; is the same as
141&lsquo;<samp>core-file <var>filename</var></samp>&rsquo;.
142</p>
143</dd>
144<dt><code>target remote <var>medium</var></code></dt>
145<dd><a name="index-remote-target"></a>
146<p>A remote system connected to <small>GDB</small> via a serial line or network
147connection.  This command tells <small>GDB</small> to use its own remote
148protocol over <var>medium</var> for debugging.  See <a href="Remote-Debugging.html#Remote-Debugging">Remote Debugging</a>.
149</p>
150<p>For example, if you have a board connected to <samp>/dev/ttya</samp> on the
151machine running <small>GDB</small>, you could say:
152</p>
153<div class="smallexample">
154<pre class="smallexample">target remote /dev/ttya
155</pre></div>
156
157<p><code>target remote</code> supports the <code>load</code> command.  This is only
158useful if you have some other way of getting the stub to the target
159system, and you can put it somewhere in memory where it won&rsquo;t get
160clobbered by the download.
161</p>
162</dd>
163<dt><code>target sim <span class="roman">[</span><var>simargs</var><span class="roman">]</span> &hellip;</code></dt>
164<dd><a name="index-built_002din-simulator-target"></a>
165<p>Builtin CPU simulator.  <small>GDB</small> includes simulators for most architectures.
166In general,
167</p><div class="smallexample">
168<pre class="smallexample">        target sim
169        load
170        run
171</pre></div>
172<p>works; however, you cannot assume that a specific memory map, device
173drivers, or even basic I/O is available, although some simulators do
174provide these.  For info about any processor-specific simulator details,
175see the appropriate section in <a href="Embedded-Processors.html#Embedded-Processors">Embedded
176Processors</a>.
177</p>
178</dd>
179<dt><code>target native</code></dt>
180<dd><a name="index-native-target"></a>
181<p>Setup for local/native process debugging.  Useful to make the
182<code>run</code> command spawn native processes (likewise <code>attach</code>,
183etc.) even when <code>set auto-connect-native-target</code> is <code>off</code>
184(see <a href="Starting.html#set-auto_002dconnect_002dnative_002dtarget">set auto-connect-native-target</a>).
185</p>
186</dd>
187</dl>
188
189<p>Different targets are available on different configurations of <small>GDB</small>;
190your configuration may have more or fewer targets.
191</p>
192<p>Many remote targets require you to download the executable&rsquo;s code once
193you&rsquo;ve successfully established a connection.  You may wish to control
194various aspects of this process.
195</p>
196<dl compact="compact">
197<dt><code>set hash</code></dt>
198<dd><a name="index-set-hash_002c-for-remote-monitors"></a>
199<a name="index-hash-mark-while-downloading"></a>
200<p>This command controls whether a hash mark &lsquo;<samp>#</samp>&rsquo; is displayed while
201downloading a file to the remote monitor.  If on, a hash mark is
202displayed after each S-record is successfully downloaded to the
203monitor.
204</p>
205</dd>
206<dt><code>show hash</code></dt>
207<dd><a name="index-show-hash_002c-for-remote-monitors"></a>
208<p>Show the current status of displaying the hash mark.
209</p>
210</dd>
211<dt><code>set debug monitor</code></dt>
212<dd><a name="index-set-debug-monitor"></a>
213<a name="index-display-remote-monitor-communications"></a>
214<p>Enable or disable display of communications messages between
215<small>GDB</small> and the remote monitor.
216</p>
217</dd>
218<dt><code>show debug monitor</code></dt>
219<dd><a name="index-show-debug-monitor"></a>
220<p>Show the current status of displaying communications between
221<small>GDB</small> and the remote monitor.
222</p></dd>
223</dl>
224
225<dl compact="compact">
226<dd>
227<a name="index-load-filename-offset"></a>
228</dd>
229<dt><code>load <var>filename</var> <var>offset</var></code></dt>
230<dd><a name="load"></a><p>Depending on what remote debugging facilities are configured into
231<small>GDB</small>, the <code>load</code> command may be available.  Where it exists, it
232is meant to make <var>filename</var> (an executable) available for debugging
233on the remote system&mdash;by downloading, or dynamic linking, for example.
234<code>load</code> also records the <var>filename</var> symbol table in <small>GDB</small>, like
235the <code>add-symbol-file</code> command.
236</p>
237<p>If your <small>GDB</small> does not have a <code>load</code> command, attempting to
238execute it gets the error message &ldquo;<code>You can't do that when your
239target is &hellip;</code>&rdquo;
240</p>
241<p>The file is loaded at whatever address is specified in the executable.
242For some object file formats, you can specify the load address when you
243link the program; for other formats, like a.out, the object file format
244specifies a fixed address.
245</p>
246<p>It is also possible to tell <small>GDB</small> to load the executable file at a
247specific offset described by the optional argument <var>offset</var>.  When
248<var>offset</var> is provided, <var>filename</var> must also be provided.
249</p>
250<p>Depending on the remote side capabilities, <small>GDB</small> may be able to
251load programs into flash memory.
252</p>
253<p><code>load</code> does not repeat if you press <tt class="key">RET</tt> again after using it.
254</p></dd>
255</dl>
256
257<dl compact="compact">
258<dd>
259<a name="index-flash_002derase"></a>
260</dd>
261<dt><code>flash-erase</code></dt>
262<dd><a name="flash_002derase"></a>
263<p>Erases all known flash memory regions on the target.
264</p>
265</dd>
266</dl>
267
268<hr>
269<div class="header">
270<p>
271Next: <a href="Byte-Order.html#Byte-Order" accesskey="n" rel="next">Byte Order</a>, Previous: <a href="Active-Targets.html#Active-Targets" accesskey="p" rel="previous">Active Targets</a>, Up: <a href="Targets.html#Targets" accesskey="u" rel="up">Targets</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>
272</div>
273
274
275
276</body>
277</html>
278