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