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.

152 lines
7.5KB

  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>Disassembly In Guile (Debugging with GDB)</title>
  17. <meta name="description" content="Disassembly In Guile (Debugging with GDB)">
  18. <meta name="keywords" content="Disassembly In Guile (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="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" rel="next" title="I/O Ports in Guile">
  27. <link href="Architectures-In-Guile.html#Architectures-In-Guile" rel="prev" title="Architectures In Guile">
  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="Disassembly-In-Guile"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" accesskey="n" rel="next">I/O Ports in Guile</a>, Previous: <a href="Architectures-In-Guile.html#Architectures-In-Guile" accesskey="p" rel="prev">Architectures In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</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="Disassembly-In-Guile-1"></a>
  64. <h4 class="subsubsection">23.3.3.22 Disassembly In Guile</h4>
  65. <p>The disassembler can be invoked from Scheme code.
  66. Furthermore, the disassembler can take a Guile port as input,
  67. allowing one to disassemble from any source, and not just target memory.
  68. </p>
  69. <dl>
  70. <dt><a name="index-arch_002ddisassemble"></a>Scheme Procedure: <strong>arch-disassemble</strong> <em>arch start-pc <span class="roman">[</span>#:port port<span class="roman">]</span> <span class="roman">[</span>#:offset offset<span class="roman">]</span> <span class="roman">[</span>#:size size<span class="roman">]</span> <span class="roman">[</span>#:count count<span class="roman">]</span></em></dt>
  71. <dd><p>Return a list of disassembled instructions starting from the memory
  72. address <var>start-pc</var>.
  73. </p>
  74. <p>The optional argument <var>port</var> specifies the input port to read bytes from.
  75. If <var>port</var> is <code>#f</code> then bytes are read from target memory.
  76. </p>
  77. <p>The optional argument <var>offset</var> specifies the address offset of the
  78. first byte in <var>port</var>. This is useful, for example, when <var>port</var>
  79. specifies a &lsquo;<samp>bytevector</samp>&rsquo; and you want the bytevector to be disassembled
  80. as if it came from that address. The <var>start-pc</var> passed to the reader
  81. for <var>port</var> is offset by the same amount.
  82. </p>
  83. <p>Example:
  84. </p><div class="smallexample">
  85. <pre class="smallexample">(gdb) guile (use-modules (rnrs io ports))
  86. (gdb) guile (define pc (value-&gt;integer (parse-and-eval &quot;$pc&quot;)))
  87. (gdb) guile (define mem (open-memory #:start pc))
  88. (gdb) guile (define bv (get-bytevector-n mem 10))
  89. (gdb) guile (define bv-port (open-bytevector-input-port bv))
  90. (gdb) guile (define arch (current-arch))
  91. (gdb) guile (arch-disassemble arch pc #:port bv-port #:offset pc)
  92. (((address . 4195516) (asm . &quot;mov $0x4005c8,%edi&quot;) (length . 5)))
  93. </pre></div>
  94. <p>The optional arguments <var>size</var> and
  95. <var>count</var> determine the number of instructions in the returned list.
  96. If either <var>size</var> or <var>count</var> is specified as zero, then
  97. no instructions are disassembled and an empty list is returned.
  98. If both the optional arguments <var>size</var> and <var>count</var> are
  99. specified, then a list of at most <var>count</var> disassembled instructions
  100. whose start address falls in the closed memory address interval from
  101. <var>start-pc</var> to (<var>start-pc</var> + <var>size</var> - 1) are returned.
  102. If <var>size</var> is not specified, but <var>count</var> is specified,
  103. then <var>count</var> number of instructions starting from the address
  104. <var>start-pc</var> are returned. If <var>count</var> is not specified but
  105. <var>size</var> is specified, then all instructions whose start address
  106. falls in the closed memory address interval from <var>start-pc</var> to
  107. (<var>start-pc</var> + <var>size</var> - 1) are returned.
  108. If neither <var>size</var> nor <var>count</var> are specified, then a single
  109. instruction at <var>start-pc</var> is returned.
  110. </p>
  111. <p>Each element of the returned list is an alist (associative list)
  112. with the following keys:
  113. </p>
  114. <dl compact="compact">
  115. <dt><code>address</code></dt>
  116. <dd><p>The value corresponding to this key is a Guile integer of
  117. the memory address of the instruction.
  118. </p>
  119. </dd>
  120. <dt><code>asm</code></dt>
  121. <dd><p>The value corresponding to this key is a string value which represents
  122. the instruction with assembly language mnemonics. The assembly
  123. language flavor used is the same as that specified by the current CLI
  124. variable <code>disassembly-flavor</code>. See <a href="Machine-Code.html#Machine-Code">Machine Code</a>.
  125. </p>
  126. </dd>
  127. <dt><code>length</code></dt>
  128. <dd><p>The value corresponding to this key is the length of the instruction in bytes.
  129. </p>
  130. </dd>
  131. </dl>
  132. </dd></dl>
  133. <hr>
  134. <div class="header">
  135. <p>
  136. Next: <a href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" accesskey="n" rel="next">I/O Ports in Guile</a>, Previous: <a href="Architectures-In-Guile.html#Architectures-In-Guile" accesskey="p" rel="prev">Architectures In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</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>
  137. </div>
  138. </body>
  139. </html>