1 //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
11 
12 #include "DWARFDefines.h"
13 #include "DWARFFormValue.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include <vector>
16 
17 class DWARFUnit;
18 
19 class DWARFAttribute {
20 public:
21   DWARFAttribute(dw_attr_t attr, dw_form_t form,
22                  DWARFFormValue::ValueType value)
23       : m_attr(attr), m_form(form), m_value(value) {}
24 
25   dw_attr_t get_attr() const { return m_attr; }
26   dw_form_t get_form() const { return m_form; }
27   DWARFFormValue::ValueType get_value() const { return m_value; }
28   void get(dw_attr_t &attr, dw_form_t &form,
29            DWARFFormValue::ValueType &val) const {
30     attr = m_attr;
31     form = m_form;
32     val = m_value;
33   }
34 protected:
35   dw_attr_t m_attr;
36   dw_form_t m_form;
37   DWARFFormValue::ValueType m_value;
38 };
39 
40 class DWARFAttributes {
41 public:
42   DWARFAttributes();
43   ~DWARFAttributes();
44 
45   void Append(const DWARFFormValue &form_value, dw_offset_t attr_die_offset,
46               dw_attr_t attr);
47   DWARFUnit *CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; }
48   dw_offset_t DIEOffsetAtIndex(uint32_t i) const {
49     return m_infos[i].die_offset;
50   }
51   dw_attr_t AttributeAtIndex(uint32_t i) const {
52     return m_infos[i].attr.get_attr();
53   }
54   dw_form_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); }
55   DWARFFormValue::ValueType ValueAtIndex(uint32_t i) const {
56     return m_infos[i].attr.get_value();
57   }
58   bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const;
59   DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const;
60   DWARFDIE FormValueAsReference(dw_attr_t attr) const;
61   uint32_t FindAttributeIndex(dw_attr_t attr) const;
62   void Clear() { m_infos.clear(); }
63   size_t Size() const { return m_infos.size(); }
64 
65 protected:
66   struct AttributeValue {
67     DWARFUnit *cu; // Keep the compile unit with each attribute in
68                    // case we have DW_FORM_ref_addr values
69     dw_offset_t die_offset;
70     DWARFAttribute attr;
71   };
72   typedef llvm::SmallVector<AttributeValue, 8> collection;
73   collection m_infos;
74 };
75 
76 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
77