5e7b89b5a6e848f15a1b5cc60555f285102b0eb7
[oota-llvm.git] / lib / DebugInfo / DWARFDebugInfoEntry.h
1 //===-- 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
16 namespace llvm {
17
18 class DWARFCompileUnit;
19 class DWARFContext;
20 class DWARFFormValue;
21
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.
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;
35 public:
36   DWARFDebugInfoEntryMinimal()
37     : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
38
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;
44
45   bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
46                    uint32_t *offset_ptr);
47
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);
51
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;
57   }
58   bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
59
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;
64   }
65   const DWARFDebugInfoEntryMinimal *getParent() const {
66     return ParentIdx > 0 ? this - ParentIdx : 0;
67   }
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;
72   }
73   const DWARFDebugInfoEntryMinimal *getSibling() const {
74     return SiblingIdx > 0 ? this + SiblingIdx : 0;
75   }
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;
81   }
82   const DWARFDebugInfoEntryMinimal *getFirstChild() const {
83     return hasChildren() ? this + 1 : 0;
84   }
85
86   void setParent(DWARFDebugInfoEntryMinimal *parent) {
87     if (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;
91     } else
92       ParentIdx = 0;
93   }
94   void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
95     if (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());
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