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