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. https://reviews.llvm.org/D84815 Files: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 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)
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)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits