5

I have a program built in one environment and I want to debug it in my own environment. I have copied executable, .dSYM and the source code but I can't find ways to let lldb know where to find the source code.

For example, in the building environment there are source files:

/build_src/rel_path/source1.c
/build_src/rel_path/source1.dSYM
/build_src/rel_path/app1

And in my environment the files and .dSYM are copied to:

/source/rel_path/source1.c
/source/rel_path/source1.dSYM
/source/rel_path/app1

Is there any way to set the discover path or any other way to remap the source code path?

Denis C de Azevedo
  • 6,276
  • 2
  • 32
  • 49
user4187988
  • 55
  • 1
  • 4
  • a similar question: http://stackoverflow.com/questions/12973633/lldb-equivalent-of-gdb-directory-command-for-specifying-source-search-path – guini Oct 30 '15 at 07:16

1 Answers1

9

That's what the "target.source-map" setting is for:

(lldb) settings list target.source-map
  source-map -- Source path remappings used to track the change of location between a source file when built, and where it exists on the current system. 
                It consists of an array of duples, the first element of each duple is some part (starting at the root) of the path to the file when it
                was built, and the second is where the remainder of the original build hierarchy is rooted on the local system.  Each element of the
                array is checked in order and the first one that results in a match wins.

So for instance in your case you would do:

settings set target.source-map /build_src /source

lldb has an apropos command you can use to find these sort of buried goodies, so for instance apropos source would have shown you the help above, as well as a pretty short list of other things.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • This doesn't work if the build files do no longer exist but a copy of the source is available. – rwst May 07 '18 at 06:56
  • I'm not quite sure I understand you. But you have to have debug information in some form or other or lldb has no way to map source to instructions. On macOS, the debug information is left in the .o files (or .a files if you make them) and not linked into the final image. If you want to debug after removing the intermediate .o files, you need to make a `dSYM` file. Xcode can do this for you (select the `DWARF with dSYM` debug option) or you can run the `dsymutil` tool on the binary. ELF generally does link the debug info into the binary, so this shouldn't be necessary on Linux. – Jim Ingham May 15 '18 at 00:29
  • I should have added that I'm using `lldb` on Linux. There might be a difference. – rwst May 16 '18 at 03:23
  • I'm not terribly familiar with Linux. There is a way to store the debug information in a separate file on linux though I'm not up on the details. Maybe you are inadvertently doing that? – Jim Ingham May 16 '18 at 16:36