Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
39645 views
//===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H1011#include "DWARFDataExtractor.h"12#include <cstddef>13#include <optional>1415namespace lldb_private::plugin {16namespace dwarf {17class DWARFUnit;18class SymbolFileDWARF;19class DWARFDIE;2021class DWARFFormValue {22public:23typedef struct ValueTypeTag {24ValueTypeTag() : value() { value.uval = 0; }2526union {27uint64_t uval;28int64_t sval;29const char *cstr;30} value;31const uint8_t *data = nullptr;32} ValueType;3334enum {35eValueTypeInvalid = 0,36eValueTypeUnsigned,37eValueTypeSigned,38eValueTypeCStr,39eValueTypeBlock40};4142DWARFFormValue() = default;43DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {}44DWARFFormValue(const DWARFUnit *unit, dw_form_t form)45: m_unit(unit), m_form(form) {}46const DWARFUnit *GetUnit() const { return m_unit; }47void SetUnit(const DWARFUnit *unit) { m_unit = unit; }48dw_form_t Form() const { return m_form; }49dw_form_t &FormRef() { return m_form; }50void SetForm(dw_form_t form) { m_form = form; }51const ValueType &Value() const { return m_value; }52ValueType &ValueRef() { return m_value; }53void SetValue(const ValueType &val) { m_value = val; }5455void Dump(Stream &s) const;56bool ExtractValue(const DWARFDataExtractor &data, lldb::offset_t *offset_ptr);57const uint8_t *BlockData() const;58static std::optional<uint8_t> GetFixedSize(dw_form_t form,59const DWARFUnit *u);60std::optional<uint8_t> GetFixedSize() const;61DWARFDIE Reference() const;6263/// If this is a reference to another DIE, return the corresponding DWARFUnit64/// and DIE offset such that Unit->GetDIE(offset) produces the desired DIE.65/// Otherwise, a nullptr and unspecified offset are returned.66std::pair<DWARFUnit *, uint64_t> ReferencedUnitAndOffset() const;6768uint64_t Reference(dw_offset_t offset) const;69bool Boolean() const { return m_value.value.uval != 0; }70uint64_t Unsigned() const { return m_value.value.uval; }71void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; }72int64_t Signed() const { return m_value.value.sval; }73void SetSigned(int64_t sval) { m_value.value.sval = sval; }74const char *AsCString() const;75dw_addr_t Address() const;76bool IsValid() const { return m_form != 0; }77bool SkipValue(const DWARFDataExtractor &debug_info_data,78lldb::offset_t *offset_ptr) const;79static bool SkipValue(const dw_form_t form,80const DWARFDataExtractor &debug_info_data,81lldb::offset_t *offset_ptr, const DWARFUnit *unit);82static bool IsBlockForm(const dw_form_t form);83static bool IsDataForm(const dw_form_t form);84static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);85void Clear();86static bool FormIsSupported(dw_form_t form);8788protected:89// Compile unit where m_value was located.90// It may be different from compile unit where m_value refers to.91const DWARFUnit *m_unit = nullptr; // Unit for this form92dw_form_t m_form = dw_form_t(0); // Form for this value93ValueType m_value; // Contains all data for the form94};95} // namespace dwarf96} // namespace lldb_private::plugin9798#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H99100101