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

1

5

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)

Deduct answered 26/3, 2014 at 11:46 Comment(0)
O
12

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.

Ouzo answered 26/3, 2014 at 13:22 Comment(3)
This works in my experiments on GDB 8.2, but I wonder where GDB gets the information from, since DDI0487 da says CPSR[5] is res0, and that you should read PSTATE.P from SPSR[5], and SPSR does not seem accessible from user mode.Grim
Keep in mind that this answer is from 2014, referring to ARMv7, the document you linked to is for ARMv8. PSTATE was only introduced in ARMv8 and took some of the former CPSR bits.Ouzo
Yes, I understand. And this still works, which is great :-)Grim

© 2022 - 2024 — McMap. All rights reserved.