ValueObject.h revision ccf4450f17759b2e6f15eb12134f88a0128dfde7
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 : public ExecutionContextScope 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 lldb::TargetSP & 354 GetTargetSP () const 355 { 356 return m_target_sp; 357 } 358 359 const lldb::ProcessSP & 360 GetProcessSP () const 361 { 362 return m_process_sp; 363 } 364 365 // Set the EvaluationPoint to the values in exe_scope, 366 // Return true if the Evaluation Point changed. 367 // Since the ExecutionContextScope is always going to be valid currently, 368 // the Updated Context will also always be valid. 369 370 bool 371 SetContext (ExecutionContextScope *exe_scope); 372 373 void 374 SetIsConstant () 375 { 376 SetUpdated(); 377 m_mod_id.SetInvalid(); 378 } 379 380 bool 381 IsConstant () const 382 { 383 return !m_mod_id.IsValid(); 384 } 385 386 ProcessModID 387 GetModID () const 388 { 389 return m_mod_id; 390 } 391 392 void 393 SetUpdateID (ProcessModID new_id) 394 { 395 m_mod_id = new_id; 396 } 397 398 bool 399 IsFirstEvaluation () const 400 { 401 return m_first_update; 402 } 403 404 void 405 SetNeedsUpdate () 406 { 407 m_needs_update = true; 408 } 409 410 void 411 SetUpdated (); 412 413 bool 414 NeedsUpdating() 415 { 416 SyncWithProcessState(); 417 return m_needs_update; 418 } 419 420 bool 421 IsValid () 422 { 423 if (!m_mod_id.IsValid()) 424 return false; 425 else if (SyncWithProcessState ()) 426 { 427 if (!m_mod_id.IsValid()) 428 return false; 429 } 430 return true; 431 } 432 433 void 434 SetInvalid () 435 { 436 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 437 // history purposes. 438 m_mod_id.SetInvalid(); 439 440 // Can't update an invalid state. 441 m_needs_update = false; 442 443 } 444 445 // If this EvaluationPoint is created without a target, then we could have it 446 // hand out a NULL ExecutionContextScope. But then everybody would have to check that before 447 // calling through it, which is annoying. So instead, we make the EvaluationPoint BE an 448 // ExecutionContextScope, and it hands out the right things. 449 virtual Target *CalculateTarget (); 450 451 virtual Process *CalculateProcess (); 452 453 virtual Thread *CalculateThread (); 454 455 virtual StackFrame *CalculateStackFrame (); 456 457 virtual void CalculateExecutionContext (ExecutionContext &exe_ctx); 458 459 private: 460 bool 461 SyncWithProcessState () 462 { 463 ExecutionContextScope *exe_scope; 464 return SyncWithProcessState(exe_scope); 465 } 466 467 bool 468 SyncWithProcessState (ExecutionContextScope *&exe_scope); 469 470 bool m_needs_update; 471 bool m_first_update; 472 473 lldb::TargetSP m_target_sp; 474 lldb::ProcessSP m_process_sp; 475 lldb::user_id_t m_thread_id; 476 StackID m_stack_id; 477 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. 478 }; 479 480 const EvaluationPoint & 481 GetUpdatePoint () const 482 { 483 return m_update_point; 484 } 485 486 EvaluationPoint & 487 GetUpdatePoint () 488 { 489 return m_update_point; 490 } 491 492 ExecutionContextScope * 493 GetExecutionContextScope () 494 { 495 return &m_update_point; 496 } 497 498 void 499 SetNeedsUpdate (); 500 501 virtual ~ValueObject(); 502 503 //------------------------------------------------------------------ 504 // Sublasses must implement the functions below. 505 //------------------------------------------------------------------ 506 virtual size_t 507 GetByteSize() = 0; 508 509 virtual clang::ASTContext * 510 GetClangAST () = 0; 511 512 virtual lldb::clang_type_t 513 GetClangType () = 0; 514 515 virtual lldb::ValueType 516 GetValueType() const = 0; 517 518 virtual ConstString 519 GetTypeName() = 0; 520 521 virtual lldb::LanguageType 522 GetObjectRuntimeLanguage(); 523 524 virtual bool 525 IsPointerType (); 526 527 virtual bool 528 IsArrayType (); 529 530 virtual bool 531 IsScalarType (); 532 533 virtual bool 534 IsPointerOrReferenceType (); 535 536 virtual bool 537 IsPossibleCPlusPlusDynamicType (); 538 539 virtual bool 540 IsPossibleDynamicType (); 541 542 virtual bool 543 IsBaseClass () 544 { 545 return false; 546 } 547 548 virtual bool 549 IsDereferenceOfParent () 550 { 551 return false; 552 } 553 554 bool 555 IsIntegerType (bool &is_signed); 556 557 virtual bool 558 GetBaseClassPath (Stream &s); 559 560 virtual void 561 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eDereferencePointers); 562 563 lldb::ValueObjectSP 564 GetValueForExpressionPath(const char* expression, 565 const char** first_unparsed = NULL, 566 ExpressionPathScanEndReason* reason_to_stop = NULL, 567 ExpressionPathEndResultType* final_value_type = NULL, 568 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 569 ExpressionPathAftermath* final_task_on_target = NULL); 570 571 int 572 GetValuesForExpressionPath(const char* expression, 573 lldb::ValueObjectListSP& list, 574 const char** first_unparsed = NULL, 575 ExpressionPathScanEndReason* reason_to_stop = NULL, 576 ExpressionPathEndResultType* final_value_type = NULL, 577 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 578 ExpressionPathAftermath* final_task_on_target = NULL); 579 580 virtual bool 581 IsInScope () 582 { 583 return true; 584 } 585 586 virtual off_t 587 GetByteOffset() 588 { 589 return 0; 590 } 591 592 virtual uint32_t 593 GetBitfieldBitSize() 594 { 595 return 0; 596 } 597 598 virtual uint32_t 599 GetBitfieldBitOffset() 600 { 601 return 0; 602 } 603 604 virtual bool 605 IsArrayItemForPointer() 606 { 607 return m_is_array_item_for_pointer; 608 } 609 610 virtual bool 611 SetClangAST (clang::ASTContext *ast) 612 { 613 return false; 614 } 615 616 virtual const char * 617 GetValueAsCString (); 618 619 virtual uint64_t 620 GetValueAsUnsigned (uint64_t fail_value); 621 622 virtual bool 623 SetValueFromCString (const char *value_str); 624 625 // Return the module associated with this value object in case the 626 // value is from an executable file and might have its data in 627 // sections of the file. This can be used for variables. 628 virtual Module * 629 GetModule() 630 { 631 if (m_parent) 632 return m_parent->GetModule(); 633 return NULL; 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 CastPointerType (const char *name, 778 ClangASTType &ast_type); 779 780 virtual lldb::ValueObjectSP 781 CastPointerType (const char *name, 782 lldb::TypeSP &type_sp); 783 784 // The backing bits of this value object were updated, clear any 785 // descriptive string, so we know we have to refetch them 786 virtual void 787 ValueUpdated () 788 { 789 m_value_str.clear(); 790 m_summary_str.clear(); 791 m_object_desc_str.clear(); 792 } 793 794 virtual bool 795 IsDynamic () 796 { 797 return false; 798 } 799 800 virtual SymbolContextScope * 801 GetSymbolContextScope(); 802 803 static void 804 DumpValueObject (Stream &s, 805 ValueObject *valobj) 806 { 807 808 if (!valobj) 809 return; 810 811 ValueObject::DumpValueObject(s, 812 valobj, 813 DumpValueObjectOptions::DefaultOptions()); 814 } 815 816 static void 817 DumpValueObject (Stream &s, 818 ValueObject *valobj, 819 const char *root_valobj_name) 820 { 821 822 if (!valobj) 823 return; 824 825 ValueObject::DumpValueObject(s, 826 valobj, 827 root_valobj_name, 828 DumpValueObjectOptions::DefaultOptions()); 829 } 830 831 static void 832 DumpValueObject (Stream &s, 833 ValueObject *valobj, 834 const DumpValueObjectOptions& options, 835 lldb::Format format = lldb::eFormatDefault) 836 { 837 838 if (!valobj) 839 return; 840 841 ValueObject::DumpValueObject(s, 842 valobj, 843 valobj->GetName().AsCString(), 844 options.m_ptr_depth, 845 0, 846 options.m_max_depth, 847 options.m_show_types, 848 options.m_show_location, 849 options.m_use_objc, 850 options.m_use_dynamic, 851 options.m_use_synthetic, 852 options.m_scope_already_checked, 853 options.m_flat_output, 854 options.m_omit_summary_depth, 855 options.m_ignore_cap, 856 format); 857 } 858 859 static void 860 DumpValueObject (Stream &s, 861 ValueObject *valobj, 862 const char *root_valobj_name, 863 const DumpValueObjectOptions& options, 864 lldb::Format format = lldb::eFormatDefault) 865 { 866 867 if (!valobj) 868 return; 869 870 ValueObject::DumpValueObject(s, 871 valobj, 872 root_valobj_name, 873 options.m_ptr_depth, 874 0, 875 options.m_max_depth, 876 options.m_show_types, 877 options.m_show_location, 878 options.m_use_objc, 879 options.m_use_dynamic, 880 options.m_use_synthetic, 881 options.m_scope_already_checked, 882 options.m_flat_output, 883 options.m_omit_summary_depth, 884 options.m_ignore_cap, 885 format); 886 } 887 888 static void 889 DumpValueObject (Stream &s, 890 ValueObject *valobj, 891 const char *root_valobj_name, 892 uint32_t ptr_depth, 893 uint32_t curr_depth, 894 uint32_t max_depth, 895 bool show_types, 896 bool show_location, 897 bool use_objc, 898 lldb::DynamicValueType use_dynamic, 899 bool use_synthetic, 900 bool scope_already_checked, 901 bool flat_output, 902 uint32_t omit_summary_depth, 903 bool ignore_cap, 904 lldb::Format format = lldb::eFormatDefault); 905 906 // returns true if this is a char* or a char[] 907 // if it is a char* and check_pointer is true, 908 // it also checks that the pointer is valid 909 bool 910 IsCStringContainer (bool check_pointer = false); 911 912 void 913 ReadPointedString (Stream& s, 914 Error& error, 915 uint32_t max_length = 0, 916 bool honor_array = true, 917 lldb::Format item_format = lldb::eFormatCharArray); 918 919 virtual size_t 920 GetPointeeData (DataExtractor& data, 921 uint32_t item_idx = 0, 922 uint32_t item_count = 1); 923 924 virtual size_t 925 GetData (DataExtractor& data); 926 927 bool 928 GetIsConstant () const 929 { 930 return m_update_point.IsConstant(); 931 } 932 933 void 934 SetIsConstant () 935 { 936 m_update_point.SetIsConstant(); 937 } 938 939 lldb::Format 940 GetFormat () const 941 { 942 if (m_parent && m_format == lldb::eFormatDefault) 943 return m_parent->GetFormat(); 944 return m_format; 945 } 946 947 void 948 SetFormat (lldb::Format format) 949 { 950 if (format != m_format) 951 m_value_str.clear(); 952 m_format = format; 953 } 954 955 void 956 SetCustomSummaryFormat(lldb::SummaryFormatSP format) 957 { 958 m_forced_summary_format = format; 959 m_user_id_of_forced_summary = m_update_point.GetModID(); 960 m_summary_str.clear(); 961 m_is_getting_summary = false; 962 } 963 964 lldb::SummaryFormatSP 965 GetCustomSummaryFormat() 966 { 967 return m_forced_summary_format; 968 } 969 970 void 971 ClearCustomSummaryFormat() 972 { 973 m_forced_summary_format.reset(); 974 m_summary_str.clear(); 975 } 976 977 bool 978 HasCustomSummaryFormat() 979 { 980 return (m_forced_summary_format.get()); 981 } 982 983 lldb::SummaryFormatSP 984 GetSummaryFormat() 985 { 986 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 987 if (HasCustomSummaryFormat()) 988 return m_forced_summary_format; 989 return m_last_summary_format; 990 } 991 992 void 993 SetSummaryFormat(lldb::SummaryFormatSP format) 994 { 995 m_last_summary_format = format; 996 m_summary_str.clear(); 997 m_is_getting_summary = false; 998 } 999 1000 void 1001 SetValueFormat(lldb::ValueFormatSP format) 1002 { 1003 m_last_value_format = format; 1004 m_value_str.clear(); 1005 } 1006 1007 lldb::ValueFormatSP 1008 GetValueFormat() 1009 { 1010 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1011 return m_last_value_format; 1012 } 1013 1014 void 1015 SetSyntheticChildren(lldb::SyntheticChildrenSP synth) 1016 { 1017 m_last_synthetic_filter = synth; 1018 m_synthetic_value = NULL; 1019 } 1020 1021 lldb::SyntheticChildrenSP 1022 GetSyntheticChildren() 1023 { 1024 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1025 return m_last_synthetic_filter; 1026 } 1027 1028 // Use GetParent for display purposes, but if you want to tell the parent to update itself 1029 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 1030 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 1031 virtual ValueObject * 1032 GetParent() 1033 { 1034 return m_parent; 1035 } 1036 1037 virtual const ValueObject * 1038 GetParent() const 1039 { 1040 return m_parent; 1041 } 1042 1043 ValueObject * 1044 GetNonBaseClassParent(); 1045 1046 void 1047 SetAddressTypeOfChildren(AddressType at) 1048 { 1049 m_address_type_of_ptr_or_ref_children = at; 1050 } 1051 1052 AddressType 1053 GetAddressTypeOfChildren() 1054 { 1055 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 1056 { 1057 if (m_parent) 1058 return m_parent->GetAddressTypeOfChildren(); 1059 } 1060 return m_address_type_of_ptr_or_ref_children; 1061 } 1062 1063protected: 1064 typedef ClusterManager<ValueObject> ValueObjectManager; 1065 1066 //------------------------------------------------------------------ 1067 // Classes that inherit from ValueObject can see and modify these 1068 //------------------------------------------------------------------ 1069 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1070 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1071 // updated. When we are asked to update the value object, we check whether 1072 // the context & stop id are the same before updating. 1073 ConstString m_name; // The name of this object 1074 DataExtractor m_data; // A data extractor that can be used to extract the value. 1075 Value m_value; 1076 Error m_error; // An error object that can describe any errors that occur when updating values. 1077 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1078 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1079 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1080 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1081 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1082 // in that the summary is consed up by us, the object_desc_string is builtin. 1083 1084 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1085 // without a parent.) The manager gets passed through all the generations of 1086 // dependent objects, and will keep the whole cluster of objects alive as long 1087 // as a shared pointer to any of them has been handed out. Shared pointers to 1088 // value objects must always be made with the GetSP method. 1089 1090 std::vector<ValueObject *> m_children; 1091 std::map<ConstString, ValueObject *> m_synthetic_children; 1092 1093 ValueObject* m_dynamic_value; 1094 ValueObject* m_synthetic_value; 1095 ValueObject* m_deref_valobj; 1096 1097 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1098 // as an independent ValueObjectConstResult, which isn't managed by us. 1099 1100 lldb::Format m_format; 1101 uint32_t m_last_format_mgr_revision; 1102 lldb::DynamicValueType m_last_format_mgr_dynamic; 1103 lldb::SummaryFormatSP m_last_summary_format; 1104 lldb::SummaryFormatSP m_forced_summary_format; 1105 lldb::ValueFormatSP m_last_value_format; 1106 lldb::SyntheticChildrenSP m_last_synthetic_filter; 1107 ProcessModID m_user_id_of_forced_summary; 1108 AddressType m_address_type_of_ptr_or_ref_children; 1109 1110 bool m_value_is_valid:1, 1111 m_value_did_change:1, 1112 m_children_count_valid:1, 1113 m_old_value_valid:1, 1114 m_is_deref_of_parent:1, 1115 m_is_array_item_for_pointer:1, 1116 m_is_bitfield_for_scalar:1, 1117 m_is_expression_path_child:1, 1118 m_is_child_at_offset:1, 1119 m_is_getting_summary:1; 1120 1121 friend class ClangExpressionDeclMap; // For GetValue 1122 friend class ClangExpressionVariable; // For SetName 1123 friend class Target; // For SetName 1124 friend class ValueObjectConstResultImpl; 1125 1126 //------------------------------------------------------------------ 1127 // Constructors and Destructors 1128 //------------------------------------------------------------------ 1129 1130 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1131 1132 ValueObject(); 1133 1134 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1135 // through-out its lifespan. 1136 1137 ValueObject (ExecutionContextScope *exe_scope, 1138 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1139 1140 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1141 // of its parent. 1142 1143 ValueObject (ValueObject &parent); 1144 1145 ValueObjectManager * 1146 GetManager() 1147 { 1148 return m_manager; 1149 } 1150 1151 virtual bool 1152 UpdateValue () = 0; 1153 1154 virtual void 1155 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1156 1157 virtual void 1158 CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic); 1159 1160 // Should only be called by ValueObject::GetChildAtIndex() 1161 // Returns a ValueObject managed by this ValueObject's manager. 1162 virtual ValueObject * 1163 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1164 1165 // Should only be called by ValueObject::GetNumChildren() 1166 virtual uint32_t 1167 CalculateNumChildren() = 0; 1168 1169 void 1170 SetNumChildren (uint32_t num_children); 1171 1172 void 1173 SetValueDidChange (bool value_changed); 1174 1175 void 1176 SetValueIsValid (bool valid); 1177 1178 void 1179 ClearUserVisibleData(); 1180 1181 void 1182 AddSyntheticChild (const ConstString &key, 1183 ValueObject *valobj); 1184 1185 DataExtractor & 1186 GetDataExtractor (); 1187 1188private: 1189 //------------------------------------------------------------------ 1190 // For ValueObject only 1191 //------------------------------------------------------------------ 1192 1193 lldb::ValueObjectSP 1194 GetValueForExpressionPath_Impl(const char* expression_cstr, 1195 const char** first_unparsed, 1196 ExpressionPathScanEndReason* reason_to_stop, 1197 ExpressionPathEndResultType* final_value_type, 1198 const GetValueForExpressionPathOptions& options, 1199 ExpressionPathAftermath* final_task_on_target); 1200 1201 // this method will ONLY expand [] expressions into a VOList and return 1202 // the number of elements it added to the VOList 1203 // it will NOT loop through expanding the follow-up of the expression_cstr 1204 // for all objects in the list 1205 int 1206 ExpandArraySliceExpression(const char* expression_cstr, 1207 const char** first_unparsed, 1208 lldb::ValueObjectSP root, 1209 lldb::ValueObjectListSP& list, 1210 ExpressionPathScanEndReason* reason_to_stop, 1211 ExpressionPathEndResultType* final_value_type, 1212 const GetValueForExpressionPathOptions& options, 1213 ExpressionPathAftermath* final_task_on_target); 1214 1215 1216 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1217 1218}; 1219 1220} // namespace lldb_private 1221 1222#endif // liblldb_ValueObject_h_ 1223