Search code examples
gdbarmthumb

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


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)


Solution

  • 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.