Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

252 lines
12KB

  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>Rationale (Debugging with GDB)</title>
  17. <meta name="description" content="Rationale (Debugging with GDB)">
  18. <meta name="keywords" content="Rationale (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="Agent-Expressions.html#Agent-Expressions" rel="up" title="Agent Expressions">
  26. <link href="Target-Descriptions.html#Target-Descriptions" rel="next" title="Target Descriptions">
  27. <link href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" rel="prev" title="Varying Target Capabilities">
  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="Rationale"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" accesskey="p" rel="prev">Varying Target Capabilities</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</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="Rationale-1"></a>
  64. <h3 class="section">F.5 Rationale</h3>
  65. <p>Some of the design decisions apparent above are arguable.
  66. </p>
  67. <dl compact="compact">
  68. <dt><b>What about stack overflow/underflow?</b></dt>
  69. <dd><p>GDB should be able to query the target to discover its stack size.
  70. Given that information, GDB can determine at translation time whether a
  71. given expression will overflow the stack. But this spec isn&rsquo;t about
  72. what kinds of error-checking GDB ought to do.
  73. </p>
  74. </dd>
  75. <dt><b>Why are you doing everything in LONGEST?</b></dt>
  76. <dd>
  77. <p>Speed isn&rsquo;t important, but agent code size is; using LONGEST brings in a
  78. bunch of support code to do things like division, etc. So this is a
  79. serious concern.
  80. </p>
  81. <p>First, note that you don&rsquo;t need different bytecodes for different
  82. operand sizes. You can generate code without <em>knowing</em> how big the
  83. stack elements actually are on the target. If the target only supports
  84. 32-bit ints, and you don&rsquo;t send any 64-bit bytecodes, everything just
  85. works. The observation here is that the MIPS and the Alpha have only
  86. fixed-size registers, and you can still get C&rsquo;s semantics even though
  87. most instructions only operate on full-sized words. You just need to
  88. make sure everything is properly sign-extended at the right times. So
  89. there is no need for 32- and 64-bit variants of the bytecodes. Just
  90. implement everything using the largest size you support.
  91. </p>
  92. <p>GDB should certainly check to see what sizes the target supports, so the
  93. user can get an error earlier, rather than later. But this information
  94. is not necessary for correctness.
  95. </p>
  96. </dd>
  97. <dt><b>Why don&rsquo;t you have <code>&gt;</code> or <code>&lt;=</code> operators?</b></dt>
  98. <dd><p>I want to keep the interpreter small, and we don&rsquo;t need them. We can
  99. combine the <code>less_</code> opcodes with <code>log_not</code>, and swap the order
  100. of the operands, yielding all four asymmetrical comparison operators.
  101. For example, <code>(x &lt;= y)</code> is <code>! (x &gt; y)</code>, which is <code>! (y &lt;
  102. x)</code>.
  103. </p>
  104. </dd>
  105. <dt><b>Why do you have <code>log_not</code>?</b></dt>
  106. <dt><b>Why do you have <code>ext</code>?</b></dt>
  107. <dt><b>Why do you have <code>zero_ext</code>?</b></dt>
  108. <dd><p>These are all easily synthesized from other instructions, but I expect
  109. them to be used frequently, and they&rsquo;re simple, so I include them to
  110. keep bytecode strings short.
  111. </p>
  112. <p><code>log_not</code> is equivalent to <code>const8 0 equal</code>; it&rsquo;s used in half
  113. the relational operators.
  114. </p>
  115. <p><code>ext <var>n</var></code> is equivalent to <code>const8 <var>s-n</var> lsh const8
  116. <var>s-n</var> rsh_signed</code>, where <var>s</var> is the size of the stack elements;
  117. it follows <code>ref<var>m</var></code> and <var>reg</var> bytecodes when the value
  118. should be signed. See the next bulleted item.
  119. </p>
  120. <p><code>zero_ext <var>n</var></code> is equivalent to <code>const<var>m</var> <var>mask</var>
  121. log_and</code>; it&rsquo;s used whenever we push the value of a register, because we
  122. can&rsquo;t assume the upper bits of the register aren&rsquo;t garbage.
  123. </p>
  124. </dd>
  125. <dt><b>Why not have sign-extending variants of the <code>ref</code> operators?</b></dt>
  126. <dd><p>Because that would double the number of <code>ref</code> operators, and we
  127. need the <code>ext</code> bytecode anyway for accessing bitfields.
  128. </p>
  129. </dd>
  130. <dt><b>Why not have constant-address variants of the <code>ref</code> operators?</b></dt>
  131. <dd><p>Because that would double the number of <code>ref</code> operators again, and
  132. <code>const32 <var>address</var> ref32</code> is only one byte longer.
  133. </p>
  134. </dd>
  135. <dt><b>Why do the <code>ref<var>n</var></code> operators have to support unaligned fetches?</b></dt>
  136. <dd><p>GDB will generate bytecode that fetches multi-byte values at unaligned
  137. addresses whenever the executable&rsquo;s debugging information tells it to.
  138. Furthermore, GDB does not know the value the pointer will have when GDB
  139. generates the bytecode, so it cannot determine whether a particular
  140. fetch will be aligned or not.
  141. </p>
  142. <p>In particular, structure bitfields may be several bytes long, but follow
  143. no alignment rules; members of packed structures are not necessarily
  144. aligned either.
  145. </p>
  146. <p>In general, there are many cases where unaligned references occur in
  147. correct C code, either at the programmer&rsquo;s explicit request, or at the
  148. compiler&rsquo;s discretion. Thus, it is simpler to make the GDB agent
  149. bytecodes work correctly in all circumstances than to make GDB guess in
  150. each case whether the compiler did the usual thing.
  151. </p>
  152. </dd>
  153. <dt><b>Why are there no side-effecting operators?</b></dt>
  154. <dd><p>Because our current client doesn&rsquo;t want them? That&rsquo;s a cheap answer. I
  155. think the real answer is that I&rsquo;m afraid of implementing function
  156. calls. We should re-visit this issue after the present contract is
  157. delivered.
  158. </p>
  159. </dd>
  160. <dt><b>Why aren&rsquo;t the <code>goto</code> ops PC-relative?</b></dt>
  161. <dd><p>The interpreter has the base address around anyway for PC bounds
  162. checking, and it seemed simpler.
  163. </p>
  164. </dd>
  165. <dt><b>Why is there only one offset size for the <code>goto</code> ops?</b></dt>
  166. <dd><p>Offsets are currently sixteen bits. I&rsquo;m not happy with this situation
  167. either:
  168. </p>
  169. <p>Suppose we have multiple branch ops with different offset sizes. As I
  170. generate code left-to-right, all my jumps are forward jumps (there are
  171. no loops in expressions), so I never know the target when I emit the
  172. jump opcode. Thus, I have to either always assume the largest offset
  173. size, or do jump relaxation on the code after I generate it, which seems
  174. like a big waste of time.
  175. </p>
  176. <p>I can imagine a reasonable expression being longer than 256 bytes. I
  177. can&rsquo;t imagine one being longer than 64k. Thus, we need 16-bit offsets.
  178. This kind of reasoning is so bogus, but relaxation is pathetic.
  179. </p>
  180. <p>The other approach would be to generate code right-to-left. Then I&rsquo;d
  181. always know my offset size. That might be fun.
  182. </p>
  183. </dd>
  184. <dt><b>Where is the function call bytecode?</b></dt>
  185. <dd>
  186. <p>When we add side-effects, we should add this.
  187. </p>
  188. </dd>
  189. <dt><b>Why does the <code>reg</code> bytecode take a 16-bit register number?</b></dt>
  190. <dd>
  191. <p>Intel&rsquo;s IA-64 architecture has 128 general-purpose registers,
  192. and 128 floating-point registers, and I&rsquo;m sure it has some random
  193. control registers.
  194. </p>
  195. </dd>
  196. <dt><b>Why do we need <code>trace</code> and <code>trace_quick</code>?</b></dt>
  197. <dd><p>Because GDB needs to record all the memory contents and registers an
  198. expression touches. If the user wants to evaluate an expression
  199. <code>x-&gt;y-&gt;z</code>, the agent must record the values of <code>x</code> and
  200. <code>x-&gt;y</code> as well as the value of <code>x-&gt;y-&gt;z</code>.
  201. </p>
  202. </dd>
  203. <dt><b>Don&rsquo;t the <code>trace</code> bytecodes make the interpreter less general?</b></dt>
  204. <dd><p>They do mean that the interpreter contains special-purpose code, but
  205. that doesn&rsquo;t mean the interpreter can only be used for that purpose. If
  206. an expression doesn&rsquo;t use the <code>trace</code> bytecodes, they don&rsquo;t get in
  207. its way.
  208. </p>
  209. </dd>
  210. <dt><b>Why doesn&rsquo;t <code>trace_quick</code> consume its arguments the way everything else does?</b></dt>
  211. <dd><p>In general, you do want your operators to consume their arguments; it&rsquo;s
  212. consistent, and generally reduces the amount of stack rearrangement
  213. necessary. However, <code>trace_quick</code> is a kludge to save space; it
  214. only exists so we needn&rsquo;t write <code>dup const8 <var>SIZE</var> trace</code>
  215. before every memory reference. Therefore, it&rsquo;s okay for it not to
  216. consume its arguments; it&rsquo;s meant for a specific context in which we
  217. know exactly what it should do with the stack. If we&rsquo;re going to have a
  218. kludge, it should be an effective kludge.
  219. </p>
  220. </dd>
  221. <dt><b>Why does <code>trace16</code> exist?</b></dt>
  222. <dd><p>That opcode was added by the customer that contracted Cygnus for the
  223. data tracing work. I personally think it is unnecessary; objects that
  224. large will be quite rare, so it is okay to use <code>dup const16
  225. <var>size</var> trace</code> in those cases.
  226. </p>
  227. <p>Whatever we decide to do with <code>trace16</code>, we should at least leave
  228. opcode 0x30 reserved, to remain compatible with the customer who added
  229. it.
  230. </p>
  231. </dd>
  232. </dl>
  233. <hr>
  234. <div class="header">
  235. <p>
  236. Previous: <a href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" accesskey="p" rel="prev">Varying Target Capabilities</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</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>
  237. </div>
  238. </body>
  239. </html>