DavidSpickett created this revision. Herald added a project: All. DavidSpickett requested review of this revision. Herald added a reviewer: jdoerfert. Herald added subscribers: lldb-commits, jplehr, sstefan1. Herald added a project: LLDB.
Relative DWO files are normally found at some/path/to/file.dwo. Currently lldb will find the file by adding that path to the binary's location and to any debug search paths that are set. This patch adds a fallback on top of that where lldb will look for just the filename (file.dwo) in those same places. So if you had flattened a build directory before distribution, you could still get symbols. Or perhaps you send out a DWO file on demand, and don't want people to have to recreate the directory layout. For example if you were built: program obj/program.dwo And changed to: program program.dwo <binary dir>/obj/program.dwo is not found. <binary dir>/program.dwo is. If the layout was changed to: program mydebuginfo/progam.dwo And we had a debug search path of <binary dir>/mydebuginfo: - <binary dir>/mydebuginfo/obj/program.dwo is not found. - <binary dir>/mydebuginfo/program.dwo is found. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D158182 Files: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c Index: lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c @@ -0,0 +1,22 @@ +/// Check that LLDB can find a relative DWO file next to a binary just using the +/// filename of that DWO. For example "main.dwo" not "a/b/main.dwo". +// RUN: rm -rf %t.compdir/ +// RUN: mkdir -p %t.compdir/a/b/ +// RUN: cp %s %t.compdir/a/b/main.c +// RUN: cd %t.compdir/a/ +/// The produced DWO is named b/main-main.dwo, with a DW_AT_comp_dir of a/. +// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. b/main.c -o b/main +// RUN: cd ../.. +/// Move binary and DWO out of expected locations. +// RUN: mv %t.compdir/a/b/main %t.compdir/ +// RUN: mv %t.compdir/a/b/main-main.dwo %t.compdir/ +// RUN: %lldb --no-lldbinit %t.compdir/main \ +// RUN: -o "b main.c:21" -o "run" -o "frame variable" --batch 2>&1 | FileCheck %s + +// CHECK-NOT: warning: {{.*}}main unable to locate separate debug file (dwo, dwp). Debugging will be degraded. +// CHECK: (int) num = 5 + +int main(void) { + int num = 5; + return 0; +} \ No newline at end of file Index: lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c @@ -0,0 +1,27 @@ +/// Check that when LLDB is looking for a relative DWO it uses the debug search +/// paths setting. If it doesn't find it by adding the whole relative path to +/// of DWO it should try adding just the filename (e.g. main.dwo) to each debug +/// search path. +// RUN: rm -rf %t.compdir/ +// RUN: mkdir -p %t.compdir/a/b/ +// RUN: cp %s %t.compdir/a/b/main.c +// RUN: cd %t.compdir/a/ +/// The produced DWO is named /b//main-main.dwo, with a DW_AT_comp_dir of a/. +// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. b/main.c -o b/main +// RUN: cd ../.. +/// Move the DWO file away from the expected location. +// RUN: mv %t.compdir/a/b/main-main.dwo %t.compdir/ +/// LLDB won't find the DWO next to the binary or by adding the relative path +/// to any of the search paths. So it should find the DWO file at +/// %t.compdir/main-main.dwo. +// RUN: %lldb --no-lldbinit %t.compdir/a/b/main \ +// RUN: -O "settings append target.debug-file-search-paths %t.compdir" \ +// RUN: -o "b main.c:26" -o "run" -o "frame variable" --batch 2>&1 | FileCheck %s + +// CHECK-NOT: warning: {{.*}}main unable to locate separate debug file (dwo, dwp). Debugging will be degraded. +// CHECK: (int) num = 5 + +int main(void) { + int num = 5; + return 0; +} \ No newline at end of file Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1781,6 +1781,27 @@ dwo_paths.Append(dirspec); } + FileSpec spec_to_get_name(dwo_name); + llvm::StringRef filename_only = spec_to_get_name.GetFilename(); + + // Try binary dir plus DWO filename only. + FileSpec filename_next_to_binary( + m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef()); + FileSystem::Instance().Resolve(filename_next_to_binary); + filename_next_to_binary.AppendPathComponent(filename_only); + dwo_paths.Append(filename_next_to_binary); + + // Try adding just the filename to each of the search paths. + for (size_t idx = 0; idx < num_directories; ++idx) { + FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx); + FileSystem::Instance().Resolve(dirspec); + if (!FileSystem::Instance().IsDirectory(dirspec)) + continue; + + dirspec.AppendPathComponent(filename_only); + dwo_paths.Append(dirspec); + } + size_t num_possible = dwo_paths.GetSize(); for (size_t idx = 0; idx < num_possible && !found; ++idx) { FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
Index: lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c @@ -0,0 +1,22 @@ +/// Check that LLDB can find a relative DWO file next to a binary just using the +/// filename of that DWO. For example "main.dwo" not "a/b/main.dwo". +// RUN: rm -rf %t.compdir/ +// RUN: mkdir -p %t.compdir/a/b/ +// RUN: cp %s %t.compdir/a/b/main.c +// RUN: cd %t.compdir/a/ +/// The produced DWO is named b/main-main.dwo, with a DW_AT_comp_dir of a/. +// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. b/main.c -o b/main +// RUN: cd ../.. +/// Move binary and DWO out of expected locations. +// RUN: mv %t.compdir/a/b/main %t.compdir/ +// RUN: mv %t.compdir/a/b/main-main.dwo %t.compdir/ +// RUN: %lldb --no-lldbinit %t.compdir/main \ +// RUN: -o "b main.c:21" -o "run" -o "frame variable" --batch 2>&1 | FileCheck %s + +// CHECK-NOT: warning: {{.*}}main unable to locate separate debug file (dwo, dwp). Debugging will be degraded. +// CHECK: (int) num = 5 + +int main(void) { + int num = 5; + return 0; +} \ No newline at end of file Index: lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c @@ -0,0 +1,27 @@ +/// Check that when LLDB is looking for a relative DWO it uses the debug search +/// paths setting. If it doesn't find it by adding the whole relative path to +/// of DWO it should try adding just the filename (e.g. main.dwo) to each debug +/// search path. +// RUN: rm -rf %t.compdir/ +// RUN: mkdir -p %t.compdir/a/b/ +// RUN: cp %s %t.compdir/a/b/main.c +// RUN: cd %t.compdir/a/ +/// The produced DWO is named /b//main-main.dwo, with a DW_AT_comp_dir of a/. +// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. b/main.c -o b/main +// RUN: cd ../.. +/// Move the DWO file away from the expected location. +// RUN: mv %t.compdir/a/b/main-main.dwo %t.compdir/ +/// LLDB won't find the DWO next to the binary or by adding the relative path +/// to any of the search paths. So it should find the DWO file at +/// %t.compdir/main-main.dwo. +// RUN: %lldb --no-lldbinit %t.compdir/a/b/main \ +// RUN: -O "settings append target.debug-file-search-paths %t.compdir" \ +// RUN: -o "b main.c:26" -o "run" -o "frame variable" --batch 2>&1 | FileCheck %s + +// CHECK-NOT: warning: {{.*}}main unable to locate separate debug file (dwo, dwp). Debugging will be degraded. +// CHECK: (int) num = 5 + +int main(void) { + int num = 5; + return 0; +} \ No newline at end of file Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1781,6 +1781,27 @@ dwo_paths.Append(dirspec); } + FileSpec spec_to_get_name(dwo_name); + llvm::StringRef filename_only = spec_to_get_name.GetFilename(); + + // Try binary dir plus DWO filename only. + FileSpec filename_next_to_binary( + m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef()); + FileSystem::Instance().Resolve(filename_next_to_binary); + filename_next_to_binary.AppendPathComponent(filename_only); + dwo_paths.Append(filename_next_to_binary); + + // Try adding just the filename to each of the search paths. + for (size_t idx = 0; idx < num_directories; ++idx) { + FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx); + FileSystem::Instance().Resolve(dirspec); + if (!FileSystem::Instance().IsDirectory(dirspec)) + continue; + + dirspec.AppendPathComponent(filename_only); + dwo_paths.Append(dirspec); + } + size_t num_possible = dwo_paths.GetSize(); for (size_t idx = 0; idx < num_possible && !found; ++idx) { FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits