Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I tell if I am in ARM mode or Thumb mode in gdb?

Tags:

gdb

arm

thumb

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)

like image 691
daehee Avatar asked Mar 26 '14 11:03

daehee


People also ask

What is the difference between arm and Thumb code symbols?

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.

How to check if a function is arm or C++?

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.

What is the minimum address range for thumb and ARM instructions?

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.

How do I read an arm file?

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.


1 Answers

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.

like image 109
Nico Erfurth Avatar answered Oct 03 '22 00:10

Nico Erfurth