7

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.

2
  • 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, stackoverflow.com/questions/3286675/… Commented Nov 7, 2016 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. Commented Nov 7, 2016 at 13:23

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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)
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?
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.