1//===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
10
11#include "llvm/DebugInfo/CodeView/CodeView.h"
12#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
13#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
14#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
15#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
16#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
17#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
18
19using namespace llvm;
20using namespace llvm::pdb;
21
22static DbiStream *getDbiStreamPtr(NativeSession &Session) {
23 Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream();
24 if (DbiS)
25 return &DbiS.get();
26
27 consumeError(Err: DbiS.takeError());
28 return nullptr;
29}
30
31NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
32 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
33 Dbi(getDbiStreamPtr(Session)) {}
34
35std::unique_ptr<IPDBEnumSymbols>
36NativeExeSymbol::findChildren(PDB_SymType Type) const {
37 switch (Type) {
38 case PDB_SymType::Compiland: {
39 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
40 break;
41 }
42 case PDB_SymType::ArrayType:
43 return Session.getSymbolCache().createTypeEnumerator(Kind: codeview::LF_ARRAY);
44 case PDB_SymType::Enum:
45 return Session.getSymbolCache().createTypeEnumerator(Kind: codeview::LF_ENUM);
46 case PDB_SymType::PointerType:
47 return Session.getSymbolCache().createTypeEnumerator(Kind: codeview::LF_POINTER);
48 case PDB_SymType::UDT:
49 return Session.getSymbolCache().createTypeEnumerator(Kinds: {
50 codeview::LF_STRUCTURE,
51 codeview::LF_STRUCTURE2,
52 codeview::LF_CLASS,
53 codeview::LF_CLASS2,
54 codeview::LF_UNION,
55 codeview::LF_UNION2,
56 codeview::LF_INTERFACE,
57 codeview::LF_INTERFACE2,
58 });
59 case PDB_SymType::VTableShape:
60 return Session.getSymbolCache().createTypeEnumerator(Kind: codeview::LF_VTSHAPE);
61 case PDB_SymType::FunctionSig:
62 return Session.getSymbolCache().createTypeEnumerator(
63 Kinds: {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
64 case PDB_SymType::Typedef:
65 return Session.getSymbolCache().createGlobalsEnumerator(Kind: codeview::S_UDT);
66
67 default:
68 break;
69 }
70 return nullptr;
71}
72
73uint32_t NativeExeSymbol::getAge() const {
74 auto IS = Session.getPDBFile().getPDBInfoStream();
75 if (IS)
76 return IS->getAge();
77 consumeError(Err: IS.takeError());
78 return 0;
79}
80
81std::string NativeExeSymbol::getSymbolsFileName() const {
82 return std::string(Session.getPDBFile().getFilePath());
83}
84
85codeview::GUID NativeExeSymbol::getGuid() const {
86 auto IS = Session.getPDBFile().getPDBInfoStream();
87 if (IS)
88 return IS->getGuid();
89 consumeError(Err: IS.takeError());
90 return codeview::GUID{.Guid: {0}};
91}
92
93bool NativeExeSymbol::hasCTypes() const {
94 auto Dbi = Session.getPDBFile().getPDBDbiStream();
95 if (Dbi)
96 return Dbi->hasCTypes();
97 consumeError(Err: Dbi.takeError());
98 return false;
99}
100
101bool NativeExeSymbol::hasPrivateSymbols() const {
102 auto Dbi = Session.getPDBFile().getPDBDbiStream();
103 if (Dbi)
104 return !Dbi->isStripped();
105 consumeError(Err: Dbi.takeError());
106 return false;
107}
108