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 "lldb/Core/dwarf.h"
14#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
15#include <optional>
16
17namespace lldb_private::plugin {
18namespace dwarf {
19class DWARFUnit;
20class SymbolFileDWARF;
21class DWARFDIE;
22
24public:
25 typedef llvm::DWARFFormValue::ValueType ValueType;
26 enum {
32 };
33
34 DWARFFormValue() = default;
35 DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {}
37 : m_unit(unit), m_form(form) {}
38 const DWARFUnit *GetUnit() const { return m_unit; }
39 void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
40 dw_form_t Form() const { return m_form; }
41 dw_form_t &FormRef() { return m_form; }
42 void SetForm(dw_form_t form) { m_form = form; }
43 const ValueType &Value() const { return m_value; }
44 ValueType &ValueRef() { return m_value; }
45 void SetValue(const ValueType &val) { m_value = val; }
46
47 void Dump(Stream &s) const;
48 bool ExtractValue(const DWARFDataExtractor &data, lldb::offset_t *offset_ptr);
49 const uint8_t *BlockData() const;
50 static std::optional<uint8_t> GetFixedSize(dw_form_t form,
51 const DWARFUnit *u);
52 std::optional<uint8_t> GetFixedSize() const;
53 DWARFDIE Reference() const;
54
55 /// If this is a reference to another DIE, return the corresponding DWARFUnit
56 /// and DIE offset such that Unit->GetDIE(offset) produces the desired DIE.
57 /// Otherwise, a nullptr and unspecified offset are returned.
58 std::pair<DWARFUnit *, uint64_t> ReferencedUnitAndOffset() const;
59
60 uint64_t Reference(dw_offset_t offset) const;
61 bool Boolean() const { return m_value.uval != 0; }
62 uint64_t Unsigned() const { return m_value.uval; }
63 void SetUnsigned(uint64_t uval) { m_value.uval = uval; }
64 int64_t Signed() const { return m_value.sval; }
65 void SetSigned(int64_t sval) { m_value.sval = sval; }
66 const char *AsCString() const;
67 dw_addr_t Address() const;
68 bool IsValid() const { return m_form != 0; }
69 bool SkipValue(const DWARFDataExtractor &debug_info_data,
70 lldb::offset_t *offset_ptr) const;
71 static bool SkipValue(const dw_form_t form,
72 const DWARFDataExtractor &debug_info_data,
73 lldb::offset_t *offset_ptr, const DWARFUnit *unit);
74 static bool IsBlockForm(const dw_form_t form);
75 static bool IsDataForm(const dw_form_t form);
76 static bool IsFlagForm(const dw_form_t form);
77 static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);
78 void Clear();
79 static bool FormIsSupported(dw_form_t form);
80
81 // The following methods use LLVM naming convension in order to be are used by
82 // LLVM libraries.
83 std::optional<uint64_t> getAsUnsignedConstant() const;
84 std::optional<int64_t> getAsSignedConstant() const;
85 const char *getAsCString() const { return AsCString(); }
86
87protected:
88 // Compile unit where m_value was located.
89 // It may be different from compile unit where m_value refers to.
90 const DWARFUnit *m_unit = nullptr; // Unit for this form
91 dw_form_t m_form = dw_form_t(0); // Form for this value
92 ValueType m_value; // Contains all data for the form
93};
94} // namespace dwarf
95} // namespace lldb_private::plugin
96
97#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)
llvm::DWARFFormValue::ValueType ValueType
static bool IsDataForm(const dw_form_t form)
std::optional< uint8_t > GetFixedSize() const
std::pair< DWARFUnit *, uint64_t > ReferencedUnitAndOffset() const
If this is a reference to another DIE, return the corresponding DWARFUnit and DIE offset such that Un...
static int Compare(const DWARFFormValue &a, const DWARFFormValue &b)
bool SkipValue(const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr) const
static bool IsFlagForm(const dw_form_t form)
std::optional< int64_t > getAsSignedConstant() const
static bool IsBlockForm(const dw_form_t form)
DWARFFormValue(const DWARFUnit *unit, dw_form_t form)
std::optional< uint64_t > getAsUnsignedConstant() const
uint64_t dw_offset_t
Definition dwarf.h:24
uint64_t dw_addr_t
Definition dwarf.h:20
llvm::dwarf::Form dw_form_t
Definition dwarf.h:18
uint64_t offset_t
Definition lldb-types.h:86