Using The Python API for GDB to Help with Assembler Programming - StevenLwcz/gdb-python GitHub Wiki
aarch64pp.py and armv8-app.py contain a number of new info command to help with assembly programming on ARM. They also contain a number of pretty printers to simplify the display of floating point vectors when you are only interested in using them as scalars.
There are a number of ways the python files can be loaded into gdb but the simplest is:
gdb -x aarch64pp.py <exe>
For full detail on each command in gdb use:
(gdb) help info cmd
This also gives a summary of the ARM ABI for that set of registers.
info cpsr -- Display the status of the pstate/cpsr register and condition codes info double -- List double precision floating point registers and values info general -- List general registers and values info single -- List the single precision floating point registers and values
(gdb) help info general
List general registers and values
info general [[start [length]] | [args|callee|temp]]
start: start register (0-30)
length: number of registers:
args: arguments 0-8 (XR: 8)
temporary: 9-18 (IP0: 16, IP1: 17, Platform specific: 18)
callee: callee saved 19-29 (FP: 29)
link reg: 30
default: info general 0 31
info fpcr -- Display the status of the floating point control register (fpcr) register info fpsr -- Display the status of the floating point status register (fpsr) register
(gdb) help info fpcr Display the status of the floating point control register (fpcr) register RN Round to nearest (tie zero) RP Round towards plus infinity (ceil) RM Round towards minus infinity (floor) RZ Round towards zero (truncate) DZE Divide by Zero Enabled
info fpscr -- Display the status of the floating point status control register (fpscr) register
To view the pretty printers
(gdb) info pretty-printer
AsmLibrary
double_float_registers
single_float_registers
These will affect display of the D and S registers in aarch64 and D registers in armv8a. Use the /r switch to go back to gdb's default view.
p /r $d0
You can put tui commands you want to run each time in a text file and use -x to load it.
gdb -q -x a1.gdb -x ../gdb-python/aarch64pp.py a1
break _start run layout src layout reg tui reg general winheight reg +4 winheight src +6
This will display a window with registers at the top. Below will be the source from your .s file. This might be more desirable than the default disassembler view you will get. To debug the source like this you need to specify as -g ... when you compile your assembler.
You can use (gdb) tui reg reggroup to change which set of registers the reg window.
(gdb) focus reg will change the focus so you can scroll in the window if needed.
(gdb) focus src to switch back to src as desired.
To get the register group
(gdb) tui reg "tui reg" must be followed by the name of either a register group, or one of 'next' or 'prev'. Known register groups are: general, float, system, vector, all, save, restore
or
(gdb) maint print reggroup
To display gdb's internal view of registers.
(gdb) maint print registers
This is useful when using the Python APIs for gdb for accessing register values. Also knowing the internal type can help with writing new pretty printers. You can also find what internal type gdb is using for a register.
(gdb) whatis $s0 type = __gdb_builtin_type_vns (gdb) whatis $d0 type = __gdb_builtin_type_vnd
In armv8-a $s0 is float and $d0 is neon_d.
info all-registers -- List of all registers and their contents, for selected stack frame. info float -- Print the status of the floating point unit. info registers, info r -- List of integer registers and their contents, for selected stack frame. info vector -- Print the status of the vector unit.
Gdb's display {expr} command will display the expression after every step.
(gdb) display $x0
You can use gdb's hook mechanism to hook into any command or event to run another set of gdb commands.
(gdb) define hook-step > info single args > print $d15 > end
After each step the above command will be executed. There is also a command {num} to automatically run commands after that breakpoint has been hit.