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