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 liblldb_DWARFAbbreviationDeclaration_h_
11 #define liblldb_DWARFAbbreviationDeclaration_h_
12 
13 #include "DWARFAttribute.h"
14 #include "SymbolFileDWARF.h"
15 
16 class DWARFAbbreviationDeclaration {
17 public:
18   enum { InvalidCode = 0 };
19   DWARFAbbreviationDeclaration();
20 
21   // For hand crafting an abbreviation declaration
22   DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
AddAttribute(const DWARFAttribute & attr)23   void AddAttribute(const DWARFAttribute &attr) {
24     m_attributes.push_back(attr);
25   }
26 
Code()27   dw_uleb128_t Code() const { return m_code; }
SetCode(dw_uleb128_t code)28   void SetCode(dw_uleb128_t code) { m_code = code; }
Tag()29   dw_tag_t Tag() const { return m_tag; }
HasChildren()30   bool HasChildren() const { return m_has_children; }
NumAttributes()31   size_t NumAttributes() const { return m_attributes.size(); }
GetAttrByIndex(uint32_t idx)32   dw_attr_t GetAttrByIndex(uint32_t idx) const {
33     return m_attributes.size() > idx ? m_attributes[idx].get_attr() : 0;
34   }
GetFormByIndex(uint32_t idx)35   dw_form_t GetFormByIndex(uint32_t idx) const {
36     return m_attributes.size() > idx ? m_attributes[idx].get_form() : 0;
37   }
38 
39   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
GetAttrAndFormValueByIndex(uint32_t idx,dw_attr_t & attr,DWARFFormValue & form_value)40   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t &attr,
41                                   DWARFFormValue &form_value) const {
42     m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
43   }
GetFormByIndexUnchecked(uint32_t idx)44   dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
45     return m_attributes[idx].get_form();
46   }
47   uint32_t FindAttributeIndex(dw_attr_t attr) const;
48   bool Extract(const lldb_private::DWARFDataExtractor &data,
49                lldb::offset_t *offset_ptr);
50   bool Extract(const lldb_private::DWARFDataExtractor &data,
51                lldb::offset_t *offset_ptr, dw_uleb128_t code);
52   bool IsValid();
53   void Dump(lldb_private::Stream *s) const;
54   bool operator==(const DWARFAbbreviationDeclaration &rhs) const;
Attributes()55   const DWARFAttribute::collection &Attributes() const { return m_attributes; }
56 
57 protected:
58   dw_uleb128_t m_code;
59   dw_tag_t m_tag;
60   uint8_t m_has_children;
61   DWARFAttribute::collection m_attributes;
62 };
63 
64 #endif // liblldb_DWARFAbbreviationDeclaration_h_
65