Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 2.06 KB

README.md

File metadata and controls

27 lines (18 loc) · 2.06 KB

Appendix

The following will teach you how to debug both MAMBO and an application running under MAMBO, using gdb. This is a useful skill to have if you wish to contribute to the development of MAMBO, or are developing complex plugins.

Pre-requisites

You will need gdb installed on the system.

Running MAMBO with gdb

  1. Run MAMBO with gdb gdb ./dbm. Note that this launches gdb with the MAMBO binary.
  2. Run the application under MAMBO after running gdb: run binary-to-run. For example, to run ls: run /bin/ls.

Tip

Arguments for the application can be passed directly to gdb using the --args flag, e.g. gdb --args ./dbm /bin/ls.

Setting a breakpoint within MAMBO

To inspect MAMBO internals such as the scanner or dispatcher, simply set a breakpoint at the required line. For example, to break when scanning a new aarch64 basic block: break arch/aarch64/scanner_a64.c:scan_a64. Now run the application as before.

You will now see gdb break within the scanner.

To step through the scanner line by line, type: layout src. This will switch to a view displaying the source code. Step through using n.

Inspecting a basic block

You can find the start address of a basic block by stepping through the scanner as described above. Typing print start_address will print the starting address of the current basic block. Similarly, print basic_block will print the number of the current basic block being scanned.

To inspect a basic block as it is constructed (or any other time), type disassemble <start-address>, <start-address>+<offset>. This will print out the instructions at this range of memory.

Alternatively, you can follow execution out of the scanner and back into the code cache by stepping through instructions until you reach the code cache. Note, that there is no source code available to display here, because this code is not internal to MAMBO, rather it is generated by scanning basic blocks from the loaded binary. Type layout asm to switch to an assembler view of memory and step through the code cache using ni to step instruction by instruction.