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: Remote Stub</title>
18
19<meta name="description" content="Debugging with GDB: Remote Stub">
20<meta name="keywords" content="Debugging with GDB: Remote Stub">
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="Remote-Debugging.html#Remote-Debugging" rel="up" title="Remote Debugging">
29<link href="Stub-Contents.html#Stub-Contents" rel="next" title="Stub Contents">
30<link href="Remote-Configuration.html#Remote-Configuration" rel="previous" title="Remote Configuration">
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="Remote-Stub"></a>
65<div class="header">
66<p>
67Previous: <a href="Remote-Configuration.html#Remote-Configuration" accesskey="p" rel="previous">Remote Configuration</a>, Up: <a href="Remote-Debugging.html#Remote-Debugging" accesskey="u" rel="up">Remote Debugging</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="Implementing-a-Remote-Stub"></a>
71<h3 class="section">20.5 Implementing a Remote Stub</h3>
72
73<a name="index-debugging-stub_002c-example"></a>
74<a name="index-remote-stub_002c-example"></a>
75<a name="index-stub-example_002c-remote-debugging"></a>
76<p>The stub files provided with <small>GDB</small> implement the target side of the
77communication protocol, and the <small>GDB</small> side is implemented in the
78<small>GDB</small> source file <samp>remote.c</samp>.  Normally, you can simply allow
79these subroutines to communicate, and ignore the details.  (If you&rsquo;re
80implementing your own stub file, you can still ignore the details: start
81with one of the existing stub files.  <samp>sparc-stub.c</samp> is the best
82organized, and therefore the easiest to read.)
83</p>
84<a name="index-remote-serial-debugging_002c-overview"></a>
85<p>To debug a program running on another machine (the debugging
86<em>target</em> machine), you must first arrange for all the usual
87prerequisites for the program to run by itself.  For example, for a C
88program, you need:
89</p>
90<ol>
91<li> A startup routine to set up the C runtime environment; these usually
92have a name like <samp>crt0</samp>.  The startup routine may be supplied by
93your hardware supplier, or you may have to write your own.
94
95</li><li> A C subroutine library to support your program&rsquo;s
96subroutine calls, notably managing input and output.
97
98</li><li> A way of getting your program to the other machine&mdash;for example, a
99download program.  These are often supplied by the hardware
100manufacturer, but you may have to write your own from hardware
101documentation.
102</li></ol>
103
104<p>The next step is to arrange for your program to use a serial port to
105communicate with the machine where <small>GDB</small> is running (the <em>host</em>
106machine).  In general terms, the scheme looks like this:
107</p>
108<dl compact="compact">
109<dt><em>On the host,</em></dt>
110<dd><p><small>GDB</small> already understands how to use this protocol; when everything
111else is set up, you can simply use the &lsquo;<samp>target remote</samp>&rsquo; command
112(see <a href="Targets.html#Targets">Specifying a Debugging Target</a>).
113</p>
114</dd>
115<dt><em>On the target,</em></dt>
116<dd><p>you must link with your program a few special-purpose subroutines that
117implement the <small>GDB</small> remote serial protocol.  The file containing these
118subroutines is called  a <em>debugging stub</em>.
119</p>
120<p>On certain remote targets, you can use an auxiliary program
121<code>gdbserver</code> instead of linking a stub into your program.
122See <a href="Server.html#Server">Using the <code>gdbserver</code> Program</a>, for details.
123</p></dd>
124</dl>
125
126<p>The debugging stub is specific to the architecture of the remote
127machine; for example, use <samp>sparc-stub.c</samp> to debug programs on
128<small>SPARC</small> boards.
129</p>
130<a name="index-remote-serial-stub-list"></a>
131<p>These working remote stubs are distributed with <small>GDB</small>:
132</p>
133<dl compact="compact">
134<dt><code>i386-stub.c</code></dt>
135<dd><a name="index-i386_002dstub_002ec"></a>
136<a name="index-Intel"></a>
137<a name="index-i386"></a>
138<p>For Intel 386 and compatible architectures.
139</p>
140</dd>
141<dt><code>m68k-stub.c</code></dt>
142<dd><a name="index-m68k_002dstub_002ec"></a>
143<a name="index-Motorola-680x0"></a>
144<a name="index-m680x0"></a>
145<p>For Motorola 680x0 architectures.
146</p>
147</dd>
148<dt><code>sh-stub.c</code></dt>
149<dd><a name="index-sh_002dstub_002ec"></a>
150<a name="index-Renesas"></a>
151<a name="index-SH"></a>
152<p>For Renesas SH architectures.
153</p>
154</dd>
155<dt><code>sparc-stub.c</code></dt>
156<dd><a name="index-sparc_002dstub_002ec"></a>
157<a name="index-Sparc"></a>
158<p>For <small>SPARC</small> architectures.
159</p>
160</dd>
161<dt><code>sparcl-stub.c</code></dt>
162<dd><a name="index-sparcl_002dstub_002ec"></a>
163<a name="index-Fujitsu"></a>
164<a name="index-SparcLite"></a>
165<p>For Fujitsu <small>SPARCLITE</small> architectures.
166</p>
167</dd>
168</dl>
169
170<p>The <samp>README</samp> file in the <small>GDB</small> distribution may list other
171recently added stubs.
172</p>
173<table class="menu" border="0" cellspacing="0">
174<tr><td align="left" valign="top">&bull; <a href="Stub-Contents.html#Stub-Contents" accesskey="1">Stub Contents</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">What the stub can do for you
175</td></tr>
176<tr><td align="left" valign="top">&bull; <a href="Bootstrapping.html#Bootstrapping" accesskey="2">Bootstrapping</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">What you must do for the stub
177</td></tr>
178<tr><td align="left" valign="top">&bull; <a href="Debug-Session.html#Debug-Session" accesskey="3">Debug Session</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Putting it all together
179</td></tr>
180</table>
181
182<hr>
183<div class="header">
184<p>
185Previous: <a href="Remote-Configuration.html#Remote-Configuration" accesskey="p" rel="previous">Remote Configuration</a>, Up: <a href="Remote-Debugging.html#Remote-Debugging" accesskey="u" rel="up">Remote Debugging</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>
186</div>
187
188
189
190</body>
191</html>
192