ValueObject.h revision e41494a9092e15192012a5e0a8a1ffd66c70b8bb
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/ExecutionContext.h" 28#include "lldb/Target/ExecutionContextScope.h" 29#include "lldb/Target/StackID.h" 30 31namespace lldb_private { 32 33/// ValueObject: 34/// This abstract class provides an interface to a particular value, be it a register, a local or global variable, 35/// that is evaluated in some particular scope. The ValueObject also has the capibility of being the "child" of 36/// some other variable object, and in turn of having children. 37/// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some 38/// particular ExecutionContextScope. If it is a child, it inherits the ExecutionContextScope from its parent. 39/// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc. 40/// But it will always update itself in the ExecutionContextScope with which it was originally created. 41class ValueObject : public UserID 42{ 43public: 44 45 class EvaluationPoint 46 { 47 public: 48 49 EvaluationPoint (); 50 51 EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false); 52 53 EvaluationPoint (const EvaluationPoint &rhs); 54 55 ~EvaluationPoint (); 56 57 ExecutionContextScope * 58 GetExecutionContextScope (); 59 60 Target * 61 GetTarget () const 62 { 63 return m_target_sp.get(); 64 } 65 66 Process * 67 GetProcess () const 68 { 69 return m_process_sp.get(); 70 } 71 72 // Set the EvaluationPoint to the values in exe_scope, 73 // Return true if the Evaluation Point changed. 74 // Since the ExecutionContextScope is always going to be valid currently, 75 // the Updated Context will also always be valid. 76 77 bool 78 SetContext (ExecutionContextScope *exe_scope); 79 80 void 81 SetIsConstant () 82 { 83 SetUpdated(); 84 m_stop_id = LLDB_INVALID_UID; 85 } 86 87 bool 88 IsConstant () const 89 { 90 return m_stop_id == LLDB_INVALID_UID; 91 } 92 93 lldb::user_id_t 94 GetUpdateID () const 95 { 96 return m_stop_id; 97 } 98 99 void 100 SetUpdateID (lldb::user_id_t new_id) 101 { 102 m_stop_id = new_id; 103 } 104 105 bool 106 IsFirstEvaluation () const 107 { 108 return m_first_update; 109 } 110 111 void 112 SetNeedsUpdate () 113 { 114 m_needs_update = true; 115 } 116 117 void 118 SetUpdated () 119 { 120 m_first_update = false; 121 m_needs_update = false; 122 } 123 124 bool 125 NeedsUpdating() 126 { 127 SyncWithProcessState(); 128 return m_needs_update; 129 } 130 131 bool 132 IsValid () 133 { 134 if (m_stop_id == LLDB_INVALID_UID) 135 return false; 136 else if (SyncWithProcessState ()) 137 { 138 if (m_stop_id == LLDB_INVALID_UID) 139 return false; 140 } 141 return true; 142 } 143 144 void 145 SetInvalid () 146 { 147 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 148 // history purposes. 149 m_stop_id = LLDB_INVALID_UID; 150 151 // Can't update an invalid state. 152 m_needs_update = false; 153 154// m_thread_id = LLDB_INVALID_THREAD_ID; 155// m_stack_id.Clear(); 156 } 157 158 private: 159 bool 160 SyncWithProcessState (); 161 162 ExecutionContextScope *m_exe_scope; // This is not the way to store the evaluation point state, it is just 163 // a cache of the lookup, and gets thrown away when we update. 164 bool m_needs_update; 165 bool m_first_update; 166 167 lldb::TargetSP m_target_sp; 168 lldb::ProcessSP m_process_sp; 169 lldb::user_id_t m_thread_id; 170 StackID m_stack_id; 171 lldb::user_id_t m_stop_id; // This is the stop id when this ValueObject was last evaluated. 172 }; 173 174 const EvaluationPoint & 175 GetUpdatePoint () const 176 { 177 return m_update_point; 178 } 179 180 EvaluationPoint & 181 GetUpdatePoint () 182 { 183 return m_update_point; 184 } 185 186 ExecutionContextScope * 187 GetExecutionContextScope () 188 { 189 return m_update_point.GetExecutionContextScope(); 190 } 191 192 friend class ValueObjectList; 193 194 virtual ~ValueObject(); 195 196 //------------------------------------------------------------------ 197 // Sublasses must implement the functions below. 198 //------------------------------------------------------------------ 199 virtual size_t 200 GetByteSize() = 0; 201 202 virtual clang::ASTContext * 203 GetClangAST () = 0; 204 205 virtual lldb::clang_type_t 206 GetClangType () = 0; 207 208 virtual lldb::ValueType 209 GetValueType() const = 0; 210 211 virtual ConstString 212 GetTypeName() = 0; 213 214 virtual lldb::LanguageType 215 GetObjectRuntimeLanguage(); 216 217 virtual bool 218 IsPointerType (); 219 220 virtual bool 221 IsPointerOrReferenceType (); 222 223 virtual bool 224 IsBaseClass () 225 { 226 return false; 227 } 228 229 virtual bool 230 IsDereferenceOfParent () 231 { 232 return false; 233 } 234 235 bool 236 IsIntegerType (bool &is_signed); 237 238 virtual bool 239 GetBaseClassPath (Stream &s); 240 241 virtual void 242 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes); 243 244 virtual bool 245 IsInScope () 246 { 247 return true; 248 } 249 250 virtual off_t 251 GetByteOffset() 252 { 253 return 0; 254 } 255 256 virtual uint32_t 257 GetBitfieldBitSize() 258 { 259 return 0; 260 } 261 262 virtual uint32_t 263 GetBitfieldBitOffset() 264 { 265 return 0; 266 } 267 268 virtual bool 269 SetClangAST (clang::ASTContext *ast) 270 { 271 return false; 272 } 273 274 virtual const char * 275 GetValueAsCString (); 276 277 virtual bool 278 SetValueFromCString (const char *value_str); 279 280 //------------------------------------------------------------------ 281 // The functions below should NOT be modified by sublasses 282 //------------------------------------------------------------------ 283 const Error & 284 GetError() const; 285 286 const ConstString & 287 GetName() const; 288 289 lldb::ValueObjectSP 290 GetChildAtIndex (uint32_t idx, bool can_create); 291 292 virtual lldb::ValueObjectSP 293 GetChildMemberWithName (const ConstString &name, bool can_create); 294 295 virtual uint32_t 296 GetIndexOfChildWithName (const ConstString &name); 297 298 uint32_t 299 GetNumChildren (); 300 301 const Value & 302 GetValue() const; 303 304 Value & 305 GetValue(); 306 307 bool 308 ResolveValue (Scalar &scalar); 309 310 const char * 311 GetLocationAsCString (); 312 313 const char * 314 GetSummaryAsCString (); 315 316 const char * 317 GetObjectDescription (); 318 319 bool 320 GetValueIsValid () const; 321 322 bool 323 GetValueDidChange (); 324 325 bool 326 UpdateValueIfNeeded (); 327 328 DataExtractor & 329 GetDataExtractor (); 330 331 bool 332 Write (); 333 334 void 335 AddSyntheticChild (const ConstString &key, 336 lldb::ValueObjectSP& valobj_sp); 337 338 lldb::ValueObjectSP 339 GetSyntheticChild (const ConstString &key) const; 340 341 lldb::ValueObjectSP 342 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 343 344 lldb::ValueObjectSP 345 GetDynamicValue (bool can_create); 346 347 lldb::ValueObjectSP 348 GetDynamicValue (bool can_create, lldb::ValueObjectSP &owning_valobj_sp); 349 350 virtual lldb::ValueObjectSP 351 CreateConstantValue (const ConstString &name); 352 353 virtual lldb::ValueObjectSP 354 Dereference (Error &error); 355 356 virtual lldb::ValueObjectSP 357 AddressOf (Error &error); 358 359 // The backing bits of this value object were updated, clear any value 360 // values, summaries or descriptions so we refetch them. 361 virtual void 362 ValueUpdated () 363 { 364 m_value_str.clear(); 365 m_summary_str.clear(); 366 m_object_desc_str.clear(); 367 } 368 369 virtual bool 370 IsDynamic () 371 { 372 return false; 373 } 374 375 static void 376 DumpValueObject (Stream &s, 377 ValueObject *valobj, 378 const char *root_valobj_name, 379 uint32_t ptr_depth, 380 uint32_t curr_depth, 381 uint32_t max_depth, 382 bool show_types, 383 bool show_location, 384 bool use_objc, 385 bool use_dynamic, 386 bool scope_already_checked, 387 bool flat_output); 388 389 bool 390 GetIsConstant () const 391 { 392 return m_update_point.IsConstant(); 393 } 394 395 void 396 SetIsConstant () 397 { 398 m_update_point.SetIsConstant(); 399 } 400 401 lldb::Format 402 GetFormat () const 403 { 404 return m_format; 405 } 406 407 void 408 SetFormat (lldb::Format format) 409 { 410 if (format != m_format) 411 m_value_str.clear(); 412 m_format = format; 413 } 414 415 // Use GetParent for display purposes, but if you want to tell the parent to update itself 416 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 417 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 418 virtual ValueObject * 419 GetParent() 420 { 421 return m_parent; 422 } 423 424 virtual const ValueObject * 425 GetParent() const 426 { 427 return m_parent; 428 } 429 430 ValueObject * 431 GetNonBaseClassParent(); 432 433 void 434 SetPointersPointToLoadAddrs (bool b) 435 { 436 m_pointers_point_to_load_addrs = b; 437 } 438 439protected: 440 //------------------------------------------------------------------ 441 // Classes that inherit from ValueObject can see and modify these 442 //------------------------------------------------------------------ 443 ValueObject *m_parent; // The parent value object, or NULL if this has no parent 444 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 445 // updated. When we are asked to update the value object, we check whether 446 // the context & stop id are the same before updating. 447 ConstString m_name; // The name of this object 448 DataExtractor m_data; // A data extractor that can be used to extract the value. 449 Value m_value; 450 Error m_error; // An error object that can describe any errors that occur when updating values. 451 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 452 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 453 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 454 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 455 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 456 // in that the summary is consed up by us, the object_desc_string is builtin. 457 std::vector<lldb::ValueObjectSP> m_children; 458 std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children; 459 lldb::ValueObjectSP m_dynamic_value_sp; 460 lldb::ValueObjectSP m_addr_of_valobj_sp; // These two shared pointers help root the ValueObject shared pointers that 461 lldb::ValueObjectSP m_deref_valobj_sp; // we hand out, so that we can use them in their dynamic types and ensure 462 // they will last as long as this ValueObject... 463 464 lldb::Format m_format; 465 bool m_value_is_valid:1, 466 m_value_did_change:1, 467 m_children_count_valid:1, 468 m_old_value_valid:1, 469 m_pointers_point_to_load_addrs:1, 470 m_is_deref_of_parent:1; 471 472 friend class CommandObjectExpression; 473 friend class ClangExpressionVariable; 474 friend class ClangExpressionDeclMap; // For GetValue... 475 friend class Target; 476 friend class ValueObjectChild; 477 //------------------------------------------------------------------ 478 // Constructors and Destructors 479 //------------------------------------------------------------------ 480 481 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 482 483 ValueObject(); 484 485 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 486 // through-out its lifespan. 487 488 ValueObject (ExecutionContextScope *exe_scope); 489 490 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 491 // of its parent. 492 493 ValueObject (ValueObject &parent); 494 495 virtual bool 496 UpdateValue () = 0; 497 498 virtual void 499 CalculateDynamicValue (); 500 501 // Should only be called by ValueObject::GetChildAtIndex() 502 virtual lldb::ValueObjectSP 503 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 504 505 // Should only be called by ValueObject::GetNumChildren() 506 virtual uint32_t 507 CalculateNumChildren() = 0; 508 509 void 510 SetName (const char *name); 511 512 void 513 SetName (const ConstString &name); 514 515 void 516 SetNumChildren (uint32_t num_children); 517 518 void 519 SetValueDidChange (bool value_changed); 520 521 void 522 SetValueIsValid (bool valid); 523 524public: 525 lldb::addr_t 526 GetPointerValue (AddressType &address_type, 527 bool scalar_is_load_address); 528 529 lldb::addr_t 530 GetAddressOf (AddressType &address_type, 531 bool scalar_is_load_address); 532private: 533 //------------------------------------------------------------------ 534 // For ValueObject only 535 //------------------------------------------------------------------ 536 DISALLOW_COPY_AND_ASSIGN (ValueObject); 537 538}; 539 540} // namespace lldb_private 541 542#endif // liblldb_ValueObject_h_ 543