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