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 DWARFDebugAranges;
19 class DWARFCompileUnit;
23 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
24 class DWARFDebugInfoEntryMinimal {
25 /// Offset within the .debug_info of the start of this entry.
28 /// How many to subtract from "this" to get the parent.
29 /// If zero this die has no parent.
32 /// How many to add to "this" to get the sibling.
35 const DWARFAbbreviationDeclaration *AbbrevDecl;
37 DWARFDebugInfoEntryMinimal()
38 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
40 void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
41 unsigned recurseDepth, unsigned indent = 0) const;
42 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
43 uint32_t *offset_ptr, uint16_t attr, uint16_t form,
44 unsigned indent = 0) const;
46 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
47 uint32_t *offset_ptr);
49 /// Extract a debug info entry for a given compile unit from the
50 /// .debug_info and .debug_abbrev data starting at the given offset.
51 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
53 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
54 bool isNULL() const { return AbbrevDecl == 0; }
55 uint32_t getOffset() const { return Offset; }
56 uint32_t getNumAttributes() const {
57 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
59 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
61 // We know we are kept in a vector of contiguous entries, so we know
62 // our parent will be some index behind "this".
63 DWARFDebugInfoEntryMinimal *getParent() {
64 return ParentIdx > 0 ? this - ParentIdx : 0;
66 const DWARFDebugInfoEntryMinimal *getParent() const {
67 return ParentIdx > 0 ? this - ParentIdx : 0;
69 // We know we are kept in a vector of contiguous entries, so we know
70 // our sibling will be some index after "this".
71 DWARFDebugInfoEntryMinimal *getSibling() {
72 return SiblingIdx > 0 ? this + SiblingIdx : 0;
74 const DWARFDebugInfoEntryMinimal *getSibling() const {
75 return SiblingIdx > 0 ? this + SiblingIdx : 0;
77 // We know we are kept in a vector of contiguous entries, so we know
78 // we don't need to store our child pointer, if we have a child it will
79 // be the next entry in the list...
80 DWARFDebugInfoEntryMinimal *getFirstChild() {
81 return hasChildren() ? this + 1 : 0;
83 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
84 return hasChildren() ? this + 1 : 0;
87 void setParent(DWARFDebugInfoEntryMinimal *parent) {
89 // We know we are kept in a vector of contiguous entries, so we know
90 // our parent will be some index behind "this".
91 ParentIdx = this - parent;
95 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
97 // We know we are kept in a vector of contiguous entries, so we know
98 // our sibling will be some index after "this".
99 SiblingIdx = sibling - this;
100 sibling->setParent(getParent());
105 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
109 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
110 const uint16_t attr, DWARFFormValue &formValue,
111 uint32_t *end_attr_offset_ptr = 0) const;
113 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
115 const char *fail_value) const;
117 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
119 uint64_t fail_value) const;
121 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
123 uint64_t fail_value) const;
125 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
127 int64_t fail_value) const;
129 void buildAddressRangeTable(const DWARFCompileUnit *cu,
130 DWARFDebugAranges *debug_aranges) const;