You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 satır
9.0KB

  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>General Bytecode Design (Debugging with GDB)</title>
  17. <meta name="description" content="General Bytecode Design (Debugging with GDB)">
  18. <meta name="keywords" content="General Bytecode Design (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="Bytecode-Descriptions.html#Bytecode-Descriptions" rel="next" title="Bytecode Descriptions">
  27. <link href="Agent-Expressions.html#Agent-Expressions" rel="prev" title="Agent Expressions">
  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="General-Bytecode-Design"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Bytecode-Descriptions.html#Bytecode-Descriptions" accesskey="n" rel="next">Bytecode Descriptions</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="General-Bytecode-Design-1"></a>
  64. <h3 class="section">F.1 General Bytecode Design</h3>
  65. <p>The agent represents bytecode expressions as an array of bytes. Each
  66. instruction is one byte long (thus the term <em>bytecode</em>). Some
  67. instructions are followed by operand bytes; for example, the <code>goto</code>
  68. instruction is followed by a destination for the jump.
  69. </p>
  70. <p>The bytecode interpreter is a stack-based machine; most instructions pop
  71. their operands off the stack, perform some operation, and push the
  72. result back on the stack for the next instruction to consume. Each
  73. element of the stack may contain either a integer or a floating point
  74. value; these values are as many bits wide as the largest integer that
  75. can be directly manipulated in the source language. Stack elements
  76. carry no record of their type; bytecode could push a value as an
  77. integer, then pop it as a floating point value. However, GDB will not
  78. generate code which does this. In C, one might define the type of a
  79. stack element as follows:
  80. </p><div class="example">
  81. <pre class="example">union agent_val {
  82. LONGEST l;
  83. DOUBLEST d;
  84. };
  85. </pre></div>
  86. <p>where <code>LONGEST</code> and <code>DOUBLEST</code> are <code>typedef</code> names for
  87. the largest integer and floating point types on the machine.
  88. </p>
  89. <p>By the time the bytecode interpreter reaches the end of the expression,
  90. the value of the expression should be the only value left on the stack.
  91. For tracing applications, <code>trace</code> bytecodes in the expression will
  92. have recorded the necessary data, and the value on the stack may be
  93. discarded. For other applications, like conditional breakpoints, the
  94. value may be useful.
  95. </p>
  96. <p>Separate from the stack, the interpreter has two registers:
  97. </p><dl compact="compact">
  98. <dt><code>pc</code></dt>
  99. <dd><p>The address of the next bytecode to execute.
  100. </p>
  101. </dd>
  102. <dt><code>start</code></dt>
  103. <dd><p>The address of the start of the bytecode expression, necessary for
  104. interpreting the <code>goto</code> and <code>if_goto</code> instructions.
  105. </p>
  106. </dd>
  107. </dl>
  108. <p>Neither of these registers is directly visible to the bytecode language
  109. itself, but they are useful for defining the meanings of the bytecode
  110. operations.
  111. </p>
  112. <p>There are no instructions to perform side effects on the running
  113. program, or call the program&rsquo;s functions; we assume that these
  114. expressions are only used for unobtrusive debugging, not for patching
  115. the running code.
  116. </p>
  117. <p>Most bytecode instructions do not distinguish between the various sizes
  118. of values, and operate on full-width values; the upper bits of the
  119. values are simply ignored, since they do not usually make a difference
  120. to the value computed. The exceptions to this rule are:
  121. </p><dl compact="compact">
  122. <dt>memory reference instructions (<code>ref</code><var>n</var>)</dt>
  123. <dd><p>There are distinct instructions to fetch different word sizes from
  124. memory. Once on the stack, however, the values are treated as full-size
  125. integers. They may need to be sign-extended; the <code>ext</code> instruction
  126. exists for this purpose.
  127. </p>
  128. </dd>
  129. <dt>the sign-extension instruction (<code>ext</code> <var>n</var>)</dt>
  130. <dd><p>These clearly need to know which portion of their operand is to be
  131. extended to occupy the full length of the word.
  132. </p>
  133. </dd>
  134. </dl>
  135. <p>If the interpreter is unable to evaluate an expression completely for
  136. some reason (a memory location is inaccessible, or a divisor is zero,
  137. for example), we say that interpretation &ldquo;terminates with an error&rdquo;.
  138. This means that the problem is reported back to the interpreter&rsquo;s caller
  139. in some helpful way. In general, code using agent expressions should
  140. assume that they may attempt to divide by zero, fetch arbitrary memory
  141. locations, and misbehave in other ways.
  142. </p>
  143. <p>Even complicated C expressions compile to a few bytecode instructions;
  144. for example, the expression <code>x + y * z</code> would typically produce
  145. code like the following, assuming that <code>x</code> and <code>y</code> live in
  146. registers, and <code>z</code> is a global variable holding a 32-bit
  147. <code>int</code>:
  148. </p><div class="example">
  149. <pre class="example">reg 1
  150. reg 2
  151. const32 <i>address of z</i>
  152. ref32
  153. ext 32
  154. mul
  155. add
  156. end
  157. </pre></div>
  158. <p>In detail, these mean:
  159. </p><dl compact="compact">
  160. <dt><code>reg 1</code></dt>
  161. <dd><p>Push the value of register 1 (presumably holding <code>x</code>) onto the
  162. stack.
  163. </p>
  164. </dd>
  165. <dt><code>reg 2</code></dt>
  166. <dd><p>Push the value of register 2 (holding <code>y</code>).
  167. </p>
  168. </dd>
  169. <dt><code>const32 <i>address of z</i></code></dt>
  170. <dd><p>Push the address of <code>z</code> onto the stack.
  171. </p>
  172. </dd>
  173. <dt><code>ref32</code></dt>
  174. <dd><p>Fetch a 32-bit word from the address at the top of the stack; replace
  175. the address on the stack with the value. Thus, we replace the address
  176. of <code>z</code> with <code>z</code>&rsquo;s value.
  177. </p>
  178. </dd>
  179. <dt><code>ext 32</code></dt>
  180. <dd><p>Sign-extend the value on the top of the stack from 32 bits to full
  181. length. This is necessary because <code>z</code> is a signed integer.
  182. </p>
  183. </dd>
  184. <dt><code>mul</code></dt>
  185. <dd><p>Pop the top two numbers on the stack, multiply them, and push their
  186. product. Now the top of the stack contains the value of the expression
  187. <code>y * z</code>.
  188. </p>
  189. </dd>
  190. <dt><code>add</code></dt>
  191. <dd><p>Pop the top two numbers, add them, and push the sum. Now the top of the
  192. stack contains the value of <code>x + y * z</code>.
  193. </p>
  194. </dd>
  195. <dt><code>end</code></dt>
  196. <dd><p>Stop executing; the value left on the stack top is the value to be
  197. recorded.
  198. </p>
  199. </dd>
  200. </dl>
  201. <hr>
  202. <div class="header">
  203. <p>
  204. Next: <a href="Bytecode-Descriptions.html#Bytecode-Descriptions" accesskey="n" rel="next">Bytecode Descriptions</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>
  205. </div>
  206. </body>
  207. </html>