如何在 Xcode 4 中检查程序集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5433935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:39:01  来源:igfitidea点击:

How can I examine assembly in Xcode 4?

objective-cxcodegccassemblyxcode4

提问by Bill

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 Codeoption 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”,但我的理解是这与整个项目的编译方式不同。

回答by Stephen Canon

The "View Disassembly" option is gone, as far as I can tell.

据我所知,“查看反汇编”选项消失了。

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.
  4. Paste the build command from the build log into the terminal, and append -save-temps. Hit enter.
  5. You now have two new files, yourFile.iand yourFile.s, which are the preprocessed source and generated assembly, respectively, built exactly as they are in your project.
  1. 构建你的项目
  2. 打开构建日志,并使用搜索窗口查找用于构建您感兴趣的源文件的编译命令。复制整个构建命令。
  3. 打开终端窗口,然后 cd 到您的项目目录。
  4. 将构建日志中的构建命令粘贴到终端中,并附加-save-temps. 按回车。
  5. 您现在有两个新文件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. In the assistant editor pane, select "Generated Output -> YourFilename (Assembly)". Boom!

编辑:此功能在 Xcode 4.1 中又回来了。在助手编辑器窗格中,选择“生成的输出 -> YourFilename (Assembly)”。繁荣!

回答by arnoapp

You can build Assembly by going to Product->Generate Output->Assembly File. Hope this is what you are looking for.

您可以通过转到 Product->Generate Output->Assembly File 来构建 Assembly。希望这是你正在寻找的。

Note: They changed it again in Xcode 5. The above answer is doing the thing now

注意:他们在 Xcode 5 中再次更改了它。上面的答案是现在做的事情

回答by seo

In Xcode 5.0.2 you can select Product → Perform Action → "Assemble MyController.m"

在 Xcode 5.0.2 中,您可以选择Product → Perform Action → "Assemble MyController.m"

N.B. While this question refers to Xcode 4, it comes up high in results on google.

注意虽然这个问题是指 Xcode 4,但它在 google 上的结果很高。

回答by Tyler Daniel

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.

对于像我这样的懒人,Stephen Canon 建议使用 -save-temps 标志可以用更少的工作完成:转到项目设置 -> 构建阶段 -> 编译源并注意“编译器标志”列。将 -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 中删除的?!?!

回答by GendoIkari

According to this thorough reviewof 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 中删除。如果您想尝试将其恢复,则需要提交错误/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

回答by esmirnov

Try to press Ctrl+F7 one or more times and you will see assembly code.

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

回答by Glenn Maynard

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

在调试器中运行并中断执行,您可以在调试器中键入“disass”。默认情况下,它会反汇编当前函数,因此通常在您想要查看的函数中放置断点是最快的。在 LLDB 中,“disass -h”将显示其他选项,例如反汇编命名函数(不确定这是否适用于 ObjC 选择器)。

A lot easier than rebuilding source files by hand, at least...

至少比手动重建源文件容易得多......