when debugging ARMv7 binary with GDB, aside from looking the instruction length, is there a way to figure out which mode the CPU is currently in? (ARM, Thumb)
Note: This allows a linker to distinguish Arm and Thumb code symbols without having to refer to the map. An Arm symbol will always have an even value, while a Thumb symbol will always have an odd value. However, a linker should strip the discriminating bit from the value before using it for relocation.
When compiling C/C++ code, you can also detect the ARM/thumb status for a function by looking at the symbol table. The lowest bit of the address is set to 1 for Thumb and 0 for ARM instructions. To see this, you can use readelf --symWhen using objdump -t and readelf`, though.
The lowest bit of the address is set to 1 for Thumb and 0 for ARM instructions. To see this, you can use readelf --symWhen using objdump -t and readelf`, though.
An ARM object file should contain symbols identifying the regions that are arm code ( $a ), thumb code ( $t) and literal data ( $d ). You can see these as symbols #4 and #5 in your read-elf output. i.e. offset 0 is arm, offset 8 is thumb obj-dump will output these symbols too if you use the --special-syms option.
I'm using this little gdb-script to determine the current state from the CPSR field, just put it inside your ~/.gdbinit file and call arm_isa when needed.
define arm_isa
if ($cpsr & 0x20)
printf "Using THUMB(2) ISA\n"
else
printf "Using ARM ISA\n"
end
end
It checks bit 5 in cpsr, which indicates the current state and outputs the used ISA.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With