diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/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); diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c b/lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths-filename-only.c new file mode 100644 --- /dev/null +++ b/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 diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c b/lldb/test/Shell/SymbolFile/DWARF/dwo-relative-filename-only-binary-dir.c new file mode 100644 --- /dev/null +++ b/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