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> // for NULL 15 16 class DWARFCompileUnit; 17 18 class DWARFFormValue { 19 public: 20 typedef struct ValueTypeTag { 21 ValueTypeTag() : value(), data(NULL) { value.uval = 0; } 22 23 union { 24 uint64_t uval; 25 int64_t sval; 26 const char *cstr; 27 } value; 28 const uint8_t *data; 29 } ValueType; 30 31 class FixedFormSizes { 32 public: 33 FixedFormSizes() : m_fix_sizes(nullptr), m_size(0) {} 34 35 FixedFormSizes(const uint8_t *fix_sizes, size_t size) 36 : m_fix_sizes(fix_sizes), m_size(size) {} 37 38 uint8_t GetSize(uint32_t index) const { 39 return index < m_size ? m_fix_sizes[index] : 0; 40 } 41 42 bool Empty() const { return m_size == 0; } 43 44 private: 45 const uint8_t *m_fix_sizes; 46 size_t m_size; 47 }; 48 49 enum { 50 eValueTypeInvalid = 0, 51 eValueTypeUnsigned, 52 eValueTypeSigned, 53 eValueTypeCStr, 54 eValueTypeBlock 55 }; 56 57 DWARFFormValue(); 58 DWARFFormValue(const DWARFCompileUnit *cu, dw_form_t form); 59 const DWARFCompileUnit *GetCompileUnit() const { return m_cu; } 60 void SetCompileUnit(const DWARFCompileUnit *cu) { m_cu = cu; } 61 dw_form_t Form() const { return m_form; } 62 void SetForm(dw_form_t form) { m_form = form; } 63 const ValueType &Value() const { return m_value; } 64 void Dump(lldb_private::Stream &s) const; 65 bool ExtractValue(const lldb_private::DWARFDataExtractor &data, 66 lldb::offset_t *offset_ptr); 67 const uint8_t *BlockData() const; 68 uint64_t Reference() const; 69 uint64_t Reference(dw_offset_t offset) const; 70 bool Boolean() const { return m_value.value.uval != 0; } 71 uint64_t Unsigned() const { return m_value.value.uval; } 72 void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; } 73 int64_t Signed() const { return m_value.value.sval; } 74 void SetSigned(int64_t sval) { m_value.value.sval = sval; } 75 const char *AsCString() const; 76 dw_addr_t Address() const; 77 bool IsValid() const { return m_form != 0; } 78 bool SkipValue(const lldb_private::DWARFDataExtractor &debug_info_data, 79 lldb::offset_t *offset_ptr) const; 80 static bool SkipValue(const dw_form_t form, 81 const lldb_private::DWARFDataExtractor &debug_info_data, 82 lldb::offset_t *offset_ptr, const DWARFCompileUnit *cu); 83 static bool IsBlockForm(const dw_form_t form); 84 static bool IsDataForm(const dw_form_t form); 85 static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size, 86 bool is_dwarf64); 87 static int Compare(const DWARFFormValue &a, const DWARFFormValue &b); 88 void Clear(); 89 90 protected: 91 const DWARFCompileUnit *m_cu; // Compile unit for this form 92 dw_form_t m_form; // Form for this value 93 ValueType m_value; // Contains all data for the form 94 }; 95 96 #endif // SymbolFileDWARF_DWARFFormValue_h_ 97