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