1 //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H
12 #include "DWARFDefines.h"
13 #include "DWARFFormValue.h"
14 #include "llvm/ADT/SmallVector.h"
17 namespace lldb_private::plugin
{
21 class DWARFAttribute
{
23 DWARFAttribute(dw_attr_t attr
, dw_form_t form
,
24 DWARFFormValue::ValueType value
)
25 : m_attr(attr
), m_form(form
), m_value(value
) {}
27 dw_attr_t
get_attr() const { return m_attr
; }
28 dw_form_t
get_form() const { return m_form
; }
29 DWARFFormValue::ValueType
get_value() const { return m_value
; }
30 void get(dw_attr_t
&attr
, dw_form_t
&form
,
31 DWARFFormValue::ValueType
&val
) const {
40 DWARFFormValue::ValueType m_value
;
43 class DWARFAttributes
{
48 void Append(const DWARFFormValue
&form_value
, dw_offset_t attr_die_offset
,
50 DWARFUnit
*CompileUnitAtIndex(uint32_t i
) const { return m_infos
[i
].cu
; }
51 dw_offset_t
DIEOffsetAtIndex(uint32_t i
) const {
52 return m_infos
[i
].die_offset
;
54 dw_attr_t
AttributeAtIndex(uint32_t i
) const {
55 return m_infos
[i
].attr
.get_attr();
57 dw_form_t
FormAtIndex(uint32_t i
) const { return m_infos
[i
].attr
.get_form(); }
58 DWARFFormValue::ValueType
ValueAtIndex(uint32_t i
) const {
59 return m_infos
[i
].attr
.get_value();
61 bool ExtractFormValueAtIndex(uint32_t i
, DWARFFormValue
&form_value
) const;
62 DWARFDIE
FormValueAsReferenceAtIndex(uint32_t i
) const;
63 DWARFDIE
FormValueAsReference(dw_attr_t attr
) const;
64 uint32_t FindAttributeIndex(dw_attr_t attr
) const;
65 void Clear() { m_infos
.clear(); }
66 size_t Size() const { return m_infos
.size(); }
69 struct AttributeValue
{
70 DWARFUnit
*cu
; // Keep the compile unit with each attribute in
71 // case we have DW_FORM_ref_addr values
72 dw_offset_t die_offset
;
75 typedef llvm::SmallVector
<AttributeValue
, 8> collection
;
79 } // namespace lldb_private::plugin
81 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H