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