LLVM  4.0.0
DWARFAbbreviationDeclaration.h
Go to the documentation of this file.
1 //===-- DWARFAbbreviationDeclaration.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_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
11 #define LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
12 
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/Support/Dwarf.h"
17 namespace llvm {
18 
19 class DWARFUnit;
20 class DWARFFormValue;
21 class raw_ostream;
22 
24 public:
25  struct AttributeSpec {
27  : Attr(A), Form(F), ByteSizeOrValue(V) {}
30  /// The following field is used for ByteSize for non-implicit_const
31  /// attributes and as value for implicit_const ones, indicated by
32  /// Form == DW_FORM_implicit_const.
33  /// The following cases are distinguished:
34  /// * Form != DW_FORM_implicit_const and ByteSizeOrValue has a value:
35  /// ByteSizeOrValue contains the fixed size in bytes
36  /// for the Form in this object.
37  /// * Form != DW_FORM_implicit_const and ByteSizeOrValue is None:
38  /// byte size of Form either varies according to the DWARFUnit
39  /// that it is contained in or the value size varies and must be
40  /// decoded from the debug information in order to determine its size.
41  /// * Form == DW_FORM_implicit_const:
42  /// ByteSizeOrValue contains value for the implicit_const attribute.
44  bool isImplicitConst() const {
45  return Form == dwarf::DW_FORM_implicit_const;
46  }
47  /// Get the fixed byte size of this Form if possible. This function might
48  /// use the DWARFUnit to calculate the size of the Form, like for
49  /// DW_AT_address and DW_AT_ref_addr, so this isn't just an accessor for
50  /// the ByteSize member.
51  Optional<int64_t> getByteSize(const DWARFUnit &U) const;
52  };
54 
56 
57  uint32_t getCode() const { return Code; }
58  dwarf::Tag getTag() const { return Tag; }
59  bool hasChildren() const { return HasChildren; }
60 
63 
65  return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
66  }
67 
69  if (idx < AttributeSpecs.size())
70  return AttributeSpecs[idx].Form;
71  return dwarf::Form(0);
72  }
73 
74  /// Get the index of the specified attribute.
75  ///
76  /// Searches the this abbreviation declaration for the index of the specified
77  /// attribute.
78  ///
79  /// \param attr DWARF attribute to search for.
80  /// \returns Optional index of the attribute if found, None otherwise.
82 
83  /// Extract a DWARF form value from a DIE specified by DIE offset.
84  ///
85  /// Extract an attribute value for a DWARFUnit given the DIE offset and the
86  /// attribute.
87  ///
88  /// \param DIEOffset the DIE offset that points to the ULEB128 abbreviation
89  /// code in the .debug_info data.
90  /// \param Attr DWARF attribute to search for.
91  /// \param U the DWARFUnit the contains the DIE.
92  /// \returns Optional DWARF form value if the attribute was extracted.
94  const dwarf::Attribute Attr,
95  const DWARFUnit &U) const;
96 
97  bool extract(DataExtractor Data, uint32_t* OffsetPtr);
98  void dump(raw_ostream &OS) const;
99 
100  // Return an optional byte size of all attribute data in this abbreviation
101  // if a constant byte size can be calculated given a DWARFUnit. This allows
102  // DWARF parsing to be faster as many DWARF DIEs have a fixed byte size.
104 
105 private:
106  void clear();
107 
108  /// A helper structure that can quickly determine the size in bytes of an
109  /// abbreviation declaration.
110  struct FixedSizeInfo {
111  /// The fixed byte size for fixed size forms.
112  uint16_t NumBytes;
113  /// Number of DW_FORM_address forms in this abbrevation declaration.
114  uint8_t NumAddrs;
115  /// Number of DW_FORM_ref_addr forms in this abbrevation declaration.
116  uint8_t NumRefAddrs;
117  /// Number of 4 byte in DWARF32 and 8 byte in DWARF64 forms.
118  uint8_t NumDwarfOffsets;
119  /// Constructor
120  FixedSizeInfo()
121  : NumBytes(0), NumAddrs(0), NumRefAddrs(0), NumDwarfOffsets(0) {}
122  /// Calculate the fixed size in bytes given a DWARFUnit.
123  ///
124  /// \param U the DWARFUnit to use when determing the byte size.
125  /// \returns the size in bytes for all attribute data in this abbreviation.
126  /// The returned size does not include bytes for the ULEB128 abbreviation
127  /// code
128  size_t getByteSize(const DWARFUnit &U) const;
129  };
130 
131  uint32_t Code;
132  dwarf::Tag Tag;
133  uint8_t CodeByteSize;
134  bool HasChildren;
135  AttributeSpecVector AttributeSpecs;
136  /// If this abbreviation has a fixed byte size then FixedAttributeSize member
137  /// variable below will have a value.
138  Optional<FixedSizeInfo> FixedAttributeSize;
139 };
140 
141 }
142 
143 #endif
Optional< int64_t > ByteSizeOrValue
The following field is used for ByteSize for non-implicit_const attributes and as value for implicit_...
bool extract(DataExtractor Data, uint32_t *OffsetPtr)
Attribute
Attributes.
Definition: Dwarf.h:94
Optional< DWARFFormValue > getAttributeValue(const uint32_t DIEOffset, const dwarf::Attribute Attr, const DWARFUnit &U) const
Extract a DWARF form value from a DIE specified by DIE offset.
Optional< size_t > getFixedAttributesByteSize(const DWARFUnit &U) const
#define F(x, y, z)
Definition: MD5.cpp:51
iterator_range< AttributeSpecVector::const_iterator > attr_iterator_range
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
A range adaptor for a pair of iterators.
AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional< int64_t > V)
Optional< int64_t > getByteSize(const DWARFUnit &U) const
Get the fixed byte size of this Form if possible.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
Optional< uint32_t > findAttributeIndex(dwarf::Attribute attr) const
Get the index of the specified attribute.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
dwarf::Form getFormByIndex(uint32_t idx) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
SmallVector< AttributeSpec, 8 > AttributeSpecVector
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")