1 //===- DWARFDebugInfoEntry.h ------------------------------------*- 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 
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
11 
12 #include "llvm/BinaryFormat/Dwarf.h"
13 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
14 #include <cstdint>
15 
16 namespace llvm {
17 
18 class DWARFUnit;
19 class DWARFDataExtractor;
20 
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 
26   /// Index of the parent die. UINT32_MAX if there is no parent.
27   uint32_t ParentIdx = UINT32_MAX;
28 
29   /// Index of the sibling die. Zero if there is no sibling.
30   uint32_t SiblingIdx = 0;
31 
32   const DWARFAbbreviationDeclaration *AbbrevDecl = nullptr;
33 
34 public:
35   DWARFDebugInfoEntry() = default;
36 
37   /// Extracts a debug info entry, which is a child of a given unit,
38   /// starting at a given offset. If DIE can't be extracted, returns false and
39   /// doesn't change OffsetPtr.
40   /// High performance extraction should use this call.
41   bool extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
42                    const DWARFDataExtractor &DebugInfoData, uint64_t UEndOffset,
43                    uint32_t ParentIdx);
44 
getOffset()45   uint64_t getOffset() const { return Offset; }
46 
47   /// Returns index of the parent die.
getParentIdx()48   std::optional<uint32_t> getParentIdx() const {
49     if (ParentIdx == UINT32_MAX)
50       return std::nullopt;
51 
52     return ParentIdx;
53   }
54 
55   /// Returns index of the sibling die.
getSiblingIdx()56   std::optional<uint32_t> getSiblingIdx() const {
57     if (SiblingIdx == 0)
58       return std::nullopt;
59 
60     return SiblingIdx;
61   }
62 
63   /// Set index of sibling.
setSiblingIdx(uint32_t Idx)64   void setSiblingIdx(uint32_t Idx) { SiblingIdx = Idx; }
65 
getTag()66   dwarf::Tag getTag() const {
67     return AbbrevDecl ? AbbrevDecl->getTag() : dwarf::DW_TAG_null;
68   }
69 
hasChildren()70   bool hasChildren() const { return AbbrevDecl && AbbrevDecl->hasChildren(); }
71 
getAbbreviationDeclarationPtr()72   const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
73     return AbbrevDecl;
74   }
75 };
76 
77 } // end namespace llvm
78 
79 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGINFOENTRY_H
80