NativeEnumGlobals.cpp 1.9 KB

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