@@ -662,50 +662,64 @@ LLVMSymbolizer::getOrCreateModuleInfo(StringRef ModuleName) {
662662 ObjectPair Objects = ObjectsOrErr.get ();
663663
664664 std::unique_ptr<DIContext> Context;
665- // If this is a COFF object containing PDB info and not containing DWARF
666- // section, use a PDBContext to symbolize. Otherwise, use DWARF.
667- // Create a DIContext to symbolize as follows:
668- // - If there is a GSYM file, create a GsymContext.
669- // - Otherwise, if this is a COFF object containing PDB info, create a
670- // PDBContext.
671- // - Otherwise, create a DWARFContext.
672- const auto GsymFile = lookUpGsymFile (BinaryName.str ());
673- if (!GsymFile.empty ()) {
674- auto ReaderOrErr = gsym::GsymReader::openFile (GsymFile);
675-
676- if (ReaderOrErr) {
677- std::unique_ptr<gsym::GsymReader> Reader =
678- std::make_unique<gsym::GsymReader>(std::move (*ReaderOrErr));
679-
680- Context = std::make_unique<gsym::GsymContext>(std::move (Reader));
665+ pdb::PDB_ReaderType ReaderType =
666+ Opts.UseDIA ? pdb::PDB_ReaderType::DIA : pdb::PDB_ReaderType::Native;
667+ const auto *CoffObject = dyn_cast<COFFObjectFile>(Objects.first );
668+
669+ // First, if the user specified a pdb file on the command line, use that.
670+ if (CoffObject && !Opts.PDBName .empty ()) {
671+ using namespace pdb ;
672+ std::unique_ptr<IPDBSession> Session;
673+ if (auto Err = loadDataForPDB (ReaderType, Opts.PDBName , Session)) {
674+ Modules.emplace (ModuleName, std::unique_ptr<SymbolizableModule>());
675+ return createFileError (Opts.PDBName , std::move (Err));
681676 }
677+ Context.reset (new PDBContext (*CoffObject, std::move (Session)));
682678 }
679+
683680 if (!Context) {
684- if (auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first )) {
685- const codeview::DebugInfo *DebugInfo;
686- StringRef PDBFileName;
687- auto EC = CoffObject->getDebugPDBInfo (DebugInfo, PDBFileName);
688- // Use DWARF if there're DWARF sections.
689- bool HasDwarf = llvm::any_of (
690- Objects.first ->sections (), [](SectionRef Section) -> bool {
691- if (Expected<StringRef> SectionName = Section.getName ())
692- return SectionName.get () == " .debug_info" ;
693- return false ;
694- });
695- if (!EC && !HasDwarf && DebugInfo != nullptr && !PDBFileName.empty ()) {
696- using namespace pdb ;
697- std::unique_ptr<IPDBSession> Session;
698-
699- PDB_ReaderType ReaderType =
700- Opts.UseDIA ? PDB_ReaderType::DIA : PDB_ReaderType::Native;
701- if (auto Err = loadDataForEXE (ReaderType, Objects.first ->getFileName (),
702- Session)) {
703- Modules.emplace (ModuleName, std::unique_ptr<SymbolizableModule>());
704- // Return along the PDB filename to provide more context
705- return createFileError (PDBFileName, std::move (Err));
706- }
707- Context.reset (new PDBContext (*CoffObject, std::move (Session)));
681+ // If this is a COFF object containing PDB info and not containing DWARF
682+ // section, use a PDBContext to symbolize. Otherwise, use DWARF.
683+ // Create a DIContext to symbolize as follows:
684+ // - If there is a GSYM file, create a GsymContext.
685+ // - Otherwise, if this is a COFF object containing PDB info, create a
686+ // PDBContext.
687+ // - Otherwise, create a DWARFContext.
688+ const auto GsymFile = lookUpGsymFile (BinaryName.str ());
689+ if (!GsymFile.empty ()) {
690+ auto ReaderOrErr = gsym::GsymReader::openFile (GsymFile);
691+
692+ if (ReaderOrErr) {
693+ std::unique_ptr<gsym::GsymReader> Reader =
694+ std::make_unique<gsym::GsymReader>(std::move (*ReaderOrErr));
695+
696+ Context = std::make_unique<gsym::GsymContext>(std::move (Reader));
697+ }
698+ }
699+ }
700+
701+ if (!Context && CoffObject) {
702+ const codeview::DebugInfo *DebugInfo;
703+ StringRef PDBFileName;
704+ auto EC = CoffObject->getDebugPDBInfo (DebugInfo, PDBFileName);
705+ // Use DWARF if there're DWARF sections.
706+ bool HasDwarf =
707+ llvm::any_of (Objects.first ->sections (), [](SectionRef Section) -> bool {
708+ if (Expected<StringRef> SectionName = Section.getName ())
709+ return SectionName.get () == " .debug_info" ;
710+ return false ;
711+ });
712+ if (!EC && !HasDwarf && DebugInfo != nullptr && !PDBFileName.empty ()) {
713+ using namespace pdb ;
714+ std::unique_ptr<IPDBSession> Session;
715+
716+ if (auto Err = loadDataForEXE (ReaderType, Objects.first ->getFileName (),
717+ Session)) {
718+ Modules.emplace (ModuleName, std::unique_ptr<SymbolizableModule>());
719+ // Return along the PDB filename to provide more context
720+ return createFileError (PDBFileName, std::move (Err));
708721 }
722+ Context.reset (new PDBContext (*CoffObject, std::move (Session)));
709723 }
710724 }
711725 if (!Context)
0 commit comments