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 18 // Other libraries and framework includes 19 #include "llvm/ADT/Optional.h" 20 #include "llvm/ADT/SmallVector.h" 21 22 // Project includes 23 #include "lldb/lldb-private.h" 24 #include "lldb/Core/DataExtractor.h" 25 #include "lldb/Core/Error.h" 26 #include "lldb/Core/Flags.h" 27 #include "lldb/Core/ConstString.h" 28 #include "lldb/Core/UserID.h" 29 #include "lldb/Core/Value.h" 30 #include "lldb/Symbol/ClangASTType.h" 31 #include "lldb/Target/ExecutionContext.h" 32 #include "lldb/Target/ExecutionContextScope.h" 33 #include "lldb/Target/Process.h" 34 #include "lldb/Target/StackID.h" 35 #include "lldb/Utility/SharedCluster.h" 36 37 namespace lldb_private { 38 39 /// ValueObject: 40 /// 41 /// This abstract class provides an interface to a particular value, be it a register, a local or global variable, 42 /// that is evaluated in some particular scope. The ValueObject also has the capability of being the "child" of 43 /// some other variable object, and in turn of having children. 44 /// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some 45 /// particular ExecutionContextScope. If it is a child, it inherits the ExecutionContextScope from its parent. 46 /// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc. 47 /// But it will always update itself in the ExecutionContextScope with which it was originally created. 48 49 /// A brief note on life cycle management for ValueObjects. This is a little tricky because a ValueObject can contain 50 /// various other ValueObjects - the Dynamic Value, its children, the dereference value, etc. Any one of these can be 51 /// handed out as a shared pointer, but for that contained value object to be valid, the root object and potentially other 52 /// of the value objects need to stay around. 53 /// We solve this problem by handing out shared pointers to the Value Object and any of its dependents using a shared 54 /// ClusterManager. This treats each shared pointer handed out for the entire cluster as a reference to the whole 55 /// cluster. The whole cluster will stay around until the last reference is released. 56 /// 57 /// The ValueObject mostly handle this automatically, if a value object is made with a Parent ValueObject, then it adds 58 /// itself to the ClusterManager of the parent. 59 60 /// It does mean that external to the ValueObjects we should only ever make available ValueObjectSP's, never ValueObjects 61 /// or pointers to them. So all the "Root level" ValueObject derived constructors should be private, and 62 /// should implement a Create function that new's up object and returns a Shared Pointer that it gets from the GetSP() method. 63 /// 64 /// However, if you are making an derived ValueObject that will be contained in a parent value object, you should just 65 /// hold onto a pointer to it internally, and by virtue of passing the parent ValueObject into its constructor, it will 66 /// be added to the ClusterManager for the parent. Then if you ever hand out a Shared Pointer to the contained ValueObject, 67 /// just do so by calling GetSP() on the contained object. 68 69 class ValueObject : public UserID 70 { 71 public: 72 73 enum GetExpressionPathFormat 74 { 75 eGetExpressionPathFormatDereferencePointers = 1, 76 eGetExpressionPathFormatHonorPointers 77 }; 78 79 enum ValueObjectRepresentationStyle 80 { 81 eValueObjectRepresentationStyleValue = 1, 82 eValueObjectRepresentationStyleSummary, 83 eValueObjectRepresentationStyleLanguageSpecific, 84 eValueObjectRepresentationStyleLocation, 85 eValueObjectRepresentationStyleChildrenCount, 86 eValueObjectRepresentationStyleType, 87 eValueObjectRepresentationStyleName, 88 eValueObjectRepresentationStyleExpressionPath 89 }; 90 91 enum ExpressionPathScanEndReason 92 { 93 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse 94 eExpressionPathScanEndReasonNoSuchChild, // child element not found 95 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child element not found 96 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for arrays 97 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be used 98 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be used 99 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion not allowed 100 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by options 101 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects other than scalars, pointers or arrays 102 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays, but I cannot parse it 103 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for bitfields, but I cannot parse after it 104 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in the expression 105 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply & operator 106 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply * operator 107 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a VOList 108 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic children failed 109 eExpressionPathScanEndReasonUnknown = 0xFFFF 110 }; 111 112 enum ExpressionPathEndResultType 113 { 114 eExpressionPathEndResultTypePlain = 1, // anything but... 115 eExpressionPathEndResultTypeBitfield, // a bitfield 116 eExpressionPathEndResultTypeBoundedRange, // a range [low-high] 117 eExpressionPathEndResultTypeUnboundedRange, // a range [] 118 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList 119 eExpressionPathEndResultTypeInvalid = 0xFFFF 120 }; 121 122 enum ExpressionPathAftermath 123 { 124 eExpressionPathAftermathNothing = 1, // just return it 125 eExpressionPathAftermathDereference, // dereference the target 126 eExpressionPathAftermathTakeAddress // take target's address 127 }; 128 129 enum ClearUserVisibleDataItems 130 { 131 eClearUserVisibleDataItemsNothing = 1u << 0, 132 eClearUserVisibleDataItemsValue = 1u << 1, 133 eClearUserVisibleDataItemsSummary = 1u << 2, 134 eClearUserVisibleDataItemsLocation = 1u << 3, 135 eClearUserVisibleDataItemsDescription = 1u << 4, 136 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5, 137 eClearUserVisibleDataItemsValidator = 1u << 6, 138 eClearUserVisibleDataItemsAllStrings = eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsLocation | eClearUserVisibleDataItemsDescription, 139 eClearUserVisibleDataItemsAll = 0xFFFF 140 }; 141 142 struct GetValueForExpressionPathOptions 143 { 144 enum class SyntheticChildrenTraversal 145 { 146 None, 147 ToSynthetic, 148 FromSynthetic, 149 Both 150 }; 151 152 bool m_check_dot_vs_arrow_syntax; 153 bool m_no_fragile_ivar; 154 bool m_allow_bitfields_syntax; 155 SyntheticChildrenTraversal m_synthetic_children_traversal; 156 157 GetValueForExpressionPathOptions(bool dot = false, 158 bool no_ivar = false, 159 bool bitfield = true, 160 SyntheticChildrenTraversal synth_traverse = SyntheticChildrenTraversal::ToSynthetic) : m_check_dot_vs_arrow_syntaxGetValueForExpressionPathOptions161 m_check_dot_vs_arrow_syntax(dot), 162 m_no_fragile_ivar(no_ivar), 163 m_allow_bitfields_syntax(bitfield), 164 m_synthetic_children_traversal(synth_traverse) 165 { 166 } 167 168 GetValueForExpressionPathOptions& DoCheckDotVsArrowSyntaxGetValueForExpressionPathOptions169 DoCheckDotVsArrowSyntax() 170 { 171 m_check_dot_vs_arrow_syntax = true; 172 return *this; 173 } 174 175 GetValueForExpressionPathOptions& DontCheckDotVsArrowSyntaxGetValueForExpressionPathOptions176 DontCheckDotVsArrowSyntax() 177 { 178 m_check_dot_vs_arrow_syntax = false; 179 return *this; 180 } 181 182 GetValueForExpressionPathOptions& DoAllowFragileIVarGetValueForExpressionPathOptions183 DoAllowFragileIVar() 184 { 185 m_no_fragile_ivar = false; 186 return *this; 187 } 188 189 GetValueForExpressionPathOptions& DontAllowFragileIVarGetValueForExpressionPathOptions190 DontAllowFragileIVar() 191 { 192 m_no_fragile_ivar = true; 193 return *this; 194 } 195 196 GetValueForExpressionPathOptions& DoAllowBitfieldSyntaxGetValueForExpressionPathOptions197 DoAllowBitfieldSyntax() 198 { 199 m_allow_bitfields_syntax = true; 200 return *this; 201 } 202 203 GetValueForExpressionPathOptions& DontAllowBitfieldSyntaxGetValueForExpressionPathOptions204 DontAllowBitfieldSyntax() 205 { 206 m_allow_bitfields_syntax = false; 207 return *this; 208 } 209 210 GetValueForExpressionPathOptions& SetSyntheticChildrenTraversalGetValueForExpressionPathOptions211 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse) 212 { 213 m_synthetic_children_traversal = traverse; 214 return *this; 215 } 216 217 static const GetValueForExpressionPathOptions DefaultOptionsGetValueForExpressionPathOptions218 DefaultOptions() 219 { 220 static GetValueForExpressionPathOptions g_default_options; 221 222 return g_default_options; 223 } 224 225 }; 226 227 class EvaluationPoint 228 { 229 public: 230 231 EvaluationPoint (); 232 233 EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false); 234 235 EvaluationPoint (const EvaluationPoint &rhs); 236 237 ~EvaluationPoint (); 238 239 const ExecutionContextRef & GetExecutionContextRef()240 GetExecutionContextRef() const 241 { 242 return m_exe_ctx_ref; 243 } 244 245 // Set the EvaluationPoint to the values in exe_scope, 246 // Return true if the Evaluation Point changed. 247 // Since the ExecutionContextScope is always going to be valid currently, 248 // the Updated Context will also always be valid. 249 250 // bool 251 // SetContext (ExecutionContextScope *exe_scope); 252 253 void SetIsConstant()254 SetIsConstant () 255 { 256 SetUpdated(); 257 m_mod_id.SetInvalid(); 258 } 259 260 bool IsConstant()261 IsConstant () const 262 { 263 return !m_mod_id.IsValid(); 264 } 265 266 ProcessModID GetModID()267 GetModID () const 268 { 269 return m_mod_id; 270 } 271 272 void SetUpdateID(ProcessModID new_id)273 SetUpdateID (ProcessModID new_id) 274 { 275 m_mod_id = new_id; 276 } 277 278 void SetNeedsUpdate()279 SetNeedsUpdate () 280 { 281 m_needs_update = true; 282 } 283 284 void 285 SetUpdated (); 286 287 bool NeedsUpdating(bool accept_invalid_exe_ctx)288 NeedsUpdating(bool accept_invalid_exe_ctx) 289 { 290 SyncWithProcessState(accept_invalid_exe_ctx); 291 return m_needs_update; 292 } 293 294 bool IsValid()295 IsValid () 296 { 297 const bool accept_invalid_exe_ctx = false; 298 if (!m_mod_id.IsValid()) 299 return false; 300 else if (SyncWithProcessState (accept_invalid_exe_ctx)) 301 { 302 if (!m_mod_id.IsValid()) 303 return false; 304 } 305 return true; 306 } 307 308 void SetInvalid()309 SetInvalid () 310 { 311 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 312 // history purposes. 313 m_mod_id.SetInvalid(); 314 315 // Can't update an invalid state. 316 m_needs_update = false; 317 318 } 319 320 private: 321 bool 322 SyncWithProcessState (bool accept_invalid_exe_ctx); 323 324 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. 325 ExecutionContextRef m_exe_ctx_ref; 326 bool m_needs_update; 327 }; 328 329 const EvaluationPoint & GetUpdatePoint()330 GetUpdatePoint () const 331 { 332 return m_update_point; 333 } 334 335 EvaluationPoint & GetUpdatePoint()336 GetUpdatePoint () 337 { 338 return m_update_point; 339 } 340 341 const ExecutionContextRef & GetExecutionContextRef()342 GetExecutionContextRef() const 343 { 344 return m_update_point.GetExecutionContextRef(); 345 } 346 347 lldb::TargetSP GetTargetSP()348 GetTargetSP() const 349 { 350 return m_update_point.GetExecutionContextRef().GetTargetSP(); 351 } 352 353 lldb::ProcessSP GetProcessSP()354 GetProcessSP() const 355 { 356 return m_update_point.GetExecutionContextRef().GetProcessSP(); 357 } 358 359 lldb::ThreadSP GetThreadSP()360 GetThreadSP() const 361 { 362 return m_update_point.GetExecutionContextRef().GetThreadSP(); 363 } 364 365 lldb::StackFrameSP GetFrameSP()366 GetFrameSP() const 367 { 368 return m_update_point.GetExecutionContextRef().GetFrameSP(); 369 } 370 371 void 372 SetNeedsUpdate (); 373 374 virtual ~ValueObject(); 375 376 ClangASTType 377 GetClangType (); 378 379 // this vends a TypeImpl that is useful at the SB API layer 380 virtual TypeImpl 381 GetTypeImpl (); 382 383 virtual bool 384 CanProvideValue (); 385 386 //------------------------------------------------------------------ 387 // Subclasses must implement the functions below. 388 //------------------------------------------------------------------ 389 virtual uint64_t 390 GetByteSize() = 0; 391 392 virtual lldb::ValueType 393 GetValueType() const = 0; 394 395 //------------------------------------------------------------------ 396 // Subclasses can implement the functions below. 397 //------------------------------------------------------------------ 398 virtual ConstString 399 GetTypeName(); 400 401 virtual ConstString 402 GetDisplayTypeName(); 403 404 virtual ConstString 405 GetQualifiedTypeName(); 406 407 virtual lldb::LanguageType 408 GetObjectRuntimeLanguage(); 409 410 virtual uint32_t 411 GetTypeInfo (ClangASTType *pointee_or_element_clang_type = NULL); 412 413 virtual bool 414 IsPointerType (); 415 416 virtual bool 417 IsArrayType (); 418 419 virtual bool 420 IsScalarType (); 421 422 virtual bool 423 IsPointerOrReferenceType (); 424 425 virtual bool 426 IsPossibleDynamicType (); 427 428 virtual bool 429 IsObjCNil (); 430 431 virtual bool IsBaseClass()432 IsBaseClass () 433 { 434 return false; 435 } 436 437 bool 438 IsBaseClass (uint32_t& depth); 439 440 virtual bool IsDereferenceOfParent()441 IsDereferenceOfParent () 442 { 443 return false; 444 } 445 446 bool 447 IsIntegerType (bool &is_signed); 448 449 virtual bool 450 GetBaseClassPath (Stream &s); 451 452 virtual void 453 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers); 454 455 lldb::ValueObjectSP 456 GetValueForExpressionPath(const char* expression, 457 const char** first_unparsed = NULL, 458 ExpressionPathScanEndReason* reason_to_stop = NULL, 459 ExpressionPathEndResultType* final_value_type = NULL, 460 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 461 ExpressionPathAftermath* final_task_on_target = NULL); 462 463 int 464 GetValuesForExpressionPath(const char* expression, 465 lldb::ValueObjectListSP& list, 466 const char** first_unparsed = NULL, 467 ExpressionPathScanEndReason* reason_to_stop = NULL, 468 ExpressionPathEndResultType* final_value_type = NULL, 469 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 470 ExpressionPathAftermath* final_task_on_target = NULL); 471 472 virtual bool IsInScope()473 IsInScope () 474 { 475 return true; 476 } 477 478 virtual lldb::offset_t GetByteOffset()479 GetByteOffset() 480 { 481 return 0; 482 } 483 484 virtual uint32_t GetBitfieldBitSize()485 GetBitfieldBitSize () 486 { 487 return 0; 488 } 489 490 virtual uint32_t GetBitfieldBitOffset()491 GetBitfieldBitOffset () 492 { 493 return 0; 494 } 495 496 bool IsBitfield()497 IsBitfield () 498 { 499 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0); 500 } 501 502 virtual bool IsArrayItemForPointer()503 IsArrayItemForPointer() 504 { 505 return m_is_array_item_for_pointer; 506 } 507 508 virtual const char * 509 GetValueAsCString (); 510 511 virtual bool 512 GetValueAsCString (const lldb_private::TypeFormatImpl& format, 513 std::string& destination); 514 515 bool 516 GetValueAsCString (lldb::Format format, 517 std::string& destination); 518 519 virtual uint64_t 520 GetValueAsUnsigned (uint64_t fail_value, bool *success = NULL); 521 522 virtual int64_t 523 GetValueAsSigned (int64_t fail_value, bool *success = NULL); 524 525 virtual bool 526 SetValueFromCString (const char *value_str, Error& error); 527 528 // Return the module associated with this value object in case the 529 // value is from an executable file and might have its data in 530 // sections of the file. This can be used for variables. 531 virtual lldb::ModuleSP 532 GetModule(); 533 534 ValueObject* 535 GetRoot (); 536 537 // Given a ValueObject, loop over itself and its parent, and its parent's parent, .. 538 // until either the given callback returns false, or you end up at a null pointer 539 ValueObject* 540 FollowParentChain (std::function<bool(ValueObject*)>); 541 542 virtual bool 543 GetDeclaration (Declaration &decl); 544 545 //------------------------------------------------------------------ 546 // The functions below should NOT be modified by subclasses 547 //------------------------------------------------------------------ 548 const Error & 549 GetError(); 550 551 const ConstString & 552 GetName() const; 553 554 virtual lldb::ValueObjectSP 555 GetChildAtIndex (size_t idx, bool can_create); 556 557 // this will always create the children if necessary 558 lldb::ValueObjectSP 559 GetChildAtIndexPath (const std::initializer_list<size_t> &idxs, 560 size_t* index_of_error = NULL); 561 562 lldb::ValueObjectSP 563 GetChildAtIndexPath (const std::vector<size_t> &idxs, 564 size_t* index_of_error = NULL); 565 566 lldb::ValueObjectSP 567 GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> > &idxs, 568 size_t* index_of_error = NULL); 569 570 lldb::ValueObjectSP 571 GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs, 572 size_t* index_of_error = NULL); 573 574 // this will always create the children if necessary 575 lldb::ValueObjectSP 576 GetChildAtNamePath (const std::initializer_list<ConstString> &names, 577 ConstString* name_of_error = NULL); 578 579 lldb::ValueObjectSP 580 GetChildAtNamePath (const std::vector<ConstString> &names, 581 ConstString* name_of_error = NULL); 582 583 lldb::ValueObjectSP 584 GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names, 585 ConstString* name_of_error = NULL); 586 587 lldb::ValueObjectSP 588 GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names, 589 ConstString* name_of_error = NULL); 590 591 virtual lldb::ValueObjectSP 592 GetChildMemberWithName (const ConstString &name, bool can_create); 593 594 virtual size_t 595 GetIndexOfChildWithName (const ConstString &name); 596 597 size_t 598 GetNumChildren (); 599 600 const Value & 601 GetValue() const; 602 603 Value & 604 GetValue(); 605 606 virtual bool 607 ResolveValue (Scalar &scalar); 608 609 virtual const char * 610 GetLocationAsCString (); 611 612 const char * 613 GetSummaryAsCString (); 614 615 bool 616 GetSummaryAsCString (TypeSummaryImpl* summary_ptr, 617 std::string& destination); 618 619 bool 620 GetSummaryAsCString (std::string& destination, 621 const TypeSummaryOptions& options); 622 623 bool 624 GetSummaryAsCString (TypeSummaryImpl* summary_ptr, 625 std::string& destination, 626 const TypeSummaryOptions& options); 627 628 std::pair<TypeValidatorResult, std::string> 629 GetValidationStatus (); 630 631 const char * 632 GetObjectDescription (); 633 634 bool 635 HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display, 636 lldb::Format custom_format); 637 638 enum PrintableRepresentationSpecialCases 639 { 640 ePrintableRepresentationSpecialCasesDisable = 0, 641 ePrintableRepresentationSpecialCasesAllow = 1, 642 ePrintableRepresentationSpecialCasesOnly = 3 643 }; 644 645 bool 646 DumpPrintableRepresentation (Stream& s, 647 ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary, 648 lldb::Format custom_format = lldb::eFormatInvalid, 649 PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow, 650 bool do_dump_error = true); 651 bool 652 GetValueIsValid () const; 653 654 // If you call this on a newly created ValueObject, it will always return false. 655 bool 656 GetValueDidChange (); 657 658 bool 659 UpdateValueIfNeeded (bool update_format = true); 660 661 bool 662 UpdateFormatsIfNeeded(); 663 664 lldb::ValueObjectSP GetSP()665 GetSP () 666 { 667 return m_manager->GetSharedPointer(this); 668 } 669 670 void 671 SetName (const ConstString &name); 672 673 virtual lldb::addr_t 674 GetAddressOf (bool scalar_is_load_address = true, 675 AddressType *address_type = NULL); 676 677 lldb::addr_t 678 GetPointerValue (AddressType *address_type = NULL); 679 680 lldb::ValueObjectSP 681 GetSyntheticChild (const ConstString &key) const; 682 683 lldb::ValueObjectSP 684 GetSyntheticArrayMember (size_t index, bool can_create); 685 686 lldb::ValueObjectSP 687 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create); 688 689 lldb::ValueObjectSP 690 GetSyntheticExpressionPathChild(const char* expression, bool can_create); 691 692 virtual lldb::ValueObjectSP 693 GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create); 694 695 virtual lldb::ValueObjectSP 696 GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create); 697 698 virtual lldb::ValueObjectSP 699 GetDynamicValue (lldb::DynamicValueType valueType); 700 701 lldb::DynamicValueType 702 GetDynamicValueType (); 703 704 virtual lldb::ValueObjectSP 705 GetStaticValue (); 706 707 virtual lldb::ValueObjectSP 708 GetNonSyntheticValue (); 709 710 lldb::ValueObjectSP 711 GetSyntheticValue (bool use_synthetic = true); 712 713 virtual bool 714 HasSyntheticValue(); 715 716 virtual bool IsSynthetic()717 IsSynthetic() { return false; } 718 719 lldb::ValueObjectSP 720 GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue, 721 bool synthValue); 722 723 virtual lldb::ValueObjectSP 724 CreateConstantValue (const ConstString &name); 725 726 virtual lldb::ValueObjectSP 727 Dereference (Error &error); 728 729 virtual lldb::ValueObjectSP 730 AddressOf (Error &error); 731 732 virtual lldb::addr_t GetLiveAddress()733 GetLiveAddress() 734 { 735 return LLDB_INVALID_ADDRESS; 736 } 737 738 virtual void 739 SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS, 740 AddressType address_type = eAddressTypeLoad) 741 { 742 } 743 744 // Find the address of the C++ vtable pointer 745 virtual lldb::addr_t 746 GetCPPVTableAddress(AddressType &address_type); 747 748 virtual lldb::ValueObjectSP 749 Cast (const ClangASTType &clang_ast_type); 750 751 virtual lldb::ValueObjectSP 752 CastPointerType (const char *name, 753 ClangASTType &ast_type); 754 755 virtual lldb::ValueObjectSP 756 CastPointerType (const char *name, 757 lldb::TypeSP &type_sp); 758 759 // The backing bits of this value object were updated, clear any 760 // descriptive string, so we know we have to refetch them 761 virtual void ValueUpdated()762 ValueUpdated () 763 { 764 ClearUserVisibleData(eClearUserVisibleDataItemsValue | 765 eClearUserVisibleDataItemsSummary | 766 eClearUserVisibleDataItemsDescription); 767 } 768 769 virtual bool IsDynamic()770 IsDynamic () 771 { 772 return false; 773 } 774 775 virtual bool DoesProvideSyntheticValue()776 DoesProvideSyntheticValue () 777 { 778 return false; 779 } 780 781 bool 782 IsSyntheticChildrenGenerated (); 783 784 void 785 SetSyntheticChildrenGenerated (bool b); 786 787 virtual SymbolContextScope * 788 GetSymbolContextScope(); 789 790 void 791 Dump (Stream &s); 792 793 void 794 Dump (Stream &s, 795 const DumpValueObjectOptions& options); 796 797 static lldb::ValueObjectSP 798 CreateValueObjectFromExpression (const char* name, 799 const char* expression, 800 const ExecutionContext& exe_ctx); 801 802 static lldb::ValueObjectSP 803 CreateValueObjectFromExpression (const char* name, 804 const char* expression, 805 const ExecutionContext& exe_ctx, 806 const EvaluateExpressionOptions& options); 807 808 static lldb::ValueObjectSP 809 CreateValueObjectFromAddress (const char* name, 810 uint64_t address, 811 const ExecutionContext& exe_ctx, 812 ClangASTType type); 813 814 static lldb::ValueObjectSP 815 CreateValueObjectFromData (const char* name, 816 const DataExtractor& data, 817 const ExecutionContext& exe_ctx, 818 ClangASTType type); 819 820 void 821 LogValueObject (Log *log); 822 823 void 824 LogValueObject (Log *log, 825 const DumpValueObjectOptions& options); 826 827 828 lldb::ValueObjectSP 829 Persist (); 830 831 // returns true if this is a char* or a char[] 832 // if it is a char* and check_pointer is true, 833 // it also checks that the pointer is valid 834 bool 835 IsCStringContainer (bool check_pointer = false); 836 837 size_t 838 ReadPointedString (lldb::DataBufferSP& buffer_sp, 839 Error& error, 840 uint32_t max_length = 0, 841 bool honor_array = true, 842 lldb::Format item_format = lldb::eFormatCharArray); 843 844 virtual size_t 845 GetPointeeData (DataExtractor& data, 846 uint32_t item_idx = 0, 847 uint32_t item_count = 1); 848 849 virtual uint64_t 850 GetData (DataExtractor& data, Error &error); 851 852 virtual bool 853 SetData (DataExtractor &data, Error &error); 854 855 virtual bool GetIsConstant()856 GetIsConstant () const 857 { 858 return m_update_point.IsConstant(); 859 } 860 861 bool NeedsUpdating()862 NeedsUpdating () 863 { 864 const bool accept_invalid_exe_ctx = CanUpdateWithInvalidExecutionContext(); 865 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx); 866 } 867 868 void SetIsConstant()869 SetIsConstant () 870 { 871 m_update_point.SetIsConstant(); 872 } 873 874 lldb::Format 875 GetFormat () const; 876 877 virtual void SetFormat(lldb::Format format)878 SetFormat (lldb::Format format) 879 { 880 if (format != m_format) 881 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 882 m_format = format; 883 } 884 885 886 virtual lldb::LanguageType 887 GetPreferredDisplayLanguage (); 888 889 void 890 SetPreferredDisplayLanguage (lldb::LanguageType); 891 892 lldb::TypeSummaryImplSP GetSummaryFormat()893 GetSummaryFormat() 894 { 895 UpdateFormatsIfNeeded(); 896 return m_type_summary_sp; 897 } 898 899 void SetSummaryFormat(lldb::TypeSummaryImplSP format)900 SetSummaryFormat(lldb::TypeSummaryImplSP format) 901 { 902 m_type_summary_sp = format; 903 ClearUserVisibleData(eClearUserVisibleDataItemsSummary); 904 } 905 906 lldb::TypeValidatorImplSP GetValidator()907 GetValidator() 908 { 909 UpdateFormatsIfNeeded(); 910 return m_type_validator_sp; 911 } 912 913 void SetValidator(lldb::TypeValidatorImplSP format)914 SetValidator(lldb::TypeValidatorImplSP format) 915 { 916 m_type_validator_sp = format; 917 ClearUserVisibleData(eClearUserVisibleDataItemsValidator); 918 } 919 920 void SetValueFormat(lldb::TypeFormatImplSP format)921 SetValueFormat(lldb::TypeFormatImplSP format) 922 { 923 m_type_format_sp = format; 924 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 925 } 926 927 lldb::TypeFormatImplSP GetValueFormat()928 GetValueFormat() 929 { 930 UpdateFormatsIfNeeded(); 931 return m_type_format_sp; 932 } 933 934 void SetSyntheticChildren(const lldb::SyntheticChildrenSP & synth_sp)935 SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) 936 { 937 if (synth_sp.get() == m_synthetic_children_sp.get()) 938 return; 939 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren); 940 m_synthetic_children_sp = synth_sp; 941 } 942 943 lldb::SyntheticChildrenSP GetSyntheticChildren()944 GetSyntheticChildren() 945 { 946 UpdateFormatsIfNeeded(); 947 return m_synthetic_children_sp; 948 } 949 950 // Use GetParent for display purposes, but if you want to tell the parent to update itself 951 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 952 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 953 virtual ValueObject * GetParent()954 GetParent() 955 { 956 return m_parent; 957 } 958 959 virtual const ValueObject * GetParent()960 GetParent() const 961 { 962 return m_parent; 963 } 964 965 ValueObject * 966 GetNonBaseClassParent(); 967 968 void SetAddressTypeOfChildren(AddressType at)969 SetAddressTypeOfChildren(AddressType at) 970 { 971 m_address_type_of_ptr_or_ref_children = at; 972 } 973 974 AddressType 975 GetAddressTypeOfChildren(); 976 977 void SetHasCompleteType()978 SetHasCompleteType() 979 { 980 m_did_calculate_complete_objc_class_type = true; 981 } 982 983 //------------------------------------------------------------------ 984 /// Find out if a ValueObject might have children. 985 /// 986 /// This call is much more efficient than CalculateNumChildren() as 987 /// it doesn't need to complete the underlying type. This is designed 988 /// to be used in a UI environment in order to detect if the 989 /// disclosure triangle should be displayed or not. 990 /// 991 /// This function returns true for class, union, structure, 992 /// pointers, references, arrays and more. Again, it does so without 993 /// doing any expensive type completion. 994 /// 995 /// @return 996 /// Returns \b true if the ValueObject might have children, or \b 997 /// false otherwise. 998 //------------------------------------------------------------------ 999 virtual bool 1000 MightHaveChildren(); 1001 1002 virtual bool 1003 IsRuntimeSupportValue (); 1004 1005 protected: 1006 typedef ClusterManager<ValueObject> ValueObjectManager; 1007 1008 class ChildrenManager 1009 { 1010 public: ChildrenManager()1011 ChildrenManager() : 1012 m_mutex(Mutex::eMutexTypeRecursive), 1013 m_children(), 1014 m_children_count(0) 1015 {} 1016 1017 bool HasChildAtIndex(size_t idx)1018 HasChildAtIndex (size_t idx) 1019 { 1020 Mutex::Locker locker(m_mutex); 1021 ChildrenIterator iter = m_children.find(idx); 1022 ChildrenIterator end = m_children.end(); 1023 return (iter != end); 1024 } 1025 1026 ValueObject* GetChildAtIndex(size_t idx)1027 GetChildAtIndex (size_t idx) 1028 { 1029 Mutex::Locker locker(m_mutex); 1030 ChildrenIterator iter = m_children.find(idx); 1031 ChildrenIterator end = m_children.end(); 1032 if (iter == end) 1033 return NULL; 1034 else 1035 return iter->second; 1036 } 1037 1038 void SetChildAtIndex(size_t idx,ValueObject * valobj)1039 SetChildAtIndex (size_t idx, ValueObject* valobj) 1040 { 1041 ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair 1042 Mutex::Locker locker(m_mutex); 1043 m_children.insert(pair); 1044 } 1045 1046 void SetChildrenCount(size_t count)1047 SetChildrenCount (size_t count) 1048 { 1049 Clear(count); 1050 } 1051 1052 size_t GetChildrenCount()1053 GetChildrenCount () 1054 { 1055 return m_children_count; 1056 } 1057 1058 void 1059 Clear(size_t new_count = 0) 1060 { 1061 Mutex::Locker locker(m_mutex); 1062 m_children_count = new_count; 1063 m_children.clear(); 1064 } 1065 1066 private: 1067 typedef std::map<size_t, ValueObject*> ChildrenMap; 1068 typedef ChildrenMap::iterator ChildrenIterator; 1069 typedef ChildrenMap::value_type ChildrenPair; 1070 Mutex m_mutex; 1071 ChildrenMap m_children; 1072 size_t m_children_count; 1073 }; 1074 1075 //------------------------------------------------------------------ 1076 // Classes that inherit from ValueObject can see and modify these 1077 //------------------------------------------------------------------ 1078 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1079 ValueObject * m_root; // The root of the hierarchy for this ValueObject (or NULL if never calculated) 1080 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1081 // updated. When we are asked to update the value object, we check whether 1082 // the context & stop id are the same before updating. 1083 ConstString m_name; // The name of this object 1084 DataExtractor m_data; // A data extractor that can be used to extract the value. 1085 Value m_value; 1086 Error m_error; // An error object that can describe any errors that occur when updating values. 1087 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1088 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1089 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1090 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1091 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1092 // in that the summary is consed up by us, the object_desc_string is builtin. 1093 1094 llvm::Optional<std::pair<TypeValidatorResult, std::string>> m_validation_result; 1095 1096 ClangASTType m_override_type;// If the type of the value object should be overridden, the type to impose. 1097 1098 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1099 // without a parent.) The manager gets passed through all the generations of 1100 // dependent objects, and will keep the whole cluster of objects alive as long 1101 // as a shared pointer to any of them has been handed out. Shared pointers to 1102 // value objects must always be made with the GetSP method. 1103 1104 ChildrenManager m_children; 1105 std::map<ConstString, ValueObject *> m_synthetic_children; 1106 1107 ValueObject* m_dynamic_value; 1108 ValueObject* m_synthetic_value; 1109 ValueObject* m_deref_valobj; 1110 1111 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1112 // as an independent ValueObjectConstResult, which isn't managed by us. 1113 1114 lldb::Format m_format; 1115 lldb::Format m_last_format; 1116 uint32_t m_last_format_mgr_revision; 1117 lldb::TypeSummaryImplSP m_type_summary_sp; 1118 lldb::TypeFormatImplSP m_type_format_sp; 1119 lldb::SyntheticChildrenSP m_synthetic_children_sp; 1120 lldb::TypeValidatorImplSP m_type_validator_sp; 1121 ProcessModID m_user_id_of_forced_summary; 1122 AddressType m_address_type_of_ptr_or_ref_children; 1123 1124 llvm::SmallVector<uint8_t, 16> m_value_checksum; 1125 1126 lldb::LanguageType m_preferred_display_language; 1127 1128 bool m_value_is_valid:1, 1129 m_value_did_change:1, 1130 m_children_count_valid:1, 1131 m_old_value_valid:1, 1132 m_is_deref_of_parent:1, 1133 m_is_array_item_for_pointer:1, 1134 m_is_bitfield_for_scalar:1, 1135 m_is_child_at_offset:1, 1136 m_is_getting_summary:1, 1137 m_did_calculate_complete_objc_class_type:1, 1138 m_is_synthetic_children_generated:1; 1139 1140 friend class ValueObjectChild; 1141 friend class ClangExpressionDeclMap; // For GetValue 1142 friend class ClangExpressionVariable; // For SetName 1143 friend class Target; // For SetName 1144 friend class ValueObjectConstResultImpl; 1145 friend class ValueObjectSynthetic; // For ClearUserVisibleData 1146 1147 //------------------------------------------------------------------ 1148 // Constructors and Destructors 1149 //------------------------------------------------------------------ 1150 1151 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1152 1153 ValueObject(); 1154 1155 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1156 // through-out its lifespan. 1157 1158 ValueObject (ExecutionContextScope *exe_scope, 1159 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1160 1161 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1162 // of its parent. 1163 1164 ValueObject (ValueObject &parent); 1165 1166 ValueObjectManager * GetManager()1167 GetManager() 1168 { 1169 return m_manager; 1170 } 1171 1172 virtual bool 1173 UpdateValue () = 0; 1174 1175 virtual bool CanUpdateWithInvalidExecutionContext()1176 CanUpdateWithInvalidExecutionContext () 1177 { 1178 return false; 1179 } 1180 1181 virtual void 1182 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1183 1184 virtual lldb::DynamicValueType GetDynamicValueTypeImpl()1185 GetDynamicValueTypeImpl () 1186 { 1187 return lldb::eNoDynamicValues; 1188 } 1189 1190 virtual bool HasDynamicValueTypeInfo()1191 HasDynamicValueTypeInfo () 1192 { 1193 return false; 1194 } 1195 1196 virtual void 1197 CalculateSyntheticValue (bool use_synthetic = true); 1198 1199 // Should only be called by ValueObject::GetChildAtIndex() 1200 // Returns a ValueObject managed by this ValueObject's manager. 1201 virtual ValueObject * 1202 CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index); 1203 1204 // Should only be called by ValueObject::GetNumChildren() 1205 virtual size_t 1206 CalculateNumChildren() = 0; 1207 1208 void 1209 SetNumChildren (size_t num_children); 1210 1211 void 1212 SetValueDidChange (bool value_changed); 1213 1214 void 1215 SetValueIsValid (bool valid); 1216 1217 void 1218 ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings); 1219 1220 void 1221 AddSyntheticChild (const ConstString &key, 1222 ValueObject *valobj); 1223 1224 DataExtractor & 1225 GetDataExtractor (); 1226 1227 void 1228 ClearDynamicTypeInformation (); 1229 1230 //------------------------------------------------------------------ 1231 // Subclasses must implement the functions below. 1232 //------------------------------------------------------------------ 1233 1234 virtual ClangASTType 1235 GetClangTypeImpl () = 0; 1236 1237 const char * 1238 GetLocationAsCStringImpl (const Value& value, 1239 const DataExtractor& data); 1240 1241 bool 1242 IsChecksumEmpty (); 1243 1244 private: 1245 //------------------------------------------------------------------ 1246 // For ValueObject only 1247 //------------------------------------------------------------------ 1248 1249 virtual ClangASTType 1250 MaybeCalculateCompleteType (); 1251 1252 lldb::ValueObjectSP 1253 GetValueForExpressionPath_Impl(const char* expression_cstr, 1254 const char** first_unparsed, 1255 ExpressionPathScanEndReason* reason_to_stop, 1256 ExpressionPathEndResultType* final_value_type, 1257 const GetValueForExpressionPathOptions& options, 1258 ExpressionPathAftermath* final_task_on_target); 1259 1260 // this method will ONLY expand [] expressions into a VOList and return 1261 // the number of elements it added to the VOList 1262 // it will NOT loop through expanding the follow-up of the expression_cstr 1263 // for all objects in the list 1264 int 1265 ExpandArraySliceExpression(const char* expression_cstr, 1266 const char** first_unparsed, 1267 lldb::ValueObjectSP root, 1268 lldb::ValueObjectListSP& list, 1269 ExpressionPathScanEndReason* reason_to_stop, 1270 ExpressionPathEndResultType* final_value_type, 1271 const GetValueForExpressionPathOptions& options, 1272 ExpressionPathAftermath* final_task_on_target); 1273 1274 1275 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1276 1277 }; 1278 1279 } // namespace lldb_private 1280 1281 #endif // liblldb_ValueObject_h_ 1282