Description
Hi,
I'm currently learning Arm64 assembly and I find it quiet cumbersome to get gdb ready for debugging.
I guess on native ARM hardware it shouldn't be that hard but unfortunatly I'm doing the exercises on my x86 machine.
.macro debug reg fmt_str=""
.pushsection .rodata
.ifeqs "\fmt_str", ""
l_fmt_str\@: .asciz "Register \reg: %d\n"
.else
l_fmt_str\@: .asciz "\fmt_str"
.endif
.popsection
sub sp, sp, #16
stp x29, x30, [sp]
mov x29, sp // FP points to frame record
mov x1, \reg
ldr x0, =l_fmt_str\@
bl printf
ldp x29, x30, [sp]
add sp, sp, #16
.endm
I know, it's not perfect and there is a lot of room for improvement.
For example the register x0 and x1 are modified when the macro is used (the user might not expect this).
But I posted it so you get the idea what I have in mind.
An additional file like debug.s
could be provided with the exercises which can be included by the user with .include "debug.s"
The macro is then called like so:
debug x1
which give an output like Register x1: 42
.
It can also be called with a user defined format string:
debug x1 "My custom debug message: Register x1 is now set to %d\n"
which will give something like "My custom debug message: Register x1 is now set to 42"
.