DavidSpickett updated this revision to Diff 549872. DavidSpickett added a comment.
Cleanup, add testing. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157609/new/ https://reviews.llvm.org/D157609 Files: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c
Index: lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c @@ -0,0 +1,28 @@ +/// Check that LLDB uses the paths in target.debug-file-search-paths to find +/// split DWARF files with DW_AT_comp_dir set, when the program file has been +/// moved and/or we're executing it from another directory. +// RUN: rm -rf %t.compdir/ %t.e/ +// RUN: mkdir -p %t.compdir/a/b/c/d/ +// RUN: cp %s %t.compdir/a/b/c/d/main.c +// RUN: cd %t.compdir/a/b/ +/// The produced DWO is named c/d/main-main.dwo, with a DW_AT_comp_dir of a/b. +// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. c/d/main.c -o c/d/main +// RUN: cd ../../.. +/// Move only the program, leaving the DWO file in place. +// RUN: mv %t.compdir/a/b/c/d/main %t.compdir/a/ +/// Debug it from yet another path. +// RUN: mkdir -p %t.e/ +// RUN: cd %t.e +/// LLDB won't find the DWO next to the binary or in the current dir, so it +/// should find the DWO file by doing %t.compdir/ + a/b/ + c/d/main-main.dwo. +// RUN: %lldb --no-lldbinit %t.compdir/a/main \ +// RUN: -O "settings append target.debug-file-search-paths %t.compdir" \ +// RUN: -o "b main.c:27" -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 @@ -1731,7 +1731,11 @@ const char *comp_dir = nullptr; FileSpec dwo_file(dwo_name); FileSystem::Instance().Resolve(dwo_file); - if (dwo_file.IsRelative()) { + bool found = false; + + if (!dwo_file.IsRelative()) { + found = FileSystem::Instance().Exists(dwo_file); + } else { comp_dir = cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir, nullptr); if (!comp_dir) { @@ -1744,18 +1748,51 @@ } dwo_file.SetFile(comp_dir, FileSpec::Style::native); - if (dwo_file.IsRelative()) { + + if (!dwo_file.IsRelative()) { + FileSystem::Instance().Resolve(dwo_file); + dwo_file.AppendPathComponent(dwo_name); + found = FileSystem::Instance().Exists(dwo_file); + } else { + FileSpecList dwo_paths; + // if DW_AT_comp_dir is relative, it should be relative to the location // of the executable, not to the location from which the debugger was // launched. - dwo_file.PrependPathComponent( + FileSpec relative_to_binary = dwo_file; + relative_to_binary.PrependPathComponent( m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef()); + FileSystem::Instance().Resolve(relative_to_binary); + relative_to_binary.AppendPathComponent(dwo_name); + dwo_paths.Append(relative_to_binary); + + // Or it's relative to one of the user specified debug directories. + const FileSpecList &debug_file_search_paths = + Target::GetDefaultDebugFileSearchPaths(); + size_t num_directories = debug_file_search_paths.GetSize(); + for (size_t idx = 0; idx < num_directories; ++idx) { + FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx); + dirspec.AppendPathComponent(comp_dir); + FileSystem::Instance().Resolve(dirspec); + if (!FileSystem::Instance().IsDirectory(dirspec)) + continue; + + dirspec.AppendPathComponent(dwo_name); + 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); + if (FileSystem::Instance().Exists(dwo_spec)) { + dwo_file = dwo_spec; + found = true; + } + } } - FileSystem::Instance().Resolve(dwo_file); - dwo_file.AppendPathComponent(dwo_name); } - if (!FileSystem::Instance().Exists(dwo_file)) { + if (!found) { unit.SetDwoError(Status::createWithFormat( "unable to locate .dwo debug file \"{0}\" for skeleton DIE " "{1:x16}",
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits