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