gdb: Disassembly In Guile
23.3.3.22 Disassembly In Guile
..............................
The disassembler can be invoked from Scheme code. Furthermore, the
disassembler can take a Guile port as input, allowing one to disassemble
from any source, and not just target memory.
-- Scheme Procedure: arch-disassemble arch start-pc [#:port port]
[#:offset offset] [#:size size] [#:count count]
Return a list of disassembled instructions starting from the memory
address START-PC.
The optional argument PORT specifies the input port to read bytes
from. If PORT is '#f' then bytes are read from target memory.
The optional argument OFFSET specifies the address offset of the
first byte in PORT. This is useful, for example, when PORT
specifies a 'bytevector' and you want the bytevector to be
disassembled as if it came from that address. The START-PC passed
to the reader for PORT is offset by the same amount.
Example:
(gdb) guile (use-modules (rnrs io ports))
(gdb) guile (define pc (value->integer (parse-and-eval "$pc")))
(gdb) guile (define mem (open-memory #:start pc))
(gdb) guile (define bv (get-bytevector-n mem 10))
(gdb) guile (define bv-port (open-bytevector-input-port bv))
(gdb) guile (define arch (current-arch))
(gdb) guile (arch-disassemble arch pc #:port bv-port #:offset pc)
(((address . 4195516) (asm . "mov $0x4005c8,%edi") (length . 5)))
The optional arguments SIZE and COUNT determine the number of
instructions in the returned list. If either SIZE or COUNT is
specified as zero, then no instructions are disassembled and an
empty list is returned. If both the optional arguments SIZE and
COUNT are specified, then a list of at most COUNT disassembled
instructions whose start address falls in the closed memory address
interval from START-PC to (START-PC + SIZE - 1) are returned. If
SIZE is not specified, but COUNT is specified, then COUNT number of
instructions starting from the address START-PC are returned. If
COUNT is not specified but SIZE is specified, then all instructions
whose start address falls in the closed memory address interval
from START-PC to (START-PC + SIZE - 1) are returned. If neither
SIZE nor COUNT are specified, then a single instruction at START-PC
is returned.
Each element of the returned list is an alist (associative list)
with the following keys:
'address'
The value corresponding to this key is a Guile integer of the
memory address of the instruction.
'asm'
The value corresponding to this key is a string value which
represents the instruction with assembly language mnemonics.
The assembly language flavor used is the same as that
specified by the current CLI variable 'disassembly-flavor'.
Machine Code.
'length'
The value corresponding to this key is the length of the
instruction in bytes.