1 //===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" 11 12 #include "llvm/ADT/STLExtras.h" 13 #include "llvm/DebugInfo/PDB/Native/DbiStream.h" 14 #include "llvm/DebugInfo/PDB/Native/InfoStream.h" 15 #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" 16 #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" 17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h" 18 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" 19 20 using namespace llvm; 21 using namespace llvm::pdb; 22 23 NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) 24 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId), 25 File(Session.getPDBFile()) { 26 Expected<DbiStream &> DbiS = File.getPDBDbiStream(); 27 if (!DbiS) { 28 consumeError(DbiS.takeError()); 29 return; 30 } 31 Dbi = &DbiS.get(); 32 Compilands.resize(Dbi->modules().getModuleCount()); 33 } 34 35 std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const { 36 return llvm::make_unique<NativeExeSymbol>(Session, SymbolId); 37 } 38 39 std::unique_ptr<IPDBEnumSymbols> 40 NativeExeSymbol::findChildren(PDB_SymType Type) const { 41 switch (Type) { 42 case PDB_SymType::Compiland: { 43 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session)); 44 break; 45 } 46 case PDB_SymType::Enum: 47 return Session.createTypeEnumerator(codeview::LF_ENUM); 48 default: 49 break; 50 } 51 return nullptr; 52 } 53 54 uint32_t NativeExeSymbol::getAge() const { 55 auto IS = File.getPDBInfoStream(); 56 if (IS) 57 return IS->getAge(); 58 consumeError(IS.takeError()); 59 return 0; 60 } 61 62 std::string NativeExeSymbol::getSymbolsFileName() const { 63 return File.getFilePath(); 64 } 65 66 codeview::GUID NativeExeSymbol::getGuid() const { 67 auto IS = File.getPDBInfoStream(); 68 if (IS) 69 return IS->getGuid(); 70 consumeError(IS.takeError()); 71 return codeview::GUID{{0}}; 72 } 73 74 bool NativeExeSymbol::hasCTypes() const { 75 auto Dbi = File.getPDBDbiStream(); 76 if (Dbi) 77 return Dbi->hasCTypes(); 78 consumeError(Dbi.takeError()); 79 return false; 80 } 81 82 bool NativeExeSymbol::hasPrivateSymbols() const { 83 auto Dbi = File.getPDBDbiStream(); 84 if (Dbi) 85 return !Dbi->isStripped(); 86 consumeError(Dbi.takeError()); 87 return false; 88 } 89 90 uint32_t NativeExeSymbol::getNumCompilands() const { 91 if (!Dbi) 92 return 0; 93 94 return Dbi->modules().getModuleCount(); 95 } 96 97 std::unique_ptr<PDBSymbolCompiland> 98 NativeExeSymbol::getOrCreateCompiland(uint32_t Index) { 99 if (!Dbi) 100 return nullptr; 101 102 if (Index >= Compilands.size()) 103 return nullptr; 104 105 if (Compilands[Index] == 0) { 106 const DbiModuleList &Modules = Dbi->modules(); 107 Compilands[Index] = Session.createSymbol<NativeCompilandSymbol>( 108 Modules.getModuleDescriptor(Index)); 109 } 110 111 return Session.getConcreteSymbolById<PDBSymbolCompiland>(Compilands[Index]); 112 } 113