ValueObject.h revision bd5871561db60b84c38466534694ca246b60d108
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 m_is_getting_summary = false; 970 } 971 972 void 973 SetValueFormat(lldb::TypeFormatImplSP format) 974 { 975 m_type_format_sp = format; 976 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 977 } 978 979 lldb::TypeFormatImplSP 980 GetValueFormat() 981 { 982 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 983 return m_type_format_sp; 984 } 985 986 void 987 SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) 988 { 989 if (synth_sp.get() == m_synthetic_children_sp.get()) 990 return; 991 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren); 992 m_synthetic_children_sp = synth_sp; 993 } 994 995 lldb::SyntheticChildrenSP 996 GetSyntheticChildren() 997 { 998 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 999 return m_synthetic_children_sp; 1000 } 1001 1002 // Use GetParent for display purposes, but if you want to tell the parent to update itself 1003 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 1004 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 1005 virtual ValueObject * 1006 GetParent() 1007 { 1008 return m_parent; 1009 } 1010 1011 virtual const ValueObject * 1012 GetParent() const 1013 { 1014 return m_parent; 1015 } 1016 1017 ValueObject * 1018 GetNonBaseClassParent(); 1019 1020 void 1021 SetAddressTypeOfChildren(AddressType at) 1022 { 1023 m_address_type_of_ptr_or_ref_children = at; 1024 } 1025 1026 AddressType 1027 GetAddressTypeOfChildren() 1028 { 1029 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 1030 { 1031 if (m_parent) 1032 return m_parent->GetAddressTypeOfChildren(); 1033 } 1034 return m_address_type_of_ptr_or_ref_children; 1035 } 1036 1037protected: 1038 typedef ClusterManager<ValueObject> ValueObjectManager; 1039 1040 class ChildrenManager 1041 { 1042 public: 1043 ChildrenManager() : 1044 m_mutex(Mutex::eMutexTypeRecursive), 1045 m_children(), 1046 m_children_count(0) 1047 {} 1048 1049 bool 1050 HasChildAtIndex (uint32_t idx) 1051 { 1052 Mutex::Locker(m_mutex); 1053 ChildrenIterator iter = m_children.find(idx); 1054 ChildrenIterator end = m_children.end(); 1055 return (iter != end); 1056 } 1057 1058 ValueObject* 1059 GetChildAtIndex (uint32_t idx) 1060 { 1061 Mutex::Locker(m_mutex); 1062 ChildrenIterator iter = m_children.find(idx); 1063 ChildrenIterator end = m_children.end(); 1064 if (iter == end) 1065 return NULL; 1066 else 1067 return iter->second; 1068 } 1069 1070 void 1071 SetChildAtIndex (uint32_t idx, ValueObject* valobj) 1072 { 1073 ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair 1074 Mutex::Locker(m_mutex); 1075 m_children.insert(pair); 1076 } 1077 1078 void 1079 SetChildrenCount (uint32_t count) 1080 { 1081 m_children_count = count; 1082 } 1083 1084 uint32_t 1085 GetChildrenCount () 1086 { 1087 return m_children_count; 1088 } 1089 1090 void 1091 Clear() 1092 { 1093 m_children_count = 0; 1094 Mutex::Locker(m_mutex); 1095 m_children.clear(); 1096 } 1097 1098 private: 1099 typedef std::map<uint32_t, ValueObject*> ChildrenMap; 1100 typedef ChildrenMap::iterator ChildrenIterator; 1101 typedef ChildrenMap::value_type ChildrenPair; 1102 Mutex m_mutex; 1103 ChildrenMap m_children; 1104 uint32_t m_children_count; 1105 }; 1106 1107 //------------------------------------------------------------------ 1108 // Classes that inherit from ValueObject can see and modify these 1109 //------------------------------------------------------------------ 1110 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1111 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1112 // updated. When we are asked to update the value object, we check whether 1113 // the context & stop id are the same before updating. 1114 ConstString m_name; // The name of this object 1115 DataExtractor m_data; // A data extractor that can be used to extract the value. 1116 Value m_value; 1117 Error m_error; // An error object that can describe any errors that occur when updating values. 1118 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1119 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1120 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1121 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1122 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1123 // in that the summary is consed up by us, the object_desc_string is builtin. 1124 1125 ClangASTType m_override_type;// If the type of the value object should be overridden, the type to impose. 1126 1127 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1128 // without a parent.) The manager gets passed through all the generations of 1129 // dependent objects, and will keep the whole cluster of objects alive as long 1130 // as a shared pointer to any of them has been handed out. Shared pointers to 1131 // value objects must always be made with the GetSP method. 1132 1133 ChildrenManager m_children; 1134 std::map<ConstString, ValueObject *> m_synthetic_children; 1135 1136 ValueObject* m_dynamic_value; 1137 ValueObject* m_synthetic_value; 1138 ValueObject* m_deref_valobj; 1139 1140 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1141 // as an independent ValueObjectConstResult, which isn't managed by us. 1142 1143 lldb::Format m_format; 1144 uint32_t m_last_format_mgr_revision; 1145 lldb::DynamicValueType m_last_format_mgr_dynamic; 1146 lldb::TypeSummaryImplSP m_type_summary_sp; 1147 lldb::TypeFormatImplSP m_type_format_sp; 1148 lldb::SyntheticChildrenSP m_synthetic_children_sp; 1149 ProcessModID m_user_id_of_forced_summary; 1150 AddressType m_address_type_of_ptr_or_ref_children; 1151 1152 bool m_value_is_valid:1, 1153 m_value_did_change:1, 1154 m_children_count_valid:1, 1155 m_old_value_valid:1, 1156 m_is_deref_of_parent:1, 1157 m_is_array_item_for_pointer:1, 1158 m_is_bitfield_for_scalar:1, 1159 m_is_expression_path_child:1, 1160 m_is_child_at_offset:1, 1161 m_is_getting_summary:1, 1162 m_did_calculate_complete_objc_class_type:1; 1163 1164 friend class ClangExpressionDeclMap; // For GetValue 1165 friend class ClangExpressionVariable; // For SetName 1166 friend class Target; // For SetName 1167 friend class ValueObjectConstResultImpl; 1168 1169 //------------------------------------------------------------------ 1170 // Constructors and Destructors 1171 //------------------------------------------------------------------ 1172 1173 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1174 1175 ValueObject(); 1176 1177 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1178 // through-out its lifespan. 1179 1180 ValueObject (ExecutionContextScope *exe_scope, 1181 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1182 1183 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1184 // of its parent. 1185 1186 ValueObject (ValueObject &parent); 1187 1188 ValueObjectManager * 1189 GetManager() 1190 { 1191 return m_manager; 1192 } 1193 1194 virtual bool 1195 UpdateValue () = 0; 1196 1197 virtual void 1198 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1199 1200 virtual void 1201 CalculateSyntheticValue (bool use_synthetic = true); 1202 1203 // Should only be called by ValueObject::GetChildAtIndex() 1204 // Returns a ValueObject managed by this ValueObject's manager. 1205 virtual ValueObject * 1206 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1207 1208 // Should only be called by ValueObject::GetNumChildren() 1209 virtual uint32_t 1210 CalculateNumChildren() = 0; 1211 1212 void 1213 SetNumChildren (uint32_t num_children); 1214 1215 void 1216 SetValueDidChange (bool value_changed); 1217 1218 void 1219 SetValueIsValid (bool valid); 1220 1221 void 1222 ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings); 1223 1224 void 1225 AddSyntheticChild (const ConstString &key, 1226 ValueObject *valobj); 1227 1228 DataExtractor & 1229 GetDataExtractor (); 1230 1231 //------------------------------------------------------------------ 1232 // Sublasses must implement the functions below. 1233 //------------------------------------------------------------------ 1234 1235 virtual clang::ASTContext * 1236 GetClangASTImpl () = 0; 1237 1238 virtual lldb::clang_type_t 1239 GetClangTypeImpl () = 0; 1240 1241private: 1242 //------------------------------------------------------------------ 1243 // For ValueObject only 1244 //------------------------------------------------------------------ 1245 1246 virtual ClangASTType 1247 MaybeCalculateCompleteType (); 1248 1249 lldb::ValueObjectSP 1250 GetValueForExpressionPath_Impl(const char* expression_cstr, 1251 const char** first_unparsed, 1252 ExpressionPathScanEndReason* reason_to_stop, 1253 ExpressionPathEndResultType* final_value_type, 1254 const GetValueForExpressionPathOptions& options, 1255 ExpressionPathAftermath* final_task_on_target); 1256 1257 // this method will ONLY expand [] expressions into a VOList and return 1258 // the number of elements it added to the VOList 1259 // it will NOT loop through expanding the follow-up of the expression_cstr 1260 // for all objects in the list 1261 int 1262 ExpandArraySliceExpression(const char* expression_cstr, 1263 const char** first_unparsed, 1264 lldb::ValueObjectSP root, 1265 lldb::ValueObjectListSP& list, 1266 ExpressionPathScanEndReason* reason_to_stop, 1267 ExpressionPathEndResultType* final_value_type, 1268 const GetValueForExpressionPathOptions& options, 1269 ExpressionPathAftermath* final_task_on_target); 1270 1271 1272 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1273 1274}; 1275 1276} // namespace lldb_private 1277 1278#endif // liblldb_ValueObject_h_ 1279