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: Bytecode Descriptions</title> 18 19<meta name="description" content="Debugging with GDB: Bytecode Descriptions"> 20<meta name="keywords" content="Debugging with GDB: Bytecode Descriptions"> 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="Agent-Expressions.html#Agent-Expressions" rel="up" title="Agent Expressions"> 29<link href="Using-Agent-Expressions.html#Using-Agent-Expressions" rel="next" title="Using Agent Expressions"> 30<link href="General-Bytecode-Design.html#General-Bytecode-Design" rel="previous" title="General Bytecode Design"> 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="Bytecode-Descriptions"></a> 65<div class="header"> 66<p> 67Next: <a href="Using-Agent-Expressions.html#Using-Agent-Expressions" accesskey="n" rel="next">Using Agent Expressions</a>, Previous: <a href="General-Bytecode-Design.html#General-Bytecode-Design" accesskey="p" rel="previous">General Bytecode Design</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</a> [<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="Bytecode-Descriptions-1"></a> 71<h3 class="section">F.2 Bytecode Descriptions</h3> 72 73<p>Each bytecode description has the following form: 74</p> 75<dl compact="compact"> 76<dt><code>add</code> (0x02): <var>a</var> <var>b</var> ⇒ <var>a+b</var></dt> 77<dd> 78<p>Pop the top two stack items, <var>a</var> and <var>b</var>, as integers; push 79their sum, as an integer. 80</p> 81</dd> 82</dl> 83 84<p>In this example, <code>add</code> is the name of the bytecode, and 85<code>(0x02)</code> is the one-byte value used to encode the bytecode, in 86hexadecimal. The phrase “<var>a</var> <var>b</var> ⇒ <var>a+b</var>” shows 87the stack before and after the bytecode executes. Beforehand, the stack 88must contain at least two values, <var>a</var> and <var>b</var>; since the top of 89the stack is to the right, <var>b</var> is on the top of the stack, and 90<var>a</var> is underneath it. After execution, the bytecode will have 91popped <var>a</var> and <var>b</var> from the stack, and replaced them with a 92single value, <var>a+b</var>. There may be other values on the stack below 93those shown, but the bytecode affects only those shown. 94</p> 95<p>Here is another example: 96</p> 97<dl compact="compact"> 98<dt><code>const8</code> (0x22) <var>n</var>: ⇒ <var>n</var></dt> 99<dd><p>Push the 8-bit integer constant <var>n</var> on the stack, without sign 100extension. 101</p> 102</dd> 103</dl> 104 105<p>In this example, the bytecode <code>const8</code> takes an operand <var>n</var> 106directly from the bytecode stream; the operand follows the <code>const8</code> 107bytecode itself. We write any such operands immediately after the name 108of the bytecode, before the colon, and describe the exact encoding of 109the operand in the bytecode stream in the body of the bytecode 110description. 111</p> 112<p>For the <code>const8</code> bytecode, there are no stack items given before 113the ⇒; this simply means that the bytecode consumes no values 114from the stack. If a bytecode consumes no values, or produces no 115values, the list on either side of the ⇒ may be empty. 116</p> 117<p>If a value is written as <var>a</var>, <var>b</var>, or <var>n</var>, then the bytecode 118treats it as an integer. If a value is written is <var>addr</var>, then the 119bytecode treats it as an address. 120</p> 121<p>We do not fully describe the floating point operations here; although 122this design can be extended in a clean way to handle floating point 123values, they are not of immediate interest to the customer, so we avoid 124describing them, to save time. 125</p> 126 127<dl compact="compact"> 128<dt><code>float</code> (0x01): ⇒</dt> 129<dd> 130<p>Prefix for floating-point bytecodes. Not implemented yet. 131</p> 132</dd> 133<dt><code>add</code> (0x02): <var>a</var> <var>b</var> ⇒ <var>a+b</var></dt> 134<dd><p>Pop two integers from the stack, and push their sum, as an integer. 135</p> 136</dd> 137<dt><code>sub</code> (0x03): <var>a</var> <var>b</var> ⇒ <var>a-b</var></dt> 138<dd><p>Pop two integers from the stack, subtract the top value from the 139next-to-top value, and push the difference. 140</p> 141</dd> 142<dt><code>mul</code> (0x04): <var>a</var> <var>b</var> ⇒ <var>a*b</var></dt> 143<dd><p>Pop two integers from the stack, multiply them, and push the product on 144the stack. Note that, when one multiplies two <var>n</var>-bit numbers 145yielding another <var>n</var>-bit number, it is irrelevant whether the 146numbers are signed or not; the results are the same. 147</p> 148</dd> 149<dt><code>div_signed</code> (0x05): <var>a</var> <var>b</var> ⇒ <var>a/b</var></dt> 150<dd><p>Pop two signed integers from the stack; divide the next-to-top value by 151the top value, and push the quotient. If the divisor is zero, terminate 152with an error. 153</p> 154</dd> 155<dt><code>div_unsigned</code> (0x06): <var>a</var> <var>b</var> ⇒ <var>a/b</var></dt> 156<dd><p>Pop two unsigned integers from the stack; divide the next-to-top value 157by the top value, and push the quotient. If the divisor is zero, 158terminate with an error. 159</p> 160</dd> 161<dt><code>rem_signed</code> (0x07): <var>a</var> <var>b</var> ⇒ <var>a modulo b</var></dt> 162<dd><p>Pop two signed integers from the stack; divide the next-to-top value by 163the top value, and push the remainder. If the divisor is zero, 164terminate with an error. 165</p> 166</dd> 167<dt><code>rem_unsigned</code> (0x08): <var>a</var> <var>b</var> ⇒ <var>a modulo b</var></dt> 168<dd><p>Pop two unsigned integers from the stack; divide the next-to-top value 169by the top value, and push the remainder. If the divisor is zero, 170terminate with an error. 171</p> 172</dd> 173<dt><code>lsh</code> (0x09): <var>a</var> <var>b</var> ⇒ <var>a<<b</var></dt> 174<dd><p>Pop two integers from the stack; let <var>a</var> be the next-to-top value, 175and <var>b</var> be the top value. Shift <var>a</var> left by <var>b</var> bits, and 176push the result. 177</p> 178</dd> 179<dt><code>rsh_signed</code> (0x0a): <var>a</var> <var>b</var> ⇒ <code>(signed)</code><var>a>>b</var></dt> 180<dd><p>Pop two integers from the stack; let <var>a</var> be the next-to-top value, 181and <var>b</var> be the top value. Shift <var>a</var> right by <var>b</var> bits, 182inserting copies of the top bit at the high end, and push the result. 183</p> 184</dd> 185<dt><code>rsh_unsigned</code> (0x0b): <var>a</var> <var>b</var> ⇒ <var>a>>b</var></dt> 186<dd><p>Pop two integers from the stack; let <var>a</var> be the next-to-top value, 187and <var>b</var> be the top value. Shift <var>a</var> right by <var>b</var> bits, 188inserting zero bits at the high end, and push the result. 189</p> 190</dd> 191<dt><code>log_not</code> (0x0e): <var>a</var> ⇒ <var>!a</var></dt> 192<dd><p>Pop an integer from the stack; if it is zero, push the value one; 193otherwise, push the value zero. 194</p> 195</dd> 196<dt><code>bit_and</code> (0x0f): <var>a</var> <var>b</var> ⇒ <var>a&b</var></dt> 197<dd><p>Pop two integers from the stack, and push their bitwise <code>and</code>. 198</p> 199</dd> 200<dt><code>bit_or</code> (0x10): <var>a</var> <var>b</var> ⇒ <var>a|b</var></dt> 201<dd><p>Pop two integers from the stack, and push their bitwise <code>or</code>. 202</p> 203</dd> 204<dt><code>bit_xor</code> (0x11): <var>a</var> <var>b</var> ⇒ <var>a^b</var></dt> 205<dd><p>Pop two integers from the stack, and push their bitwise 206exclusive-<code>or</code>. 207</p> 208</dd> 209<dt><code>bit_not</code> (0x12): <var>a</var> ⇒ <var>~a</var></dt> 210<dd><p>Pop an integer from the stack, and push its bitwise complement. 211</p> 212</dd> 213<dt><code>equal</code> (0x13): <var>a</var> <var>b</var> ⇒ <var>a=b</var></dt> 214<dd><p>Pop two integers from the stack; if they are equal, push the value one; 215otherwise, push the value zero. 216</p> 217</dd> 218<dt><code>less_signed</code> (0x14): <var>a</var> <var>b</var> ⇒ <var>a<b</var></dt> 219<dd><p>Pop two signed integers from the stack; if the next-to-top value is less 220than the top value, push the value one; otherwise, push the value zero. 221</p> 222</dd> 223<dt><code>less_unsigned</code> (0x15): <var>a</var> <var>b</var> ⇒ <var>a<b</var></dt> 224<dd><p>Pop two unsigned integers from the stack; if the next-to-top value is less 225than the top value, push the value one; otherwise, push the value zero. 226</p> 227</dd> 228<dt><code>ext</code> (0x16) <var>n</var>: <var>a</var> ⇒ <var>a</var>, sign-extended from <var>n</var> bits</dt> 229<dd><p>Pop an unsigned value from the stack; treating it as an <var>n</var>-bit 230twos-complement value, extend it to full length. This means that all 231bits to the left of bit <var>n-1</var> (where the least significant bit is bit 2320) are set to the value of bit <var>n-1</var>. Note that <var>n</var> may be 233larger than or equal to the width of the stack elements of the bytecode 234engine; in this case, the bytecode should have no effect. 235</p> 236<p>The number of source bits to preserve, <var>n</var>, is encoded as a single 237byte unsigned integer following the <code>ext</code> bytecode. 238</p> 239</dd> 240<dt><code>zero_ext</code> (0x2a) <var>n</var>: <var>a</var> ⇒ <var>a</var>, zero-extended from <var>n</var> bits</dt> 241<dd><p>Pop an unsigned value from the stack; zero all but the bottom <var>n</var> 242bits. 243</p> 244<p>The number of source bits to preserve, <var>n</var>, is encoded as a single 245byte unsigned integer following the <code>zero_ext</code> bytecode. 246</p> 247</dd> 248<dt><code>ref8</code> (0x17): <var>addr</var> ⇒ <var>a</var></dt> 249<dt><code>ref16</code> (0x18): <var>addr</var> ⇒ <var>a</var></dt> 250<dt><code>ref32</code> (0x19): <var>addr</var> ⇒ <var>a</var></dt> 251<dt><code>ref64</code> (0x1a): <var>addr</var> ⇒ <var>a</var></dt> 252<dd><p>Pop an address <var>addr</var> from the stack. For bytecode 253<code>ref</code><var>n</var>, fetch an <var>n</var>-bit value from <var>addr</var>, using the 254natural target endianness. Push the fetched value as an unsigned 255integer. 256</p> 257<p>Note that <var>addr</var> may not be aligned in any particular way; the 258<code>ref<var>n</var></code> bytecodes should operate correctly for any address. 259</p> 260<p>If attempting to access memory at <var>addr</var> would cause a processor 261exception of some sort, terminate with an error. 262</p> 263</dd> 264<dt><code>ref_float</code> (0x1b): <var>addr</var> ⇒ <var>d</var></dt> 265<dt><code>ref_double</code> (0x1c): <var>addr</var> ⇒ <var>d</var></dt> 266<dt><code>ref_long_double</code> (0x1d): <var>addr</var> ⇒ <var>d</var></dt> 267<dt><code>l_to_d</code> (0x1e): <var>a</var> ⇒ <var>d</var></dt> 268<dt><code>d_to_l</code> (0x1f): <var>d</var> ⇒ <var>a</var></dt> 269<dd><p>Not implemented yet. 270</p> 271</dd> 272<dt><code>dup</code> (0x28): <var>a</var> => <var>a</var> <var>a</var></dt> 273<dd><p>Push another copy of the stack’s top element. 274</p> 275</dd> 276<dt><code>swap</code> (0x2b): <var>a</var> <var>b</var> => <var>b</var> <var>a</var></dt> 277<dd><p>Exchange the top two items on the stack. 278</p> 279</dd> 280<dt><code>pop</code> (0x29): <var>a</var> =></dt> 281<dd><p>Discard the top value on the stack. 282</p> 283</dd> 284<dt><code>pick</code> (0x32) <var>n</var>: <var>a</var> … <var>b</var> => <var>a</var> … <var>b</var> <var>a</var></dt> 285<dd><p>Duplicate an item from the stack and push it on the top of the stack. 286<var>n</var>, a single byte, indicates the stack item to copy. If <var>n</var> 287is zero, this is the same as <code>dup</code>; if <var>n</var> is one, it copies 288the item under the top item, etc. If <var>n</var> exceeds the number of 289items on the stack, terminate with an error. 290</p> 291</dd> 292<dt><code>rot</code> (0x33): <var>a</var> <var>b</var> <var>c</var> => <var>c</var> <var>a</var> <var>b</var></dt> 293<dd><p>Rotate the top three items on the stack. The top item (c) becomes the third 294item, the next-to-top item (b) becomes the top item and the third item (a) from 295the top becomes the next-to-top item. 296</p> 297</dd> 298<dt><code>if_goto</code> (0x20) <var>offset</var>: <var>a</var> ⇒</dt> 299<dd><p>Pop an integer off the stack; if it is non-zero, branch to the given 300offset in the bytecode string. Otherwise, continue to the next 301instruction in the bytecode stream. In other words, if <var>a</var> is 302non-zero, set the <code>pc</code> register to <code>start</code> + <var>offset</var>. 303Thus, an offset of zero denotes the beginning of the expression. 304</p> 305<p>The <var>offset</var> is stored as a sixteen-bit unsigned value, stored 306immediately following the <code>if_goto</code> bytecode. It is always stored 307most significant byte first, regardless of the target’s normal 308endianness. The offset is not guaranteed to fall at any particular 309alignment within the bytecode stream; thus, on machines where fetching a 31016-bit on an unaligned address raises an exception, you should fetch the 311offset one byte at a time. 312</p> 313</dd> 314<dt><code>goto</code> (0x21) <var>offset</var>: ⇒</dt> 315<dd><p>Branch unconditionally to <var>offset</var>; in other words, set the 316<code>pc</code> register to <code>start</code> + <var>offset</var>. 317</p> 318<p>The offset is stored in the same way as for the <code>if_goto</code> bytecode. 319</p> 320</dd> 321<dt><code>const8</code> (0x22) <var>n</var>: ⇒ <var>n</var></dt> 322<dt><code>const16</code> (0x23) <var>n</var>: ⇒ <var>n</var></dt> 323<dt><code>const32</code> (0x24) <var>n</var>: ⇒ <var>n</var></dt> 324<dt><code>const64</code> (0x25) <var>n</var>: ⇒ <var>n</var></dt> 325<dd><p>Push the integer constant <var>n</var> on the stack, without sign extension. 326To produce a small negative value, push a small twos-complement value, 327and then sign-extend it using the <code>ext</code> bytecode. 328</p> 329<p>The constant <var>n</var> is stored in the appropriate number of bytes 330following the <code>const</code><var>b</var> bytecode. The constant <var>n</var> is 331always stored most significant byte first, regardless of the target’s 332normal endianness. The constant is not guaranteed to fall at any 333particular alignment within the bytecode stream; thus, on machines where 334fetching a 16-bit on an unaligned address raises an exception, you 335should fetch <var>n</var> one byte at a time. 336</p> 337</dd> 338<dt><code>reg</code> (0x26) <var>n</var>: ⇒ <var>a</var></dt> 339<dd><p>Push the value of register number <var>n</var>, without sign extension. The 340registers are numbered following GDB’s conventions. 341</p> 342<p>The register number <var>n</var> is encoded as a 16-bit unsigned integer 343immediately following the <code>reg</code> bytecode. It is always stored most 344significant byte first, regardless of the target’s normal endianness. 345The register number is not guaranteed to fall at any particular 346alignment within the bytecode stream; thus, on machines where fetching a 34716-bit on an unaligned address raises an exception, you should fetch the 348register number one byte at a time. 349</p> 350</dd> 351<dt><code>getv</code> (0x2c) <var>n</var>: ⇒ <var>v</var></dt> 352<dd><p>Push the value of trace state variable number <var>n</var>, without sign 353extension. 354</p> 355<p>The variable number <var>n</var> is encoded as a 16-bit unsigned integer 356immediately following the <code>getv</code> bytecode. It is always stored most 357significant byte first, regardless of the target’s normal endianness. 358The variable number is not guaranteed to fall at any particular 359alignment within the bytecode stream; thus, on machines where fetching a 36016-bit on an unaligned address raises an exception, you should fetch the 361register number one byte at a time. 362</p> 363</dd> 364<dt><code>setv</code> (0x2d) <var>n</var>: <var>v</var> ⇒ <var>v</var></dt> 365<dd><p>Set trace state variable number <var>n</var> to the value found on the top 366of the stack. The stack is unchanged, so that the value is readily 367available if the assignment is part of a larger expression. The 368handling of <var>n</var> is as described for <code>getv</code>. 369</p> 370</dd> 371<dt><code>trace</code> (0x0c): <var>addr</var> <var>size</var> ⇒</dt> 372<dd><p>Record the contents of the <var>size</var> bytes at <var>addr</var> in a trace 373buffer, for later retrieval by GDB. 374</p> 375</dd> 376<dt><code>trace_quick</code> (0x0d) <var>size</var>: <var>addr</var> ⇒ <var>addr</var></dt> 377<dd><p>Record the contents of the <var>size</var> bytes at <var>addr</var> in a trace 378buffer, for later retrieval by GDB. <var>size</var> is a single byte 379unsigned integer following the <code>trace</code> opcode. 380</p> 381<p>This bytecode is equivalent to the sequence <code>dup const8 <var>size</var> 382trace</code>, but we provide it anyway to save space in bytecode strings. 383</p> 384</dd> 385<dt><code>trace16</code> (0x30) <var>size</var>: <var>addr</var> ⇒ <var>addr</var></dt> 386<dd><p>Identical to trace_quick, except that <var>size</var> is a 16-bit big-endian 387unsigned integer, not a single byte. This should probably have been 388named <code>trace_quick16</code>, for consistency. 389</p> 390</dd> 391<dt><code>tracev</code> (0x2e) <var>n</var>: ⇒ <var>a</var></dt> 392<dd><p>Record the value of trace state variable number <var>n</var> in the trace 393buffer. The handling of <var>n</var> is as described for <code>getv</code>. 394</p> 395</dd> 396<dt><code>tracenz</code> (0x2f) <var>addr</var> <var>size</var> ⇒</dt> 397<dd><p>Record the bytes at <var>addr</var> in a trace buffer, for later retrieval 398by GDB. Stop at either the first zero byte, or when <var>size</var> bytes 399have been recorded, whichever occurs first. 400</p> 401</dd> 402<dt><code>printf</code> (0x34) <var>numargs</var> <var>string</var> ⇒</dt> 403<dd><p>Do a formatted print, in the style of the C function <code>printf</code>). 404The value of <var>numargs</var> is the number of arguments to expect on the 405stack, while <var>string</var> is the format string, prefixed with a 406two-byte length. The last byte of the string must be zero, and is 407included in the length. The format string includes escaped sequences 408just as it appears in C source, so for instance the format string 409<code>"\t%d\n"</code> is six characters long, and the output will consist of 410a tab character, a decimal number, and a newline. At the top of the 411stack, above the values to be printed, this bytecode will pop a 412“function” and “channel”. If the function is nonzero, then the 413target may treat it as a function and call it, passing the channel as 414a first argument, as with the C function <code>fprintf</code>. If the 415function is zero, then the target may simply call a standard formatted 416print function of its choice. In all, this bytecode pops 2 + 417<var>numargs</var> stack elements, and pushes nothing. 418</p> 419</dd> 420<dt><code>end</code> (0x27): ⇒</dt> 421<dd><p>Stop executing bytecode; the result should be the top element of the 422stack. If the purpose of the expression was to compute an lvalue or a 423range of memory, then the next-to-top of the stack is the lvalue’s 424address, and the top of the stack is the lvalue’s size, in bytes. 425</p> 426</dd> 427</dl> 428 429 430<hr> 431<div class="header"> 432<p> 433Next: <a href="Using-Agent-Expressions.html#Using-Agent-Expressions" accesskey="n" rel="next">Using Agent Expressions</a>, Previous: <a href="General-Bytecode-Design.html#General-Bytecode-Design" accesskey="p" rel="previous">General Bytecode Design</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</a> [<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> 434</div> 435 436 437 438</body> 439</html> 440