6

According to the official guideline of lldb, the ability to view source code during debug session (using the command source list) is done by setting new pathname for source files.

i.e. if i compiled my project in /tmp on one computer and deployed it on another computer where the source code reside in /Users/Src/ , i should type settings set target.source-map /tmp /Users/Src from running lldb in the deployment machine.

However, what happens if i got the executable from someone else, and don't know the build directory. and maybe the source-code is organized differently from where is was built (but the file contents is the same).

my questions are :

  1. Does lldb know how to search for matching source file recursively in the supplied path ?

  2. How can I get the original pathname form the mach-o executable ?

here's the formal description of the command :

Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built --- maybe the program was built on a different computer --- you need to tell the debugger how to find the sources at their local file path instead of the build system's file path.

Zohar81
  • 4,554
  • 5
  • 29
  • 82
  • I'm not familiar neither of lldb nor osx, but I suggest you try `readelf -a` and `objdump -p` to get some path info from your executable. But `readelf` seems not available in osx, http://stackoverflow.com/questions/3286675/readelf-like-tool-for-mac-os-x – 林果皞 Nov 07 '16 at 12:57
  • thanks for you comment. However, ORX executable binary structure is different than ELF and called MACH-O, but i'll try to find synonym to objdump. – Zohar81 Nov 07 '16 at 13:23

1 Answers1

6

If you know a function name in the code in question, do:

(lldb) image lookup -vn <FunctionName> <BinaryImageNameContainingFunction>

and look for the CompileUnit entry. The path given there is the path lldb got from the debug information.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • I desperately try to use that on Mac OSX to lookup the default path for a C++ function from a Qt framework.... image lookup -vn QStyledItemDelegate::paint /Users/leo/Qt_online/5.15.0/clang_64/lib/QtGui.framework/QtGui gives "warning: Unable to find an image that matches '/Users/leo/Qt_online/5.15.0/clang_64/lib/QtGui.framework/Versions/Current/QtGui' (so the question is probably how to specify frameworks) – Leo Sep 15 '20 at 20:07
  • 2
    You can just supply the base name (QtGui in your case) which is simpler and all you need unless you have a bundle & shared library with the same base name. Not sure why the full path didn't work for you. The `image list` command will list all the images, see if you can find the library there. Maybe there's a symlink in the path somewhere so you and lldb are spelling it differently? – Jim Ingham Sep 15 '20 at 20:50
  • `image list` is the super command I was looking for...turned out my QtGui is spelled `/Users/leo/Qt_online/5.15.0/clang_64/lib/QtGui.framework/Versions/5/QtGui` (and that there is no `QStyledItemDelegate::paint` in it, but `image lookup -vn paint /Users/leo/Qt_online/5.15.0/clang_64/lib/QtGui.framework/Versions/5/QtGui` gives me all `paint` functions in that framework), thanks a lot! – Leo Sep 17 '20 at 11:41