ValueObject.h revision 1b42575189379cb0c1441f74a48127e9ab7335e3
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 const lldb::TargetSP & 355 GetTargetSP () const 356 { 357 return m_target_sp; 358 } 359 360 const 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 uint64_t 602 GetValueAsUnsigned (uint64_t fail_value); 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 bool 683 UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues); 684 685 lldb::ValueObjectSP 686 GetSP () 687 { 688 return m_manager->GetSharedPointer(this); 689 } 690 691 void 692 SetName (const ConstString &name); 693 694 lldb::addr_t 695 GetAddressOf (bool scalar_is_load_address = true, 696 AddressType *address_type = NULL); 697 698 lldb::addr_t 699 GetPointerValue (AddressType *address_type = NULL); 700 701 lldb::ValueObjectSP 702 GetSyntheticChild (const ConstString &key) const; 703 704 lldb::ValueObjectSP 705 GetSyntheticArrayMember (int32_t index, bool can_create); 706 707 lldb::ValueObjectSP 708 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 709 710 lldb::ValueObjectSP 711 GetSyntheticArrayMemberFromArray (int32_t index, bool can_create); 712 713 lldb::ValueObjectSP 714 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create); 715 716 lldb::ValueObjectSP 717 GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create); 718 719 lldb::ValueObjectSP 720 GetSyntheticExpressionPathChild(const char* expression, bool can_create); 721 722 virtual lldb::ValueObjectSP 723 GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create); 724 725 lldb::ValueObjectSP 726 GetDynamicValue (lldb::DynamicValueType valueType); 727 728 virtual lldb::ValueObjectSP 729 GetStaticValue (); 730 731 lldb::ValueObjectSP 732 GetSyntheticValue (lldb::SyntheticValueType use_synthetic); 733 734 virtual bool 735 HasSyntheticValue(); 736 737 virtual lldb::ValueObjectSP 738 CreateConstantValue (const ConstString &name); 739 740 virtual lldb::ValueObjectSP 741 Dereference (Error &error); 742 743 virtual lldb::ValueObjectSP 744 AddressOf (Error &error); 745 746 virtual lldb::ValueObjectSP 747 CastPointerType (const char *name, 748 ClangASTType &ast_type); 749 750 virtual lldb::ValueObjectSP 751 CastPointerType (const char *name, 752 lldb::TypeSP &type_sp); 753 754 // The backing bits of this value object were updated, clear any 755 // descriptive string, so we know we have to refetch them 756 virtual void 757 ValueUpdated () 758 { 759 m_value_str.clear(); 760 m_summary_str.clear(); 761 m_object_desc_str.clear(); 762 } 763 764 virtual bool 765 IsDynamic () 766 { 767 return false; 768 } 769 770 virtual SymbolContextScope * 771 GetSymbolContextScope(); 772 773 static void 774 DumpValueObject (Stream &s, 775 ValueObject *valobj) 776 { 777 778 if (!valobj) 779 return; 780 781 ValueObject::DumpValueObject(s, 782 valobj, 783 DumpValueObjectOptions::DefaultOptions()); 784 } 785 786 static void 787 DumpValueObject (Stream &s, 788 ValueObject *valobj, 789 const char *root_valobj_name) 790 { 791 792 if (!valobj) 793 return; 794 795 ValueObject::DumpValueObject(s, 796 valobj, 797 root_valobj_name, 798 DumpValueObjectOptions::DefaultOptions()); 799 } 800 801 static void 802 DumpValueObject (Stream &s, 803 ValueObject *valobj, 804 const DumpValueObjectOptions& options) 805 { 806 807 if (!valobj) 808 return; 809 810 ValueObject::DumpValueObject(s, 811 valobj, 812 valobj->GetName().AsCString(), 813 options.m_ptr_depth, 814 0, 815 options.m_max_depth, 816 options.m_show_types, 817 options.m_show_location, 818 options.m_use_objc, 819 options.m_use_dynamic, 820 options.m_use_synthetic, 821 options.m_scope_already_checked, 822 options.m_flat_output, 823 options.m_omit_summary_depth, 824 options.m_ignore_cap); 825 } 826 827 static void 828 DumpValueObject (Stream &s, 829 ValueObject *valobj, 830 const char *root_valobj_name, 831 const DumpValueObjectOptions& options) 832 { 833 834 if (!valobj) 835 return; 836 837 ValueObject::DumpValueObject(s, 838 valobj, 839 root_valobj_name, 840 options.m_ptr_depth, 841 0, 842 options.m_max_depth, 843 options.m_show_types, 844 options.m_show_location, 845 options.m_use_objc, 846 options.m_use_dynamic, 847 options.m_use_synthetic, 848 options.m_scope_already_checked, 849 options.m_flat_output, 850 options.m_omit_summary_depth, 851 options.m_ignore_cap); 852 } 853 854 static void 855 DumpValueObject (Stream &s, 856 ValueObject *valobj, 857 const char *root_valobj_name, 858 uint32_t ptr_depth, 859 uint32_t curr_depth, 860 uint32_t max_depth, 861 bool show_types, 862 bool show_location, 863 bool use_objc, 864 lldb::DynamicValueType use_dynamic, 865 bool use_synthetic, 866 bool scope_already_checked, 867 bool flat_output, 868 uint32_t omit_summary_depth, 869 bool ignore_cap); 870 871 // returns true if this is a char* or a char[] 872 // if it is a char* and check_pointer is true, 873 // it also checks that the pointer is valid 874 bool 875 IsCStringContainer (bool check_pointer = false); 876 877 void 878 ReadPointedString (Stream& s, 879 Error& error, 880 uint32_t max_length = 0, 881 bool honor_array = true, 882 lldb::Format item_format = lldb::eFormatCharArray); 883 884 virtual size_t 885 GetPointeeData (DataExtractor& data, 886 uint32_t item_idx = 0, 887 uint32_t item_count = 1); 888 889 virtual size_t 890 GetData (DataExtractor& data); 891 892 bool 893 GetIsConstant () const 894 { 895 return m_update_point.IsConstant(); 896 } 897 898 void 899 SetIsConstant () 900 { 901 m_update_point.SetIsConstant(); 902 } 903 904 lldb::Format 905 GetFormat () const 906 { 907 if (m_parent && m_format == lldb::eFormatDefault) 908 return m_parent->GetFormat(); 909 return m_format; 910 } 911 912 void 913 SetFormat (lldb::Format format) 914 { 915 if (format != m_format) 916 m_value_str.clear(); 917 m_format = format; 918 } 919 920 void 921 SetCustomSummaryFormat(lldb::SummaryFormatSP format) 922 { 923 m_forced_summary_format = format; 924 m_user_id_of_forced_summary = m_update_point.GetModID(); 925 m_summary_str.clear(); 926 m_trying_summary_already = false; 927 } 928 929 lldb::SummaryFormatSP 930 GetCustomSummaryFormat() 931 { 932 return m_forced_summary_format; 933 } 934 935 void 936 ClearCustomSummaryFormat() 937 { 938 m_forced_summary_format.reset(); 939 m_summary_str.clear(); 940 } 941 942 bool 943 HasCustomSummaryFormat() 944 { 945 return (m_forced_summary_format.get()); 946 } 947 948 lldb::SummaryFormatSP 949 GetSummaryFormat() 950 { 951 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 952 if (HasCustomSummaryFormat()) 953 return m_forced_summary_format; 954 return m_last_summary_format; 955 } 956 957 void 958 SetSummaryFormat(lldb::SummaryFormatSP format) 959 { 960 m_last_summary_format = format; 961 m_summary_str.clear(); 962 m_trying_summary_already = false; 963 } 964 965 void 966 SetValueFormat(lldb::ValueFormatSP format) 967 { 968 m_last_value_format = format; 969 m_value_str.clear(); 970 } 971 972 lldb::ValueFormatSP 973 GetValueFormat() 974 { 975 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 976 return m_last_value_format; 977 } 978 979 void 980 SetSyntheticChildren(lldb::SyntheticChildrenSP synth) 981 { 982 m_last_synthetic_filter = synth; 983 m_synthetic_value = NULL; 984 } 985 986 lldb::SyntheticChildrenSP 987 GetSyntheticChildren() 988 { 989 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 990 return m_last_synthetic_filter; 991 } 992 993 // Use GetParent for display purposes, but if you want to tell the parent to update itself 994 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 995 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 996 virtual ValueObject * 997 GetParent() 998 { 999 return m_parent; 1000 } 1001 1002 virtual const ValueObject * 1003 GetParent() const 1004 { 1005 return m_parent; 1006 } 1007 1008 ValueObject * 1009 GetNonBaseClassParent(); 1010 1011 void 1012 SetAddressTypeOfChildren(AddressType at) 1013 { 1014 m_address_type_of_ptr_or_ref_children = at; 1015 } 1016 1017 AddressType 1018 GetAddressTypeOfChildren() 1019 { 1020 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 1021 { 1022 if (m_parent) 1023 return m_parent->GetAddressTypeOfChildren(); 1024 } 1025 return m_address_type_of_ptr_or_ref_children; 1026 } 1027 1028protected: 1029 typedef ClusterManager<ValueObject> ValueObjectManager; 1030 1031 //------------------------------------------------------------------ 1032 // Classes that inherit from ValueObject can see and modify these 1033 //------------------------------------------------------------------ 1034 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1035 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1036 // updated. When we are asked to update the value object, we check whether 1037 // the context & stop id are the same before updating. 1038 ConstString m_name; // The name of this object 1039 DataExtractor m_data; // A data extractor that can be used to extract the value. 1040 Value m_value; 1041 Error m_error; // An error object that can describe any errors that occur when updating values. 1042 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1043 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1044 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1045 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1046 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1047 // in that the summary is consed up by us, the object_desc_string is builtin. 1048 1049 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1050 // without a parent.) The manager gets passed through all the generations of 1051 // dependent objects, and will keep the whole cluster of objects alive as long 1052 // as a shared pointer to any of them has been handed out. Shared pointers to 1053 // value objects must always be made with the GetSP method. 1054 1055 std::vector<ValueObject *> m_children; 1056 std::map<ConstString, ValueObject *> m_synthetic_children; 1057 1058 ValueObject* m_dynamic_value; 1059 ValueObject* m_synthetic_value; 1060 ValueObject* m_deref_valobj; 1061 1062 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1063 // as an independent ValueObjectConstResult, which isn't managed by us. 1064 1065 lldb::Format m_format; 1066 uint32_t m_last_format_mgr_revision; 1067 lldb::DynamicValueType m_last_format_mgr_dynamic; 1068 lldb::SummaryFormatSP m_last_summary_format; 1069 lldb::SummaryFormatSP m_forced_summary_format; 1070 lldb::ValueFormatSP m_last_value_format; 1071 lldb::SyntheticChildrenSP m_last_synthetic_filter; 1072 ProcessModID m_user_id_of_forced_summary; 1073 AddressType m_address_type_of_ptr_or_ref_children; 1074 1075 bool m_value_is_valid:1, 1076 m_value_did_change:1, 1077 m_children_count_valid:1, 1078 m_old_value_valid:1, 1079 m_is_deref_of_parent:1, 1080 m_is_array_item_for_pointer:1, 1081 m_is_bitfield_for_scalar:1, 1082 m_is_expression_path_child:1, 1083 m_is_child_at_offset:1, 1084 m_trying_summary_already:1; // used to prevent endless recursion in printing summaries 1085 1086 friend class ClangExpressionDeclMap; // For GetValue 1087 friend class ClangExpressionVariable; // For SetName 1088 friend class Target; // For SetName 1089 friend class ValueObjectConstResultImpl; 1090 1091 //------------------------------------------------------------------ 1092 // Constructors and Destructors 1093 //------------------------------------------------------------------ 1094 1095 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1096 1097 ValueObject(); 1098 1099 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1100 // through-out its lifespan. 1101 1102 ValueObject (ExecutionContextScope *exe_scope, 1103 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1104 1105 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1106 // of its parent. 1107 1108 ValueObject (ValueObject &parent); 1109 1110 ValueObjectManager * 1111 GetManager() 1112 { 1113 return m_manager; 1114 } 1115 1116 virtual bool 1117 UpdateValue () = 0; 1118 1119 virtual void 1120 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1121 1122 virtual void 1123 CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic); 1124 1125 // Should only be called by ValueObject::GetChildAtIndex() 1126 // Returns a ValueObject managed by this ValueObject's manager. 1127 virtual ValueObject * 1128 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1129 1130 // Should only be called by ValueObject::GetNumChildren() 1131 virtual uint32_t 1132 CalculateNumChildren() = 0; 1133 1134 void 1135 SetNumChildren (uint32_t num_children); 1136 1137 void 1138 SetValueDidChange (bool value_changed); 1139 1140 void 1141 SetValueIsValid (bool valid); 1142 1143 void 1144 ClearUserVisibleData(); 1145 1146 void 1147 AddSyntheticChild (const ConstString &key, 1148 ValueObject *valobj); 1149 1150 DataExtractor & 1151 GetDataExtractor (); 1152 1153private: 1154 //------------------------------------------------------------------ 1155 // For ValueObject only 1156 //------------------------------------------------------------------ 1157 1158 lldb::ValueObjectSP 1159 GetValueForExpressionPath_Impl(const char* expression_cstr, 1160 const char** first_unparsed, 1161 ExpressionPathScanEndReason* reason_to_stop, 1162 ExpressionPathEndResultType* final_value_type, 1163 const GetValueForExpressionPathOptions& options, 1164 ExpressionPathAftermath* final_task_on_target); 1165 1166 // this method will ONLY expand [] expressions into a VOList and return 1167 // the number of elements it added to the VOList 1168 // it will NOT loop through expanding the follow-up of the expression_cstr 1169 // for all objects in the list 1170 int 1171 ExpandArraySliceExpression(const char* expression_cstr, 1172 const char** first_unparsed, 1173 lldb::ValueObjectSP root, 1174 lldb::ValueObjectListSP& list, 1175 ExpressionPathScanEndReason* reason_to_stop, 1176 ExpressionPathEndResultType* final_value_type, 1177 const GetValueForExpressionPathOptions& options, 1178 ExpressionPathAftermath* final_task_on_target); 1179 1180 1181 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1182 1183}; 1184 1185} // namespace lldb_private 1186 1187#endif // liblldb_ValueObject_h_ 1188