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 void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
37 unsigned recurseDepth, unsigned indent = 0) const;
38 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
39 uint32_t *offset_ptr, uint16_t attr, uint16_t form,
40 unsigned indent = 0) const;
42 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
43 uint32_t *offset_ptr);
45 /// Extract a debug info entry for a given compile unit from the
46 /// .debug_info and .debug_abbrev data starting at the given offset.
47 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
49 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
50 bool isNULL() const { return AbbrevDecl == 0; }
51 uint64_t getOffset() const { return Offset; }
52 uint32_t getNumAttributes() const {
53 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
55 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
57 // We know we are kept in a vector of contiguous entries, so we know
58 // our parent will be some index behind "this".
59 DWARFDebugInfoEntryMinimal *getParent() {
60 return ParentIdx > 0 ? this - ParentIdx : 0;
62 const DWARFDebugInfoEntryMinimal *getParent() const {
63 return ParentIdx > 0 ? this - ParentIdx : 0;
65 // We know we are kept in a vector of contiguous entries, so we know
66 // our sibling will be some index after "this".
67 DWARFDebugInfoEntryMinimal *getSibling() {
68 return SiblingIdx > 0 ? this + SiblingIdx : 0;
70 const DWARFDebugInfoEntryMinimal *getSibling() const {
71 return SiblingIdx > 0 ? this + SiblingIdx : 0;
73 // We know we are kept in a vector of contiguous entries, so we know
74 // we don't need to store our child pointer, if we have a child it will
75 // be the next entry in the list...
76 DWARFDebugInfoEntryMinimal *getFirstChild() {
77 return hasChildren() ? this + 1 : 0;
79 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
80 return hasChildren() ? this + 1 : 0;
83 void setParent(DWARFDebugInfoEntryMinimal *parent) {
85 // We know we are kept in a vector of contiguous entries, so we know
86 // our parent will be some index behind "this".
87 ParentIdx = this - parent;
91 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
93 // We know we are kept in a vector of contiguous entries, so we know
94 // our sibling will be some index after "this".
95 SiblingIdx = sibling - this;
96 sibling->setParent(getParent());
101 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
105 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
106 const uint16_t attr, DWARFFormValue &formValue,
107 uint32_t *end_attr_offset_ptr = 0) const;
109 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
111 const char *fail_value) const;
113 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
115 uint64_t fail_value) const;
117 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
119 uint64_t fail_value) const;
121 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
123 int64_t fail_value) const;