ValueObject.h revision 6f30287bdc836c715fcac75b06ec58d13b79e715
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 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 ExecutionContextScope * 352 GetExecutionContextScope (); 353 354 lldb::TargetSP 355 GetTargetSP () const 356 { 357 return m_target_sp; 358 } 359 360 lldb::ProcessSP 361 GetProcessSP () const 362 { 363 return m_process_sp; 364 } 365 366 // Set the EvaluationPoint to the values in exe_scope, 367 // Return true if the Evaluation Point changed. 368 // Since the ExecutionContextScope is always going to be valid currently, 369 // the Updated Context will also always be valid. 370 371 bool 372 SetContext (ExecutionContextScope *exe_scope); 373 374 void 375 SetIsConstant () 376 { 377 SetUpdated(); 378 m_mod_id.SetInvalid(); 379 } 380 381 bool 382 IsConstant () const 383 { 384 return !m_mod_id.IsValid(); 385 } 386 387 ProcessModID 388 GetModID () const 389 { 390 return m_mod_id; 391 } 392 393 void 394 SetUpdateID (ProcessModID new_id) 395 { 396 m_mod_id = new_id; 397 } 398 399 bool 400 IsFirstEvaluation () const 401 { 402 return m_first_update; 403 } 404 405 void 406 SetNeedsUpdate () 407 { 408 m_needs_update = true; 409 } 410 411 void 412 SetUpdated (); 413 414 bool 415 NeedsUpdating() 416 { 417 SyncWithProcessState(); 418 return m_needs_update; 419 } 420 421 bool 422 IsValid () 423 { 424 if (!m_mod_id.IsValid()) 425 return false; 426 else if (SyncWithProcessState ()) 427 { 428 if (!m_mod_id.IsValid()) 429 return false; 430 } 431 return true; 432 } 433 434 void 435 SetInvalid () 436 { 437 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 438 // history purposes. 439 m_mod_id.SetInvalid(); 440 441 // Can't update an invalid state. 442 m_needs_update = false; 443 444 } 445 446 private: 447 bool 448 SyncWithProcessState (); 449 450 ExecutionContextScope *m_exe_scope; // This is not the way to store the evaluation point state, it is just 451 // a cache of the lookup, and gets thrown away when we update. 452 bool m_needs_update; 453 bool m_first_update; 454 455 lldb::TargetSP m_target_sp; 456 lldb::ProcessSP m_process_sp; 457 lldb::user_id_t m_thread_id; 458 StackID m_stack_id; 459 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. 460 }; 461 462 const EvaluationPoint & 463 GetUpdatePoint () const 464 { 465 return m_update_point; 466 } 467 468 EvaluationPoint & 469 GetUpdatePoint () 470 { 471 return m_update_point; 472 } 473 474 ExecutionContextScope * 475 GetExecutionContextScope () 476 { 477 return m_update_point.GetExecutionContextScope(); 478 } 479 480 void 481 SetNeedsUpdate (); 482 483 virtual ~ValueObject(); 484 485 //------------------------------------------------------------------ 486 // Sublasses must implement the functions below. 487 //------------------------------------------------------------------ 488 virtual size_t 489 GetByteSize() = 0; 490 491 virtual clang::ASTContext * 492 GetClangAST () = 0; 493 494 virtual lldb::clang_type_t 495 GetClangType () = 0; 496 497 virtual lldb::ValueType 498 GetValueType() const = 0; 499 500 virtual ConstString 501 GetTypeName() = 0; 502 503 virtual lldb::LanguageType 504 GetObjectRuntimeLanguage(); 505 506 virtual bool 507 IsPointerType (); 508 509 virtual bool 510 IsArrayType (); 511 512 virtual bool 513 IsScalarType (); 514 515 virtual bool 516 IsPointerOrReferenceType (); 517 518 virtual bool 519 IsPossibleCPlusPlusDynamicType (); 520 521 virtual bool 522 IsPossibleDynamicType (); 523 524 virtual bool 525 IsBaseClass () 526 { 527 return false; 528 } 529 530 virtual bool 531 IsDereferenceOfParent () 532 { 533 return false; 534 } 535 536 bool 537 IsIntegerType (bool &is_signed); 538 539 virtual bool 540 GetBaseClassPath (Stream &s); 541 542 virtual void 543 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eDereferencePointers); 544 545 lldb::ValueObjectSP 546 GetValueForExpressionPath(const char* expression, 547 const char** first_unparsed = NULL, 548 ExpressionPathScanEndReason* reason_to_stop = NULL, 549 ExpressionPathEndResultType* final_value_type = NULL, 550 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 551 ExpressionPathAftermath* final_task_on_target = NULL); 552 553 int 554 GetValuesForExpressionPath(const char* expression, 555 lldb::ValueObjectListSP& list, 556 const char** first_unparsed = NULL, 557 ExpressionPathScanEndReason* reason_to_stop = NULL, 558 ExpressionPathEndResultType* final_value_type = NULL, 559 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 560 ExpressionPathAftermath* final_task_on_target = NULL); 561 562 virtual bool 563 IsInScope () 564 { 565 return true; 566 } 567 568 virtual off_t 569 GetByteOffset() 570 { 571 return 0; 572 } 573 574 virtual uint32_t 575 GetBitfieldBitSize() 576 { 577 return 0; 578 } 579 580 virtual uint32_t 581 GetBitfieldBitOffset() 582 { 583 return 0; 584 } 585 586 virtual bool 587 IsArrayItemForPointer() 588 { 589 return m_is_array_item_for_pointer; 590 } 591 592 virtual bool 593 SetClangAST (clang::ASTContext *ast) 594 { 595 return false; 596 } 597 598 virtual const char * 599 GetValueAsCString (); 600 601 virtual unsigned long long 602 GetValueAsUnsigned(); 603 604 virtual bool 605 SetValueFromCString (const char *value_str); 606 607 // Return the module associated with this value object in case the 608 // value is from an executable file and might have its data in 609 // sections of the file. This can be used for variables. 610 virtual Module * 611 GetModule() 612 { 613 if (m_parent) 614 return m_parent->GetModule(); 615 return NULL; 616 } 617 //------------------------------------------------------------------ 618 // The functions below should NOT be modified by sublasses 619 //------------------------------------------------------------------ 620 const Error & 621 GetError(); 622 623 const ConstString & 624 GetName() const; 625 626 virtual lldb::ValueObjectSP 627 GetChildAtIndex (uint32_t idx, bool can_create); 628 629 virtual lldb::ValueObjectSP 630 GetChildMemberWithName (const ConstString &name, bool can_create); 631 632 virtual uint32_t 633 GetIndexOfChildWithName (const ConstString &name); 634 635 uint32_t 636 GetNumChildren (); 637 638 const Value & 639 GetValue() const; 640 641 Value & 642 GetValue(); 643 644 virtual bool 645 ResolveValue (Scalar &scalar); 646 647 const char * 648 GetLocationAsCString (); 649 650 const char * 651 GetSummaryAsCString (); 652 653 const char * 654 GetObjectDescription (); 655 656 bool 657 GetPrintableRepresentation(Stream& s, 658 ValueObjectRepresentationStyle val_obj_display = eDisplaySummary, 659 lldb::Format custom_format = lldb::eFormatInvalid); 660 661 bool 662 HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, 663 lldb::Format custom_format); 664 665 bool 666 DumpPrintableRepresentation(Stream& s, 667 ValueObjectRepresentationStyle val_obj_display = eDisplaySummary, 668 lldb::Format custom_format = lldb::eFormatInvalid, 669 bool only_special = false); 670 bool 671 GetValueIsValid () const; 672 673 bool 674 GetValueDidChange (); 675 676 bool 677 UpdateValueIfNeeded (bool update_format = true); 678 679 bool 680 UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true); 681 682 void 683 UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues); 684 685 DataExtractor & 686 GetDataExtractor (); 687 688 lldb::ValueObjectSP 689 GetSP () 690 { 691 return m_manager->GetSharedPointer(this); 692 } 693 694protected: 695 void 696 AddSyntheticChild (const ConstString &key, 697 ValueObject *valobj); 698public: 699 lldb::ValueObjectSP 700 GetSyntheticChild (const ConstString &key) const; 701 702 lldb::ValueObjectSP 703 GetSyntheticArrayMember (int32_t index, bool can_create); 704 705 lldb::ValueObjectSP 706 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 707 708 lldb::ValueObjectSP 709 GetSyntheticArrayMemberFromArray (int32_t index, bool can_create); 710 711 lldb::ValueObjectSP 712 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create); 713 714 lldb::ValueObjectSP 715 GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create); 716 717 lldb::ValueObjectSP 718 GetSyntheticExpressionPathChild(const char* expression, bool can_create); 719 720 virtual lldb::ValueObjectSP 721 GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create); 722 723 lldb::ValueObjectSP 724 GetDynamicValue (lldb::DynamicValueType valueType); 725 726 lldb::ValueObjectSP 727 GetSyntheticValue (lldb::SyntheticValueType use_synthetic); 728 729 virtual bool 730 HasSyntheticValue(); 731 732 virtual lldb::ValueObjectSP 733 CreateConstantValue (const ConstString &name); 734 735 virtual lldb::ValueObjectSP 736 Dereference (Error &error); 737 738 virtual lldb::ValueObjectSP 739 AddressOf (Error &error); 740 741 virtual lldb::ValueObjectSP 742 CastPointerType (const char *name, 743 ClangASTType &ast_type); 744 745 virtual lldb::ValueObjectSP 746 CastPointerType (const char *name, 747 lldb::TypeSP &type_sp); 748 749 // The backing bits of this value object were updated, clear any 750 // descriptive string, so we know we have to refetch them 751 virtual void 752 ValueUpdated () 753 { 754 m_value_str.clear(); 755 m_summary_str.clear(); 756 m_object_desc_str.clear(); 757 } 758 759 virtual bool 760 IsDynamic () 761 { 762 return false; 763 } 764 765 static void 766 DumpValueObject (Stream &s, 767 ValueObject *valobj) 768 { 769 770 if (!valobj) 771 return; 772 773 ValueObject::DumpValueObject(s, 774 valobj, 775 DumpValueObjectOptions::DefaultOptions()); 776 } 777 778 static void 779 DumpValueObject (Stream &s, 780 ValueObject *valobj, 781 const char *root_valobj_name) 782 { 783 784 if (!valobj) 785 return; 786 787 ValueObject::DumpValueObject(s, 788 valobj, 789 root_valobj_name, 790 DumpValueObjectOptions::DefaultOptions()); 791 } 792 793 static void 794 DumpValueObject (Stream &s, 795 ValueObject *valobj, 796 const DumpValueObjectOptions& options) 797 { 798 799 if (!valobj) 800 return; 801 802 ValueObject::DumpValueObject(s, 803 valobj, 804 valobj->GetName().AsCString(), 805 options.m_ptr_depth, 806 0, 807 options.m_max_depth, 808 options.m_show_types, 809 options.m_show_location, 810 options.m_use_objc, 811 options.m_use_dynamic, 812 options.m_use_synthetic, 813 options.m_scope_already_checked, 814 options.m_flat_output, 815 options.m_omit_summary_depth, 816 options.m_ignore_cap); 817 } 818 819 static void 820 DumpValueObject (Stream &s, 821 ValueObject *valobj, 822 const char *root_valobj_name, 823 const DumpValueObjectOptions& options) 824 { 825 826 if (!valobj) 827 return; 828 829 ValueObject::DumpValueObject(s, 830 valobj, 831 root_valobj_name, 832 options.m_ptr_depth, 833 0, 834 options.m_max_depth, 835 options.m_show_types, 836 options.m_show_location, 837 options.m_use_objc, 838 options.m_use_dynamic, 839 options.m_use_synthetic, 840 options.m_scope_already_checked, 841 options.m_flat_output, 842 options.m_omit_summary_depth, 843 options.m_ignore_cap); 844 } 845 846 static void 847 DumpValueObject (Stream &s, 848 ValueObject *valobj, 849 const char *root_valobj_name, 850 uint32_t ptr_depth, 851 uint32_t curr_depth, 852 uint32_t max_depth, 853 bool show_types, 854 bool show_location, 855 bool use_objc, 856 lldb::DynamicValueType use_dynamic, 857 bool use_synthetic, 858 bool scope_already_checked, 859 bool flat_output, 860 uint32_t omit_summary_depth, 861 bool ignore_cap); 862 863 // returns true if this is a char* or a char[] 864 // if it is a char* and check_pointer is true, 865 // it also checks that the pointer is valid 866 bool 867 IsCStringContainer(bool check_pointer = false); 868 869 void 870 ReadPointedString(Stream& s, 871 Error& error, 872 uint32_t max_length = 0, 873 bool honor_array = true, 874 lldb::Format item_format = lldb::eFormatCharArray); 875 876 bool 877 GetIsConstant () const 878 { 879 return m_update_point.IsConstant(); 880 } 881 882 void 883 SetIsConstant () 884 { 885 m_update_point.SetIsConstant(); 886 } 887 888 lldb::Format 889 GetFormat () const 890 { 891 if (m_parent && m_format == lldb::eFormatDefault) 892 return m_parent->GetFormat(); 893 return m_format; 894 } 895 896 void 897 SetIsExpressionResult(bool expr) 898 { 899 m_is_expression_result = expr; 900 } 901 902 bool 903 GetIsExpressionResult() 904 { 905 return m_is_expression_result; 906 } 907 908 void 909 SetFormat (lldb::Format format) 910 { 911 if (format != m_format) 912 m_value_str.clear(); 913 m_format = format; 914 } 915 916 void 917 SetCustomSummaryFormat(lldb::SummaryFormatSP format) 918 { 919 m_forced_summary_format = format; 920 m_user_id_of_forced_summary = m_update_point.GetModID(); 921 m_summary_str.clear(); 922 } 923 924 lldb::SummaryFormatSP 925 GetCustomSummaryFormat() 926 { 927 return m_forced_summary_format; 928 } 929 930 void 931 ClearCustomSummaryFormat() 932 { 933 m_forced_summary_format.reset(); 934 m_summary_str.clear(); 935 } 936 937 bool 938 HasCustomSummaryFormat() 939 { 940 return (m_forced_summary_format.get()); 941 } 942 943 lldb::SummaryFormatSP 944 GetSummaryFormat() 945 { 946 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 947 if (HasCustomSummaryFormat()) 948 return m_forced_summary_format; 949 return m_last_summary_format; 950 } 951 952 // Use GetParent for display purposes, but if you want to tell the parent to update itself 953 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 954 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 955 virtual ValueObject * 956 GetParent() 957 { 958 return m_parent; 959 } 960 961 virtual const ValueObject * 962 GetParent() const 963 { 964 return m_parent; 965 } 966 967 ValueObject * 968 GetNonBaseClassParent(); 969 970 void 971 SetPointersPointToLoadAddrs (bool b) 972 { 973 m_pointers_point_to_load_addrs = b; 974 } 975 976protected: 977 typedef ClusterManager<ValueObject> ValueObjectManager; 978 979 //------------------------------------------------------------------ 980 // Classes that inherit from ValueObject can see and modify these 981 //------------------------------------------------------------------ 982 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 983 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 984 // updated. When we are asked to update the value object, we check whether 985 // the context & stop id are the same before updating. 986 ConstString m_name; // The name of this object 987 DataExtractor m_data; // A data extractor that can be used to extract the value. 988 Value m_value; 989 Error m_error; // An error object that can describe any errors that occur when updating values. 990 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 991 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 992 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 993 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 994 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 995 // in that the summary is consed up by us, the object_desc_string is builtin. 996 997 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 998 // without a parent.) The manager gets passed through all the generations of 999 // dependent objects, and will keep the whole cluster of objects alive as long 1000 // as a shared pointer to any of them has been handed out. Shared pointers to 1001 // value objects must always be made with the GetSP method. 1002 1003 std::vector<ValueObject *> m_children; 1004 std::map<ConstString, ValueObject *> m_synthetic_children; 1005 ValueObject *m_dynamic_value; 1006 ValueObject *m_synthetic_value; 1007 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1008 // as an independent ValueObjectConstResult, which isn't managed by us. 1009 ValueObject *m_deref_valobj; 1010 1011 lldb::Format m_format; 1012 uint32_t m_last_format_mgr_revision; 1013 lldb::DynamicValueType m_last_format_mgr_dynamic; 1014 lldb::SummaryFormatSP m_last_summary_format; 1015 lldb::SummaryFormatSP m_forced_summary_format; 1016 lldb::ValueFormatSP m_last_value_format; 1017 lldb::SyntheticChildrenSP m_last_synthetic_filter; 1018 ProcessModID m_user_id_of_forced_summary; 1019 1020 bool m_value_is_valid:1, 1021 m_value_did_change:1, 1022 m_children_count_valid:1, 1023 m_old_value_valid:1, 1024 m_pointers_point_to_load_addrs:1, 1025 m_is_deref_of_parent:1, 1026 m_is_array_item_for_pointer:1, 1027 m_is_bitfield_for_scalar:1, 1028 m_is_expression_path_child:1, 1029 m_is_child_at_offset:1, 1030 m_is_expression_result:1; 1031 1032 // used to prevent endless looping into GetpPrintableRepresentation() 1033 uint32_t m_dump_printable_counter; 1034 friend class ClangExpressionDeclMap; // For GetValue 1035 friend class ClangExpressionVariable; // For SetName 1036 friend class Target; // For SetName 1037 1038 //------------------------------------------------------------------ 1039 // Constructors and Destructors 1040 //------------------------------------------------------------------ 1041 1042 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1043 1044 ValueObject(); 1045 1046 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1047 // through-out its lifespan. 1048 1049 ValueObject (ExecutionContextScope *exe_scope); 1050 1051 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1052 // of its parent. 1053 1054 ValueObject (ValueObject &parent); 1055 1056 ValueObjectManager * 1057 GetManager() 1058 { 1059 return m_manager; 1060 } 1061 1062 virtual bool 1063 UpdateValue () = 0; 1064 1065 virtual void 1066 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1067 1068 virtual void 1069 CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic); 1070 1071 // Should only be called by ValueObject::GetChildAtIndex() 1072 // Returns a ValueObject managed by this ValueObject's manager. 1073 virtual ValueObject * 1074 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1075 1076 // Should only be called by ValueObject::GetNumChildren() 1077 virtual uint32_t 1078 CalculateNumChildren() = 0; 1079 1080 void 1081 SetNumChildren (uint32_t num_children); 1082 1083 void 1084 SetValueDidChange (bool value_changed); 1085 1086 void 1087 SetValueIsValid (bool valid); 1088 1089 void 1090 ClearUserVisibleData(); 1091 1092public: 1093 1094 void 1095 SetName (const ConstString &name); 1096 1097 lldb::addr_t 1098 GetPointerValue (AddressType &address_type, 1099 bool scalar_is_load_address); 1100 1101 lldb::addr_t 1102 GetAddressOf (AddressType &address_type, 1103 bool scalar_is_load_address); 1104private: 1105 //------------------------------------------------------------------ 1106 // For ValueObject only 1107 //------------------------------------------------------------------ 1108 1109 lldb::ValueObjectSP 1110 GetValueForExpressionPath_Impl(const char* expression_cstr, 1111 const char** first_unparsed, 1112 ExpressionPathScanEndReason* reason_to_stop, 1113 ExpressionPathEndResultType* final_value_type, 1114 const GetValueForExpressionPathOptions& options, 1115 ExpressionPathAftermath* final_task_on_target); 1116 1117 // this method will ONLY expand [] expressions into a VOList and return 1118 // the number of elements it added to the VOList 1119 // it will NOT loop through expanding the follow-up of the expression_cstr 1120 // for all objects in the list 1121 int 1122 ExpandArraySliceExpression(const char* expression_cstr, 1123 const char** first_unparsed, 1124 lldb::ValueObjectSP root, 1125 lldb::ValueObjectListSP& list, 1126 ExpressionPathScanEndReason* reason_to_stop, 1127 ExpressionPathEndResultType* final_value_type, 1128 const GetValueForExpressionPathOptions& options, 1129 ExpressionPathAftermath* final_task_on_target); 1130 1131 1132 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1133 1134}; 1135 1136} // namespace lldb_private 1137 1138#endif // liblldb_ValueObject_h_ 1139