Disassembly In Guile (Debugging with GDB)
Next: I/O Ports in Guile, Previous: Architectures In Guile, Up: Guile API [Contents][Index]
23.4.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
portspecifies the input port to read bytes from. Ifportis#fthen bytes are read from target memory.The optional argument
offsetspecifies the address offset of the first byte inport. This is useful, for example, whenportspecifies a ‘bytevector’ and you want the bytevector to be disassembled as if it came from that address. Thestart-pcpassed to the reader forportis 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
sizeandcountdetermine the number of instructions in the returned list. If eithersizeorcountis specified as zero, then no instructions are disassembled and an empty list is returned. If both the optional argumentssizeandcountare specified, then a list of at mostcountdisassembled instructions whose start address falls in the closed memory address interval fromstart-pcto (start-pc+size- 1) are returned. Ifsizeis not specified, butcountis specified, thencountnumber of instructions starting from the addressstart-pcare returned. Ifcountis not specified butsizeis specified, then all instructions whose start address falls in the closed memory address interval fromstart-pcto (start-pc+size- 1) are returned. If neithersizenorcountare specified, then a single instruction atstart-pcis returned.Each element of the returned list is an alist (associative list) with the following keys:
addressThe value corresponding to this key is a Guile integer of the memory address of the instruction.
asmThe 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. See Machine Code.lengthThe value corresponding to this key is the length of the instruction in bytes.
Next: I/O Ports in Guile, Previous: Architectures In Guile, Up: Guile API [Contents][Index]