Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Overview.html 11KB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Overview (Debugging with GDB)</title>
  17. <meta name="description" content="Overview (Debugging with GDB)">
  18. <meta name="keywords" content="Overview (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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-Protocol.html#Remote-Protocol" rel="up" title="Remote Protocol">
  26. <link href="Packets.html#Packets" rel="next" title="Packets">
  27. <link href="Remote-Protocol.html#Remote-Protocol" rel="prev" title="Remote Protocol">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Overview"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Packets.html#Packets" accesskey="n" rel="next">Packets</a>, Up: <a href="Remote-Protocol.html#Remote-Protocol" accesskey="u" rel="up">Remote Protocol</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>
  61. </div>
  62. <hr>
  63. <a name="Overview-1"></a>
  64. <h3 class="section">E.1 Overview</h3>
  65. <p>There may be occasions when you need to know something about the
  66. protocol&mdash;for example, if there is only one serial port to your target
  67. machine, you might want your program to do something special if it
  68. recognizes a packet meant for <small>GDB</small>.
  69. </p>
  70. <p>In the examples below, &lsquo;<samp>-&gt;</samp>&rsquo; and &lsquo;<samp>&lt;-</samp>&rsquo; are used to indicate
  71. transmitted and received data, respectively.
  72. </p>
  73. <a name="index-protocol_002c-GDB-remote-serial"></a>
  74. <a name="index-serial-protocol_002c-GDB-remote"></a>
  75. <a name="index-remote-serial-protocol"></a>
  76. <p>All <small>GDB</small> commands and responses (other than acknowledgments
  77. and notifications, see <a href="Notification-Packets.html#Notification-Packets">Notification Packets</a>) are sent as a
  78. <var>packet</var>. A <var>packet</var> is introduced with the character
  79. &lsquo;<samp>$</samp>&rsquo;, the actual <var>packet-data</var>, and the terminating character
  80. &lsquo;<samp>#</samp>&rsquo; followed by a two-digit <var>checksum</var>:
  81. </p>
  82. <div class="smallexample">
  83. <pre class="smallexample"><code>$</code><var>packet-data</var><code>#</code><var>checksum</var>
  84. </pre></div>
  85. <a name="index-checksum_002c-for-GDB-remote"></a>
  86. <p>The two-digit <var>checksum</var> is computed as the modulo 256 sum of all
  87. characters between the leading &lsquo;<samp>$</samp>&rsquo; and the trailing &lsquo;<samp>#</samp>&rsquo; (an
  88. eight bit unsigned checksum).
  89. </p>
  90. <p>Implementors should note that prior to <small>GDB</small> 5.0 the protocol
  91. specification also included an optional two-digit <var>sequence-id</var>:
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample"><code>$</code><var>sequence-id</var><code>:</code><var>packet-data</var><code>#</code><var>checksum</var>
  95. </pre></div>
  96. <a name="index-sequence_002did_002c-for-GDB-remote"></a>
  97. <p>That <var>sequence-id</var> was appended to the acknowledgment. <small>GDB</small>
  98. has never output <var>sequence-id</var>s. Stubs that handle packets added
  99. since <small>GDB</small> 5.0 must not accept <var>sequence-id</var>.
  100. </p>
  101. <p>When either the host or the target machine receives a packet, the first
  102. response expected is an acknowledgment: either &lsquo;<samp>+</samp>&rsquo; (to indicate
  103. the package was received correctly) or &lsquo;<samp>-</samp>&rsquo; (to request
  104. retransmission):
  105. </p>
  106. <div class="smallexample">
  107. <pre class="smallexample">-&gt; <code>$</code><var>packet-data</var><code>#</code><var>checksum</var>
  108. &lt;- <code>+</code>
  109. </pre></div>
  110. <p>The &lsquo;<samp>+</samp>&rsquo;/&lsquo;<samp>-</samp>&rsquo; acknowledgments can be disabled
  111. once a connection is established.
  112. See <a href="Packet-Acknowledgment.html#Packet-Acknowledgment">Packet Acknowledgment</a>, for details.
  113. </p>
  114. <p>The host (<small>GDB</small>) sends <var>command</var>s, and the target (the
  115. debugging stub incorporated in your program) sends a <var>response</var>. In
  116. the case of step and continue <var>command</var>s, the response is only sent
  117. when the operation has completed, and the target has again stopped all
  118. threads in all attached processes. This is the default all-stop mode
  119. behavior, but the remote protocol also supports <small>GDB</small>&rsquo;s non-stop
  120. execution mode; see <a href="Remote-Non_002dStop.html#Remote-Non_002dStop">Remote Non-Stop</a>, for details.
  121. </p>
  122. <p><var>packet-data</var> consists of a sequence of characters with the
  123. exception of &lsquo;<samp>#</samp>&rsquo; and &lsquo;<samp>$</samp>&rsquo; (see &lsquo;<samp>X</samp>&rsquo; packet for additional
  124. exceptions).
  125. </p>
  126. <a name="index-remote-protocol_002c-field-separator"></a>
  127. <p>Fields within the packet should be separated using &lsquo;<samp>,</samp>&rsquo; &lsquo;<samp>;</samp>&rsquo; or
  128. &lsquo;<samp>:</samp>&rsquo;. Except where otherwise noted all numbers are represented in
  129. <small>HEX</small> with leading zeros suppressed.
  130. </p>
  131. <p>Implementors should note that prior to <small>GDB</small> 5.0, the character
  132. &lsquo;<samp>:</samp>&rsquo; could not appear as the third character in a packet (as it
  133. would potentially conflict with the <var>sequence-id</var>).
  134. </p>
  135. <a name="index-remote-protocol_002c-binary-data"></a>
  136. <a name="Binary-Data"></a><p>Binary data in most packets is encoded either as two hexadecimal
  137. digits per byte of binary data. This allowed the traditional remote
  138. protocol to work over connections which were only seven-bit clean.
  139. Some packets designed more recently assume an eight-bit clean
  140. connection, and use a more efficient encoding to send and receive
  141. binary data.
  142. </p>
  143. <p>The binary data representation uses <code>7d</code> (<small>ASCII</small> &lsquo;<samp>}</samp>&rsquo;)
  144. as an escape character. Any escaped byte is transmitted as the escape
  145. character followed by the original character XORed with <code>0x20</code>.
  146. For example, the byte <code>0x7d</code> would be transmitted as the two
  147. bytes <code>0x7d 0x5d</code>. The bytes <code>0x23</code> (<small>ASCII</small> &lsquo;<samp>#</samp>&rsquo;),
  148. <code>0x24</code> (<small>ASCII</small> &lsquo;<samp>$</samp>&rsquo;), and <code>0x7d</code> (<small>ASCII</small>
  149. &lsquo;<samp>}</samp>&rsquo;) must always be escaped. Responses sent by the stub
  150. must also escape <code>0x2a</code> (<small>ASCII</small> &lsquo;<samp>*</samp>&rsquo;), so that it
  151. is not interpreted as the start of a run-length encoded sequence
  152. (described next).
  153. </p>
  154. <p>Response <var>data</var> can be run-length encoded to save space.
  155. Run-length encoding replaces runs of identical characters with one
  156. instance of the repeated character, followed by a &lsquo;<samp>*</samp>&rsquo; and a
  157. repeat count. The repeat count is itself sent encoded, to avoid
  158. binary characters in <var>data</var>: a value of <var>n</var> is sent as
  159. <code><var>n</var>+29</code>. For a repeat count greater or equal to 3, this
  160. produces a printable <small>ASCII</small> character, e.g. a space (<small>ASCII</small>
  161. code 32) for a repeat count of 3. (This is because run-length
  162. encoding starts to win for counts 3 or more.) Thus, for example,
  163. &lsquo;<samp>0* </samp>&rsquo; is a run-length encoding of &ldquo;0000&rdquo;: the space character
  164. after &lsquo;<samp>*</samp>&rsquo; means repeat the leading <code>0</code> <code>32&nbsp;<span class="nolinebreak">-</span>&nbsp;29&nbsp;=&nbsp;3</code><!-- /@w --> more times.
  165. </p>
  166. <p>The printable characters &lsquo;<samp>#</samp>&rsquo; and &lsquo;<samp>$</samp>&rsquo; or with a numeric value
  167. greater than 126 must not be used. Runs of six repeats (&lsquo;<samp>#</samp>&rsquo;) or
  168. seven repeats (&lsquo;<samp>$</samp>&rsquo;) can be expanded using a repeat count of only
  169. five (&lsquo;<samp>&quot;</samp>&rsquo;). For example, &lsquo;<samp>00000000</samp>&rsquo; can be encoded as
  170. &lsquo;<samp>0*&quot;00</samp>&rsquo;.
  171. </p>
  172. <p>The error response returned for some packets includes a two character
  173. error number. That number is not well defined.
  174. </p>
  175. <a name="index-empty-response_002c-for-unsupported-packets"></a>
  176. <p>For any <var>command</var> not supported by the stub, an empty response
  177. (&lsquo;<samp>$#00</samp>&rsquo;) should be returned. That way it is possible to extend the
  178. protocol. A newer <small>GDB</small> can tell if a packet is supported based
  179. on that response.
  180. </p>
  181. <p>At a minimum, a stub is required to support the &lsquo;<samp>?</samp>&rsquo; command to
  182. tell <small>GDB</small> the reason for halting, &lsquo;<samp>g</samp>&rsquo; and &lsquo;<samp>G</samp>&rsquo;
  183. commands for register access, and the &lsquo;<samp>m</samp>&rsquo; and &lsquo;<samp>M</samp>&rsquo; commands
  184. for memory access. Stubs that only control single-threaded targets
  185. can implement run control with the &lsquo;<samp>c</samp>&rsquo; (continue) command, and if
  186. the target architecture supports hardware-assisted single-stepping,
  187. the &lsquo;<samp>s</samp>&rsquo; (step) command. Stubs that support multi-threading
  188. targets should support the &lsquo;<samp>vCont</samp>&rsquo; command. All other commands
  189. are optional.
  190. </p>
  191. <hr>
  192. <div class="header">
  193. <p>
  194. Next: <a href="Packets.html#Packets" accesskey="n" rel="next">Packets</a>, Up: <a href="Remote-Protocol.html#Remote-Protocol" accesskey="u" rel="up">Remote Protocol</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>
  195. </div>
  196. </body>
  197. </html>