1254721Semaste//===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===// 2254721Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6254721Semaste// 7254721Semaste//===----------------------------------------------------------------------===// 8254721Semaste 9254721Semaste#ifndef SymbolFileDWARF_DWARFFormValue_h_ 10254721Semaste#define SymbolFileDWARF_DWARFFormValue_h_ 11254721Semaste 12314564Sdim#include "DWARFDataExtractor.h" 13344779Sdim#include <stddef.h> 14353358Sdim#include "llvm/ADT/Optional.h" 15254721Semaste 16341825Sdimclass DWARFUnit; 17344779Sdimclass SymbolFileDWARF; 18353358Sdimclass DWARFDIE; 19254721Semaste 20314564Sdimclass DWARFFormValue { 21254721Semastepublic: 22314564Sdim typedef struct ValueTypeTag { 23353358Sdim ValueTypeTag() : value(), data(nullptr) { value.uval = 0; } 24254721Semaste 25314564Sdim union { 26314564Sdim uint64_t uval; 27314564Sdim int64_t sval; 28314564Sdim const char *cstr; 29314564Sdim } value; 30314564Sdim const uint8_t *data; 31314564Sdim } ValueType; 32254721Semaste 33314564Sdim enum { 34314564Sdim eValueTypeInvalid = 0, 35314564Sdim eValueTypeUnsigned, 36314564Sdim eValueTypeSigned, 37314564Sdim eValueTypeCStr, 38314564Sdim eValueTypeBlock 39314564Sdim }; 40314564Sdim 41353358Sdim DWARFFormValue() = default; 42353358Sdim DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {} 43353358Sdim DWARFFormValue(const DWARFUnit *unit, dw_form_t form) 44353358Sdim : m_unit(unit), m_form(form) {} 45353358Sdim void SetUnit(const DWARFUnit *unit) { m_unit = unit; } 46314564Sdim dw_form_t Form() const { return m_form; } 47344779Sdim dw_form_t& FormRef() { return m_form; } 48314564Sdim void SetForm(dw_form_t form) { m_form = form; } 49314564Sdim const ValueType &Value() const { return m_value; } 50344779Sdim ValueType &ValueRef() { return m_value; } 51344779Sdim void SetValue(const ValueType &val) { m_value = val; } 52344779Sdim 53314564Sdim void Dump(lldb_private::Stream &s) const; 54314564Sdim bool ExtractValue(const lldb_private::DWARFDataExtractor &data, 55314564Sdim lldb::offset_t *offset_ptr); 56314564Sdim const uint8_t *BlockData() const; 57353358Sdim static llvm::Optional<uint8_t> GetFixedSize(dw_form_t form, 58353358Sdim const DWARFUnit *u); 59353358Sdim llvm::Optional<uint8_t> GetFixedSize() const; 60353358Sdim DWARFDIE Reference() const; 61314564Sdim uint64_t Reference(dw_offset_t offset) const; 62314564Sdim bool Boolean() const { return m_value.value.uval != 0; } 63314564Sdim uint64_t Unsigned() const { return m_value.value.uval; } 64314564Sdim void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; } 65314564Sdim int64_t Signed() const { return m_value.value.sval; } 66314564Sdim void SetSigned(int64_t sval) { m_value.value.sval = sval; } 67314564Sdim const char *AsCString() const; 68314564Sdim dw_addr_t Address() const; 69314564Sdim bool IsValid() const { return m_form != 0; } 70314564Sdim bool SkipValue(const lldb_private::DWARFDataExtractor &debug_info_data, 71314564Sdim lldb::offset_t *offset_ptr) const; 72314564Sdim static bool SkipValue(const dw_form_t form, 73314564Sdim const lldb_private::DWARFDataExtractor &debug_info_data, 74353358Sdim lldb::offset_t *offset_ptr, const DWARFUnit *unit); 75314564Sdim static bool IsBlockForm(const dw_form_t form); 76314564Sdim static bool IsDataForm(const dw_form_t form); 77314564Sdim static int Compare(const DWARFFormValue &a, const DWARFFormValue &b); 78314564Sdim void Clear(); 79327952Sdim static bool FormIsSupported(dw_form_t form); 80314564Sdim 81254721Semasteprotected: 82353358Sdim // Compile unit where m_value was located. 83353358Sdim // It may be different from compile unit where m_value refers to. 84353358Sdim const DWARFUnit *m_unit = nullptr; // Unit for this form 85353358Sdim dw_form_t m_form = 0; // Form for this value 86314564Sdim ValueType m_value; // Contains all data for the form 87254721Semaste}; 88254721Semaste 89314564Sdim#endif // SymbolFileDWARF_DWARFFormValue_h_ 90