2

I'm reading over this awesome article on friday.com. bbum shows some objective-c code and the corresponding assembly. How can I view objective-c assembly code?

Assume I'm compiling from the OS X Terminal using gcc.

SundayMonday
  • 19,147
  • 29
  • 100
  • 154
  • 1
    If you are willing to use xcode, it has a built feature to view the assembly of a file. –  Mar 06 '12 at 17:57
  • 3
    Much of the assembly in that article was copy/pasted directly from the source; the messenger in Objective-C -- objc_msgSend() -- is written in assembly directly. Speaking of, I need to update the article for the newer runtime that supports tagged pointers, imps-as-blocks, and has a faster caching mechanism. – bbum Mar 06 '12 at 18:27

2 Answers2

6

Use otool after compilation, or gcc -S <input>.c -o <output>.S, or just use XCode, it's pretty awesome... /Developer/usr/bin/xcodebuild from the directory containing your project, then:

enter image description here

QED
  • 9,803
  • 7
  • 50
  • 87
  • Actually his words were "OS X Terminal" but who's being pedantic? – QED Mar 07 '12 at 11:40
  • I updated my answer with instructions for running XCode from the command line! Bahahahah anyway I think everybody is happy here – QED Mar 07 '12 at 11:48
5

I never tried with objective-c (it works with C) but I guess you can use simply

gcc -S program.m

You can also use -fverbose-asm to make a more readable output

Manlio
  • 10,768
  • 9
  • 50
  • 79