1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
13 #include "DWARFAbbreviationDeclaration.h"
14 #include "llvm/Support/DataTypes.h"
18 class DWARFCompileUnit;
22 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
23 class DWARFDebugInfoEntryMinimal {
24 /// Offset within the .debug_info of the start of this entry.
27 /// How many to subtract from "this" to get the parent.
28 /// If zero this die has no parent.
31 /// How many to add to "this" to get the sibling.
34 const DWARFAbbreviationDeclaration *AbbrevDecl;
36 DWARFDebugInfoEntryMinimal()
37 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
39 void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
40 unsigned recurseDepth, unsigned indent = 0) const;
41 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
42 uint32_t *offset_ptr, uint16_t attr, uint16_t form,
43 unsigned indent = 0) const;
45 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
46 uint32_t *offset_ptr);
48 /// Extract a debug info entry for a given compile unit from the
49 /// .debug_info and .debug_abbrev data starting at the given offset.
50 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
52 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
53 bool isNULL() const { return AbbrevDecl == 0; }
54 uint64_t getOffset() const { return Offset; }
55 uint32_t getNumAttributes() const {
56 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
58 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
60 // We know we are kept in a vector of contiguous entries, so we know
61 // our parent will be some index behind "this".
62 DWARFDebugInfoEntryMinimal *getParent() {
63 return ParentIdx > 0 ? this - ParentIdx : 0;
65 const DWARFDebugInfoEntryMinimal *getParent() const {
66 return ParentIdx > 0 ? this - ParentIdx : 0;
68 // We know we are kept in a vector of contiguous entries, so we know
69 // our sibling will be some index after "this".
70 DWARFDebugInfoEntryMinimal *getSibling() {
71 return SiblingIdx > 0 ? this + SiblingIdx : 0;
73 const DWARFDebugInfoEntryMinimal *getSibling() const {
74 return SiblingIdx > 0 ? this + SiblingIdx : 0;
76 // We know we are kept in a vector of contiguous entries, so we know
77 // we don't need to store our child pointer, if we have a child it will
78 // be the next entry in the list...
79 DWARFDebugInfoEntryMinimal *getFirstChild() {
80 return hasChildren() ? this + 1 : 0;
82 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
83 return hasChildren() ? this + 1 : 0;
86 void setParent(DWARFDebugInfoEntryMinimal *parent) {
88 // We know we are kept in a vector of contiguous entries, so we know
89 // our parent will be some index behind "this".
90 ParentIdx = this - parent;
94 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
96 // We know we are kept in a vector of contiguous entries, so we know
97 // our sibling will be some index after "this".
98 SiblingIdx = sibling - this;
99 sibling->setParent(getParent());
104 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
108 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
109 const uint16_t attr, DWARFFormValue &formValue,
110 uint32_t *end_attr_offset_ptr = 0) const;
112 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
114 const char *fail_value) const;
116 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
118 uint64_t fail_value) const;
120 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
122 uint64_t fail_value) const;
124 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
126 int64_t fail_value) const;