ValueObject.h revision 642036f22366d47ea8e6f8498bedb92b88f7f79f
1//===-- ValueObject.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 liblldb_ValueObject_h_ 11#define liblldb_ValueObject_h_ 12 13// C Includes 14// C++ Includes 15#include <map> 16#include <vector> 17// Other libraries and framework includes 18// Project includes 19 20#include "lldb/lldb-private.h" 21#include "lldb/Core/DataExtractor.h" 22#include "lldb/Core/Error.h" 23#include "lldb/Core/Flags.h" 24#include "lldb/Core/ConstString.h" 25#include "lldb/Core/UserID.h" 26#include "lldb/Core/Value.h" 27#include "lldb/Target/ExecutionContextScope.h" 28 29namespace lldb_private { 30 31class ValueObject : public UserID 32{ 33public: 34 friend class ValueObjectList; 35 36 virtual ~ValueObject(); 37 38 //------------------------------------------------------------------ 39 // Sublasses must implement the functions below. 40 //------------------------------------------------------------------ 41 virtual size_t 42 GetByteSize() = 0; 43 44 virtual clang::ASTContext * 45 GetClangAST () = 0; 46 47 virtual void * 48 GetOpaqueClangQualType () = 0; 49 50 virtual lldb::ValueType 51 GetValueType() const = 0; 52 53protected: 54 // Should only be called by ValueObject::GetNumChildren() 55 virtual uint32_t 56 CalculateNumChildren() = 0; 57 58public: 59 virtual ConstString 60 GetTypeName() = 0; 61 62 virtual void 63 UpdateValue (ExecutionContextScope *exe_scope) = 0; 64 65 //------------------------------------------------------------------ 66 // Sublasses can implement the functions below if they need to. 67 //------------------------------------------------------------------ 68protected: 69 // Should only be called by ValueObject::GetChildAtIndex() 70 virtual lldb::ValueObjectSP 71 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 72 73public: 74 75 virtual bool 76 IsPointerType (); 77 78 virtual bool 79 IsPointerOrReferenceType (); 80 81 virtual bool 82 IsInScope (StackFrame *frame) 83 { 84 return true; 85 } 86 87 virtual off_t 88 GetByteOffset() 89 { 90 return 0; 91 } 92 93 virtual uint32_t 94 GetBitfieldBitSize() 95 { 96 return 0; 97 } 98 99 virtual uint32_t 100 GetBitfieldBitOffset() 101 { 102 return 0; 103 } 104 105 virtual const char * 106 GetValueAsCString (ExecutionContextScope *exe_scope); 107 108 virtual bool 109 SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str); 110 111 //------------------------------------------------------------------ 112 // The functions below should NOT be modified by sublasses 113 //------------------------------------------------------------------ 114 const Error & 115 GetError() const; 116 117 const ConstString & 118 GetName() const; 119 120 lldb::ValueObjectSP 121 GetChildAtIndex (uint32_t idx, bool can_create); 122 123 lldb::ValueObjectSP 124 GetChildMemberWithName (const ConstString &name, bool can_create); 125 126 uint32_t 127 GetIndexOfChildWithName (const ConstString &name); 128 129 uint32_t 130 GetNumChildren (); 131 132 const Value & 133 GetValue() const; 134 135 Value & 136 GetValue(); 137 138 const char * 139 GetLocationAsCString (ExecutionContextScope *exe_scope); 140 141 const char * 142 GetSummaryAsCString (ExecutionContextScope *exe_scope); 143 144 const char * 145 GetObjectDescription (ExecutionContextScope *exe_scope); 146 147 148 lldb::user_id_t 149 GetUpdateID() const; 150 151 bool 152 GetValueIsValid () const; 153 154 bool 155 GetValueDidChange (ExecutionContextScope *exe_scope); 156 157 bool 158 UpdateValueIfNeeded (ExecutionContextScope *exe_scope); 159 160 const DataExtractor & 161 GetDataExtractor () const; 162 163 DataExtractor & 164 GetDataExtractor (); 165 166 bool 167 Write (); 168 169 void 170 AddSyntheticChild (const ConstString &key, 171 lldb::ValueObjectSP& valobj_sp); 172 173 lldb::ValueObjectSP 174 GetSyntheticChild (const ConstString &key) const; 175 176 lldb::ValueObjectSP 177 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 178 179 lldb::ValueObjectSP 180 GetDynamicValue () 181 { 182 return m_dynamic_value_sp; 183 } 184 185 bool 186 SetDynamicValue (); 187 188protected: 189 //------------------------------------------------------------------ 190 // Classes that inherit from ValueObject can see and modify these 191 //------------------------------------------------------------------ 192 lldb::user_id_t m_update_id; // An integer that specifies the update number for this value in 193 // this value object list. If this value object is asked to update itself 194 // it will first check if the update ID match the value object 195 // list update number. If the update numbers match, no update is 196 // needed, if it does not match, this value object should update its 197 // the next time it is asked. 198 ConstString m_name; // The name of this object 199 DataExtractor m_data; // A data extractor that can be used to extract the value. 200 Value m_value; 201 Error m_error; // An error object that can describe any errors that occur when updating values. 202 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 203 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 204 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 205 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 206 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 207 // in that the summary is consed up by us, the object_desc_string is builtin. 208 std::vector<lldb::ValueObjectSP> m_children; 209 std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children; 210 lldb::ValueObjectSP m_dynamic_value_sp; 211 bool m_value_is_valid:1, 212 m_value_did_change:1, 213 m_children_count_valid:1, 214 m_old_value_valid:1; 215 216 //------------------------------------------------------------------ 217 // Constructors and Destructors 218 //------------------------------------------------------------------ 219 ValueObject (); 220 221 void 222 SetName (const char *name); 223 224 void 225 SetName (const ConstString &name); 226 227 void 228 SetNumChildren (uint32_t num_children); 229 230 void 231 SetValueDidChange (bool value_changed); 232 233 void 234 SetValueIsValid (bool valid); 235 236 237 lldb::addr_t 238 GetPointerValue (lldb::AddressType &address_type, 239 bool scalar_is_load_address); 240private: 241 //------------------------------------------------------------------ 242 // For ValueObject only 243 //------------------------------------------------------------------ 244 DISALLOW_COPY_AND_ASSIGN (ValueObject); 245 246}; 247 248} // namespace lldb_private 249 250#endif // liblldb_ValueObject_h_ 251