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/NativeEnumModules.h"
16 #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
18 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
19 
20 namespace llvm {
21 namespace pdb {
22 
23 NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
24     : NativeRawSymbol(Session, SymbolId), File(Session.getPDBFile()) {}
25 
26 std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const {
27   return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
28 }
29 
30 std::unique_ptr<IPDBEnumSymbols>
31 NativeExeSymbol::findChildren(PDB_SymType Type) const {
32   switch (Type) {
33   case PDB_SymType::Compiland: {
34     auto Dbi = File.getPDBDbiStream();
35     if (Dbi) {
36       const DbiModuleList &Modules = Dbi->modules();
37       return std::unique_ptr<IPDBEnumSymbols>(
38           new NativeEnumModules(Session, Modules));
39     }
40     consumeError(Dbi.takeError());
41     break;
42   }
43   case PDB_SymType::Enum:
44     return Session.createTypeEnumerator(codeview::LF_ENUM);
45   default:
46     break;
47   }
48   return nullptr;
49 }
50 
51 uint32_t NativeExeSymbol::getAge() const {
52   auto IS = File.getPDBInfoStream();
53   if (IS)
54     return IS->getAge();
55   consumeError(IS.takeError());
56   return 0;
57 }
58 
59 std::string NativeExeSymbol::getSymbolsFileName() const {
60   return File.getFilePath();
61 }
62 
63 codeview::GUID NativeExeSymbol::getGuid() const {
64   auto IS = File.getPDBInfoStream();
65   if (IS)
66     return IS->getGuid();
67   consumeError(IS.takeError());
68   return codeview::GUID{{0}};
69 }
70 
71 bool NativeExeSymbol::hasCTypes() const {
72   auto Dbi = File.getPDBDbiStream();
73   if (Dbi)
74     return Dbi->hasCTypes();
75   consumeError(Dbi.takeError());
76   return false;
77 }
78 
79 bool NativeExeSymbol::hasPrivateSymbols() const {
80   auto Dbi = File.getPDBDbiStream();
81   if (Dbi)
82     return !Dbi->isStripped();
83   consumeError(Dbi.takeError());
84   return false;
85 }
86 
87 } // namespace pdb
88 } // namespace llvm
89