1 //===-- DWARFFormValue.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_DWARFFORMVALUE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H
12 #include "DWARFDataExtractor.h"
13 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
16 namespace lldb_private::plugin
{
19 class SymbolFileDWARF
;
22 class DWARFFormValue
{
24 typedef llvm::DWARFFormValue::ValueType ValueType
;
26 eValueTypeInvalid
= 0,
33 DWARFFormValue() = default;
34 DWARFFormValue(const DWARFUnit
*unit
) : m_unit(unit
) {}
35 DWARFFormValue(const DWARFUnit
*unit
, dw_form_t form
)
36 : m_unit(unit
), m_form(form
) {}
37 const DWARFUnit
*GetUnit() const { return m_unit
; }
38 void SetUnit(const DWARFUnit
*unit
) { m_unit
= unit
; }
39 dw_form_t
Form() const { return m_form
; }
40 dw_form_t
&FormRef() { return m_form
; }
41 void SetForm(dw_form_t form
) { m_form
= form
; }
42 const ValueType
&Value() const { return m_value
; }
43 ValueType
&ValueRef() { return m_value
; }
44 void SetValue(const ValueType
&val
) { m_value
= val
; }
46 void Dump(Stream
&s
) const;
47 bool ExtractValue(const DWARFDataExtractor
&data
, lldb::offset_t
*offset_ptr
);
48 const uint8_t *BlockData() const;
49 static std::optional
<uint8_t> GetFixedSize(dw_form_t form
,
51 std::optional
<uint8_t> GetFixedSize() const;
52 DWARFDIE
Reference() const;
54 /// If this is a reference to another DIE, return the corresponding DWARFUnit
55 /// and DIE offset such that Unit->GetDIE(offset) produces the desired DIE.
56 /// Otherwise, a nullptr and unspecified offset are returned.
57 std::pair
<DWARFUnit
*, uint64_t> ReferencedUnitAndOffset() const;
59 uint64_t Reference(dw_offset_t offset
) const;
60 bool Boolean() const { return m_value
.uval
!= 0; }
61 uint64_t Unsigned() const { return m_value
.uval
; }
62 void SetUnsigned(uint64_t uval
) { m_value
.uval
= uval
; }
63 int64_t Signed() const { return m_value
.sval
; }
64 void SetSigned(int64_t sval
) { m_value
.sval
= sval
; }
65 const char *AsCString() const;
66 dw_addr_t
Address() const;
67 bool IsValid() const { return m_form
!= 0; }
68 bool SkipValue(const DWARFDataExtractor
&debug_info_data
,
69 lldb::offset_t
*offset_ptr
) const;
70 static bool SkipValue(const dw_form_t form
,
71 const DWARFDataExtractor
&debug_info_data
,
72 lldb::offset_t
*offset_ptr
, const DWARFUnit
*unit
);
73 static bool IsBlockForm(const dw_form_t form
);
74 static bool IsDataForm(const dw_form_t form
);
75 static int Compare(const DWARFFormValue
&a
, const DWARFFormValue
&b
);
77 static bool FormIsSupported(dw_form_t form
);
80 // Compile unit where m_value was located.
81 // It may be different from compile unit where m_value refers to.
82 const DWARFUnit
*m_unit
= nullptr; // Unit for this form
83 dw_form_t m_form
= dw_form_t(0); // Form for this value
84 ValueType m_value
; // Contains all data for the form
87 } // namespace lldb_private::plugin
89 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H