1 | //==- NativeEnumGlobals.cpp - Native Global Enumerator impl ------*- 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/NativeEnumGlobals.h" |
10 | |
11 | #include "llvm/DebugInfo/CodeView/CVRecord.h" |
12 | #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" |
13 | #include "llvm/DebugInfo/PDB/Native/NativeSession.h" |
14 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
15 | #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" |
16 | #include "llvm/DebugInfo/PDB/Native/SymbolStream.h" |
17 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" |
18 | #include "llvm/DebugInfo/PDB/PDBTypes.h" |
19 | |
20 | using namespace llvm; |
21 | using namespace llvm::codeview; |
22 | using namespace llvm::pdb; |
23 | |
24 | NativeEnumGlobals::NativeEnumGlobals(NativeSession &PDBSession, |
25 | std::vector<codeview::SymbolKind> Kinds) |
26 | : Index(0), Session(PDBSession) { |
27 | GlobalsStream &GS = cantFail(ValOrErr: Session.getPDBFile().getPDBGlobalsStream()); |
28 | SymbolStream &SS = cantFail(ValOrErr: Session.getPDBFile().getPDBSymbolStream()); |
29 | for (uint32_t Off : GS.getGlobalsTable()) { |
30 | CVSymbol S = SS.readRecord(Offset: Off); |
31 | if (!llvm::is_contained(Range&: Kinds, Element: S.kind())) |
32 | continue; |
33 | MatchOffsets.push_back(x: Off); |
34 | } |
35 | } |
36 | |
37 | uint32_t NativeEnumGlobals::getChildCount() const { |
38 | return static_cast<uint32_t>(MatchOffsets.size()); |
39 | } |
40 | |
41 | std::unique_ptr<PDBSymbol> |
42 | NativeEnumGlobals::getChildAtIndex(uint32_t N) const { |
43 | if (N >= MatchOffsets.size()) |
44 | return nullptr; |
45 | |
46 | SymIndexId Id = |
47 | Session.getSymbolCache().getOrCreateGlobalSymbolByOffset(Offset: MatchOffsets[N]); |
48 | return Session.getSymbolCache().getSymbolById(SymbolId: Id); |
49 | } |
50 | |
51 | std::unique_ptr<PDBSymbol> NativeEnumGlobals::getNext() { |
52 | return getChildAtIndex(N: Index++); |
53 | } |
54 | |
55 | void NativeEnumGlobals::reset() { Index = 0; } |
56 |