blob: d5d86b9ec0c1a52aae4aafc5c258a8de02759ac3 [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
Benjamin Kramer10df8062011-09-14 20:52:27 +000018class DWARFDebugAranges;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000019class DWARFCompileUnit;
20class DWARFContext;
21class DWARFFormValue;
22
23/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
24class DWARFDebugInfoEntryMinimal {
25 /// Offset within the .debug_info of the start of this entry.
Benjamin Kramer80cc2592011-11-05 15:35:00 +000026 uint32_t Offset;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000027
28 /// How many to subtract from "this" to get the parent.
29 /// If zero this die has no parent.
30 uint32_t ParentIdx;
31
32 /// How many to add to "this" to get the sibling.
33 uint32_t SiblingIdx;
34
35 const DWARFAbbreviationDeclaration *AbbrevDecl;
36public:
Benjamin Kramer15ec0852011-09-14 00:15:32 +000037 DWARFDebugInfoEntryMinimal()
38 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
39
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000040 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;
45
46 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
47 uint32_t *offset_ptr);
48
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);
52
53 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
54 bool isNULL() const { return AbbrevDecl == 0; }
Benjamin Kramer80cc2592011-11-05 15:35:00 +000055 uint32_t getOffset() const { return Offset; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000056 uint32_t getNumAttributes() const {
57 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
58 }
59 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
60
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;
65 }
66 const DWARFDebugInfoEntryMinimal *getParent() const {
67 return ParentIdx > 0 ? this - ParentIdx : 0;
68 }
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;
73 }
74 const DWARFDebugInfoEntryMinimal *getSibling() const {
75 return SiblingIdx > 0 ? this + SiblingIdx : 0;
76 }
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;
82 }
83 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
84 return hasChildren() ? this + 1 : 0;
85 }
86
87 void setParent(DWARFDebugInfoEntryMinimal *parent) {
88 if (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;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000092 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000093 ParentIdx = 0;
94 }
95 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000096 if (sibling) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000097 // 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());
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000101 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000102 SiblingIdx = 0;
103 }
104
105 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
106 return AbbrevDecl;
107 }
108
109 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
110 const uint16_t attr, DWARFFormValue &formValue,
111 uint32_t *end_attr_offset_ptr = 0) const;
112
113 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
114 const uint16_t attr,
115 const char *fail_value) const;
116
117 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
118 const uint16_t attr,
119 uint64_t fail_value) const;
120
121 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
122 const uint16_t attr,
123 uint64_t fail_value) const;
124
125 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
126 const uint16_t attr,
127 int64_t fail_value) const;
Benjamin Kramer10df8062011-09-14 20:52:27 +0000128
129 void buildAddressRangeTable(const DWARFCompileUnit *cu,
130 DWARFDebugAranges *debug_aranges) const;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000131
132 bool addressRangeContainsAddress(const DWARFCompileUnit *cu,
133 const uint64_t address) const;
134
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000135 // If a DIE represents a subprogram, returns its mangled name
136 // (or short name, if mangled is missing). This name may be fetched
137 // from specification or abstract origin for this subprogram.
138 // Returns null if no name is found.
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000139 const char* getSubprogramName(const DWARFCompileUnit *cu) const;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000140};
141
142}
143
144#endif