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