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