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