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