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 | |
19 | using namespace llvm; |
20 | using namespace llvm::pdb; |
21 | |
22 | static 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 | |
31 | NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) |
32 | : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId), |
33 | Dbi(getDbiStreamPtr(Session)) {} |
34 | |
35 | std::unique_ptr<IPDBEnumSymbols> |
36 | NativeExeSymbol::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( |
50 | Kinds: {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION, |
51 | codeview::LF_INTERFACE}); |
52 | case PDB_SymType::VTableShape: |
53 | return Session.getSymbolCache().createTypeEnumerator(Kind: codeview::LF_VTSHAPE); |
54 | case PDB_SymType::FunctionSig: |
55 | return Session.getSymbolCache().createTypeEnumerator( |
56 | Kinds: {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION}); |
57 | case PDB_SymType::Typedef: |
58 | return Session.getSymbolCache().createGlobalsEnumerator(Kind: codeview::S_UDT); |
59 | |
60 | default: |
61 | break; |
62 | } |
63 | return nullptr; |
64 | } |
65 | |
66 | uint32_t NativeExeSymbol::getAge() const { |
67 | auto IS = Session.getPDBFile().getPDBInfoStream(); |
68 | if (IS) |
69 | return IS->getAge(); |
70 | consumeError(Err: IS.takeError()); |
71 | return 0; |
72 | } |
73 | |
74 | std::string NativeExeSymbol::getSymbolsFileName() const { |
75 | return std::string(Session.getPDBFile().getFilePath()); |
76 | } |
77 | |
78 | codeview::GUID NativeExeSymbol::getGuid() const { |
79 | auto IS = Session.getPDBFile().getPDBInfoStream(); |
80 | if (IS) |
81 | return IS->getGuid(); |
82 | consumeError(Err: IS.takeError()); |
83 | return codeview::GUID{.Guid: {0}}; |
84 | } |
85 | |
86 | bool NativeExeSymbol::hasCTypes() const { |
87 | auto Dbi = Session.getPDBFile().getPDBDbiStream(); |
88 | if (Dbi) |
89 | return Dbi->hasCTypes(); |
90 | consumeError(Err: Dbi.takeError()); |
91 | return false; |
92 | } |
93 | |
94 | bool NativeExeSymbol::hasPrivateSymbols() const { |
95 | auto Dbi = Session.getPDBFile().getPDBDbiStream(); |
96 | if (Dbi) |
97 | return !Dbi->isStripped(); |
98 | consumeError(Err: Dbi.takeError()); |
99 | return false; |
100 | } |
101 |