NativeEnumGlobals.cpp 2.0 KB

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