ValueObject.h revision 00c3ae7dac4cf9654d1569735c41e58fb2fd8969
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 lldb::clang_type_t 48 GetClangType () = 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 lldb::LanguageType 63 GetObjectRuntimeLanguage(); 64 65 virtual void 66 UpdateValue (ExecutionContextScope *exe_scope) = 0; 67 68 //------------------------------------------------------------------ 69 // Sublasses can implement the functions below if they need to. 70 //------------------------------------------------------------------ 71protected: 72 // Should only be called by ValueObject::GetChildAtIndex() 73 virtual lldb::ValueObjectSP 74 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 75 76public: 77 78 virtual bool 79 IsPointerType (); 80 81 virtual bool 82 IsPointerOrReferenceType (); 83 84 virtual bool 85 IsBaseClass () 86 { 87 return false; 88 } 89 90 virtual bool 91 IsDereferenceOfParent () 92 { 93 return false; 94 } 95 96 virtual bool 97 GetBaseClassPath (Stream &s); 98 99 virtual void 100 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes); 101 102 virtual bool 103 IsInScope (StackFrame *frame) 104 { 105 return true; 106 } 107 108 virtual off_t 109 GetByteOffset() 110 { 111 return 0; 112 } 113 114 virtual uint32_t 115 GetBitfieldBitSize() 116 { 117 return 0; 118 } 119 120 virtual uint32_t 121 GetBitfieldBitOffset() 122 { 123 return 0; 124 } 125 126 virtual bool 127 SetClangAST (clang::ASTContext *ast) 128 { 129 return false; 130 } 131 132 virtual const char * 133 GetValueAsCString (ExecutionContextScope *exe_scope); 134 135 virtual bool 136 SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str); 137 138 //------------------------------------------------------------------ 139 // The functions below should NOT be modified by sublasses 140 //------------------------------------------------------------------ 141 const Error & 142 GetError() const; 143 144 const ConstString & 145 GetName() const; 146 147 lldb::ValueObjectSP 148 GetChildAtIndex (uint32_t idx, bool can_create); 149 150 lldb::ValueObjectSP 151 GetChildMemberWithName (const ConstString &name, bool can_create); 152 153 uint32_t 154 GetIndexOfChildWithName (const ConstString &name); 155 156 uint32_t 157 GetNumChildren (); 158 159 const Value & 160 GetValue() const; 161 162 Value & 163 GetValue(); 164 165 bool 166 ResolveValue (ExecutionContextScope *exe_scope, Scalar &scalar); 167 168 const char * 169 GetLocationAsCString (ExecutionContextScope *exe_scope); 170 171 const char * 172 GetSummaryAsCString (ExecutionContextScope *exe_scope); 173 174 const char * 175 GetObjectDescription (ExecutionContextScope *exe_scope); 176 177 178 lldb::user_id_t 179 GetUpdateID() const; 180 181 bool 182 GetValueIsValid () const; 183 184 bool 185 GetValueDidChange (ExecutionContextScope *exe_scope); 186 187 bool 188 UpdateValueIfNeeded (ExecutionContextScope *exe_scope); 189 190 const DataExtractor & 191 GetDataExtractor () const; 192 193 DataExtractor & 194 GetDataExtractor (); 195 196 bool 197 Write (); 198 199 void 200 AddSyntheticChild (const ConstString &key, 201 lldb::ValueObjectSP& valobj_sp); 202 203 lldb::ValueObjectSP 204 GetSyntheticChild (const ConstString &key) const; 205 206 lldb::ValueObjectSP 207 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 208 209 lldb::ValueObjectSP 210 GetDynamicValue () 211 { 212 return m_dynamic_value_sp; 213 } 214 215 virtual lldb::ValueObjectSP 216 CreateConstantValue (ExecutionContextScope *exe_scope, const ConstString &name); 217 218 virtual lldb::ValueObjectSP 219 Dereference (Error &error); 220 221 virtual lldb::ValueObjectSP 222 AddressOf (Error &error); 223 224 // The backing bits of this value object were updated, clear any value 225 // values, summaries or descriptions so we refetch them. 226 virtual void 227 ValueUpdated () 228 { 229 m_value_str.clear(); 230 m_summary_str.clear(); 231 m_object_desc_str.clear(); 232 } 233 234 bool 235 SetDynamicValue (); 236 237 static void 238 DumpValueObject (Stream &s, 239 ExecutionContextScope *exe_scope, 240 ValueObject *valobj, 241 const char *root_valobj_name, 242 uint32_t ptr_depth, 243 uint32_t curr_depth, 244 uint32_t max_depth, 245 bool show_types, 246 bool show_location, 247 bool use_objc, 248 bool scope_already_checked, 249 bool flat_output); 250 251 bool 252 GetIsConstant () const 253 { 254 return m_update_id == LLDB_INVALID_UID; 255 } 256 257 void 258 SetIsConstant () 259 { 260 m_update_id = LLDB_INVALID_UID; 261 } 262 263 lldb::Format 264 GetFormat () const 265 { 266 return m_format; 267 } 268 269 void 270 SetFormat (lldb::Format format) 271 { 272 if (format != m_format) 273 m_value_str.clear(); 274 m_format = format; 275 } 276 277 ValueObject * 278 GetParent() 279 { 280 return m_parent; 281 } 282 283 const ValueObject * 284 GetParent() const 285 { 286 return m_parent; 287 } 288 289 ValueObject * 290 GetNonBaseClassParent(); 291 292 void 293 SetPointersPointToLoadAddrs (bool b) 294 { 295 m_pointers_point_to_load_addrs = b; 296 } 297 298protected: 299 //------------------------------------------------------------------ 300 // Classes that inherit from ValueObject can see and modify these 301 //------------------------------------------------------------------ 302 ValueObject* m_parent; // The parent value object, or NULL if this has no parent 303 lldb::user_id_t m_update_id; // An integer that specifies the update number for this value in 304 // this value object list. If this value object is asked to update itself 305 // it will first check if the update ID match the value object 306 // list update number. If the update numbers match, no update is 307 // needed, if it does not match, this value object should update its 308 // the next time it is asked. 309 ConstString m_name; // The name of this object 310 DataExtractor m_data; // A data extractor that can be used to extract the value. 311 Value m_value; 312 Error m_error; // An error object that can describe any errors that occur when updating values. 313 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 314 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 315 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 316 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 317 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 318 // in that the summary is consed up by us, the object_desc_string is builtin. 319 std::vector<lldb::ValueObjectSP> m_children; 320 std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children; 321 lldb::ValueObjectSP m_dynamic_value_sp; 322 lldb::Format m_format; 323 bool m_value_is_valid:1, 324 m_value_did_change:1, 325 m_children_count_valid:1, 326 m_old_value_valid:1, 327 m_pointers_point_to_load_addrs:1, 328 m_is_deref_of_parent:1; 329 330 friend class CommandObjectExpression; 331 friend class ClangExpressionVariable; 332 friend class Target; 333 //------------------------------------------------------------------ 334 // Constructors and Destructors 335 //------------------------------------------------------------------ 336 ValueObject (ValueObject *parent); 337 338 void 339 SetName (const char *name); 340 341 void 342 SetName (const ConstString &name); 343 344 void 345 SetNumChildren (uint32_t num_children); 346 347 void 348 SetValueDidChange (bool value_changed); 349 350 void 351 SetValueIsValid (bool valid); 352 353 354 lldb::addr_t 355 GetPointerValue (lldb::AddressType &address_type, 356 bool scalar_is_load_address); 357 358 lldb::addr_t 359 GetAddressOf (lldb::AddressType &address_type, 360 bool scalar_is_load_address); 361private: 362 //------------------------------------------------------------------ 363 // For ValueObject only 364 //------------------------------------------------------------------ 365 DISALLOW_COPY_AND_ASSIGN (ValueObject); 366 367}; 368 369} // namespace lldb_private 370 371#endif // liblldb_ValueObject_h_ 372