ValueObject.h revision 3508c387c3f0c9ecc439d98048fd7694d41bab1b
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 lldb::Format m_override_format; 220 221 DumpValueObjectOptions() : 222 m_ptr_depth(0), 223 m_max_depth(UINT32_MAX), 224 m_show_types(false), 225 m_show_location(false), 226 m_use_objc(false), 227 m_use_dynamic(lldb::eNoDynamicValues), 228 m_use_synthetic(lldb::eUseSyntheticFilter), 229 m_scope_already_checked(false), 230 m_flat_output(false), 231 m_omit_summary_depth(0), 232 m_ignore_cap(false), 233 m_override_format (lldb::eFormatDefault) 234 {} 235 236 static const DumpValueObjectOptions 237 DefaultOptions() 238 { 239 static DumpValueObjectOptions g_default_options; 240 241 return g_default_options; 242 } 243 244 DumpValueObjectOptions& 245 SetPointerDepth(uint32_t depth = 0) 246 { 247 m_ptr_depth = depth; 248 return *this; 249 } 250 251 DumpValueObjectOptions& 252 SetMaximumDepth(uint32_t depth = 0) 253 { 254 m_max_depth = depth; 255 return *this; 256 } 257 258 DumpValueObjectOptions& 259 SetShowTypes(bool show = false) 260 { 261 m_show_types = show; 262 return *this; 263 } 264 265 DumpValueObjectOptions& 266 SetShowLocation(bool show = false) 267 { 268 m_show_location = show; 269 return *this; 270 } 271 272 DumpValueObjectOptions& 273 SetUseObjectiveC(bool use = false) 274 { 275 m_use_objc = use; 276 return *this; 277 } 278 279 DumpValueObjectOptions& 280 SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues) 281 { 282 m_use_dynamic = dyn; 283 return *this; 284 } 285 286 DumpValueObjectOptions& 287 SetUseSyntheticValue(lldb::SyntheticValueType syn = lldb::eUseSyntheticFilter) 288 { 289 m_use_synthetic = syn; 290 return *this; 291 } 292 293 DumpValueObjectOptions& 294 SetScopeChecked(bool check = true) 295 { 296 m_scope_already_checked = check; 297 return *this; 298 } 299 300 DumpValueObjectOptions& 301 SetFlatOutput(bool flat = false) 302 { 303 m_flat_output = flat; 304 return *this; 305 } 306 307 DumpValueObjectOptions& 308 SetOmitSummaryDepth(uint32_t depth = 0) 309 { 310 m_omit_summary_depth = depth; 311 return *this; 312 } 313 314 DumpValueObjectOptions& 315 SetIgnoreCap(bool ignore = false) 316 { 317 m_ignore_cap = ignore; 318 return *this; 319 } 320 321 DumpValueObjectOptions& 322 SetRawDisplay(bool raw = false) 323 { 324 if (raw) 325 { 326 SetUseSyntheticValue(lldb::eNoSyntheticFilter); 327 SetOmitSummaryDepth(UINT32_MAX); 328 SetIgnoreCap(true); 329 } 330 else 331 { 332 SetUseSyntheticValue(lldb::eUseSyntheticFilter); 333 SetOmitSummaryDepth(0); 334 SetIgnoreCap(false); 335 } 336 return *this; 337 } 338 339 }; 340 341 class EvaluationPoint 342 { 343 public: 344 345 EvaluationPoint (); 346 347 EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false); 348 349 EvaluationPoint (const EvaluationPoint &rhs); 350 351 ~EvaluationPoint (); 352 353 const ExecutionContextRef & 354 GetExecutionContextRef() const 355 { 356 return m_exe_ctx_ref; 357 } 358 359 // Set the EvaluationPoint to the values in exe_scope, 360 // Return true if the Evaluation Point changed. 361 // Since the ExecutionContextScope is always going to be valid currently, 362 // the Updated Context will also always be valid. 363 364// bool 365// SetContext (ExecutionContextScope *exe_scope); 366 367 void 368 SetIsConstant () 369 { 370 SetUpdated(); 371 m_mod_id.SetInvalid(); 372 } 373 374 bool 375 IsConstant () const 376 { 377 return !m_mod_id.IsValid(); 378 } 379 380 ProcessModID 381 GetModID () const 382 { 383 return m_mod_id; 384 } 385 386 void 387 SetUpdateID (ProcessModID new_id) 388 { 389 m_mod_id = new_id; 390 } 391 392 bool 393 IsFirstEvaluation () const 394 { 395 return m_first_update; 396 } 397 398 void 399 SetNeedsUpdate () 400 { 401 m_needs_update = true; 402 } 403 404 void 405 SetUpdated (); 406 407 bool 408 NeedsUpdating() 409 { 410 SyncWithProcessState(); 411 return m_needs_update; 412 } 413 414 bool 415 IsValid () 416 { 417 if (!m_mod_id.IsValid()) 418 return false; 419 else if (SyncWithProcessState ()) 420 { 421 if (!m_mod_id.IsValid()) 422 return false; 423 } 424 return true; 425 } 426 427 void 428 SetInvalid () 429 { 430 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 431 // history purposes. 432 m_mod_id.SetInvalid(); 433 434 // Can't update an invalid state. 435 m_needs_update = false; 436 437 } 438 439 private: 440 bool 441 SyncWithProcessState (); 442 443 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. 444 ExecutionContextRef m_exe_ctx_ref; 445 bool m_needs_update; 446 bool m_first_update; 447 }; 448 449 const EvaluationPoint & 450 GetUpdatePoint () const 451 { 452 return m_update_point; 453 } 454 455 EvaluationPoint & 456 GetUpdatePoint () 457 { 458 return m_update_point; 459 } 460 461 const ExecutionContextRef & 462 GetExecutionContextRef() const 463 { 464 return m_update_point.GetExecutionContextRef(); 465 } 466 467 lldb::TargetSP 468 GetTargetSP() const 469 { 470 return m_update_point.GetExecutionContextRef().GetTargetSP(); 471 } 472 473 lldb::ProcessSP 474 GetProcessSP() const 475 { 476 return m_update_point.GetExecutionContextRef().GetProcessSP(); 477 } 478 479 lldb::ThreadSP 480 GetThreadSP() const 481 { 482 return m_update_point.GetExecutionContextRef().GetThreadSP(); 483 } 484 485 lldb::StackFrameSP 486 GetFrameSP() const 487 { 488 return m_update_point.GetExecutionContextRef().GetFrameSP(); 489 } 490 491 void 492 SetNeedsUpdate (); 493 494 virtual ~ValueObject(); 495 496 clang::ASTContext * 497 GetClangAST (); 498 499 lldb::clang_type_t 500 GetClangType (); 501 502 //------------------------------------------------------------------ 503 // Sublasses must implement the functions below. 504 //------------------------------------------------------------------ 505 virtual size_t 506 GetByteSize() = 0; 507 508 virtual lldb::ValueType 509 GetValueType() const = 0; 510 511 virtual ConstString 512 GetTypeName() = 0; 513 514 //------------------------------------------------------------------ 515 // Sublasses can implement the functions below. 516 //------------------------------------------------------------------ 517 virtual lldb::LanguageType 518 GetObjectRuntimeLanguage(); 519 520 virtual bool 521 IsPointerType (); 522 523 virtual bool 524 IsArrayType (); 525 526 virtual bool 527 IsScalarType (); 528 529 virtual bool 530 IsPointerOrReferenceType (); 531 532 virtual bool 533 IsPossibleCPlusPlusDynamicType (); 534 535 virtual bool 536 IsPossibleDynamicType (); 537 538 virtual bool 539 IsBaseClass () 540 { 541 return false; 542 } 543 544 virtual bool 545 IsDereferenceOfParent () 546 { 547 return false; 548 } 549 550 bool 551 IsIntegerType (bool &is_signed); 552 553 virtual bool 554 GetBaseClassPath (Stream &s); 555 556 virtual void 557 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eDereferencePointers); 558 559 lldb::ValueObjectSP 560 GetValueForExpressionPath(const char* expression, 561 const char** first_unparsed = NULL, 562 ExpressionPathScanEndReason* reason_to_stop = NULL, 563 ExpressionPathEndResultType* final_value_type = NULL, 564 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 565 ExpressionPathAftermath* final_task_on_target = NULL); 566 567 int 568 GetValuesForExpressionPath(const char* expression, 569 lldb::ValueObjectListSP& list, 570 const char** first_unparsed = NULL, 571 ExpressionPathScanEndReason* reason_to_stop = NULL, 572 ExpressionPathEndResultType* final_value_type = NULL, 573 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 574 ExpressionPathAftermath* final_task_on_target = NULL); 575 576 virtual bool 577 IsInScope () 578 { 579 return true; 580 } 581 582 virtual off_t 583 GetByteOffset() 584 { 585 return 0; 586 } 587 588 virtual uint32_t 589 GetBitfieldBitSize() 590 { 591 return 0; 592 } 593 594 virtual uint32_t 595 GetBitfieldBitOffset() 596 { 597 return 0; 598 } 599 600 virtual bool 601 IsArrayItemForPointer() 602 { 603 return m_is_array_item_for_pointer; 604 } 605 606 virtual bool 607 SetClangAST (clang::ASTContext *ast) 608 { 609 return false; 610 } 611 612 virtual const char * 613 GetValueAsCString (); 614 615 virtual uint64_t 616 GetValueAsUnsigned (uint64_t fail_value); 617 618 virtual bool 619 SetValueFromCString (const char *value_str); 620 621 // Return the module associated with this value object in case the 622 // value is from an executable file and might have its data in 623 // sections of the file. This can be used for variables. 624 virtual lldb::ModuleSP 625 GetModule() 626 { 627 if (m_parent) 628 return m_parent->GetModule(); 629 return lldb::ModuleSP(); 630 } 631 632 virtual bool 633 GetDeclaration (Declaration &decl); 634 635 //------------------------------------------------------------------ 636 // The functions below should NOT be modified by sublasses 637 //------------------------------------------------------------------ 638 const Error & 639 GetError(); 640 641 const ConstString & 642 GetName() const; 643 644 virtual lldb::ValueObjectSP 645 GetChildAtIndex (uint32_t idx, bool can_create); 646 647 virtual lldb::ValueObjectSP 648 GetChildMemberWithName (const ConstString &name, bool can_create); 649 650 virtual uint32_t 651 GetIndexOfChildWithName (const ConstString &name); 652 653 uint32_t 654 GetNumChildren (); 655 656 const Value & 657 GetValue() const; 658 659 Value & 660 GetValue(); 661 662 virtual bool 663 ResolveValue (Scalar &scalar); 664 665 const char * 666 GetLocationAsCString (); 667 668 const char * 669 GetSummaryAsCString (); 670 671 const char * 672 GetObjectDescription (); 673 674 bool 675 GetPrintableRepresentation(Stream& s, 676 ValueObjectRepresentationStyle val_obj_display = eDisplaySummary, 677 lldb::Format custom_format = lldb::eFormatInvalid); 678 679 bool 680 HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, 681 lldb::Format custom_format); 682 683 bool 684 DumpPrintableRepresentation(Stream& s, 685 ValueObjectRepresentationStyle val_obj_display = eDisplaySummary, 686 lldb::Format custom_format = lldb::eFormatInvalid, 687 bool only_special = false); 688 bool 689 GetValueIsValid () const; 690 691 bool 692 GetValueDidChange (); 693 694 bool 695 UpdateValueIfNeeded (bool update_format = true); 696 697 bool 698 UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true); 699 700 bool 701 UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues); 702 703 lldb::ValueObjectSP 704 GetSP () 705 { 706 return m_manager->GetSharedPointer(this); 707 } 708 709 void 710 SetName (const ConstString &name); 711 712 virtual lldb::addr_t 713 GetAddressOf (bool scalar_is_load_address = true, 714 AddressType *address_type = NULL); 715 716 lldb::addr_t 717 GetPointerValue (AddressType *address_type = NULL); 718 719 lldb::ValueObjectSP 720 GetSyntheticChild (const ConstString &key) const; 721 722 lldb::ValueObjectSP 723 GetSyntheticArrayMember (int32_t index, bool can_create); 724 725 lldb::ValueObjectSP 726 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 727 728 lldb::ValueObjectSP 729 GetSyntheticArrayMemberFromArray (int32_t index, bool can_create); 730 731 lldb::ValueObjectSP 732 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create); 733 734 lldb::ValueObjectSP 735 GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create); 736 737 lldb::ValueObjectSP 738 GetSyntheticExpressionPathChild(const char* expression, bool can_create); 739 740 virtual lldb::ValueObjectSP 741 GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create); 742 743 lldb::ValueObjectSP 744 GetDynamicValue (lldb::DynamicValueType valueType); 745 746 virtual lldb::ValueObjectSP 747 GetStaticValue (); 748 749 lldb::ValueObjectSP 750 GetSyntheticValue (lldb::SyntheticValueType use_synthetic); 751 752 virtual bool 753 HasSyntheticValue(); 754 755 virtual lldb::ValueObjectSP 756 CreateConstantValue (const ConstString &name); 757 758 virtual lldb::ValueObjectSP 759 Dereference (Error &error); 760 761 virtual lldb::ValueObjectSP 762 AddressOf (Error &error); 763 764 virtual lldb::addr_t 765 GetLiveAddress() 766 { 767 return LLDB_INVALID_ADDRESS; 768 } 769 770 virtual void 771 SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS, 772 AddressType address_type = eAddressTypeLoad) 773 { 774 } 775 776 virtual lldb::ValueObjectSP 777 Cast (const ClangASTType &clang_ast_type); 778 779 virtual lldb::ValueObjectSP 780 CastPointerType (const char *name, 781 ClangASTType &ast_type); 782 783 virtual lldb::ValueObjectSP 784 CastPointerType (const char *name, 785 lldb::TypeSP &type_sp); 786 787 // The backing bits of this value object were updated, clear any 788 // descriptive string, so we know we have to refetch them 789 virtual void 790 ValueUpdated () 791 { 792 m_value_str.clear(); 793 m_summary_str.clear(); 794 m_object_desc_str.clear(); 795 } 796 797 virtual bool 798 IsDynamic () 799 { 800 return false; 801 } 802 803 virtual SymbolContextScope * 804 GetSymbolContextScope(); 805 806 static void 807 DumpValueObject (Stream &s, 808 ValueObject *valobj) 809 { 810 811 if (!valobj) 812 return; 813 814 ValueObject::DumpValueObject(s, 815 valobj, 816 DumpValueObjectOptions::DefaultOptions()); 817 } 818 819 static void 820 DumpValueObject (Stream &s, 821 ValueObject *valobj, 822 const char *root_valobj_name) 823 { 824 825 if (!valobj) 826 return; 827 828 ValueObject::DumpValueObject(s, 829 valobj, 830 root_valobj_name, 831 DumpValueObjectOptions::DefaultOptions()); 832 } 833 834 static void 835 DumpValueObject (Stream &s, 836 ValueObject *valobj, 837 const DumpValueObjectOptions& options, 838 lldb::Format format = lldb::eFormatDefault) 839 { 840 841 if (!valobj) 842 return; 843 844 ValueObject::DumpValueObject(s, 845 valobj, 846 valobj->GetName().AsCString(), 847 options.m_ptr_depth, 848 0, 849 options.m_max_depth, 850 options.m_show_types, 851 options.m_show_location, 852 options.m_use_objc, 853 options.m_use_dynamic, 854 options.m_use_synthetic, 855 options.m_scope_already_checked, 856 options.m_flat_output, 857 options.m_omit_summary_depth, 858 options.m_ignore_cap, 859 format); 860 } 861 862 static void 863 DumpValueObject (Stream &s, 864 ValueObject *valobj, 865 const char *root_valobj_name, 866 const DumpValueObjectOptions& options, 867 lldb::Format format = lldb::eFormatDefault) 868 { 869 870 if (!valobj) 871 return; 872 873 ValueObject::DumpValueObject(s, 874 valobj, 875 root_valobj_name, 876 options.m_ptr_depth, 877 0, 878 options.m_max_depth, 879 options.m_show_types, 880 options.m_show_location, 881 options.m_use_objc, 882 options.m_use_dynamic, 883 options.m_use_synthetic, 884 options.m_scope_already_checked, 885 options.m_flat_output, 886 options.m_omit_summary_depth, 887 options.m_ignore_cap, 888 format); 889 } 890 891 static void 892 DumpValueObject (Stream &s, 893 ValueObject *valobj, 894 const char *root_valobj_name, 895 uint32_t ptr_depth, 896 uint32_t curr_depth, 897 uint32_t max_depth, 898 bool show_types, 899 bool show_location, 900 bool use_objc, 901 lldb::DynamicValueType use_dynamic, 902 bool use_synthetic, 903 bool scope_already_checked, 904 bool flat_output, 905 uint32_t omit_summary_depth, 906 bool ignore_cap, 907 lldb::Format format = lldb::eFormatDefault); 908 909 // returns true if this is a char* or a char[] 910 // if it is a char* and check_pointer is true, 911 // it also checks that the pointer is valid 912 bool 913 IsCStringContainer (bool check_pointer = false); 914 915 void 916 ReadPointedString (Stream& s, 917 Error& error, 918 uint32_t max_length = 0, 919 bool honor_array = true, 920 lldb::Format item_format = lldb::eFormatCharArray); 921 922 virtual size_t 923 GetPointeeData (DataExtractor& data, 924 uint32_t item_idx = 0, 925 uint32_t item_count = 1); 926 927 virtual size_t 928 GetData (DataExtractor& data); 929 930 bool 931 GetIsConstant () const 932 { 933 return m_update_point.IsConstant(); 934 } 935 936 void 937 SetIsConstant () 938 { 939 m_update_point.SetIsConstant(); 940 } 941 942 lldb::Format 943 GetFormat () const 944 { 945 if (m_parent && m_format == lldb::eFormatDefault) 946 return m_parent->GetFormat(); 947 return m_format; 948 } 949 950 void 951 SetFormat (lldb::Format format) 952 { 953 if (format != m_format) 954 m_value_str.clear(); 955 m_format = format; 956 } 957 958 void 959 SetCustomSummaryFormat(lldb::TypeSummaryImplSP format) 960 { 961 m_forced_summary_format = format; 962 m_user_id_of_forced_summary = m_update_point.GetModID(); 963 m_summary_str.clear(); 964 m_is_getting_summary = false; 965 } 966 967 lldb::TypeSummaryImplSP 968 GetCustomSummaryFormat() 969 { 970 return m_forced_summary_format; 971 } 972 973 void 974 ClearCustomSummaryFormat() 975 { 976 m_forced_summary_format.reset(); 977 m_summary_str.clear(); 978 } 979 980 bool 981 HasCustomSummaryFormat() 982 { 983 return (m_forced_summary_format.get()); 984 } 985 986 lldb::TypeSummaryImplSP 987 GetSummaryFormat() 988 { 989 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 990 if (HasCustomSummaryFormat()) 991 return m_forced_summary_format; 992 return m_last_summary_format; 993 } 994 995 void 996 SetSummaryFormat(lldb::TypeSummaryImplSP format) 997 { 998 m_last_summary_format = format; 999 m_summary_str.clear(); 1000 m_is_getting_summary = false; 1001 } 1002 1003 void 1004 SetValueFormat(lldb::TypeFormatImplSP format) 1005 { 1006 m_last_value_format = format; 1007 m_value_str.clear(); 1008 } 1009 1010 lldb::TypeFormatImplSP 1011 GetValueFormat() 1012 { 1013 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1014 return m_last_value_format; 1015 } 1016 1017 void 1018 SetSyntheticChildren(lldb::SyntheticChildrenSP synth) 1019 { 1020 m_last_synthetic_filter = synth; 1021 m_synthetic_value = NULL; 1022 } 1023 1024 lldb::SyntheticChildrenSP 1025 GetSyntheticChildren() 1026 { 1027 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1028 return m_last_synthetic_filter; 1029 } 1030 1031 // Use GetParent for display purposes, but if you want to tell the parent to update itself 1032 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 1033 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 1034 virtual ValueObject * 1035 GetParent() 1036 { 1037 return m_parent; 1038 } 1039 1040 virtual const ValueObject * 1041 GetParent() const 1042 { 1043 return m_parent; 1044 } 1045 1046 ValueObject * 1047 GetNonBaseClassParent(); 1048 1049 void 1050 SetAddressTypeOfChildren(AddressType at) 1051 { 1052 m_address_type_of_ptr_or_ref_children = at; 1053 } 1054 1055 AddressType 1056 GetAddressTypeOfChildren() 1057 { 1058 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 1059 { 1060 if (m_parent) 1061 return m_parent->GetAddressTypeOfChildren(); 1062 } 1063 return m_address_type_of_ptr_or_ref_children; 1064 } 1065 1066protected: 1067 typedef ClusterManager<ValueObject> ValueObjectManager; 1068 1069 //------------------------------------------------------------------ 1070 // Classes that inherit from ValueObject can see and modify these 1071 //------------------------------------------------------------------ 1072 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1073 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1074 // updated. When we are asked to update the value object, we check whether 1075 // the context & stop id are the same before updating. 1076 ConstString m_name; // The name of this object 1077 DataExtractor m_data; // A data extractor that can be used to extract the value. 1078 Value m_value; 1079 Error m_error; // An error object that can describe any errors that occur when updating values. 1080 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1081 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1082 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1083 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1084 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1085 // in that the summary is consed up by us, the object_desc_string is builtin. 1086 1087 ClangASTType m_override_type;// If the type of the value object should be overridden, the type to impose. 1088 1089 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1090 // without a parent.) The manager gets passed through all the generations of 1091 // dependent objects, and will keep the whole cluster of objects alive as long 1092 // as a shared pointer to any of them has been handed out. Shared pointers to 1093 // value objects must always be made with the GetSP method. 1094 1095 std::vector<ValueObject *> m_children; 1096 std::map<ConstString, ValueObject *> m_synthetic_children; 1097 1098 ValueObject* m_dynamic_value; 1099 ValueObject* m_synthetic_value; 1100 ValueObject* m_deref_valobj; 1101 1102 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1103 // as an independent ValueObjectConstResult, which isn't managed by us. 1104 1105 lldb::Format m_format; 1106 uint32_t m_last_format_mgr_revision; 1107 lldb::DynamicValueType m_last_format_mgr_dynamic; 1108 lldb::TypeSummaryImplSP m_last_summary_format; 1109 lldb::TypeSummaryImplSP m_forced_summary_format; 1110 lldb::TypeFormatImplSP m_last_value_format; 1111 lldb::SyntheticChildrenSP m_last_synthetic_filter; 1112 ProcessModID m_user_id_of_forced_summary; 1113 AddressType m_address_type_of_ptr_or_ref_children; 1114 1115 bool m_value_is_valid:1, 1116 m_value_did_change:1, 1117 m_children_count_valid:1, 1118 m_old_value_valid:1, 1119 m_is_deref_of_parent:1, 1120 m_is_array_item_for_pointer:1, 1121 m_is_bitfield_for_scalar:1, 1122 m_is_expression_path_child:1, 1123 m_is_child_at_offset:1, 1124 m_is_getting_summary:1, 1125 m_did_calculate_complete_objc_class_type:1; 1126 1127 friend class ClangExpressionDeclMap; // For GetValue 1128 friend class ClangExpressionVariable; // For SetName 1129 friend class Target; // For SetName 1130 friend class ValueObjectConstResultImpl; 1131 1132 //------------------------------------------------------------------ 1133 // Constructors and Destructors 1134 //------------------------------------------------------------------ 1135 1136 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1137 1138 ValueObject(); 1139 1140 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1141 // through-out its lifespan. 1142 1143 ValueObject (ExecutionContextScope *exe_scope, 1144 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1145 1146 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1147 // of its parent. 1148 1149 ValueObject (ValueObject &parent); 1150 1151 ValueObjectManager * 1152 GetManager() 1153 { 1154 return m_manager; 1155 } 1156 1157 virtual bool 1158 UpdateValue () = 0; 1159 1160 virtual void 1161 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1162 1163 virtual void 1164 CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic); 1165 1166 // Should only be called by ValueObject::GetChildAtIndex() 1167 // Returns a ValueObject managed by this ValueObject's manager. 1168 virtual ValueObject * 1169 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1170 1171 // Should only be called by ValueObject::GetNumChildren() 1172 virtual uint32_t 1173 CalculateNumChildren() = 0; 1174 1175 void 1176 SetNumChildren (uint32_t num_children); 1177 1178 void 1179 SetValueDidChange (bool value_changed); 1180 1181 void 1182 SetValueIsValid (bool valid); 1183 1184 void 1185 ClearUserVisibleData(); 1186 1187 void 1188 AddSyntheticChild (const ConstString &key, 1189 ValueObject *valobj); 1190 1191 DataExtractor & 1192 GetDataExtractor (); 1193 1194 //------------------------------------------------------------------ 1195 // Sublasses must implement the functions below. 1196 //------------------------------------------------------------------ 1197 1198 virtual clang::ASTContext * 1199 GetClangASTImpl () = 0; 1200 1201 virtual lldb::clang_type_t 1202 GetClangTypeImpl () = 0; 1203 1204private: 1205 //------------------------------------------------------------------ 1206 // For ValueObject only 1207 //------------------------------------------------------------------ 1208 1209 virtual ClangASTType 1210 MaybeCalculateCompleteType (); 1211 1212 lldb::ValueObjectSP 1213 GetValueForExpressionPath_Impl(const char* expression_cstr, 1214 const char** first_unparsed, 1215 ExpressionPathScanEndReason* reason_to_stop, 1216 ExpressionPathEndResultType* final_value_type, 1217 const GetValueForExpressionPathOptions& options, 1218 ExpressionPathAftermath* final_task_on_target); 1219 1220 // this method will ONLY expand [] expressions into a VOList and return 1221 // the number of elements it added to the VOList 1222 // it will NOT loop through expanding the follow-up of the expression_cstr 1223 // for all objects in the list 1224 int 1225 ExpandArraySliceExpression(const char* expression_cstr, 1226 const char** first_unparsed, 1227 lldb::ValueObjectSP root, 1228 lldb::ValueObjectListSP& list, 1229 ExpressionPathScanEndReason* reason_to_stop, 1230 ExpressionPathEndResultType* final_value_type, 1231 const GetValueForExpressionPathOptions& options, 1232 ExpressionPathAftermath* final_task_on_target); 1233 1234 1235 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1236 1237}; 1238 1239} // namespace lldb_private 1240 1241#endif // liblldb_ValueObject_h_ 1242