74

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Mac Twist
  • 1,161
  • 1
  • 8
  • 7
  • I created a "Profile" build configuration to deal with this issue. See [my answer](https://stackoverflow.com/a/13528694/908621) to a similar Stackoverflow question. – fishinear Nov 23 '12 at 12:02

11 Answers11

110

I Changed my project settings to not include the dSYM file while building:

enter image description here

Changing it to include the dSYM File helped the profiler desymbolize the symbols and fixed my issue:

enter image description here

Antoine
  • 23,526
  • 11
  • 88
  • 94
  • I don't think this answers the question, since your screenshots are from Xcode and the question deliberately precludes Xcode (@mac-twist is using the command line), but I'm using Xcode and had this problem, Google directed me to this question, and your suggestion worked for me - thanks. – dumbledad Jan 17 '16 at 22:53
  • I have the same issue and using instruments and Xcode with debug build option. this worked for me. Xcode 7.3.1 & iOS 9.3.4 – Jerry Chen Aug 24 '16 at 03:06
  • 4
    Very interesting that Debug defaults to no dSYM File inclusion! :/ Thanks for sharing this. Profiling now shows all symbols! :) – Jona Sep 15 '16 at 14:54
  • 3
    @Jona: The downside of generating dSYM files is that building take significantly longer— this is why Debug build don't include them by default, since you typically want to be able to build and run quickly. – Slipp D. Thompson Apr 29 '17 at 21:57
  • 2
    I guess this is why by default Xcode will make a 'release' build when you choose "Build for profiling" – Glenn Schmidt Jun 22 '18 at 02:09
  • This solved my problem for my own symbols, but what about system libraries like AppKit and Foundation? Is there a way to symbolicate them, so my instruments stack traces are less opaque? – Alexander May 12 '20 at 02:06
69

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:

  1. Locate your dSYM file (should be in ~/Library/Developer/DerivedData/APP_NAME-XXXXXXX/Build/Products/[BUILD_TYPE]-[DEVICE-TYPE]/
  2. With Instruments stopped, click on File -> Re-Symbolicate Document
  3. Scroll down to the entry with your app name
  4. Click "Locate" and choose the folder from step 1
  5. Click the Start button to begin profiling
youdonotexist
  • 901
  • 1
  • 6
  • 6
  • I like this solution since it doesn't rely on Spotlight to work. It was also the only one which fixed this issue for me. Thanks! – William Denniss Apr 02 '12 at 22:03
  • But now I have to do this repeatedly, with each run. Any way to make it stick? – OldPeculier Jun 28 '12 at 22:39
  • I got an error when trying to re-symbolicate (something about how the dSYM file and the app didn't have matching UUID's), so I just deleted all files in the [BUILD_TYPE]-[DEVICE-TYPE]/ folder (see step 1 above) and repeated the process, and then it worked. Yeah! – Vern Jensen Aug 24 '12 at 01:47
  • 2
    Oh and also, with the latest version of XCode, DerivatedData is in your *project*'s directory, NOT in ~/Library. – Vern Jensen Aug 24 '12 at 01:48
  • @k06a - did you figure out how to get your app in the list? – bendytree Aug 31 '12 at 15:00
  • 6
    @bendytree I've just changed signature in target from distribution to developer and it helps. – k06a Aug 31 '12 at 20:12
  • @k06a Can you elaborate on that please? – ndmeiri Dec 15 '15 at 06:36
  • 2
    This worked for me, but on Xcode 7 I didn't have to locate the dSYM. I just had to go to File > Symbols and hit Done and it fixed it. If you do need to locate the dSYM, DerivedData is now at ~/Library/Developer/Xcode/DerivedData. – Liron Yahdav Jul 25 '16 at 23:59
42

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)

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

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 MyApp.app/MyApp -o MyApp.app.dSYM

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.

Mac Twist
  • 1,161
  • 1
  • 8
  • 7
  • 2
    Thank you. I'd previously excluded my Xcode DerivedData folder from the Spotlight index to help Spotlight find the correct .dsym to symbolicate crash logs. Removing that did the trick. – joerick May 02 '11 at 13:24
  • Though it may require Finder to be able to show hidden folders, and need to use drag-drop to be able to temporarily add the folder into Un-indexed folder list, it did work for me nicely right after removing it, to be indexed again – petershine Aug 06 '12 at 02:32
  • This happened to us because we changed the Debug Information Format from "DWARF with dSYM File" to "DWARF" for performance reasons. We have the format set to "DWARF with dSYM File" in another scheme. So we just have to change schemes whenever we want to profile. – Liron Yahdav Oct 15 '14 at 23:51
15

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.

fishinear
  • 6,101
  • 3
  • 36
  • 84
Matt Connolly
  • 9,757
  • 2
  • 65
  • 61
  • 1
    Also if you are building for profiling, definitely check "Profile" scheme that it has assigned some build configuration generating debug symbols like Debug! (was my problem) – k3a Feb 11 '13 at 16:17
7

With Xcode 6 Instruments you can provide dSYM file as follow:

  • File -> Symbols... menu (when profiling is stopped)
  • select your app and press Locate button
  • 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.

Also Instruments will ask you if it should use selected path to try load dSYM for this app in the future. Answer Yes :)

Anton Gaenko
  • 8,929
  • 6
  • 44
  • 39
6

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?

Jason Rice
  • 61
  • 1
  • 1
  • 3
    +1 for this answer, I've basically tried everything I could find relating to dSYM files, spotlight, build schemes, debug symbol formats, etc. Nothing fixed anything, but switching to the latest deployment target the symbols were found immediately. Now that I think about it, I think this probably also explains why the debug navigator never showed any memory or CPU statistics while running with a lower deployment target. Way to go Apple for not popping up some kind of warning or whatever :-/ – w0utert May 05 '16 at 21:15
2

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:

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

Bram
  • 7,440
  • 3
  • 52
  • 94
1

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
1

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.

Ben Guild
  • 4,881
  • 7
  • 34
  • 60
1

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.

pmb
  • 11
  • 2
0

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.

Michael Melanson
  • 1,325
  • 10
  • 21