Issue 142490
Summary [llvm-symbolizer] allow specifying pdb file path directly on command line
Labels new issue
Assignees
Reporter yshui
    and when pdb file is specified, it should override symbolizer's dwarf info detection. allow more control over where and what debug info is loaded.

here's a very crude patch that does this:

```diff
diff --git i/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h w/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index 5747ad99d0f1..1bcc84983445 100644
--- i/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ w/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -62,6 +62,7 @@ public:
     std::vector<std::string> DsymHints;
     std::string FallbackDebugPath;
     std::string DWPName;
+    std::string PDBName;
 std::vector<std::string> DebugFileDirectory;
     size_t MaxCacheSize =
 sizeof(size_t) == 4
diff --git i/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp w/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 1d8217ad587e..c823e36ee585 100644
--- i/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ w/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -637,6 +637,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(StringRef ModuleName) {
   if (auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first)) {
     const codeview::DebugInfo *DebugInfo;
     StringRef PDBFileName;
+ pdb::PDB_ReaderType ReaderType =
+        Opts.UseDIA ? pdb::PDB_ReaderType::DIA : pdb::PDB_ReaderType::Native;
     auto EC = CoffObject->getDebugPDBInfo(DebugInfo, PDBFileName);
     // Use DWARF if there're DWARF sections.
     bool HasDwarf =
@@ -649,8 +651,6 @@ LLVMSymbolizer::getOrCreateModuleInfo(StringRef ModuleName) {
       using namespace pdb;
       std::unique_ptr<IPDBSession> Session;
 
- PDB_ReaderType ReaderType =
-          Opts.UseDIA ? PDB_ReaderType::DIA : PDB_ReaderType::Native;
       if (auto Err = loadDataForEXE(ReaderType, Objects.first->getFileName(),
                                     Session)) {
         Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
@@ -658,6 +658,15 @@ LLVMSymbolizer::getOrCreateModuleInfo(StringRef ModuleName) {
 return createFileError(PDBFileName, std::move(Err));
       }
 Context.reset(new PDBContext(*CoffObject, std::move(Session)));
+    } else if (!Opts.PDBName.empty()) {
+      using namespace pdb;
+ std::unique_ptr<IPDBSession> Session;
+      if (auto Err = pdb::loadDataForPDB(ReaderType, Opts.PDBName, Session)) {
+ Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());
+ // Return along the PDB filename to provide more context
+        return createFileError(Opts.PDBName, std::move(Err));
+      }
+ Context.reset(new PDBContext(*CoffObject, std::move(Session)));
     }
 }
   if (!Context)
diff --git i/llvm/tools/llvm-symbolizer/Opts.td w/llvm/tools/llvm-symbolizer/Opts.td
index d0b227af9db4..dbaa18aa8939 100644
--- i/llvm/tools/llvm-symbolizer/Opts.td
+++ w/llvm/tools/llvm-symbolizer/Opts.td
@@ -36,6 +36,7 @@ def functions : F<"functions", "Print function name for a given address">;
 def functions_EQ : Joined<["--"], "functions=">, HelpText<"Print function name for a given address">, Values<"none,short,linkage">;
 def help : F<"help", "Display this help">;
 defm dwp : Eq<"dwp", "Path to DWP file to be use for any split CUs">, MetaVarName<"<file>">;
+defm pdb : Eq<"pdb", "Path to PDB file">, MetaVarName<"<file>">;
 defm dsym_hint
     : Eq<"dsym-hint",
          "Path to .dSYM bundles to search for debug info for the object files">,
diff --git i/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp w/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 3ba7f59d5b84..0c928964e552 100644
--- i/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ w/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -497,6 +497,7 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
 Opts.DefaultArch = Args.getLastArgValue(OPT_default_arch_EQ).str();
 Opts.Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, !IsAddr2Line);
 Opts.DWPName = Args.getLastArgValue(OPT_dwp_EQ).str();
+  Opts.PDBName = Args.getLastArgValue(OPT_pdb_EQ).str();
   Opts.FallbackDebugPath =
 Args.getLastArgValue(OPT_fallback_debug_path_EQ).str();
 Opts.PrintFunctions = decideHowToPrintFunctions(Args, IsAddr2Line);
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to