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"
14 #include "llvm/ADT/Optional.h"
17 class SymbolFileDWARF;
20 class DWARFFormValue {
22 typedef struct ValueTypeTag {
23 ValueTypeTag() : value(), data(nullptr) { value.uval = 0; }
34 eValueTypeInvalid = 0,
41 DWARFFormValue() = default;
42 DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {}
43 DWARFFormValue(const DWARFUnit *unit, dw_form_t form)
44 : m_unit(unit), m_form(form) {}
45 void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
46 dw_form_t Form() const { return m_form; }
47 dw_form_t& FormRef() { return m_form; }
48 void SetForm(dw_form_t form) { m_form = form; }
49 const ValueType &Value() const { return m_value; }
50 ValueType &ValueRef() { return m_value; }
51 void SetValue(const ValueType &val) { m_value = val; }
53 void Dump(lldb_private::Stream &s) const;
54 bool ExtractValue(const lldb_private::DWARFDataExtractor &data,
55 lldb::offset_t *offset_ptr);
56 const uint8_t *BlockData() const;
57 static llvm::Optional<uint8_t> GetFixedSize(dw_form_t form,
59 llvm::Optional<uint8_t> GetFixedSize() const;
60 DWARFDIE Reference() const;
61 uint64_t Reference(dw_offset_t offset) const;
62 bool Boolean() const { return m_value.value.uval != 0; }
63 uint64_t Unsigned() const { return m_value.value.uval; }
64 void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; }
65 int64_t Signed() const { return m_value.value.sval; }
66 void SetSigned(int64_t sval) { m_value.value.sval = sval; }
67 const char *AsCString() const;
68 dw_addr_t Address() const;
69 bool IsValid() const { return m_form != 0; }
70 bool SkipValue(const lldb_private::DWARFDataExtractor &debug_info_data,
71 lldb::offset_t *offset_ptr) const;
72 static bool SkipValue(const dw_form_t form,
73 const lldb_private::DWARFDataExtractor &debug_info_data,
74 lldb::offset_t *offset_ptr, const DWARFUnit *unit);
75 static bool IsBlockForm(const dw_form_t form);
76 static bool IsDataForm(const dw_form_t form);
77 static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);
79 static bool FormIsSupported(dw_form_t form);
82 // Compile unit where m_value was located.
83 // It may be different from compile unit where m_value refers to.
84 const DWARFUnit *m_unit = nullptr; // Unit for this form
85 dw_form_t m_form = 0; // Form for this value
86 ValueType m_value; // Contains all data for the form
89 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H