1 //===-- ValueObject.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ValueObject_h_
11 #define liblldb_ValueObject_h_
16 #include <initializer_list>
20 // Other libraries and framework includes
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/SmallVector.h"
25 #include "lldb/lldb-private.h"
26 #include "lldb/Core/DataExtractor.h"
27 #include "lldb/Core/Error.h"
28 #include "lldb/Core/Flags.h"
29 #include "lldb/Core/ConstString.h"
30 #include "lldb/Core/UserID.h"
31 #include "lldb/Core/Value.h"
32 #include "lldb/Symbol/CompilerType.h"
33 #include "lldb/Target/ExecutionContext.h"
34 #include "lldb/Target/ExecutionContextScope.h"
35 #include "lldb/Target/Process.h"
36 #include "lldb/Target/StackID.h"
37 #include "lldb/Utility/SharedCluster.h"
39 namespace lldb_private {
43 /// This abstract class provides an interface to a particular value, be it a register, a local or global variable,
44 /// that is evaluated in some particular scope. The ValueObject also has the capability of being the "child" of
45 /// some other variable object, and in turn of having children.
46 /// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some
47 /// particular ExecutionContextScope. If it is a child, it inherits the ExecutionContextScope from its parent.
48 /// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc.
49 /// But it will always update itself in the ExecutionContextScope with which it was originally created.
51 /// A brief note on life cycle management for ValueObjects. This is a little tricky because a ValueObject can contain
52 /// various other ValueObjects - the Dynamic Value, its children, the dereference value, etc. Any one of these can be
53 /// handed out as a shared pointer, but for that contained value object to be valid, the root object and potentially other
54 /// of the value objects need to stay around.
55 /// We solve this problem by handing out shared pointers to the Value Object and any of its dependents using a shared
56 /// ClusterManager. This treats each shared pointer handed out for the entire cluster as a reference to the whole
57 /// cluster. The whole cluster will stay around until the last reference is released.
59 /// The ValueObject mostly handle this automatically, if a value object is made with a Parent ValueObject, then it adds
60 /// itself to the ClusterManager of the parent.
62 /// It does mean that external to the ValueObjects we should only ever make available ValueObjectSP's, never ValueObjects
63 /// or pointers to them. So all the "Root level" ValueObject derived constructors should be private, and
64 /// should implement a Create function that new's up object and returns a Shared Pointer that it gets from the GetSP() method.
66 /// However, if you are making an derived ValueObject that will be contained in a parent value object, you should just
67 /// hold onto a pointer to it internally, and by virtue of passing the parent ValueObject into its constructor, it will
68 /// be added to the ClusterManager for the parent. Then if you ever hand out a Shared Pointer to the contained ValueObject,
69 /// just do so by calling GetSP() on the contained object.
71 class ValueObject : public UserID
74 enum GetExpressionPathFormat
76 eGetExpressionPathFormatDereferencePointers = 1,
77 eGetExpressionPathFormatHonorPointers
80 enum ValueObjectRepresentationStyle
82 eValueObjectRepresentationStyleValue = 1,
83 eValueObjectRepresentationStyleSummary,
84 eValueObjectRepresentationStyleLanguageSpecific,
85 eValueObjectRepresentationStyleLocation,
86 eValueObjectRepresentationStyleChildrenCount,
87 eValueObjectRepresentationStyleType,
88 eValueObjectRepresentationStyleName,
89 eValueObjectRepresentationStyleExpressionPath
92 enum ExpressionPathScanEndReason
94 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
95 eExpressionPathScanEndReasonNoSuchChild, // child element not found
96 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child element not found
97 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for arrays
98 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be used
99 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be used
100 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion not allowed
101 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by options
102 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects other than scalars, pointers or arrays
103 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays, but I cannot parse it
104 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for bitfields, but I cannot parse after it
105 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in the expression
106 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply & operator
107 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply * operator
108 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a VOList
109 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic children failed
110 eExpressionPathScanEndReasonUnknown = 0xFFFF
113 enum ExpressionPathEndResultType
115 eExpressionPathEndResultTypePlain = 1, // anything but...
116 eExpressionPathEndResultTypeBitfield, // a bitfield
117 eExpressionPathEndResultTypeBoundedRange, // a range [low-high]
118 eExpressionPathEndResultTypeUnboundedRange, // a range []
119 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
120 eExpressionPathEndResultTypeInvalid = 0xFFFF
123 enum ExpressionPathAftermath
125 eExpressionPathAftermathNothing = 1, // just return it
126 eExpressionPathAftermathDereference, // dereference the target
127 eExpressionPathAftermathTakeAddress // take target's address
130 enum ClearUserVisibleDataItems
132 eClearUserVisibleDataItemsNothing = 1u << 0,
133 eClearUserVisibleDataItemsValue = 1u << 1,
134 eClearUserVisibleDataItemsSummary = 1u << 2,
135 eClearUserVisibleDataItemsLocation = 1u << 3,
136 eClearUserVisibleDataItemsDescription = 1u << 4,
137 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
138 eClearUserVisibleDataItemsValidator = 1u << 6,
139 eClearUserVisibleDataItemsAllStrings = eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsLocation | eClearUserVisibleDataItemsDescription,
140 eClearUserVisibleDataItemsAll = 0xFFFF
143 struct GetValueForExpressionPathOptions
145 enum class SyntheticChildrenTraversal
153 bool m_check_dot_vs_arrow_syntax;
154 bool m_no_fragile_ivar;
155 bool m_allow_bitfields_syntax;
156 SyntheticChildrenTraversal m_synthetic_children_traversal;
158 GetValueForExpressionPathOptions(bool dot = false,
159 bool no_ivar = false,
160 bool bitfield = true,
161 SyntheticChildrenTraversal synth_traverse = SyntheticChildrenTraversal::ToSynthetic) :
162 m_check_dot_vs_arrow_syntax(dot),
163 m_no_fragile_ivar(no_ivar),
164 m_allow_bitfields_syntax(bitfield),
165 m_synthetic_children_traversal(synth_traverse)
169 GetValueForExpressionPathOptions&
170 DoCheckDotVsArrowSyntax()
172 m_check_dot_vs_arrow_syntax = true;
176 GetValueForExpressionPathOptions&
177 DontCheckDotVsArrowSyntax()
179 m_check_dot_vs_arrow_syntax = false;
183 GetValueForExpressionPathOptions&
186 m_no_fragile_ivar = false;
190 GetValueForExpressionPathOptions&
191 DontAllowFragileIVar()
193 m_no_fragile_ivar = true;
197 GetValueForExpressionPathOptions&
198 DoAllowBitfieldSyntax()
200 m_allow_bitfields_syntax = true;
204 GetValueForExpressionPathOptions&
205 DontAllowBitfieldSyntax()
207 m_allow_bitfields_syntax = false;
211 GetValueForExpressionPathOptions&
212 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse)
214 m_synthetic_children_traversal = traverse;
218 static const GetValueForExpressionPathOptions
221 static GetValueForExpressionPathOptions g_default_options;
223 return g_default_options;
227 class EvaluationPoint
232 EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false);
234 EvaluationPoint (const EvaluationPoint &rhs);
238 const ExecutionContextRef &
239 GetExecutionContextRef() const
241 return m_exe_ctx_ref;
244 // Set the EvaluationPoint to the values in exe_scope,
245 // Return true if the Evaluation Point changed.
246 // Since the ExecutionContextScope is always going to be valid currently,
247 // the Updated Context will also always be valid.
250 // SetContext (ExecutionContextScope *exe_scope);
256 m_mod_id.SetInvalid();
262 return !m_mod_id.IsValid();
272 SetUpdateID (ProcessModID new_id)
280 m_needs_update = true;
287 NeedsUpdating(bool accept_invalid_exe_ctx)
289 SyncWithProcessState(accept_invalid_exe_ctx);
290 return m_needs_update;
296 const bool accept_invalid_exe_ctx = false;
297 if (!m_mod_id.IsValid())
299 else if (SyncWithProcessState (accept_invalid_exe_ctx))
301 if (!m_mod_id.IsValid())
310 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and
312 m_mod_id.SetInvalid();
314 // Can't update an invalid state.
315 m_needs_update = false;
321 SyncWithProcessState (bool accept_invalid_exe_ctx);
323 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated.
324 ExecutionContextRef m_exe_ctx_ref;
328 virtual ~ValueObject();
330 const EvaluationPoint &
331 GetUpdatePoint () const
333 return m_update_point;
339 return m_update_point;
342 const ExecutionContextRef &
343 GetExecutionContextRef() const
345 return m_update_point.GetExecutionContextRef();
351 return m_update_point.GetExecutionContextRef().GetTargetSP();
357 return m_update_point.GetExecutionContextRef().GetProcessSP();
363 return m_update_point.GetExecutionContextRef().GetThreadSP();
369 return m_update_point.GetExecutionContextRef().GetFrameSP();
378 // this vends a TypeImpl that is useful at the SB API layer
385 //------------------------------------------------------------------
386 // Subclasses must implement the functions below.
387 //------------------------------------------------------------------
391 virtual lldb::ValueType
392 GetValueType() const = 0;
394 //------------------------------------------------------------------
395 // Subclasses can implement the functions below.
396 //------------------------------------------------------------------
401 GetDisplayTypeName();
404 GetQualifiedTypeName();
406 virtual lldb::LanguageType
407 GetObjectRuntimeLanguage();
410 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
422 IsPointerOrReferenceType ();
425 IsPossibleDynamicType ();
431 IsUninitializedReference ();
440 IsBaseClass (uint32_t& depth);
443 IsDereferenceOfParent ()
449 IsIntegerType (bool &is_signed);
452 GetBaseClassPath (Stream &s);
455 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
458 GetValueForExpressionPath(const char* expression,
459 const char** first_unparsed = nullptr,
460 ExpressionPathScanEndReason* reason_to_stop = nullptr,
461 ExpressionPathEndResultType* final_value_type = nullptr,
462 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
463 ExpressionPathAftermath* final_task_on_target = nullptr);
466 GetValuesForExpressionPath(const char* expression,
467 lldb::ValueObjectListSP& list,
468 const char** first_unparsed = nullptr,
469 ExpressionPathScanEndReason* reason_to_stop = nullptr,
470 ExpressionPathEndResultType* final_value_type = nullptr,
471 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
472 ExpressionPathAftermath* final_task_on_target = nullptr);
480 virtual lldb::offset_t
487 GetBitfieldBitSize ()
493 GetBitfieldBitOffset ()
501 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
505 IsArrayItemForPointer()
507 return m_is_array_item_for_pointer;
511 GetValueAsCString ();
514 GetValueAsCString (const lldb_private::TypeFormatImpl& format,
515 std::string& destination);
518 GetValueAsCString (lldb::Format format,
519 std::string& destination);
522 GetValueAsUnsigned(uint64_t fail_value, bool *success = nullptr);
525 GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
528 SetValueFromCString (const char *value_str, Error& error);
530 // Return the module associated with this value object in case the
531 // value is from an executable file and might have its data in
532 // sections of the file. This can be used for variables.
533 virtual lldb::ModuleSP
539 // Given a ValueObject, loop over itself and its parent, and its parent's parent, ..
540 // until either the given callback returns false, or you end up at a null pointer
542 FollowParentChain (std::function<bool(ValueObject*)>);
545 GetDeclaration (Declaration &decl);
547 //------------------------------------------------------------------
548 // The functions below should NOT be modified by subclasses
549 //------------------------------------------------------------------
556 virtual lldb::ValueObjectSP
557 GetChildAtIndex (size_t idx, bool can_create);
559 // this will always create the children if necessary
561 GetChildAtIndexPath(const std::initializer_list<size_t> &idxs,
562 size_t* index_of_error = nullptr);
565 GetChildAtIndexPath(const std::vector<size_t> &idxs,
566 size_t* index_of_error = nullptr);
569 GetChildAtIndexPath(const std::initializer_list< std::pair<size_t, bool> > &idxs,
570 size_t* index_of_error = nullptr);
573 GetChildAtIndexPath(const std::vector< std::pair<size_t, bool> > &idxs,
574 size_t* index_of_error = nullptr);
576 // this will always create the children if necessary
578 GetChildAtNamePath(const std::initializer_list<ConstString> &names,
579 ConstString* name_of_error = nullptr);
582 GetChildAtNamePath(const std::vector<ConstString> &names,
583 ConstString* name_of_error = nullptr);
586 GetChildAtNamePath(const std::initializer_list< std::pair<ConstString, bool> > &names,
587 ConstString* name_of_error = nullptr);
590 GetChildAtNamePath(const std::vector< std::pair<ConstString, bool> > &names,
591 ConstString* name_of_error = nullptr);
593 virtual lldb::ValueObjectSP
594 GetChildMemberWithName (const ConstString &name, bool can_create);
597 GetIndexOfChildWithName (const ConstString &name);
600 GetNumChildren (uint32_t max=UINT32_MAX);
609 ResolveValue (Scalar &scalar);
611 // return 'false' whenever you set the error, otherwise
612 // callers may assume true means everything is OK - this will
613 // break breakpoint conditions among potentially a few others
615 IsLogicalTrue (Error& error);
618 GetLocationAsCString ();
621 GetSummaryAsCString (lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
624 GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
625 std::string& destination,
626 lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
629 GetSummaryAsCString (std::string& destination,
630 const TypeSummaryOptions& options);
633 GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
634 std::string& destination,
635 const TypeSummaryOptions& options);
637 std::pair<TypeValidatorResult, std::string>
638 GetValidationStatus ();
641 GetObjectDescription ();
644 HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display,
645 lldb::Format custom_format);
647 enum PrintableRepresentationSpecialCases
649 ePrintableRepresentationSpecialCasesDisable = 0,
650 ePrintableRepresentationSpecialCasesAllow = 1,
651 ePrintableRepresentationSpecialCasesOnly = 3
655 DumpPrintableRepresentation (Stream& s,
656 ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary,
657 lldb::Format custom_format = lldb::eFormatInvalid,
658 PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow,
659 bool do_dump_error = true);
661 GetValueIsValid () const;
663 // If you call this on a newly created ValueObject, it will always return false.
665 GetValueDidChange ();
668 UpdateValueIfNeeded (bool update_format = true);
671 UpdateFormatsIfNeeded();
676 return m_manager->GetSharedPointer(this);
680 SetName (const ConstString &name);
683 GetAddressOf(bool scalar_is_load_address = true,
684 AddressType *address_type = nullptr);
687 GetPointerValue(AddressType *address_type = nullptr);
690 GetSyntheticChild (const ConstString &key) const;
693 GetSyntheticArrayMember (size_t index, bool can_create);
696 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
699 GetSyntheticExpressionPathChild(const char* expression, bool can_create);
701 virtual lldb::ValueObjectSP
702 GetSyntheticChildAtOffset(uint32_t offset,
703 const CompilerType& type,
705 ConstString name_const_str = ConstString());
707 virtual lldb::ValueObjectSP
708 GetSyntheticBase (uint32_t offset,
709 const CompilerType& type,
711 ConstString name_const_str = ConstString());
713 virtual lldb::ValueObjectSP
714 GetDynamicValue (lldb::DynamicValueType valueType);
716 lldb::DynamicValueType
717 GetDynamicValueType ();
719 virtual lldb::ValueObjectSP
722 virtual lldb::ValueObjectSP
723 GetNonSyntheticValue ();
726 GetSyntheticValue (bool use_synthetic = true);
732 IsSynthetic() { return false; }
735 GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
738 virtual lldb::ValueObjectSP
739 CreateConstantValue (const ConstString &name);
741 virtual lldb::ValueObjectSP
742 Dereference (Error &error);
744 virtual lldb::ValueObjectSP
745 AddressOf (Error &error);
750 return LLDB_INVALID_ADDRESS;
754 SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
755 AddressType address_type = eAddressTypeLoad)
759 // Find the address of the C++ vtable pointer
761 GetCPPVTableAddress(AddressType &address_type);
763 virtual lldb::ValueObjectSP
764 Cast (const CompilerType &compiler_type);
766 virtual lldb::ValueObjectSP
767 CastPointerType (const char *name,
768 CompilerType &ast_type);
770 virtual lldb::ValueObjectSP
771 CastPointerType (const char *name,
772 lldb::TypeSP &type_sp);
774 // The backing bits of this value object were updated, clear any
775 // descriptive string, so we know we have to refetch them
779 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
780 eClearUserVisibleDataItemsSummary |
781 eClearUserVisibleDataItemsDescription);
791 DoesProvideSyntheticValue ()
797 IsSyntheticChildrenGenerated ();
800 SetSyntheticChildrenGenerated (bool b);
802 virtual SymbolContextScope *
803 GetSymbolContextScope();
810 const DumpValueObjectOptions& options);
812 static lldb::ValueObjectSP
813 CreateValueObjectFromExpression (const char* name,
814 const char* expression,
815 const ExecutionContext& exe_ctx);
817 static lldb::ValueObjectSP
818 CreateValueObjectFromExpression (const char* name,
819 const char* expression,
820 const ExecutionContext& exe_ctx,
821 const EvaluateExpressionOptions& options);
823 static lldb::ValueObjectSP
824 CreateValueObjectFromAddress (const char* name,
826 const ExecutionContext& exe_ctx,
829 static lldb::ValueObjectSP
830 CreateValueObjectFromData (const char* name,
831 const DataExtractor& data,
832 const ExecutionContext& exe_ctx,
836 LogValueObject (Log *log);
839 LogValueObject (Log *log,
840 const DumpValueObjectOptions& options);
846 // returns true if this is a char* or a char[]
847 // if it is a char* and check_pointer is true,
848 // it also checks that the pointer is valid
850 IsCStringContainer (bool check_pointer = false);
852 std::pair<size_t,bool>
853 ReadPointedString (lldb::DataBufferSP& buffer_sp,
855 uint32_t max_length = 0,
856 bool honor_array = true,
857 lldb::Format item_format = lldb::eFormatCharArray);
860 GetPointeeData (DataExtractor& data,
861 uint32_t item_idx = 0,
862 uint32_t item_count = 1);
865 GetData (DataExtractor& data, Error &error);
868 SetData (DataExtractor &data, Error &error);
871 GetIsConstant () const
873 return m_update_point.IsConstant();
879 const bool accept_invalid_exe_ctx = (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
880 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
886 m_update_point.SetIsConstant();
893 SetFormat (lldb::Format format)
895 if (format != m_format)
896 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
900 virtual lldb::LanguageType
901 GetPreferredDisplayLanguage ();
904 SetPreferredDisplayLanguage (lldb::LanguageType);
906 lldb::TypeSummaryImplSP
909 UpdateFormatsIfNeeded();
910 return m_type_summary_sp;
914 SetSummaryFormat(lldb::TypeSummaryImplSP format)
916 m_type_summary_sp = format;
917 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
920 lldb::TypeValidatorImplSP
923 UpdateFormatsIfNeeded();
924 return m_type_validator_sp;
928 SetValidator(lldb::TypeValidatorImplSP format)
930 m_type_validator_sp = format;
931 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
935 SetValueFormat(lldb::TypeFormatImplSP format)
937 m_type_format_sp = format;
938 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
941 lldb::TypeFormatImplSP
944 UpdateFormatsIfNeeded();
945 return m_type_format_sp;
949 SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
951 if (synth_sp.get() == m_synthetic_children_sp.get())
953 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
954 m_synthetic_children_sp = synth_sp;
957 lldb::SyntheticChildrenSP
958 GetSyntheticChildren()
960 UpdateFormatsIfNeeded();
961 return m_synthetic_children_sp;
964 // Use GetParent for display purposes, but if you want to tell the parent to update itself
965 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for
966 // displaying, they are really siblings, so for display it needs to route through to its grandparent.
967 virtual ValueObject *
973 virtual const ValueObject *
980 GetNonBaseClassParent();
983 SetAddressTypeOfChildren(AddressType at)
985 m_address_type_of_ptr_or_ref_children = at;
989 GetAddressTypeOfChildren();
994 m_did_calculate_complete_objc_class_type = true;
997 //------------------------------------------------------------------
998 /// Find out if a ValueObject might have children.
1000 /// This call is much more efficient than CalculateNumChildren() as
1001 /// it doesn't need to complete the underlying type. This is designed
1002 /// to be used in a UI environment in order to detect if the
1003 /// disclosure triangle should be displayed or not.
1005 /// This function returns true for class, union, structure,
1006 /// pointers, references, arrays and more. Again, it does so without
1007 /// doing any expensive type completion.
1010 /// Returns \b true if the ValueObject might have children, or \b
1011 /// false otherwise.
1012 //------------------------------------------------------------------
1014 MightHaveChildren();
1016 virtual lldb::VariableSP
1023 IsRuntimeSupportValue ();
1026 GetLanguageFlags ();
1029 SetLanguageFlags (uint64_t flags);
1032 typedef ClusterManager<ValueObject> ValueObjectManager;
1034 class ChildrenManager
1037 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
1040 HasChildAtIndex(size_t idx)
1042 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1043 return (m_children.find(idx) != m_children.end());
1047 GetChildAtIndex(size_t idx)
1049 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1050 const auto iter = m_children.find(idx);
1051 return ((iter == m_children.end()) ? nullptr : iter->second);
1055 SetChildAtIndex(size_t idx, ValueObject *valobj)
1057 // we do not need to be mutex-protected to make a pair
1058 ChildrenPair pair(idx, valobj);
1059 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1060 m_children.insert(pair);
1064 SetChildrenCount (size_t count)
1072 return m_children_count;
1076 Clear(size_t new_count = 0)
1078 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1079 m_children_count = new_count;
1084 typedef std::map<size_t, ValueObject*> ChildrenMap;
1085 typedef ChildrenMap::iterator ChildrenIterator;
1086 typedef ChildrenMap::value_type ChildrenPair;
1087 std::recursive_mutex m_mutex;
1088 ChildrenMap m_children;
1089 size_t m_children_count;
1092 //------------------------------------------------------------------
1093 // Classes that inherit from ValueObject can see and modify these
1094 //------------------------------------------------------------------
1095 ValueObject * m_parent; // The parent value object, or nullptr if this has no parent
1096 ValueObject * m_root; // The root of the hierarchy for this ValueObject (or nullptr if never calculated)
1097 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last
1098 // updated. When we are asked to update the value object, we check whether
1099 // the context & stop id are the same before updating.
1100 ConstString m_name; // The name of this object
1101 DataExtractor m_data; // A data extractor that can be used to extract the value.
1103 Error m_error; // An error object that can describe any errors that occur when updating values.
1104 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated.
1105 std::string m_old_value_str;// Cached old value string from the last time the value was gotten
1106 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated.
1107 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated.
1108 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary
1109 // in that the summary is consed up by us, the object_desc_string is builtin.
1111 llvm::Optional<std::pair<TypeValidatorResult, std::string>> m_validation_result;
1113 CompilerType m_override_type;// If the type of the value object should be overridden, the type to impose.
1115 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created
1116 // without a parent.) The manager gets passed through all the generations of
1117 // dependent objects, and will keep the whole cluster of objects alive as long
1118 // as a shared pointer to any of them has been handed out. Shared pointers to
1119 // value objects must always be made with the GetSP method.
1121 ChildrenManager m_children;
1122 std::map<ConstString, ValueObject *> m_synthetic_children;
1124 ValueObject* m_dynamic_value;
1125 ValueObject* m_synthetic_value;
1126 ValueObject* m_deref_valobj;
1128 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1129 // as an independent ValueObjectConstResult, which isn't managed by us.
1131 lldb::Format m_format;
1132 lldb::Format m_last_format;
1133 uint32_t m_last_format_mgr_revision;
1134 lldb::TypeSummaryImplSP m_type_summary_sp;
1135 lldb::TypeFormatImplSP m_type_format_sp;
1136 lldb::SyntheticChildrenSP m_synthetic_children_sp;
1137 lldb::TypeValidatorImplSP m_type_validator_sp;
1138 ProcessModID m_user_id_of_forced_summary;
1139 AddressType m_address_type_of_ptr_or_ref_children;
1141 llvm::SmallVector<uint8_t, 16> m_value_checksum;
1143 lldb::LanguageType m_preferred_display_language;
1145 uint64_t m_language_flags;
1147 bool m_value_is_valid:1,
1148 m_value_did_change:1,
1149 m_children_count_valid:1,
1150 m_old_value_valid:1,
1151 m_is_deref_of_parent:1,
1152 m_is_array_item_for_pointer:1,
1153 m_is_bitfield_for_scalar:1,
1154 m_is_child_at_offset:1,
1155 m_is_getting_summary:1,
1156 m_did_calculate_complete_objc_class_type:1,
1157 m_is_synthetic_children_generated:1;
1159 friend class ValueObjectChild;
1160 friend class ClangExpressionDeclMap; // For GetValue
1161 friend class ExpressionVariable; // For SetName
1162 friend class Target; // For SetName
1163 friend class ValueObjectConstResultImpl;
1164 friend class ValueObjectSynthetic; // For ClearUserVisibleData
1166 //------------------------------------------------------------------
1167 // Constructors and Destructors
1168 //------------------------------------------------------------------
1170 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1174 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context
1175 // through-out its lifespan.
1177 ValueObject (ExecutionContextScope *exe_scope,
1178 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1180 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext
1183 ValueObject (ValueObject &parent);
1185 ValueObjectManager *
1195 CanUpdateWithInvalidExecutionContext ()
1197 return eLazyBoolCalculate;
1201 CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1203 virtual lldb::DynamicValueType
1204 GetDynamicValueTypeImpl ()
1206 return lldb::eNoDynamicValues;
1210 HasDynamicValueTypeInfo ()
1216 CalculateSyntheticValue (bool use_synthetic = true);
1218 // Should only be called by ValueObject::GetChildAtIndex()
1219 // Returns a ValueObject managed by this ValueObject's manager.
1220 virtual ValueObject *
1221 CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index);
1223 // Should only be called by ValueObject::GetNumChildren()
1225 CalculateNumChildren(uint32_t max=UINT32_MAX) = 0;
1228 SetNumChildren (size_t num_children);
1231 SetValueDidChange (bool value_changed);
1234 SetValueIsValid (bool valid);
1237 ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1240 AddSyntheticChild (const ConstString &key,
1241 ValueObject *valobj);
1244 GetDataExtractor ();
1247 ClearDynamicTypeInformation ();
1249 //------------------------------------------------------------------
1250 // Subclasses must implement the functions below.
1251 //------------------------------------------------------------------
1253 virtual CompilerType
1254 GetCompilerTypeImpl () = 0;
1257 GetLocationAsCStringImpl (const Value& value,
1258 const DataExtractor& data);
1264 SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType);
1267 virtual CompilerType
1268 MaybeCalculateCompleteType ();
1271 GetValueForExpressionPath_Impl(const char* expression_cstr,
1272 const char** first_unparsed,
1273 ExpressionPathScanEndReason* reason_to_stop,
1274 ExpressionPathEndResultType* final_value_type,
1275 const GetValueForExpressionPathOptions& options,
1276 ExpressionPathAftermath* final_task_on_target);
1278 // this method will ONLY expand [] expressions into a VOList and return
1279 // the number of elements it added to the VOList
1280 // it will NOT loop through expanding the follow-up of the expression_cstr
1281 // for all objects in the list
1283 ExpandArraySliceExpression(const char* expression_cstr,
1284 const char** first_unparsed,
1285 lldb::ValueObjectSP root,
1286 lldb::ValueObjectListSP& list,
1287 ExpressionPathScanEndReason* reason_to_stop,
1288 ExpressionPathEndResultType* final_value_type,
1289 const GetValueForExpressionPathOptions& options,
1290 ExpressionPathAftermath* final_task_on_target);
1292 DISALLOW_COPY_AND_ASSIGN (ValueObject);
1295 } // namespace lldb_private
1297 #endif // liblldb_ValueObject_h_