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, const CompilerType& type, bool can_create);
704 virtual lldb::ValueObjectSP
705 GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create);
707 virtual lldb::ValueObjectSP
708 GetDynamicValue (lldb::DynamicValueType valueType);
710 lldb::DynamicValueType
711 GetDynamicValueType ();
713 virtual lldb::ValueObjectSP
716 virtual lldb::ValueObjectSP
717 GetNonSyntheticValue ();
720 GetSyntheticValue (bool use_synthetic = true);
726 IsSynthetic() { return false; }
729 GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
732 virtual lldb::ValueObjectSP
733 CreateConstantValue (const ConstString &name);
735 virtual lldb::ValueObjectSP
736 Dereference (Error &error);
738 virtual lldb::ValueObjectSP
739 AddressOf (Error &error);
744 return LLDB_INVALID_ADDRESS;
748 SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
749 AddressType address_type = eAddressTypeLoad)
753 // Find the address of the C++ vtable pointer
755 GetCPPVTableAddress(AddressType &address_type);
757 virtual lldb::ValueObjectSP
758 Cast (const CompilerType &compiler_type);
760 virtual lldb::ValueObjectSP
761 CastPointerType (const char *name,
762 CompilerType &ast_type);
764 virtual lldb::ValueObjectSP
765 CastPointerType (const char *name,
766 lldb::TypeSP &type_sp);
768 // The backing bits of this value object were updated, clear any
769 // descriptive string, so we know we have to refetch them
773 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
774 eClearUserVisibleDataItemsSummary |
775 eClearUserVisibleDataItemsDescription);
785 DoesProvideSyntheticValue ()
791 IsSyntheticChildrenGenerated ();
794 SetSyntheticChildrenGenerated (bool b);
796 virtual SymbolContextScope *
797 GetSymbolContextScope();
804 const DumpValueObjectOptions& options);
806 static lldb::ValueObjectSP
807 CreateValueObjectFromExpression (const char* name,
808 const char* expression,
809 const ExecutionContext& exe_ctx);
811 static lldb::ValueObjectSP
812 CreateValueObjectFromExpression (const char* name,
813 const char* expression,
814 const ExecutionContext& exe_ctx,
815 const EvaluateExpressionOptions& options);
817 static lldb::ValueObjectSP
818 CreateValueObjectFromAddress (const char* name,
820 const ExecutionContext& exe_ctx,
823 static lldb::ValueObjectSP
824 CreateValueObjectFromData (const char* name,
825 const DataExtractor& data,
826 const ExecutionContext& exe_ctx,
830 LogValueObject (Log *log);
833 LogValueObject (Log *log,
834 const DumpValueObjectOptions& options);
840 // returns true if this is a char* or a char[]
841 // if it is a char* and check_pointer is true,
842 // it also checks that the pointer is valid
844 IsCStringContainer (bool check_pointer = false);
846 std::pair<size_t,bool>
847 ReadPointedString (lldb::DataBufferSP& buffer_sp,
849 uint32_t max_length = 0,
850 bool honor_array = true,
851 lldb::Format item_format = lldb::eFormatCharArray);
854 GetPointeeData (DataExtractor& data,
855 uint32_t item_idx = 0,
856 uint32_t item_count = 1);
859 GetData (DataExtractor& data, Error &error);
862 SetData (DataExtractor &data, Error &error);
865 GetIsConstant () const
867 return m_update_point.IsConstant();
873 const bool accept_invalid_exe_ctx = (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
874 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
880 m_update_point.SetIsConstant();
887 SetFormat (lldb::Format format)
889 if (format != m_format)
890 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
894 virtual lldb::LanguageType
895 GetPreferredDisplayLanguage ();
898 SetPreferredDisplayLanguage (lldb::LanguageType);
900 lldb::TypeSummaryImplSP
903 UpdateFormatsIfNeeded();
904 return m_type_summary_sp;
908 SetSummaryFormat(lldb::TypeSummaryImplSP format)
910 m_type_summary_sp = format;
911 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
914 lldb::TypeValidatorImplSP
917 UpdateFormatsIfNeeded();
918 return m_type_validator_sp;
922 SetValidator(lldb::TypeValidatorImplSP format)
924 m_type_validator_sp = format;
925 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
929 SetValueFormat(lldb::TypeFormatImplSP format)
931 m_type_format_sp = format;
932 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
935 lldb::TypeFormatImplSP
938 UpdateFormatsIfNeeded();
939 return m_type_format_sp;
943 SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
945 if (synth_sp.get() == m_synthetic_children_sp.get())
947 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
948 m_synthetic_children_sp = synth_sp;
951 lldb::SyntheticChildrenSP
952 GetSyntheticChildren()
954 UpdateFormatsIfNeeded();
955 return m_synthetic_children_sp;
958 // Use GetParent for display purposes, but if you want to tell the parent to update itself
959 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for
960 // displaying, they are really siblings, so for display it needs to route through to its grandparent.
961 virtual ValueObject *
967 virtual const ValueObject *
974 GetNonBaseClassParent();
977 SetAddressTypeOfChildren(AddressType at)
979 m_address_type_of_ptr_or_ref_children = at;
983 GetAddressTypeOfChildren();
988 m_did_calculate_complete_objc_class_type = true;
991 //------------------------------------------------------------------
992 /// Find out if a ValueObject might have children.
994 /// This call is much more efficient than CalculateNumChildren() as
995 /// it doesn't need to complete the underlying type. This is designed
996 /// to be used in a UI environment in order to detect if the
997 /// disclosure triangle should be displayed or not.
999 /// This function returns true for class, union, structure,
1000 /// pointers, references, arrays and more. Again, it does so without
1001 /// doing any expensive type completion.
1004 /// Returns \b true if the ValueObject might have children, or \b
1005 /// false otherwise.
1006 //------------------------------------------------------------------
1008 MightHaveChildren();
1010 virtual lldb::VariableSP
1017 IsRuntimeSupportValue ();
1020 GetLanguageFlags ();
1023 SetLanguageFlags (uint64_t flags);
1026 typedef ClusterManager<ValueObject> ValueObjectManager;
1028 class ChildrenManager
1032 m_mutex(Mutex::eMutexTypeRecursive),
1038 HasChildAtIndex (size_t idx)
1040 Mutex::Locker locker(m_mutex);
1041 return (m_children.find(idx) != m_children.end());
1045 GetChildAtIndex (size_t idx)
1047 Mutex::Locker locker(m_mutex);
1048 const auto iter = m_children.find(idx);
1049 return ((iter == m_children.end()) ? nullptr : iter->second);
1053 SetChildAtIndex (size_t idx, ValueObject* valobj)
1055 ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair
1056 Mutex::Locker locker(m_mutex);
1057 m_children.insert(pair);
1061 SetChildrenCount (size_t count)
1069 return m_children_count;
1073 Clear(size_t new_count = 0)
1075 Mutex::Locker locker(m_mutex);
1076 m_children_count = new_count;
1081 typedef std::map<size_t, ValueObject*> ChildrenMap;
1082 typedef ChildrenMap::iterator ChildrenIterator;
1083 typedef ChildrenMap::value_type ChildrenPair;
1085 ChildrenMap m_children;
1086 size_t m_children_count;
1089 //------------------------------------------------------------------
1090 // Classes that inherit from ValueObject can see and modify these
1091 //------------------------------------------------------------------
1092 ValueObject * m_parent; // The parent value object, or nullptr if this has no parent
1093 ValueObject * m_root; // The root of the hierarchy for this ValueObject (or nullptr if never calculated)
1094 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last
1095 // updated. When we are asked to update the value object, we check whether
1096 // the context & stop id are the same before updating.
1097 ConstString m_name; // The name of this object
1098 DataExtractor m_data; // A data extractor that can be used to extract the value.
1100 Error m_error; // An error object that can describe any errors that occur when updating values.
1101 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated.
1102 std::string m_old_value_str;// Cached old value string from the last time the value was gotten
1103 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated.
1104 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated.
1105 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary
1106 // in that the summary is consed up by us, the object_desc_string is builtin.
1108 llvm::Optional<std::pair<TypeValidatorResult, std::string>> m_validation_result;
1110 CompilerType m_override_type;// If the type of the value object should be overridden, the type to impose.
1112 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created
1113 // without a parent.) The manager gets passed through all the generations of
1114 // dependent objects, and will keep the whole cluster of objects alive as long
1115 // as a shared pointer to any of them has been handed out. Shared pointers to
1116 // value objects must always be made with the GetSP method.
1118 ChildrenManager m_children;
1119 std::map<ConstString, ValueObject *> m_synthetic_children;
1121 ValueObject* m_dynamic_value;
1122 ValueObject* m_synthetic_value;
1123 ValueObject* m_deref_valobj;
1125 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1126 // as an independent ValueObjectConstResult, which isn't managed by us.
1128 lldb::Format m_format;
1129 lldb::Format m_last_format;
1130 uint32_t m_last_format_mgr_revision;
1131 lldb::TypeSummaryImplSP m_type_summary_sp;
1132 lldb::TypeFormatImplSP m_type_format_sp;
1133 lldb::SyntheticChildrenSP m_synthetic_children_sp;
1134 lldb::TypeValidatorImplSP m_type_validator_sp;
1135 ProcessModID m_user_id_of_forced_summary;
1136 AddressType m_address_type_of_ptr_or_ref_children;
1138 llvm::SmallVector<uint8_t, 16> m_value_checksum;
1140 lldb::LanguageType m_preferred_display_language;
1142 uint64_t m_language_flags;
1144 bool m_value_is_valid:1,
1145 m_value_did_change:1,
1146 m_children_count_valid:1,
1147 m_old_value_valid:1,
1148 m_is_deref_of_parent:1,
1149 m_is_array_item_for_pointer:1,
1150 m_is_bitfield_for_scalar:1,
1151 m_is_child_at_offset:1,
1152 m_is_getting_summary:1,
1153 m_did_calculate_complete_objc_class_type:1,
1154 m_is_synthetic_children_generated:1;
1156 friend class ValueObjectChild;
1157 friend class ClangExpressionDeclMap; // For GetValue
1158 friend class ExpressionVariable; // For SetName
1159 friend class Target; // For SetName
1160 friend class ValueObjectConstResultImpl;
1161 friend class ValueObjectSynthetic; // For ClearUserVisibleData
1163 //------------------------------------------------------------------
1164 // Constructors and Destructors
1165 //------------------------------------------------------------------
1167 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1171 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context
1172 // through-out its lifespan.
1174 ValueObject (ExecutionContextScope *exe_scope,
1175 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1177 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext
1180 ValueObject (ValueObject &parent);
1182 ValueObjectManager *
1192 CanUpdateWithInvalidExecutionContext ()
1194 return eLazyBoolCalculate;
1198 CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1200 virtual lldb::DynamicValueType
1201 GetDynamicValueTypeImpl ()
1203 return lldb::eNoDynamicValues;
1207 HasDynamicValueTypeInfo ()
1213 CalculateSyntheticValue (bool use_synthetic = true);
1215 // Should only be called by ValueObject::GetChildAtIndex()
1216 // Returns a ValueObject managed by this ValueObject's manager.
1217 virtual ValueObject *
1218 CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index);
1220 // Should only be called by ValueObject::GetNumChildren()
1222 CalculateNumChildren(uint32_t max=UINT32_MAX) = 0;
1225 SetNumChildren (size_t num_children);
1228 SetValueDidChange (bool value_changed);
1231 SetValueIsValid (bool valid);
1234 ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1237 AddSyntheticChild (const ConstString &key,
1238 ValueObject *valobj);
1241 GetDataExtractor ();
1244 ClearDynamicTypeInformation ();
1246 //------------------------------------------------------------------
1247 // Subclasses must implement the functions below.
1248 //------------------------------------------------------------------
1250 virtual CompilerType
1251 GetCompilerTypeImpl () = 0;
1254 GetLocationAsCStringImpl (const Value& value,
1255 const DataExtractor& data);
1261 SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType);
1264 virtual CompilerType
1265 MaybeCalculateCompleteType ();
1268 GetValueForExpressionPath_Impl(const char* expression_cstr,
1269 const char** first_unparsed,
1270 ExpressionPathScanEndReason* reason_to_stop,
1271 ExpressionPathEndResultType* final_value_type,
1272 const GetValueForExpressionPathOptions& options,
1273 ExpressionPathAftermath* final_task_on_target);
1275 // this method will ONLY expand [] expressions into a VOList and return
1276 // the number of elements it added to the VOList
1277 // it will NOT loop through expanding the follow-up of the expression_cstr
1278 // for all objects in the list
1280 ExpandArraySliceExpression(const char* expression_cstr,
1281 const char** first_unparsed,
1282 lldb::ValueObjectSP root,
1283 lldb::ValueObjectListSP& list,
1284 ExpressionPathScanEndReason* reason_to_stop,
1285 ExpressionPathEndResultType* final_value_type,
1286 const GetValueForExpressionPathOptions& options,
1287 ExpressionPathAftermath* final_task_on_target);
1289 DISALLOW_COPY_AND_ASSIGN (ValueObject);
1292 } // namespace lldb_private
1294 #endif // liblldb_ValueObject_h_