使用 Instruments 分析 iPhone 应用程序时缺少符号名称
我正在通过命令行编译 iPhone 应用程序(因此不涉及 Xcode 选项),但是在使用 Instruments 进行分析时,我无法显示符号名称。
我尝试了多个标志,例如 -gdawrf-2
和 -g
但没有成功。我还尝试使用 dsymutil 生成 .dSYM 文件,但我不知道应该如何使用它,所以也失败了。
I am compiling an iPhone application via command line (so no Xcode options involved) however I am unable to get my symbol names to show when profiling with Instruments.
I have tried several flags such as -gdawrf-2
and -g
without any success. I have also tried using dsymutil
to generate a .dSYM
file but I have no clue how I'm supposed to use it so that failed as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我将项目设置更改为在构建时不包含 dSYM 文件:
将其更改为包含 dSYM 文件有帮助探查器对符号进行去符号化并解决了我的问题:
I Changed my project settings to not include the dSYM file while building:
Changing it to include the dSYM File helped the profiler desymbolize the symbols and fixed my issue:
我对此仍然有疑问。
我的问题是我能够看到正在生成的 dSYM 文件,但 Instruments 没有拾取它。
要解决此问题,请执行以下操作:
I was still having issues with this.
My issue was I was able to see the dSYM file being generated, but Instruments wasn't picking it up.
To fix this, do the following:
Instruments 如何获取调试信息:
Instruments 从 .dSYM 文件获取调试信息,该文件通常由 XCode 在将 dSYM 文件的“调试信息格式”设置为 DWARF 时自动生成,并在“生成调试符号”选项框中勾选复选标记。设置这些选项将为 XCode 构建过程添加额外的步骤,并在编译应用程序后生成 dSYM 文件。每个 dSYM 都是使用一个 UUID 构建的,该 UUID 与派生它的二进制文件中的 Mach-O 部分中的 UUID 相对应。 Spotlight 导入程序会对 Mac 上 Spotlight 可访问位置中的每个 dSym 文件的 UUID 进行索引。因此,SPOTLIGHT 完成了所有黑魔法,并负责在您正在运行的 .app 与其相应的 .dSYM 文件之间建立链接。
如何在没有 XCode 的情况下生成调试信息和 dSYM 文件:
确保使用 –gdwarf-2 和 -g 标志进行编译。 (其他标志组合可能有效)
使用 dsymutil 生成 dSYM 文件。如果在命令行中无法识别该工具,请使用聚光灯来查找它。
重要提示:如果您使用的是联网驱动器,则在生成 dSYM 之前,请将 .app 文件放置在您的 mac HD 上。
将 .dSYM 文件放在 Mac 的本地驱动器上,然后像平常一样运行 Instruments。
重置聚光灯的索引:
如果未显示符号,可能是因为聚光灯被窃听了。您可以尝试重置 Spotlight 的索引,方法是将包含 dSYM 文件(甚至驱动器)的文件夹添加到 Spotlight 首选项中的“防止 Spotlight 搜索这些位置”,然后立即将其删除。
How Instruments obtains debug information:
Instruments obtains debug info from a .dSYM file which is normally generated automatically by XCode when setting Debug Information Format to DWARF with dSYM File combined with a checkmark in the Generate Debug Symbols option box. Setting these options will add an extra step to the XCode build process and generate a dSYM file after the application has been compiled. Every dSYM is built with a UUID that corresponds to a UUID in a Mach-O section in the binary that it's derived from. A Spotlight importer indexes the UUIDs of every dSym file that is in a Spotlight-accessible location on your Mac. Therefore SPOTLIGHT does all the black magic and is responsible of making the link between the .app you are running and its corresponding .dSYM file.
How to generate debug information and dSYM file without XCode:
Make sure you are compilig with –gdwarf-2 and -g flags. (Other flag combinations might work)
Generate a dSYM file using dsymutil. If the tool isn't recognized in command line, use spotlight to find it.
IMPORTANT: Place .app file on your mac HD before you generate the dSYM if you are working on a networked drive.
Place the .dSYM file on the mac's local drive and run Instruments as you normally would.
Resettig spotlight's indexing:
If symbols aren't shown, it might be because spotligh is bugged. You can try reseting spotlight's indexing by adding your folder containing the dSYM file (or even your drive) to the “Prevent spotlight from searching these locations” in the spotlight preferences and then removing it right away.
在 Xcode 4.5 中,您可以选择从调试或发布版本进行分析。 Release 默认在复制到设备时剥离符号。可以非常轻松地切换到调试配置进行分析,而无需破坏发布配置。为此,请选择产品 ->从 XCode 菜单编辑方案。从出现的方案列表中选择“配置文件”,然后为其选择正确的构建配置。
或者,您可以进行单独的发布/配置文件配置,并在方案的配置文件部分中使用它。 XCode 用户指南。
In Xcode 4.5 you can choose to Profile from Debug or Release builds. Release defaults to stripping the symbols when copied to the device. It's very easy to switch to the Debug configuration for profiling without breaking your release configuration. To do that, select Product -> Edit Scheme from the XCode menu. Select "Profile" from the list of schemes that comes up, and then select the correct Build Configuration for that.
Or you could make a separate release/profile configuration and use that in your Profile section of your scheme. How to add a separate build configuration is described in the XCode User Guide.
使用Xcode 6 Instruments,您可以提供dSYM文件,如下所示:
⌘+SHIFT+G
。此外,Instruments 会询问您将来是否应该使用选定的路径来尝试为此应用程序加载 dSYM。回答 是的:)
With Xcode 6 Instruments you can provide dSYM file as follow:
⌘+SHIFT+G
in dialog.Also Instruments will ask you if it should use selected path to try load dSYM for this app in the future. Answer Yes :)
花了三天时间尝试解决 Xcode 7.1/7.3 的问题...将
部署目标更改为最新版本(当时为 9.3)为我解决了这个问题。我的公司的目标是 7.0,因此我可能必须创建一个自定义方案来分析 Instruments 中的代码,以避免在我们进行生产发布时必须更改目标(或忘记更改目标)。
如果 dSYM 无法根据部署目标工作,似乎这可能是一个错误?
Spent three days trying to figure this out for Xcode 7.1/7.3...
Changing the deployment target to the latest version (9.3 at the time) fixed this issue for me. My company targets 7.0 so I will probably have to create a custom Scheme for profiling the code in Instruments to avoid having to change the target (or forgetting to change the target) when we do a production release.
Seems like it's probably a bug if dSYMs fail to work based on the deployment target?
根据我的经验,这通常是因为在目标设备上安装应用程序的最新修改版本之前调用了“配置文件”。
尝试在设备/目标上运行应用,然后在重新安装后再次调用“配置文件”。
In my experience, this is usually because "Profile" has been called before the most recently modified version of the app has been installed on the target device.
Try running the app on the device/target, then calling "Profile" again after it has been reinstalled.
问题是聚光灯找不到 .dSYM 文件。
这是因为 Apple 更改了 DerivedData 文件夹的位置。
DerivedData 现在进入 ~/Library
Spotlight 不会索引 ~/Library 并且据我所知,也无法对其建立索引(例如 mdimport被忽略)。
在分析器中获取符号的一种解决方法是简单地将数据复制到 ~/Library 之外,例如您的主目录就可以了。
我使用了这个命令行:
当您终止探查器并开始新的探查器运行时,您将看到这些符号再次可用。
The problem is that spotlight cannot find the .dSYM files.
This is because Apple changed the location of the DerivedData folder.
The DerivedData now goes in ~/Library
Spotlight will not index ~/Library and as far as I have been able to establish, cannot be made to index it either (e.g. mdimport is ignored).
A work around to get symbols in your profiler, is to simply copy the data outside ~/Library e.g. your home directory will do fine.
I used this command line:
When you kill your profiler, and start a new profile run, you will see that the symbols are available again.
检查构建日志并确保您的
-g
开关已到达编译器 - 在更改项目和/或目标级别的不同构建配置等设置时很容易出错。Check the build log and make sure that your
-g
switch is getting through to the compiler - it's easy to get this wrong when changing settings at the project and/or target levels for different build configurations etc.Xcode 4 附带的 Instruments 版本中的另一个解决方法是使用 Instruments 文件菜单下的重新符号化文档菜单项。此菜单项允许您使用位于 ~/Library/... 目录中的 .dSYM 文件中的符号。
Another work around in the version of Instruments that comes with Xcode 4 is to use the Re-Symbolicate Document menu item under the File menu for Instruments. This menu item to allows you to use the symbols located in the .dSYM file in ~/Library/... directory.
我遇到这个问题是因为 XCode 项目位于网络共享上,Spotlight 找不到 dSYM 文件。确保它位于本地驱动器上。
I got this problem because the XCode project was on a network share where Spotlight wouldn't find the dSYM files. Make sure it's on the local drive.