DWARFDebugInfoEntry.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DWARFDebugInfoEntry.h ------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
  14. #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
  15. #include "llvm/BinaryFormat/Dwarf.h"
  16. #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
  17. #include <cstdint>
  18. namespace llvm {
  19. class DWARFUnit;
  20. class DWARFDataExtractor;
  21. /// DWARFDebugInfoEntry - A DIE with only the minimum required data.
  22. class DWARFDebugInfoEntry {
  23. /// Offset within the .debug_info of the start of this entry.
  24. uint64_t Offset = 0;
  25. /// Index of the parent die. UINT32_MAX if there is no parent.
  26. uint32_t ParentIdx = UINT32_MAX;
  27. /// Index of the sibling die. Zero if there is no sibling.
  28. uint32_t SiblingIdx = 0;
  29. const DWARFAbbreviationDeclaration *AbbrevDecl = nullptr;
  30. public:
  31. DWARFDebugInfoEntry() = default;
  32. /// Extracts a debug info entry, which is a child of a given unit,
  33. /// starting at a given offset. If DIE can't be extracted, returns false and
  34. /// doesn't change OffsetPtr.
  35. /// High performance extraction should use this call.
  36. bool extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
  37. const DWARFDataExtractor &DebugInfoData, uint64_t UEndOffset,
  38. uint32_t ParentIdx);
  39. uint64_t getOffset() const { return Offset; }
  40. /// Returns index of the parent die.
  41. std::optional<uint32_t> getParentIdx() const {
  42. if (ParentIdx == UINT32_MAX)
  43. return std::nullopt;
  44. return ParentIdx;
  45. }
  46. /// Returns index of the sibling die.
  47. std::optional<uint32_t> getSiblingIdx() const {
  48. if (SiblingIdx == 0)
  49. return std::nullopt;
  50. return SiblingIdx;
  51. }
  52. /// Set index of sibling.
  53. void setSiblingIdx(uint32_t Idx) { SiblingIdx = Idx; }
  54. dwarf::Tag getTag() const {
  55. return AbbrevDecl ? AbbrevDecl->getTag() : dwarf::DW_TAG_null;
  56. }
  57. bool hasChildren() const { return AbbrevDecl && AbbrevDecl->hasChildren(); }
  58. const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
  59. return AbbrevDecl;
  60. }
  61. };
  62. } // end namespace llvm
  63. #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif