• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
DWARFAttribute(dw_attr_t attr,dw_form_t form,DWARFFormValue::ValueType value)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 
set(dw_attr_t attr,dw_form_t form)25   void set(dw_attr_t attr, dw_form_t form) {
26     m_attr = attr;
27     m_form = form;
28   }
get_attr()29   dw_attr_t get_attr() const { return m_attr; }
get_form()30   dw_form_t get_form() const { return m_form; }
get(dw_attr_t & attr,dw_form_t & form,DWARFFormValue::ValueType & val)31   void get(dw_attr_t &attr, dw_form_t &form,
32            DWARFFormValue::ValueType &val) const {
33     attr = m_attr;
34     form = m_form;
35     val = m_value;
36   }
37   bool operator==(const DWARFAttribute &rhs) const {
38     return m_attr == rhs.m_attr && m_form == rhs.m_form;
39   }
40   typedef std::vector<DWARFAttribute> collection;
41   typedef collection::iterator iterator;
42   typedef collection::const_iterator const_iterator;
43 
44 protected:
45   dw_attr_t m_attr;
46   dw_form_t m_form;
47   DWARFFormValue::ValueType m_value;
48 };
49 
50 class DWARFAttributes {
51 public:
52   DWARFAttributes();
53   ~DWARFAttributes();
54 
55   void Append(DWARFUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr,
56               dw_form_t form);
CompileUnitAtIndex(uint32_t i)57   DWARFUnit *CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; }
DIEOffsetAtIndex(uint32_t i)58   dw_offset_t DIEOffsetAtIndex(uint32_t i) const {
59     return m_infos[i].die_offset;
60   }
AttributeAtIndex(uint32_t i)61   dw_attr_t AttributeAtIndex(uint32_t i) const {
62     return m_infos[i].attr.get_attr();
63   }
FormAtIndex(uint32_t i)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   DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const;
67   DWARFDIE FormValueAsReference(dw_attr_t attr) const;
68   uint32_t FindAttributeIndex(dw_attr_t attr) const;
Clear()69   void Clear() { m_infos.clear(); }
Size()70   size_t Size() const { return m_infos.size(); }
71 
72 protected:
73   struct AttributeValue {
74     DWARFUnit *cu; // Keep the compile unit with each attribute in
75                    // case we have DW_FORM_ref_addr values
76     dw_offset_t die_offset;
77     DWARFAttribute attr;
78   };
79   typedef llvm::SmallVector<AttributeValue, 8> collection;
80   collection m_infos;
81 };
82 
83 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
84