简体   繁体   English

如何检查Xcode 4中的汇编?

[英]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. 我正在调整一些在我的iPhone应用程序中以紧密循环运行的代码,我很想看到生成的汇编代码,看看是否有任何异常。

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. 在Xcode 3.x中,菜单中有一个Build> Show Assembly Code选项,但是在Xcode 4的菜单或文档中没有看到任何内容。

Anyone know how to do this? 有人知道怎么做吗? I could do "gcc -S" but my understanding is that that won't be identical to how the entire project is compiled. 我可以做“gcc -S”,但我的理解是,这与整个项目的编译方式不同。

The "View Disassembly" option is gone, as far as I can tell. 据我所知,“View Disassembly”选项已经消失。

Here's one workaround: 这是一个解决方法:

  1. Build your project 建立你的项目
  2. 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. 打开构建日志,并使用搜索窗口查找用于构建您感兴趣的源文件的编译命令。复制整个构建命令。
  3. Open a terminal window, and cd to your project directory. 打开终端窗口,然后cd到项目目录。
  4. Paste the build command from the build log into the terminal, and append -save-temps . 将build命令从构建日志粘贴到终端中,并附加-save-temps Hit enter. 点击进入。
  5. You now have two new files, yourFile.i and yourFile.s , which are the preprocessed source and generated assembly, respectively, built exactly as they are in your project. 您现在有两个新文件yourFile.iyourFile.s ,它们分别是预处理源和生成的程序集,它们的构建方式与项目中的完全相同。

Alternatively, you can disassemble the built binary (or the object file resulting from your source file) using otool -tvV /path/to/binaryOrDotOFile . 或者,您可以使用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. 编辑:此功能返回Xcode 4.1。 In the assistant editor pane, select "Generated Output -> YourFilename (Assembly)". 在助理编辑器窗格中,选择“生成的输出 - > YourFilename(程序集)”。 Boom! 繁荣!

You can build Assembly by going to Product->Generate Output->Assembly File. 您可以通过转到Product-> Generate Output-> Assembly File来构建Assembly。 Hope this is what you are looking for. 希望这是你正在寻找的。

Note: They changed it again in Xcode 5. The above answer is doing the thing now 注意:他们在Xcode 5中再次更改了它。上面的答案现在正在做的事情

In Xcode 5.0.2 you can select Product → Perform Action → "Assemble MyController.m" 在Xcode 5.0.2中,您可以选择产品→执行操作→“组装MyController.m”

NB While this question refers to Xcode 4, it comes up high in results on google. 注意虽然这个问题涉及Xcode 4,但它在谷歌上的结果很高。

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. 对于像我这样的懒人,Stephen Canon上面建议使用-save-temps标志可以用更少的工作完成:转到项目设置 - >构建阶段 - >编译源代码并注意“编译器标志”列。 Add -save-temps to whichever file you need a disassembly of, and the .ii and .s files will end up in the project directory. 将-save-temps添加到需要反汇编的文件中,.ii和.s文件最终会出现在项目目录中。

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. 可能更好的解决方案是使用类似“-Wa,-alh”和shell重定向“> myFile.s”的自定义规则,但我不知道如何轻松复制默认构建规则进行修改。

How in the world did "view assembly" get removed from XCode 4?!?! 世界上如何从“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. 根据对Xcode 4的全面回顾 ,此功能已从Xcode 4中删除。如果您想尝试将其恢复,则需要提交bug / rdar。

Another helpful quick-glance at Xcode 4 features by the same author: http://pilky.me/view/16 另一个有用的快速浏览Xcode 4功能的同一作者: http//pilky.me/view/16

尝试按Ctrl + F7一次或多次,您将看到汇编代码。

Run in the debugger and break execution, and you can type "disass" into the debugger. 在调试器中运行并中断执行,您可以在调试器中键入“disass”。 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). 在LLDB中,“disass -h”将显示其他选项,例如反汇编命名函数(不确定这是否适用于ObjC选择器)。

A lot easier than rebuilding source files by hand, at least... 比手工重建源文件容易得多,至少......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM