1 //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef SymbolFileDWARF_DWARFFormValue_h_ 11 #define SymbolFileDWARF_DWARFFormValue_h_ 12 13 #include "DWARFDataExtractor.h" 14 #include <stddef.h> 15 16 class DWARFUnit; 17 class SymbolFileDWARF; 18 19 class DWARFFormValue { 20 public: 21 typedef struct ValueTypeTag { ValueTypeTagValueTypeTag22 ValueTypeTag() : value(), data(NULL) { value.uval = 0; } 23 24 union { 25 uint64_t uval; 26 int64_t sval; 27 const char *cstr; 28 } value; 29 const uint8_t *data; 30 } ValueType; 31 32 class FixedFormSizes { 33 public: FixedFormSizes()34 FixedFormSizes() : m_fix_sizes(nullptr), m_size(0) {} 35 FixedFormSizes(const uint8_t * fix_sizes,size_t size)36 FixedFormSizes(const uint8_t *fix_sizes, size_t size) 37 : m_fix_sizes(fix_sizes), m_size(size) {} 38 GetSize(uint32_t index)39 uint8_t GetSize(uint32_t index) const { 40 return index < m_size ? m_fix_sizes[index] : 0; 41 } 42 Empty()43 bool Empty() const { return m_size == 0; } 44 45 private: 46 const uint8_t *m_fix_sizes; 47 size_t m_size; 48 }; 49 50 enum { 51 eValueTypeInvalid = 0, 52 eValueTypeUnsigned, 53 eValueTypeSigned, 54 eValueTypeCStr, 55 eValueTypeBlock 56 }; 57 58 DWARFFormValue(); 59 DWARFFormValue(const DWARFUnit *cu); 60 DWARFFormValue(const DWARFUnit *cu, dw_form_t form); GetCompileUnit()61 const DWARFUnit *GetCompileUnit() const { return m_cu; } SetCompileUnit(const DWARFUnit * cu)62 void SetCompileUnit(const DWARFUnit *cu) { m_cu = cu; } Form()63 dw_form_t Form() const { return m_form; } FormRef()64 dw_form_t& FormRef() { return m_form; } SetForm(dw_form_t form)65 void SetForm(dw_form_t form) { m_form = form; } Value()66 const ValueType &Value() const { return m_value; } ValueRef()67 ValueType &ValueRef() { return m_value; } SetValue(const ValueType & val)68 void SetValue(const ValueType &val) { m_value = val; } 69 70 void Dump(lldb_private::Stream &s) const; 71 bool ExtractValue(const lldb_private::DWARFDataExtractor &data, 72 lldb::offset_t *offset_ptr); 73 const uint8_t *BlockData() const; 74 uint64_t Reference() const; 75 uint64_t Reference(dw_offset_t offset) const; Boolean()76 bool Boolean() const { return m_value.value.uval != 0; } Unsigned()77 uint64_t Unsigned() const { return m_value.value.uval; } SetUnsigned(uint64_t uval)78 void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; } Signed()79 int64_t Signed() const { return m_value.value.sval; } SetSigned(int64_t sval)80 void SetSigned(int64_t sval) { m_value.value.sval = sval; } 81 const char *AsCString() const; 82 dw_addr_t Address() const; IsValid()83 bool IsValid() const { return m_form != 0; } 84 bool SkipValue(const lldb_private::DWARFDataExtractor &debug_info_data, 85 lldb::offset_t *offset_ptr) const; 86 static bool SkipValue(const dw_form_t form, 87 const lldb_private::DWARFDataExtractor &debug_info_data, 88 lldb::offset_t *offset_ptr, const DWARFUnit *cu); 89 static bool IsBlockForm(const dw_form_t form); 90 static bool IsDataForm(const dw_form_t form); 91 static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size, 92 bool is_dwarf64); 93 static int Compare(const DWARFFormValue &a, const DWARFFormValue &b); 94 void Clear(); 95 static bool FormIsSupported(dw_form_t form); 96 97 protected: 98 const DWARFUnit *m_cu; // Compile unit for this form 99 dw_form_t m_form; // Form for this value 100 ValueType m_value; // Contains all data for the form 101 }; 102 103 #endif // SymbolFileDWARF_DWARFFormValue_h_ 104