PDBSymbolData.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- 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/PDBSymbolData.h"
  9. #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"
  10. #include "llvm/DebugInfo/PDB/IPDBSession.h"
  11. #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
  12. #include <utility>
  13. using namespace llvm;
  14. using namespace llvm::pdb;
  15. void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
  16. std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {
  17. auto Len = RawSymbol->getLength();
  18. Len = Len ? Len : 1;
  19. if (auto RVA = RawSymbol->getRelativeVirtualAddress())
  20. return Session.findLineNumbersByRVA(RVA, Len);
  21. if (auto Section = RawSymbol->getAddressSection())
  22. return Session.findLineNumbersBySectOffset(
  23. Section, RawSymbol->getAddressOffset(), Len);
  24. return nullptr;
  25. }
  26. uint32_t PDBSymbolData::getCompilandId() const {
  27. if (auto Lines = getLineNumbers()) {
  28. if (auto FirstLine = Lines->getNext())
  29. return FirstLine->getCompilandId();
  30. }
  31. uint32_t DataSection = RawSymbol->getAddressSection();
  32. uint32_t DataOffset = RawSymbol->getAddressOffset();
  33. if (DataSection == 0) {
  34. if (auto RVA = RawSymbol->getRelativeVirtualAddress())
  35. Session.addressForRVA(RVA, DataSection, DataOffset);
  36. }
  37. if (DataSection) {
  38. if (auto SecContribs = Session.getSectionContribs()) {
  39. while (auto Section = SecContribs->getNext()) {
  40. if (Section->getAddressSection() == DataSection &&
  41. Section->getAddressOffset() <= DataOffset &&
  42. (Section->getAddressOffset() + Section->getLength()) > DataOffset)
  43. return Section->getCompilandId();
  44. }
  45. }
  46. } else {
  47. auto LexParentId = RawSymbol->getLexicalParentId();
  48. while (auto LexParent = Session.getSymbolById(LexParentId)) {
  49. if (LexParent->getSymTag() == PDB_SymType::Exe)
  50. break;
  51. if (LexParent->getSymTag() == PDB_SymType::Compiland)
  52. return LexParentId;
  53. LexParentId = LexParent->getRawSymbol().getLexicalParentId();
  54. }
  55. }
  56. return 0;
  57. }