blob: aa2b89dcbd0d92b8d7f66de1b894d196e0afc1e5 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11#define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
12
13#include "DWARFAbbreviationDeclaration.h"
14#include "llvm/Support/DataTypes.h"
15
16namespace llvm {
17
18class DWARFCompileUnit;
19class DWARFContext;
20class DWARFFormValue;
21
22/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
23class DWARFDebugInfoEntryMinimal {
24 /// Offset within the .debug_info of the start of this entry.
25 uint64_t Offset;
26
27 /// How many to subtract from "this" to get the parent.
28 /// If zero this die has no parent.
29 uint32_t ParentIdx;
30
31 /// How many to add to "this" to get the sibling.
32 uint32_t SiblingIdx;
33
34 const DWARFAbbreviationDeclaration *AbbrevDecl;
35public:
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;
41
42 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
43 uint32_t *offset_ptr);
44
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);
48
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;
54 }
55 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
56
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;
61 }
62 const DWARFDebugInfoEntryMinimal *getParent() const {
63 return ParentIdx > 0 ? this - ParentIdx : 0;
64 }
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;
69 }
70 const DWARFDebugInfoEntryMinimal *getSibling() const {
71 return SiblingIdx > 0 ? this + SiblingIdx : 0;
72 }
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;
78 }
79 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
80 return hasChildren() ? this + 1 : 0;
81 }
82
83 void setParent(DWARFDebugInfoEntryMinimal *parent) {
84 if (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;
88 }
89 else
90 ParentIdx = 0;
91 }
92 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
93 if (sibling)
94 {
95 // We know we are kept in a vector of contiguous entries, so we know
96 // our sibling will be some index after "this".
97 SiblingIdx = sibling - this;
98 sibling->setParent(getParent());
99 }
100 else
101 SiblingIdx = 0;
102 }
103
104 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
105 return AbbrevDecl;
106 }
107
108 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
109 const uint16_t attr, DWARFFormValue &formValue,
110 uint32_t *end_attr_offset_ptr = 0) const;
111
112 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
113 const uint16_t attr,
114 const char *fail_value) const;
115
116 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
117 const uint16_t attr,
118 uint64_t fail_value) const;
119
120 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
121 const uint16_t attr,
122 uint64_t fail_value) const;
123
124 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
125 const uint16_t attr,
126 int64_t fail_value) const;
127};
128
129}
130
131#endif