1 //==- NativeEnumGlobals.cpp - Native Global Enumerator impl ------*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h"
12 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
15 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
16 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
17 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
21 using namespace llvm::codeview;
22 using namespace llvm::pdb;
24 NativeEnumGlobals::NativeEnumGlobals(NativeSession &PDBSession,
25 std::vector<codeview::SymbolKind> Kinds)
26 : Index(0), Session(PDBSession) {
27 GlobalsStream &GS = cantFail(Session.getPDBFile().getPDBGlobalsStream());
28 SymbolStream &SS = cantFail(Session.getPDBFile().getPDBSymbolStream());
29 for (uint32_t Off : GS.getGlobalsTable()) {
30 CVSymbol S = SS.readRecord(Off);
31 if (!llvm::is_contained(Kinds, S.kind()))
33 MatchOffsets.push_back(Off);
37 uint32_t NativeEnumGlobals::getChildCount() const {
38 return static_cast<uint32_t>(MatchOffsets.size());
41 std::unique_ptr<PDBSymbol>
42 NativeEnumGlobals::getChildAtIndex(uint32_t N) const {
43 if (N >= MatchOffsets.size())
47 Session.getSymbolCache().getOrCreateGlobalSymbolByOffset(MatchOffsets[N]);
48 return Session.getSymbolCache().getSymbolById(Id);
51 std::unique_ptr<PDBSymbol> NativeEnumGlobals::getNext() {
52 return getChildAtIndex(Index++);
55 void NativeEnumGlobals::reset() { Index = 0; }