17a7e6055SDimitry Andric //===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===//
27a7e6055SDimitry Andric //
37a7e6055SDimitry Andric //                     The LLVM Compiler Infrastructure
47a7e6055SDimitry Andric //
57a7e6055SDimitry Andric // This file is distributed under the University of Illinois Open Source
67a7e6055SDimitry Andric // License. See LICENSE.TXT for details.
77a7e6055SDimitry Andric //
87a7e6055SDimitry Andric //===----------------------------------------------------------------------===//
97a7e6055SDimitry Andric 
107a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
117a7e6055SDimitry Andric 
12edd7eaddSDimitry Andric #include "llvm/ADT/STLExtras.h"
137a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
147a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
15*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
167a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
177a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
18*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
19*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
207a7e6055SDimitry Andric 
21*b5893f02SDimitry Andric using namespace llvm;
22*b5893f02SDimitry Andric using namespace llvm::pdb;
23*b5893f02SDimitry Andric 
getDbiStreamPtr(NativeSession & Session)24*b5893f02SDimitry Andric static DbiStream *getDbiStreamPtr(NativeSession &Session) {
25*b5893f02SDimitry Andric   Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream();
26*b5893f02SDimitry Andric   if (DbiS)
27*b5893f02SDimitry Andric     return &DbiS.get();
28*b5893f02SDimitry Andric 
29*b5893f02SDimitry Andric   consumeError(DbiS.takeError());
30*b5893f02SDimitry Andric   return nullptr;
31*b5893f02SDimitry Andric }
327a7e6055SDimitry Andric 
NativeExeSymbol(NativeSession & Session,SymIndexId SymbolId)33c4394386SDimitry Andric NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
34*b5893f02SDimitry Andric     : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
35*b5893f02SDimitry Andric       Dbi(getDbiStreamPtr(Session)) {}
367a7e6055SDimitry Andric 
377a7e6055SDimitry Andric std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type) const387a7e6055SDimitry Andric NativeExeSymbol::findChildren(PDB_SymType Type) const {
397a7e6055SDimitry Andric   switch (Type) {
407a7e6055SDimitry Andric   case PDB_SymType::Compiland: {
41*b5893f02SDimitry Andric     return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
427a7e6055SDimitry Andric     break;
437a7e6055SDimitry Andric   }
44*b5893f02SDimitry Andric   case PDB_SymType::ArrayType:
45*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY);
462cab237bSDimitry Andric   case PDB_SymType::Enum:
47*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
48*b5893f02SDimitry Andric   case PDB_SymType::PointerType:
49*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER);
50*b5893f02SDimitry Andric   case PDB_SymType::UDT:
51*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(
52*b5893f02SDimitry Andric         {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION,
53*b5893f02SDimitry Andric          codeview::LF_INTERFACE});
54*b5893f02SDimitry Andric   case PDB_SymType::VTableShape:
55*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE);
56*b5893f02SDimitry Andric   case PDB_SymType::FunctionSig:
57*b5893f02SDimitry Andric     return Session.getSymbolCache().createTypeEnumerator(
58*b5893f02SDimitry Andric         {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
59*b5893f02SDimitry Andric   case PDB_SymType::Typedef:
60*b5893f02SDimitry Andric     return Session.getSymbolCache().createGlobalsEnumerator(codeview::S_UDT);
61*b5893f02SDimitry Andric 
627a7e6055SDimitry Andric   default:
637a7e6055SDimitry Andric     break;
647a7e6055SDimitry Andric   }
657a7e6055SDimitry Andric   return nullptr;
667a7e6055SDimitry Andric }
677a7e6055SDimitry Andric 
getAge() const687a7e6055SDimitry Andric uint32_t NativeExeSymbol::getAge() const {
69*b5893f02SDimitry Andric   auto IS = Session.getPDBFile().getPDBInfoStream();
707a7e6055SDimitry Andric   if (IS)
717a7e6055SDimitry Andric     return IS->getAge();
727a7e6055SDimitry Andric   consumeError(IS.takeError());
737a7e6055SDimitry Andric   return 0;
747a7e6055SDimitry Andric }
757a7e6055SDimitry Andric 
getSymbolsFileName() const767a7e6055SDimitry Andric std::string NativeExeSymbol::getSymbolsFileName() const {
77*b5893f02SDimitry Andric   return Session.getPDBFile().getFilePath();
787a7e6055SDimitry Andric }
797a7e6055SDimitry Andric 
getGuid() const80b40b48b8SDimitry Andric codeview::GUID NativeExeSymbol::getGuid() const {
81*b5893f02SDimitry Andric   auto IS = Session.getPDBFile().getPDBInfoStream();
827a7e6055SDimitry Andric   if (IS)
837a7e6055SDimitry Andric     return IS->getGuid();
847a7e6055SDimitry Andric   consumeError(IS.takeError());
85b40b48b8SDimitry Andric   return codeview::GUID{{0}};
867a7e6055SDimitry Andric }
877a7e6055SDimitry Andric 
hasCTypes() const887a7e6055SDimitry Andric bool NativeExeSymbol::hasCTypes() const {
89*b5893f02SDimitry Andric   auto Dbi = Session.getPDBFile().getPDBDbiStream();
907a7e6055SDimitry Andric   if (Dbi)
917a7e6055SDimitry Andric     return Dbi->hasCTypes();
927a7e6055SDimitry Andric   consumeError(Dbi.takeError());
937a7e6055SDimitry Andric   return false;
947a7e6055SDimitry Andric }
957a7e6055SDimitry Andric 
hasPrivateSymbols() const967a7e6055SDimitry Andric bool NativeExeSymbol::hasPrivateSymbols() const {
97*b5893f02SDimitry Andric   auto Dbi = Session.getPDBFile().getPDBDbiStream();
987a7e6055SDimitry Andric   if (Dbi)
997a7e6055SDimitry Andric     return !Dbi->isStripped();
1007a7e6055SDimitry Andric   consumeError(Dbi.takeError());
1017a7e6055SDimitry Andric   return false;
1027a7e6055SDimitry Andric }
103