• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to switch GDB disassembly from Thumb to ARM?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to switch GDB disassembly from Thumb to ARM?


  • Subject: Re: How to switch GDB disassembly from Thumb to ARM?
  • From: Greg Parker <email@hidden>
  • Date: Wed, 9 Nov 2011 13:32:34 -0800

On Nov 9, 2011, at 9:39 AM, Don Quixote de la Mancha wrote:
> GDB's disassembly is correct for the Thumb code, but when I am in ARM
> mode, it disassembles the ARM instructions as if each one were a pair
> of completely nonsensical Thumb instructions.  Is there some way I can
> tell GDB to switch to ARM disassembly, then upon returning to Thumb
> code, use the Thumb disassembler?

gdb chooses ARM or Thumb on a per-function basis, using information provided in the assembly file.

If you mark a function as .thumb_func, then gdb will disassemble it as if it were Thumb. If it is not marked, gdb will disassemble it as if it were ARM. The linker does the same: if the function is marked .thumb_func, then the linker and loader will set the low bit of that function pointer so calls to it enter in Thumb mode.

You can force gdb to disassemble at an address using ARM or Thumb:
% x/10wi address  // disassemble 10 ARM instructions at address
% x/10hi address  // disassemble 10 Thumb instructions at address


> .globl _IntNoArgs
> .align 2
> .code 16
> .thumb_func _IntNoArgs
>
> _IntNoArgs:
>    @ int IntNoArgs( void );
>    .loc 1 __LINE__ 0
>
>    adr r0, Larm1     @ Larm1 is a PC-relative address.  r0's low bit
> will be cleared
>    bx r0                   @ Switch to ARM mode then branch to Larm1.
> That's the next instruction
>
> .align 4
> .code 32
> Larm1:
>    stmfd sp!, { r7, lr }
>
>    mov r0, #42
>
>    ldmfd sp!, { r7, lr }
>    bx lr

You're doing too much work here. iOS never used ARM CPUs with ARMv4T's limited Thumb support, so there's no need to do interworking the hard way. Write each function using whichever instruction set you want, mark your Thumb entrypoints with .thumb_func, and use `bx` or `blx` for every function call and return. The linker and loader will do the rest.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to switch GDB disassembly from Thumb to ARM? (From: Don Quixote de la Mancha <email@hidden>)

  • Prev by Date: Re: Tip: how to fix failure to compile ivars in class extensions
  • Next by Date: Logging in Xcode 4.2
  • Previous by thread: Re: How to switch GDB disassembly from Thumb to ARM?
  • Next by thread: Logging in Xcode 4.2
  • Index(es):
    • Date
    • Thread