[Lldb-commits] [PATCH] D84815: [LLDB] Improve PDB discovery

Adrian McCarthy via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 28 18:14:57 PDT 2020

amccarth created this revision.
amccarth added reviewers: labath, stella.stamenova.
amccarth requested review of this revision.

When loading a PE/COFF target, the associated PDB file often wasn't found.  The executable module contains a path for the associated PDB file, but people often debug from a different directory than the one their build system uses.  (This is especially common in post-mortem and cross platform debugging.)

Suppose the COFF executable being debugged is `~/proj/foo.exe`, but it was built elsewhere and refers to `D:\remote\build\env\foobar.pdb`, LLDB wouldn't find it.

With this change, if no file exists at the PDB path, LLDB will look in the executable directory for a PDB file that matches the name of the one it expected (e.g., `~/proj/foobar.pdb`).  If found, the PDB is subject to the same matching criteria (GUIDs and age) as would have been used had it been in the original location.

This same-directory-as-the-binary rule is commonly used by debuggers on Windows.



Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -134,8 +134,16 @@
     return nullptr;
-  // if the file doesn't exist, is not a pdb, or doesn't have a matching guid,
-  // fail.
+  // If the files doesn't exist, perhaps the path specified at build time
+  // doesn't match the PDB's current location, so check the location of the
+  // executable.
+  if (!FileSystem::Instance().Exists(pdb_file)) {
+    const auto exe_dir = FileSpec(exe_path).CopyByRemovingLastPathComponent();
+    const auto pdb_name = FileSpec(pdb_file).GetFilename().GetCString();
+    pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetCString();
+  }
+  // If the file is not a PDB of if it doesn't have a matching GUID, fail.
   llvm::file_magic magic;
   auto ec = llvm::identify_magic(pdb_file, magic);
   if (ec || magic != llvm::file_magic::pdb)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84815.281438.patch
Type: text/x-patch
Size: 1078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200729/2e162d38/attachment.bin>

More information about the lldb-commits mailing list