Remote-Stub.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Remote Stub</title>
  16. <meta name="description" content="Debugging with GDB: Remote Stub">
  17. <meta name="keywords" content="Debugging with GDB: Remote Stub">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Remote-Debugging.html#Remote-Debugging" rel="up" title="Remote Debugging">
  26. <link href="Stub-Contents.html#Stub-Contents" rel="next" title="Stub Contents">
  27. <link href="Remote-Configuration.html#Remote-Configuration" rel="previous" title="Remote Configuration">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Remote-Stub"></a>
  59. <div class="header">
  60. <p>
  61. Previous: <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>
  62. </div>
  63. <hr>
  64. <a name="Implementing-a-Remote-Stub"></a>
  65. <h3 class="section">20.5 Implementing a Remote Stub</h3>
  66. <a name="index-debugging-stub_002c-example"></a>
  67. <a name="index-remote-stub_002c-example"></a>
  68. <a name="index-stub-example_002c-remote-debugging"></a>
  69. <p>The stub files provided with <small>GDB</small> implement the target side of the
  70. communication protocol, and the <small>GDB</small> side is implemented in the
  71. <small>GDB</small> source file <samp>remote.c</samp>. Normally, you can simply allow
  72. these subroutines to communicate, and ignore the details. (If you&rsquo;re
  73. implementing your own stub file, you can still ignore the details: start
  74. with one of the existing stub files. <samp>sparc-stub.c</samp> is the best
  75. organized, and therefore the easiest to read.)
  76. </p>
  77. <a name="index-remote-serial-debugging_002c-overview"></a>
  78. <p>To debug a program running on another machine (the debugging
  79. <em>target</em> machine), you must first arrange for all the usual
  80. prerequisites for the program to run by itself. For example, for a C
  81. program, you need:
  82. </p>
  83. <ol>
  84. <li> A startup routine to set up the C runtime environment; these usually
  85. have a name like <samp>crt0</samp>. The startup routine may be supplied by
  86. your hardware supplier, or you may have to write your own.
  87. </li><li> A C subroutine library to support your program&rsquo;s
  88. subroutine calls, notably managing input and output.
  89. </li><li> A way of getting your program to the other machine&mdash;for example, a
  90. download program. These are often supplied by the hardware
  91. manufacturer, but you may have to write your own from hardware
  92. documentation.
  93. </li></ol>
  94. <p>The next step is to arrange for your program to use a serial port to
  95. communicate with the machine where <small>GDB</small> is running (the <em>host</em>
  96. machine). In general terms, the scheme looks like this:
  97. </p>
  98. <dl compact="compact">
  99. <dt><em>On the host,</em></dt>
  100. <dd><p><small>GDB</small> already understands how to use this protocol; when everything
  101. else is set up, you can simply use the &lsquo;<samp>target remote</samp>&rsquo; command
  102. (see <a href="Targets.html#Targets">Specifying a Debugging Target</a>).
  103. </p>
  104. </dd>
  105. <dt><em>On the target,</em></dt>
  106. <dd><p>you must link with your program a few special-purpose subroutines that
  107. implement the <small>GDB</small> remote serial protocol. The file containing these
  108. subroutines is called a <em>debugging stub</em>.
  109. </p>
  110. <p>On certain remote targets, you can use an auxiliary program
  111. <code>gdbserver</code> instead of linking a stub into your program.
  112. See <a href="Server.html#Server">Using the <code>gdbserver</code> Program</a>, for details.
  113. </p></dd>
  114. </dl>
  115. <p>The debugging stub is specific to the architecture of the remote
  116. machine; for example, use <samp>sparc-stub.c</samp> to debug programs on
  117. <small>SPARC</small> boards.
  118. </p>
  119. <a name="index-remote-serial-stub-list"></a>
  120. <p>These working remote stubs are distributed with <small>GDB</small>:
  121. </p>
  122. <dl compact="compact">
  123. <dt><code>i386-stub.c</code></dt>
  124. <dd><a name="index-i386_002dstub_002ec"></a>
  125. <a name="index-Intel"></a>
  126. <a name="index-i386"></a>
  127. <p>For Intel 386 and compatible architectures.
  128. </p>
  129. </dd>
  130. <dt><code>m68k-stub.c</code></dt>
  131. <dd><a name="index-m68k_002dstub_002ec"></a>
  132. <a name="index-Motorola-680x0"></a>
  133. <a name="index-m680x0"></a>
  134. <p>For Motorola 680x0 architectures.
  135. </p>
  136. </dd>
  137. <dt><code>sh-stub.c</code></dt>
  138. <dd><a name="index-sh_002dstub_002ec"></a>
  139. <a name="index-Renesas"></a>
  140. <a name="index-SH"></a>
  141. <p>For Renesas SH architectures.
  142. </p>
  143. </dd>
  144. <dt><code>sparc-stub.c</code></dt>
  145. <dd><a name="index-sparc_002dstub_002ec"></a>
  146. <a name="index-Sparc"></a>
  147. <p>For <small>SPARC</small> architectures.
  148. </p>
  149. </dd>
  150. <dt><code>sparcl-stub.c</code></dt>
  151. <dd><a name="index-sparcl_002dstub_002ec"></a>
  152. <a name="index-Fujitsu"></a>
  153. <a name="index-SparcLite"></a>
  154. <p>For Fujitsu <small>SPARCLITE</small> architectures.
  155. </p>
  156. </dd>
  157. </dl>
  158. <p>The <samp>README</samp> file in the <small>GDB</small> distribution may list other
  159. recently added stubs.
  160. </p>
  161. <table class="menu" border="0" cellspacing="0">
  162. <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
  163. </td></tr>
  164. <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
  165. </td></tr>
  166. <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
  167. </td></tr>
  168. </table>
  169. <hr>
  170. <div class="header">
  171. <p>
  172. Previous: <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>
  173. </div>
  174. </body>
  175. </html>