1 //==- NativeEnumGlobals.cpp - Native Global Enumerator impl ------*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h"
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"
20 using namespace llvm::codeview
;
21 using namespace llvm::pdb
;
23 NativeEnumGlobals::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()))
32 MatchOffsets
.push_back(Off
);
36 uint32_t NativeEnumGlobals::getChildCount() const {
37 return static_cast<uint32_t>(MatchOffsets
.size());
40 std::unique_ptr
<PDBSymbol
>
41 NativeEnumGlobals::getChildAtIndex(uint32_t N
) const {
42 if (N
>= MatchOffsets
.size())
46 Session
.getSymbolCache().getOrCreateGlobalSymbolByOffset(MatchOffsets
[N
]);
47 return Session
.getSymbolCache().getSymbolById(Id
);
50 std::unique_ptr
<PDBSymbol
> NativeEnumGlobals::getNext() {
51 return getChildAtIndex(Index
++);
54 void NativeEnumGlobals::reset() { Index
= 0; }