]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / source / Plugins / SymbolFile / DWARF / DWARFAttribute.h
1 //===-- DWARFAttribute.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 SymbolFileDWARF_DWARFAttribute_h_
11 #define SymbolFileDWARF_DWARFAttribute_h_
12
13 #include "DWARFDefines.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include <vector>
16
17 class DWARFUnit;
18 class DWARFFormValue;
19
20 class DWARFAttribute {
21 public:
22   DWARFAttribute(dw_attr_t attr, dw_form_t form) : m_attr(attr), m_form(form) {}
23
24   void set(dw_attr_t attr, dw_form_t form) {
25     m_attr = attr;
26     m_form = form;
27   }
28   void set_attr(dw_attr_t attr) { m_attr = attr; }
29   void set_form(dw_form_t form) { m_form = form; }
30   dw_attr_t get_attr() const { return m_attr; }
31   dw_form_t get_form() const { return m_form; }
32   void get(dw_attr_t &attr, dw_form_t &form) const {
33     attr = m_attr;
34     form = m_form;
35   }
36   bool operator==(const DWARFAttribute &rhs) const {
37     return m_attr == rhs.m_attr && m_form == rhs.m_form;
38   }
39   typedef std::vector<DWARFAttribute> collection;
40   typedef collection::iterator iterator;
41   typedef collection::const_iterator const_iterator;
42
43 protected:
44   dw_attr_t m_attr;
45   dw_form_t m_form;
46 };
47
48 class DWARFAttributes {
49 public:
50   DWARFAttributes();
51   ~DWARFAttributes();
52
53   void Append(const DWARFUnit *cu, dw_offset_t attr_die_offset,
54               dw_attr_t attr, dw_form_t form);
55   const DWARFUnit *CompileUnitAtIndex(uint32_t i) const {
56     return m_infos[i].cu;
57   }
58   dw_offset_t DIEOffsetAtIndex(uint32_t i) const {
59     return m_infos[i].die_offset;
60   }
61   dw_attr_t AttributeAtIndex(uint32_t i) const {
62     return m_infos[i].attr.get_attr();
63   }
64   dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); }
65   bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const;
66   uint64_t FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const;
67   uint64_t FormValueAsUnsigned(dw_attr_t attr, uint64_t fail_value) const;
68   uint32_t FindAttributeIndex(dw_attr_t attr) const;
69   bool ContainsAttribute(dw_attr_t attr) const;
70   bool RemoveAttribute(dw_attr_t attr);
71   void Clear() { m_infos.clear(); }
72   size_t Size() const { return m_infos.size(); }
73
74 protected:
75   struct AttributeValue {
76     const DWARFUnit *cu;        // Keep the compile unit with each attribute in
77                                 // case we have DW_FORM_ref_addr values
78     dw_offset_t die_offset;
79     DWARFAttribute attr;
80   };
81   typedef llvm::SmallVector<AttributeValue, 8> collection;
82   collection m_infos;
83 };
84
85 #endif // SymbolFileDWARF_DWARFAttribute_h_