Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/NativeEnumGlobals.cpp
35293 views
//==- NativeEnumGlobals.cpp - Native Global Enumerator impl ------*- C++ -*-==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h"910#include "llvm/DebugInfo/CodeView/CVRecord.h"11#include "llvm/DebugInfo/PDB/IPDBEnumChildren.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"1920using namespace llvm;21using namespace llvm::codeview;22using namespace llvm::pdb;2324NativeEnumGlobals::NativeEnumGlobals(NativeSession &PDBSession,25std::vector<codeview::SymbolKind> Kinds)26: Index(0), Session(PDBSession) {27GlobalsStream &GS = cantFail(Session.getPDBFile().getPDBGlobalsStream());28SymbolStream &SS = cantFail(Session.getPDBFile().getPDBSymbolStream());29for (uint32_t Off : GS.getGlobalsTable()) {30CVSymbol S = SS.readRecord(Off);31if (!llvm::is_contained(Kinds, S.kind()))32continue;33MatchOffsets.push_back(Off);34}35}3637uint32_t NativeEnumGlobals::getChildCount() const {38return static_cast<uint32_t>(MatchOffsets.size());39}4041std::unique_ptr<PDBSymbol>42NativeEnumGlobals::getChildAtIndex(uint32_t N) const {43if (N >= MatchOffsets.size())44return nullptr;4546SymIndexId Id =47Session.getSymbolCache().getOrCreateGlobalSymbolByOffset(MatchOffsets[N]);48return Session.getSymbolCache().getSymbolById(Id);49}5051std::unique_ptr<PDBSymbol> NativeEnumGlobals::getNext() {52return getChildAtIndex(Index++);53}5455void NativeEnumGlobals::reset() { Index = 0; }565758