3

I am developing on a Qt project, and have installed Qt from their installer onto my computer. In Visual Studio it is simple to debug-step into Qt sources: when I enter a function in an unknown file, it will open a file browser to let me locate the original Qt source code.

Is there an equivalent function in Xcode or LLDB?

Luke Worth
  • 570
  • 3
  • 18

1 Answers1

4

The debug information records the location of the QT source files when they were built. You can find this information by doing:

  (lldb) image lookup -va main
    Address: hello[0x0000000100000f40] (hello.__TEXT.__text + 0)
    Summary: hello`main at hello.c:5
     Module: file = "/private/tmp/hello", arch = "x86_64"
CompileUnit: id = {0x00000000}, file = "/tmp/hello.c", language = "ISO C:1999"
   Function: id = {0x00000026}, name = "main", range = [0x0000000100000f40-0x0000000100000f6d)
   FuncType: id = {0x00000026}, decl = hello.c:4, clang_type = "int (void)"
     Blocks: id = {0x00000026}, range = [0x100000f40-0x100000f6d)
  LineEntry: [0x0000000100000f40-0x0000000100000f56): /tmp/hello.c:5
     Symbol: id = {0x00000004}, range = [0x0000000100000f40-0x0000000100000f6d), name="main"

but substitute some QT function for "main". Then look at the CompileUnit line and see what the "file" entry says. Suppose it says

"/BuildDirectory/sources/SomeSubdirectory/SomeFile.cpp"

Now presumably you've downloaded the QT sources, and they live somewhere on your local machine, say in

"/Users/ME/QT/sources"

So what you want to do is tell lldb: "when you see a source file rooted at /BuildDirectory/sources, look in /Users/ME/QT/sources instead." You do that with the lldb "target.source-map" setting. In this example, you would say:

(lldb) settings set target.source-map /BuildDirectory/sources /Users/ME/QT/sources

You can type that in on the command line or put it in your .lldbinit file for more general use. lldb will update its source maps automatically, but if you are running in Xcode, you'll have to step once after issuing the command to get it to update.

Luke Worth
  • 570
  • 3
  • 18
Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Even when loading the debug versions of the libraries, I get no CompileUnit line. I guess they have been stripped... – Luke Worth Aug 28 '14 at 02:57
  • I've never used Qt, but a lot of projects like this will have debug & release distributions available. Might be worth checking to see if the Qt project has such a thing. – Jim Ingham Aug 28 '14 at 18:37
  • 1
    The Mac release of Qt 5.3 (installed using the web installer, not from source) doesn't seem to contain the CompileUnit information. I just compiled Qt 5.4 from the source tarball, and when setting DYLD_IMAGE_SUFFIX=_debug I get full debugging information, and can step through Qt source code. I am accepting this answer as it would probably help somebody who did actually have the CompileUnit information pointed to the wrong place, although I haven't verified this myself. – Luke Worth Sep 09 '14 at 08:19