How can I examine assembly in Xcode 4?
I'm tuning some code that runs in a tight loop in my iPhone app and I'm curious to see the generated assembly code to see if anything looks out of the ordinary.
In Xcode 3.x, there was a Build > Show Assembly Code option in the menu, but I don't see anything in the menus or the documentation for Xcode 4.
Anyone know how to do this? I could do "gcc -S" bu开发者_运维百科t my understanding is that that won't be identical to how the entire project is compiled.
The "View Disassembly" option is gone, as far as I can tell.
Here's one workaround:
- Build your project
- Open the build log, and use the search window to find the compile command that was used to build the source file you're interested in. Copy the entire build command.
- Open a terminal window, and cd to your project directory.
- Paste the build command from the build log into the terminal, and append
-save-temps
. Hit enter. - You now have two new files,
yourFile.i
andyourFile.s
, which are the preprocessed source and generated assembly, respectively, built exactly as they are in your project.
Alternatively, you can disassemble the built binary (or the object file resulting from your source file) using otool -tvV /path/to/binaryOrDotOFile
.
Finally, if this is a feature that you would like to have back, make sure to file a bug report!
Edit: This feature is back in Xcode 4.1. In the assistant editor pane, select "Generated Output -> YourFilename (Assembly)". Boom!
You can build Assembly by going to Product->Generate Output->Assembly File. Hope this is what you are looking for.
Note: They changed it again in Xcode 5. The above answer is doing the thing now
In Xcode 5.0.2 you can select Product → Perform Action → "Assemble MyController.m"
N.B. While this question refers to Xcode 4, it comes up high in results on google.
For lazy folks like me, Stephen Canon's suggestion above to use the -save-temps flag can be accomplished with even less work: go to project settings -> build phases -> compile sources and note the "Compiler Flags" column. Add -save-temps to whichever file you need a disassembly of, and the .ii and .s files will end up in the project directory.
Probably a better solution would be to make a custom rule with something like "-Wa,-alh" and a shell redirect "> myFile.s", but I don't see how to easily duplicate the default build rule for modification.
How in the world did "view assembly" get removed from XCode 4?!?!
According to this thorough review of Xcode 4, this functionality has been removed from Xcode 4. You'll need to file a bug/rdar if you want to try and get it back.
Another helpful quick-glance at Xcode 4 features by the same author: http://pilky.me/view/16
Try to press Ctrl+F7 one or more times and you will see assembly code.
Run in the debugger and break execution, and you can type "disass" into the debugger. By default it'll disassemble the current function, so it's usually quickest to put a breakpoint in the function you want to see. In LLDB, "disass -h" will show other options, like disassembling a named function (not sure if this works for ObjC selectors).
A lot easier than rebuilding source files by hand, at least...
精彩评论