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<NativeRawSymbol> NativeExeSymbol::clone() const {
38   return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
39 }
40 
41 std::unique_ptr<IPDBEnumSymbols>
42 NativeExeSymbol::findChildren(PDB_SymType Type) const {
43   switch (Type) {
44   case PDB_SymType::Compiland: {
45     return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
46     break;
47   }
48   case PDB_SymType::Enum:
49     return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
50   default:
51     break;
52   }
53   return nullptr;
54 }
55 
56 uint32_t NativeExeSymbol::getAge() const {
57   auto IS = Session.getPDBFile().getPDBInfoStream();
58   if (IS)
59     return IS->getAge();
60   consumeError(IS.takeError());
61   return 0;
62 }
63 
64 std::string NativeExeSymbol::getSymbolsFileName() const {
65   return Session.getPDBFile().getFilePath();
66 }
67 
68 codeview::GUID NativeExeSymbol::getGuid() const {
69   auto IS = Session.getPDBFile().getPDBInfoStream();
70   if (IS)
71     return IS->getGuid();
72   consumeError(IS.takeError());
73   return codeview::GUID{{0}};
74 }
75 
76 bool NativeExeSymbol::hasCTypes() const {
77   auto Dbi = Session.getPDBFile().getPDBDbiStream();
78   if (Dbi)
79     return Dbi->hasCTypes();
80   consumeError(Dbi.takeError());
81   return false;
82 }
83 
84 bool NativeExeSymbol::hasPrivateSymbols() const {
85   auto Dbi = Session.getPDBFile().getPDBDbiStream();
86   if (Dbi)
87     return !Dbi->isStripped();
88   consumeError(Dbi.takeError());
89   return false;
90 }
91