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/Native/SymbolCache.h" 19 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" 20 21 using namespace llvm; 22 using namespace llvm::pdb; 23 24 static DbiStream *getDbiStreamPtr(NativeSession &Session) { 25 Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream(); 26 if (DbiS) 27 return &DbiS.get(); 28 29 consumeError(DbiS.takeError()); 30 return nullptr; 31 } 32 33 NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) 34 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId), 35 Dbi(getDbiStreamPtr(Session)) {} 36 37 std::unique_ptr<IPDBEnumSymbols> 38 NativeExeSymbol::findChildren(PDB_SymType Type) const { 39 switch (Type) { 40 case PDB_SymType::Compiland: { 41 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session)); 42 break; 43 } 44 case PDB_SymType::Enum: 45 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM); 46 case PDB_SymType::PointerType: 47 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER); 48 case PDB_SymType::UDT: 49 return Session.getSymbolCache().createTypeEnumerator( 50 {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION, 51 codeview::LF_INTERFACE}); 52 case PDB_SymType::FunctionSig: 53 return Session.getSymbolCache().createTypeEnumerator( 54 {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION}); 55 56 default: 57 break; 58 } 59 return nullptr; 60 } 61 62 uint32_t NativeExeSymbol::getAge() const { 63 auto IS = Session.getPDBFile().getPDBInfoStream(); 64 if (IS) 65 return IS->getAge(); 66 consumeError(IS.takeError()); 67 return 0; 68 } 69 70 std::string NativeExeSymbol::getSymbolsFileName() const { 71 return Session.getPDBFile().getFilePath(); 72 } 73 74 codeview::GUID NativeExeSymbol::getGuid() const { 75 auto IS = Session.getPDBFile().getPDBInfoStream(); 76 if (IS) 77 return IS->getGuid(); 78 consumeError(IS.takeError()); 79 return codeview::GUID{{0}}; 80 } 81 82 bool NativeExeSymbol::hasCTypes() const { 83 auto Dbi = Session.getPDBFile().getPDBDbiStream(); 84 if (Dbi) 85 return Dbi->hasCTypes(); 86 consumeError(Dbi.takeError()); 87 return false; 88 } 89 90 bool NativeExeSymbol::hasPrivateSymbols() const { 91 auto Dbi = Session.getPDBFile().getPDBDbiStream(); 92 if (Dbi) 93 return !Dbi->isStripped(); 94 consumeError(Dbi.takeError()); 95 return false; 96 } 97