Andrew Hundt
Andrew Hundt

Reputation: 2591

Debugging C++ library source with Xcode 7 GUI (lldb)

I am using a library installed via cmake in Xcode, and I'd like to allow my debugger to step through that library's code while debugging my application.

After building and installing the dependency cmake project, the cmake project that depends on it would then include that one. When it is run I'd like to step through the code of the dependency library with the Xcode debugger.

Is there a way to tell Xcode for my main application where the headers, source and debug built binaries (if necessary) of the library are so I can step through?

I've found a few relevant questions, but none provides straightforward instructions for configuring your library's source to be found in Xcode with support from the GUI.

Here is an example homebrew formula which installs a cmake project and enables the debug symbols. I can come up with an example that uses the library if needed as well.

Upvotes: 0

Views: 1551

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

If you are linking to the debug version of the library into your application, and you haven't moved or deleted the .o files you used to build it or the source files for those .o files, then you shouldn't have to do anything. lldb will pick up from the loader the location of the library's binary, and that will have a "debug map" that points to the .o files (where, on OS X, the actual debug information is stored) which lldb will then read, and the debug information will contain the path to the source files.

So some part of this chain must have gotten broken if you aren't seeing source in Xcode when you stop in some code in your library.

First make sure you really are building the debug version of the library (the compile lines that build the .o files should have -g in them.)

Next, if your make process is deleting the .o files or stripping the library before installing it, then lldb won't be able to trace from the binary to the debug info. The easiest way to fix this is to make a dSYM as part of the build process, using the dsymutil utility, and install the dSYM somewhere lldb can find (next to the library, or in any location Spotlight searches) or add it explicitly with lldb's add-dsym command. Note if the library is getting stripped you need to make the dSYM before it gets stripped.

Finally, if you are moving the source files from where they are when built, then you can use the source-map as described in the first of your links.

Upvotes: 1

Related Questions