Disassembly-In-Guile.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Disassembly In Guile</title>
  16. <meta name="description" content="Debugging with GDB: Disassembly In Guile">
  17. <meta name="keywords" content="Debugging with GDB: Disassembly In Guile">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="previous" title="Architectures In Guile">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Disassembly-In-Guile"></a>
  59. <div class="header">
  60. <p>
  61. 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="previous">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>
  62. </div>
  63. <hr>
  64. <a name="Disassembly-In-Guile-1"></a>
  65. <h4 class="subsubsection">23.3.3.22 Disassembly In Guile</h4>
  66. <p>The disassembler can be invoked from Scheme code.
  67. Furthermore, the disassembler can take a Guile port as input,
  68. allowing one to disassemble from any source, and not just target memory.
  69. </p>
  70. <dl>
  71. <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>
  72. <dd><p>Return a list of disassembled instructions starting from the memory
  73. address <var>start-pc</var>.
  74. </p>
  75. <p>The optional argument <var>port</var> specifies the input port to read bytes from.
  76. If <var>port</var> is <code>#f</code> then bytes are read from target memory.
  77. </p>
  78. <p>The optional argument <var>offset</var> specifies the address offset of the
  79. first byte in <var>port</var>. This is useful, for example, when <var>port</var>
  80. specifies a &lsquo;<samp>bytevector</samp>&rsquo; and you want the bytevector to be disassembled
  81. as if it came from that address. The <var>start-pc</var> passed to the reader
  82. for <var>port</var> is offset by the same amount.
  83. </p>
  84. <p>Example:
  85. </p><div class="smallexample">
  86. <pre class="smallexample">(gdb) guile (use-modules (rnrs io ports))
  87. (gdb) guile (define pc (value-&gt;integer (parse-and-eval &quot;$pc&quot;)))
  88. (gdb) guile (define mem (open-memory #:start pc))
  89. (gdb) guile (define bv (get-bytevector-n mem 10))
  90. (gdb) guile (define bv-port (open-bytevector-input-port bv))
  91. (gdb) guile (define arch (current-arch))
  92. (gdb) guile (arch-disassemble arch pc #:port bv-port #:offset pc)
  93. (((address . 4195516) (asm . &quot;mov $0x4005c8,%edi&quot;) (length . 5)))
  94. </pre></div>
  95. <p>The optional arguments <var>size</var> and
  96. <var>count</var> determine the number of instructions in the returned list.
  97. If either <var>size</var> or <var>count</var> is specified as zero, then
  98. no instructions are disassembled and an empty list is returned.
  99. If both the optional arguments <var>size</var> and <var>count</var> are
  100. specified, then a list of at most <var>count</var> disassembled instructions
  101. whose start address falls in the closed memory address interval from
  102. <var>start-pc</var> to (<var>start-pc</var> + <var>size</var> - 1) are returned.
  103. If <var>size</var> is not specified, but <var>count</var> is specified,
  104. then <var>count</var> number of instructions starting from the address
  105. <var>start-pc</var> are returned. If <var>count</var> is not specified but
  106. <var>size</var> is specified, then all instructions whose start address
  107. falls in the closed memory address interval from <var>start-pc</var> to
  108. (<var>start-pc</var> + <var>size</var> - 1) are returned.
  109. If neither <var>size</var> nor <var>count</var> are specified, then a single
  110. instruction at <var>start-pc</var> is returned.
  111. </p>
  112. <p>Each element of the returned list is an alist (associative list)
  113. with the following keys:
  114. </p>
  115. <dl compact="compact">
  116. <dt><code>address</code></dt>
  117. <dd><p>The value corresponding to this key is a Guile integer of
  118. the memory address of the instruction.
  119. </p>
  120. </dd>
  121. <dt><code>asm</code></dt>
  122. <dd><p>The value corresponding to this key is a string value which represents
  123. the instruction with assembly language mnemonics. The assembly
  124. language flavor used is the same as that specified by the current CLI
  125. variable <code>disassembly-flavor</code>. See <a href="Machine-Code.html#Machine-Code">Machine Code</a>.
  126. </p>
  127. </dd>
  128. <dt><code>length</code></dt>
  129. <dd><p>The value corresponding to this key is the length of the instruction in bytes.
  130. </p>
  131. </dd>
  132. </dl>
  133. </dd></dl>
  134. <hr>
  135. <div class="header">
  136. <p>
  137. 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="previous">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>
  138. </div>
  139. </body>
  140. </html>