xcode 使用 Instruments 分析 iPhone 应用程序时缺少符号名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2776466/
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
Missing symbol names when profiling IPhone application with Instruments
提问by Mac Twist
I am compiling an IPhone application via command line (so no XCode options involved) and 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 dsymutils to generate a .dSYM file but i have no clue how I'm supposed to use it so that failed aswell.
我正在通过命令行编译 iPhone 应用程序(因此不涉及 XCode 选项),并且在使用 Instruments 进行分析时无法显示我的符号名称。我尝试了几个标志,例如 -gdawrf-2 和 -g,但都没有成功。我也尝试过使用 dsymutils 生成一个 .dSYM 文件,但我不知道我应该如何使用它,所以也失败了。
Any help will be greatly appreciated!
任何帮助将不胜感激!
采纳答案by Mac Twist
How Instruments obtains debug information:
Instruments 如何获取调试信息:
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.
Instruments 从 .dSYM 文件中获取调试信息,该文件通常由 XCode 在将 Debug Information Format 设置为 DWARF 时自动生成,dSYM File 结合了 Generate Debug Symbols 选项框中的复选标记。设置这些选项将为 XCode 构建过程添加额外的步骤,并在编译应用程序后生成 dSYM 文件。每个 dSYM 都使用一个 UUID 构建,该 UUID 对应于它派生自的二进制文件中 Mach-O 部分中的 UUID。Spotlight 导入器为 Mac 上 Spotlight 可访问位置中的每个 dSym 文件的 UUID 编制索引。因此,SPOTLIGHT 执行所有黑魔法,并负责在您正在运行的 .app 与其对应的 .dSYM 文件之间建立链接。
How to generate debug information and dSYM file without XCode:
如何在没有 XCode 的情况下生成调试信息和 dSYM 文件:
Make sure you are compilig with –gdwarf-2 and -g flags. (Other flag combinations might work)
确保您使用 –gdwarf-2 和 -g 标志进行编译。(其他标志组合可能有效)
-g Produce debugging information in the operating system's native format (stabs, COFF , XCOFF , or DWARF 2). GDB can work with this debugging information. On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below). GCC allows you to use -g with -O. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops.
Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.-gdwarf-2 Produce debugging information in DWARF version 2 format (if that is supported). This is the format used by DBX on IRIX 6. With this option, GCC uses features of DWARF version 3 when they are useful; version 3 is upward compatible with version 2, but may still cause problems for older debuggers.
-g 以操作系统的本机格式(stabs、COFF、XCOFF 或 DWARF 2)生成调试信息。GDB 可以使用此调试信息。在大多数使用 stabs 格式的系统上,-g 允许使用只有 GDB 才能使用的额外调试信息;这些额外的信息使 GDB 中的调试工作更好,但可能会使其他调试器崩溃或拒绝读取程序。如果您想确定是否生成额外信息,请使用 -gstabs+、-gstabs、-gxcoff+、-gxcoff 或 -gvms(见下文)。GCC 允许您将 -g 与 -O 一起使用。优化代码所采取的捷径有时可能会产生令人惊讶的结果:您声明的某些变量可能根本不存在;控制流可能会短暂地移动到您没有预料到的地方;某些语句可能无法执行,因为它们计算常量结果或它们的值已经在手上;有些语句可能会在不同的地方执行,因为它们被移出循环。
尽管如此,它证明可以调试优化的输出。这使得对可能有错误的程序使用优化器是合理的。-gdwarf-2 以 DWARF 版本 2 格式生成调试信息(如果支持)。这是 DBX 在 IRIX 6 上使用的格式。有了这个选项,GCC 会在有用时使用 DWARF 版本 3 的功能;版本 3 与版本 2 向上兼容,但可能仍会导致较旧的调试器出现问题。
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.
使用 dsymutil 生成 dSYM 文件。如果在命令行中无法识别该工具,请使用聚光灯找到它。重要提示:如果您在网络驱动器上工作,则在生成 dSYM 之前将 .app 文件放在您的 mac HD 上。
dsymutil MyApp.app/MyApp -o MyApp.app.dSYM
dsymutil MyApp.app/MyApp -o MyApp.app.dSYM
Place the .dSYM file on the mac's local drive and run Instruments as you normally would.
将 .dSYM 文件放在 mac 的本地驱动器上,然后像往常一样运行 Instruments。
Resettig spotlight's indexing:
Resettig 聚光灯的索引:
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.
如果未显示符号,则可能是因为聚光灯被窃听了。您可以尝试通过将包含 dSYM 文件(甚至您的驱动器)的文件夹添加到聚光灯首选项中的“防止聚光灯搜索这些位置”,然后立即将其删除来尝试重置聚光灯的索引。
回答by Antoine
I Changed my project settings to not include the dSYM file while building:
我在构建时更改了我的项目设置以不包含 dSYM 文件:
Changing it to include the dSYM File helped the profiler desymbolize the symbols and fixed my issue:
将其更改为包含 dSYM 文件有助于分析器对符号进行去符号化并解决了我的问题:
回答by youdonotexist
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.
我的问题是我能够看到正在生成的 dSYM 文件,但是 Instruments 没有找到它。
To fix this, do the following:
要解决此问题,请执行以下操作:
- Locate your dSYM file (should be in ~/Library/Developer/DerivedData/APP_NAME-XXXXXXX/Build/Products/[BUILD_TYPE]-[DEVICE-TYPE]/
- With Instruments stopped, click on File -> Re-Symbolicate Document
- Scroll down to the entry with your app name
- Click "Locate" and choose the folder from step 1
- Click the Start button to begin profiling
- 找到您的 dSYM 文件(应该在 ~/Library/Developer/DerivedData/APP_NAME-XXXXXXX/Build/Products/[BUILD_TYPE]-[DEVICE-TYPE]/
- 在 Instruments 停止后,单击 File -> Re-Symbolicate Document
- 向下滚动到包含您的应用名称的条目
- 单击“定位”并从步骤 1 中选择文件夹
- 单击“开始”按钮开始分析
回答by Matt Connolly
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.
在 Xcode 4.5 中,您可以选择从 Debug 或 Release 构建进行分析。释放默认为在复制到设备时剥离符号。在不破坏发布配置的情况下切换到调试配置进行分析非常容易。为此,请从 XCode 菜单中选择 Product -> Edit Scheme。从出现的方案列表中选择“配置文件”,然后为此选择正确的构建配置。
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 用户指南中描述了如何添加单独的构建配置。
回答by Anton Gaenko
With Xcode 6 Instrumentsyou can provide dSYMfile as follow:
使用Xcode 6 Instruments,您可以提供dSYM文件,如下所示:
- File -> Symbols...menu (when profiling is stopped)
- select your app and press Locatebutton
- select path which contains dSYM (usually ~/Library/Developer/DerivedData/APP_NAME-XXXXXXX/Build/Products/[BUILD_CONFIGURATION]-[TARGET_PLATFORM]/). Tip:You can copy this path from terminal and use OS X shortcut
?+SHIFT+G
in dialog.
- 文件 -> 符号...菜单(当分析停止时)
- 选择您的应用程序,然后按“定位”按钮
- 选择包含 dSYM 的路径(通常是~/Library/Developer/DerivedData/APP_NAME-XXXXXXX/Build/Products/[BUILD_CONFIGURATION]-[TARGET_PLATFORM]/)。提示:您可以从终端复制此路径并
?+SHIFT+G
在对话框中使用 OS X 快捷方式。
Also Instrumentswill ask you if it should use selected path to try load dSYM for this app in the future. Answer Yes :)
此外,Instruments会询问您是否应该使用选定的路径来尝试在将来为此应用程序加载 dSYM。回答是的:)
回答by Jason Rice
Spent three days trying to figure this out for Xcode 7.1/7.3...
花了三天时间试图为 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.
将部署目标更改为最新版本(当时为 9.3)为我解决了这个问题。我的公司以 7.0 为目标,所以我可能必须创建一个自定义 Scheme 来分析 Instruments 中的代码,以避免在我们进行生产发布时必须更改目标(或忘记更改目标)。
Seems like it's probably a bug if dSYMs fail to work based on the deployment target?
如果 dSYM 无法根据部署目标工作,这似乎是一个错误?
回答by Bram
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
问题是聚光灯找不到 .dSYM 文件。这是因为 Apple 更改了 DerivedData 文件夹的位置。DerivedData 现在进入 ~/Library
Spotlight will not index ~/Libraryand as far as I have been able to establish, cannot be made to index iteither (e.g. mdimport is ignored).
Spotlight 不会索引 ~/Library并且据我所知,也不能对其进行索引(例如 mdimport 被忽略)。
A work around to get symbols in your profiler, is to simply copy the data outside ~/Librarye.g. your home directory will do fine.
在分析器中获取符号的解决方法是简单地将数据复制到 ~/Library 之外,例如您的主目录就可以了。
I used this command line:
我使用了这个命令行:
$ cp -r ~/Library/Developer/Xcode/DerivedData/AppName-xxxxxxxxxxx/Build/Products/Release-iphoneos/ ~/
When you kill your profiler, and start a new profile run, you will see that the symbols are available again.
当您终止分析器并开始新的配置文件运行时,您将看到符号再次可用。
回答by pmb
Another work around in the version of Instruments that comes with Xcode 4 is to use the Re-Symbolicate Documentmenu 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 4 附带的 Instruments 版本中的另一个解决方法是使用Instruments 的 File 菜单下的Re-Symbolicate Document菜单项。此菜单项允许您使用位于 ~/Library/... 目录中的 .dSYM 文件中的符号。
回答by Paul R
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.
检查构建日志并确保您的-g
开关已进入编译器 - 在为不同的构建配置更改项目和/或目标级别的设置时,很容易出错。
回答by Ben Guild
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.
尝试在设备/目标上运行应用程序,然后在重新安装后再次调用“配置文件”。