LLDB mainline
DWARFFormValue.h
Go to the documentation of this file.
1//===-- DWARFFormValue.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_DWARFFORMVALUE_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H
11
12#include "DWARFDataExtractor.h"
13#include <cstddef>
14#include <optional>
15
16namespace lldb_private::plugin {
17namespace dwarf {
18class DWARFUnit;
19class SymbolFileDWARF;
20class DWARFDIE;
21
23public:
24 typedef struct ValueTypeTag {
25 ValueTypeTag() : value() { value.uval = 0; }
26
27 union {
28 uint64_t uval;
29 int64_t sval;
30 const char *cstr;
32 const uint8_t *data = nullptr;
34
35 enum {
41 };
42
43 DWARFFormValue() = default;
44 DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {}
46 : m_unit(unit), m_form(form) {}
47 const DWARFUnit *GetUnit() const { return m_unit; }
48 void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
49 dw_form_t Form() const { return m_form; }
50 dw_form_t &FormRef() { return m_form; }
51 void SetForm(dw_form_t form) { m_form = form; }
52 const ValueType &Value() const { return m_value; }
53 ValueType &ValueRef() { return m_value; }
54 void SetValue(const ValueType &val) { m_value = val; }
55
56 void Dump(Stream &s) const;
57 bool ExtractValue(const DWARFDataExtractor &data, lldb::offset_t *offset_ptr);
58 const uint8_t *BlockData() const;
59 static std::optional<uint8_t> GetFixedSize(dw_form_t form,
60 const DWARFUnit *u);
61 std::optional<uint8_t> GetFixedSize() const;
62 DWARFDIE Reference() const;
63 uint64_t Reference(dw_offset_t offset) const;
64 bool Boolean() const { return m_value.value.uval != 0; }
65 uint64_t Unsigned() const { return m_value.value.uval; }
66 void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; }
67 int64_t Signed() const { return m_value.value.sval; }
68 void SetSigned(int64_t sval) { m_value.value.sval = sval; }
69 const char *AsCString() const;
70 dw_addr_t Address() const;
71 bool IsValid() const { return m_form != 0; }
72 bool SkipValue(const DWARFDataExtractor &debug_info_data,
73 lldb::offset_t *offset_ptr) const;
74 static bool SkipValue(const dw_form_t form,
75 const DWARFDataExtractor &debug_info_data,
76 lldb::offset_t *offset_ptr, const DWARFUnit *unit);
77 static bool IsBlockForm(const dw_form_t form);
78 static bool IsDataForm(const dw_form_t form);
79 static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);
80 void Clear();
81 static bool FormIsSupported(dw_form_t form);
82
83protected:
84 // Compile unit where m_value was located.
85 // It may be different from compile unit where m_value refers to.
86 const DWARFUnit *m_unit = nullptr; // Unit for this form
87 dw_form_t m_form = dw_form_t(0); // Form for this value
88 ValueType m_value; // Contains all data for the form
89};
90} // namespace dwarf
91} // namespace lldb_private::plugin
92
93#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool ExtractValue(const DWARFDataExtractor &data, lldb::offset_t *offset_ptr)
static bool FormIsSupported(dw_form_t form)
struct lldb_private::plugin::dwarf::DWARFFormValue::ValueTypeTag ValueType
static bool IsDataForm(const dw_form_t form)
std::optional< uint8_t > GetFixedSize() const
static int Compare(const DWARFFormValue &a, const DWARFFormValue &b)
bool SkipValue(const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr) const
static bool IsBlockForm(const dw_form_t form)
DWARFFormValue(const DWARFUnit *unit, dw_form_t form)
uint64_t dw_offset_t
Definition: dwarf.h:31
uint64_t dw_addr_t
Definition: dwarf.h:27
llvm::dwarf::Form dw_form_t
Definition: dwarf.h:25
uint64_t offset_t
Definition: lldb-types.h:83
union lldb_private::plugin::dwarf::DWARFFormValue::ValueTypeTag::@160 value