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_
13 #include "lldb/Core/Value.h"
14 #include "lldb/DataFormatters/DumpValueObjectOptions.h" // for DumpValueObj...
15 #include "lldb/Symbol/CompilerType.h"
16 #include "lldb/Symbol/Type.h" // for TypeImpl
17 #include "lldb/Target/ExecutionContext.h"
18 #include "lldb/Target/Process.h"
19 #include "lldb/Utility/ConstString.h"
20 #include "lldb/Utility/DataExtractor.h"
21 #include "lldb/Utility/Error.h"
22 #include "lldb/Utility/SharedCluster.h"
23 #include "lldb/Utility/UserID.h"
24 #include "lldb/lldb-defines.h" // for LLDB_INVALID...
25 #include "lldb/lldb-enumerations.h" // for DynamicValue...
26 #include "lldb/lldb-forward.h" // for ValueObjectSP
27 #include "lldb/lldb-private-enumerations.h" // for AddressType
28 #include "lldb/lldb-types.h" // for addr_t, offs...
30 #include "llvm/ADT/ArrayRef.h"
31 #include "llvm/ADT/Optional.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringRef.h" // for StringRef
36 #include <initializer_list>
38 #include <mutex> // for recursive_mutex
39 #include <string> // for string
40 #include <utility> // for pair
42 #include <stddef.h> // for size_t
43 #include <stdint.h> // for uint32_t
44 namespace lldb_private {
47 namespace lldb_private {
48 class EvaluateExpressionOptions;
50 namespace lldb_private {
51 class ExecutionContextScope;
53 namespace lldb_private {
56 namespace lldb_private {
59 namespace lldb_private {
62 namespace lldb_private {
63 class SymbolContextScope;
65 namespace lldb_private {
68 namespace lldb_private {
69 class TypeSummaryImpl;
71 namespace lldb_private {
72 class TypeSummaryOptions;
74 namespace lldb_private {
78 /// This abstract class provides an interface to a particular value, be it a
79 /// register, a local or global variable,
80 /// that is evaluated in some particular scope. The ValueObject also has the
81 /// capability of being the "child" of
82 /// some other variable object, and in turn of having children.
83 /// If a ValueObject is a root variable object - having no parent - then it must
84 /// be constructed with respect to some
85 /// particular ExecutionContextScope. If it is a child, it inherits the
86 /// ExecutionContextScope from its parent.
87 /// The ValueObject will update itself if necessary before fetching its value,
88 /// summary, object description, etc.
89 /// But it will always update itself in the ExecutionContextScope with which it
90 /// was originally created.
92 /// A brief note on life cycle management for ValueObjects. This is a little
93 /// tricky because a ValueObject can contain
94 /// various other ValueObjects - the Dynamic Value, its children, the
95 /// dereference value, etc. Any one of these can be
96 /// handed out as a shared pointer, but for that contained value object to be
97 /// valid, the root object and potentially other
98 /// of the value objects need to stay around.
99 /// We solve this problem by handing out shared pointers to the Value Object and
100 /// any of its dependents using a shared
101 /// ClusterManager. This treats each shared pointer handed out for the entire
102 /// cluster as a reference to the whole
103 /// cluster. The whole cluster will stay around until the last reference is
106 /// The ValueObject mostly handle this automatically, if a value object is made
107 /// with a Parent ValueObject, then it adds
108 /// itself to the ClusterManager of the parent.
110 /// It does mean that external to the ValueObjects we should only ever make
111 /// available ValueObjectSP's, never ValueObjects
112 /// or pointers to them. So all the "Root level" ValueObject derived
113 /// constructors should be private, and
114 /// should implement a Create function that new's up object and returns a Shared
115 /// Pointer that it gets from the GetSP() method.
117 /// However, if you are making an derived ValueObject that will be contained in
118 /// a parent value object, you should just
119 /// hold onto a pointer to it internally, and by virtue of passing the parent
120 /// ValueObject into its constructor, it will
121 /// be added to the ClusterManager for the parent. Then if you ever hand out a
122 /// Shared Pointer to the contained ValueObject,
123 /// just do so by calling GetSP() on the contained object.
125 class ValueObject : public UserID {
127 enum GetExpressionPathFormat {
128 eGetExpressionPathFormatDereferencePointers = 1,
129 eGetExpressionPathFormatHonorPointers
132 enum ValueObjectRepresentationStyle {
133 eValueObjectRepresentationStyleValue = 1,
134 eValueObjectRepresentationStyleSummary,
135 eValueObjectRepresentationStyleLanguageSpecific,
136 eValueObjectRepresentationStyleLocation,
137 eValueObjectRepresentationStyleChildrenCount,
138 eValueObjectRepresentationStyleType,
139 eValueObjectRepresentationStyleName,
140 eValueObjectRepresentationStyleExpressionPath
143 enum ExpressionPathScanEndReason {
144 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
145 eExpressionPathScanEndReasonNoSuchChild, // child element not found
146 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child
148 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for
150 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be
152 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be
154 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion
156 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by
158 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects
159 // other than scalars,
160 // pointers or arrays
161 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays,
162 // but I cannot parse it
163 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for
165 // cannot parse after
167 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in
169 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply &
171 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply *
173 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a
175 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic
177 eExpressionPathScanEndReasonUnknown = 0xFFFF
180 enum ExpressionPathEndResultType {
181 eExpressionPathEndResultTypePlain = 1, // anything but...
182 eExpressionPathEndResultTypeBitfield, // a bitfield
183 eExpressionPathEndResultTypeBoundedRange, // a range [low-high]
184 eExpressionPathEndResultTypeUnboundedRange, // a range []
185 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
186 eExpressionPathEndResultTypeInvalid = 0xFFFF
189 enum ExpressionPathAftermath {
190 eExpressionPathAftermathNothing = 1, // just return it
191 eExpressionPathAftermathDereference, // dereference the target
192 eExpressionPathAftermathTakeAddress // take target's address
195 enum ClearUserVisibleDataItems {
196 eClearUserVisibleDataItemsNothing = 1u << 0,
197 eClearUserVisibleDataItemsValue = 1u << 1,
198 eClearUserVisibleDataItemsSummary = 1u << 2,
199 eClearUserVisibleDataItemsLocation = 1u << 3,
200 eClearUserVisibleDataItemsDescription = 1u << 4,
201 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
202 eClearUserVisibleDataItemsValidator = 1u << 6,
203 eClearUserVisibleDataItemsAllStrings =
204 eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary |
205 eClearUserVisibleDataItemsLocation |
206 eClearUserVisibleDataItemsDescription,
207 eClearUserVisibleDataItemsAll = 0xFFFF
210 struct GetValueForExpressionPathOptions {
211 enum class SyntheticChildrenTraversal {
218 bool m_check_dot_vs_arrow_syntax;
219 bool m_no_fragile_ivar;
220 bool m_allow_bitfields_syntax;
221 SyntheticChildrenTraversal m_synthetic_children_traversal;
223 GetValueForExpressionPathOptions(
224 bool dot = false, bool no_ivar = false, bool bitfield = true,
225 SyntheticChildrenTraversal synth_traverse =
226 SyntheticChildrenTraversal::ToSynthetic)
227 : m_check_dot_vs_arrow_syntax(dot), m_no_fragile_ivar(no_ivar),
228 m_allow_bitfields_syntax(bitfield),
229 m_synthetic_children_traversal(synth_traverse) {}
231 GetValueForExpressionPathOptions &DoCheckDotVsArrowSyntax() {
232 m_check_dot_vs_arrow_syntax = true;
236 GetValueForExpressionPathOptions &DontCheckDotVsArrowSyntax() {
237 m_check_dot_vs_arrow_syntax = false;
241 GetValueForExpressionPathOptions &DoAllowFragileIVar() {
242 m_no_fragile_ivar = false;
246 GetValueForExpressionPathOptions &DontAllowFragileIVar() {
247 m_no_fragile_ivar = true;
251 GetValueForExpressionPathOptions &DoAllowBitfieldSyntax() {
252 m_allow_bitfields_syntax = true;
256 GetValueForExpressionPathOptions &DontAllowBitfieldSyntax() {
257 m_allow_bitfields_syntax = false;
261 GetValueForExpressionPathOptions &
262 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse) {
263 m_synthetic_children_traversal = traverse;
267 static const GetValueForExpressionPathOptions DefaultOptions() {
268 static GetValueForExpressionPathOptions g_default_options;
270 return g_default_options;
274 class EvaluationPoint {
278 EvaluationPoint(ExecutionContextScope *exe_scope,
279 bool use_selected = false);
281 EvaluationPoint(const EvaluationPoint &rhs);
285 const ExecutionContextRef &GetExecutionContextRef() const {
286 return m_exe_ctx_ref;
289 // Set the EvaluationPoint to the values in exe_scope,
290 // Return true if the Evaluation Point changed.
291 // Since the ExecutionContextScope is always going to be valid currently,
292 // the Updated Context will also always be valid.
295 // SetContext (ExecutionContextScope *exe_scope);
297 void SetIsConstant() {
299 m_mod_id.SetInvalid();
302 bool IsConstant() const { return !m_mod_id.IsValid(); }
304 ProcessModID GetModID() const { return m_mod_id; }
306 void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
308 void SetNeedsUpdate() { m_needs_update = true; }
312 bool NeedsUpdating(bool accept_invalid_exe_ctx) {
313 SyncWithProcessState(accept_invalid_exe_ctx);
314 return m_needs_update;
318 const bool accept_invalid_exe_ctx = false;
319 if (!m_mod_id.IsValid())
321 else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
322 if (!m_mod_id.IsValid())
329 // Use the stop id to mark us as invalid, leave the thread id and the
330 // stack id around for logging and
332 m_mod_id.SetInvalid();
334 // Can't update an invalid state.
335 m_needs_update = false;
339 bool SyncWithProcessState(bool accept_invalid_exe_ctx);
341 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
343 ExecutionContextRef m_exe_ctx_ref;
347 virtual ~ValueObject();
349 const EvaluationPoint &GetUpdatePoint() const { return m_update_point; }
351 EvaluationPoint &GetUpdatePoint() { return m_update_point; }
353 const ExecutionContextRef &GetExecutionContextRef() const {
354 return m_update_point.GetExecutionContextRef();
357 lldb::TargetSP GetTargetSP() const {
358 return m_update_point.GetExecutionContextRef().GetTargetSP();
361 lldb::ProcessSP GetProcessSP() const {
362 return m_update_point.GetExecutionContextRef().GetProcessSP();
365 lldb::ThreadSP GetThreadSP() const {
366 return m_update_point.GetExecutionContextRef().GetThreadSP();
369 lldb::StackFrameSP GetFrameSP() const {
370 return m_update_point.GetExecutionContextRef().GetFrameSP();
373 void SetNeedsUpdate();
375 CompilerType GetCompilerType();
377 // this vends a TypeImpl that is useful at the SB API layer
378 virtual TypeImpl GetTypeImpl();
380 virtual bool CanProvideValue();
382 //------------------------------------------------------------------
383 // Subclasses must implement the functions below.
384 //------------------------------------------------------------------
385 virtual uint64_t GetByteSize() = 0;
387 virtual lldb::ValueType GetValueType() const = 0;
389 //------------------------------------------------------------------
390 // Subclasses can implement the functions below.
391 //------------------------------------------------------------------
392 virtual ConstString GetTypeName();
394 virtual ConstString GetDisplayTypeName();
396 virtual ConstString GetQualifiedTypeName();
398 virtual lldb::LanguageType GetObjectRuntimeLanguage();
401 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
403 virtual bool IsPointerType();
405 virtual bool IsArrayType();
407 virtual bool IsScalarType();
409 virtual bool IsPointerOrReferenceType();
411 virtual bool IsPossibleDynamicType();
413 bool IsNilReference();
415 bool IsUninitializedReference();
417 virtual bool IsBaseClass() { return false; }
419 bool IsBaseClass(uint32_t &depth);
421 virtual bool IsDereferenceOfParent() { return false; }
423 bool IsIntegerType(bool &is_signed);
425 virtual bool GetBaseClassPath(Stream &s);
427 virtual void GetExpressionPath(
428 Stream &s, bool qualify_cxx_base_classes,
429 GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
431 lldb::ValueObjectSP GetValueForExpressionPath(
432 llvm::StringRef expression,
433 ExpressionPathScanEndReason *reason_to_stop = nullptr,
434 ExpressionPathEndResultType *final_value_type = nullptr,
435 const GetValueForExpressionPathOptions &options =
436 GetValueForExpressionPathOptions::DefaultOptions(),
437 ExpressionPathAftermath *final_task_on_target = nullptr);
439 virtual bool IsInScope() { return true; }
441 virtual lldb::offset_t GetByteOffset() { return 0; }
443 virtual uint32_t GetBitfieldBitSize() { return 0; }
445 virtual uint32_t GetBitfieldBitOffset() { return 0; }
448 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
451 virtual bool IsArrayItemForPointer() { return m_is_array_item_for_pointer; }
453 virtual const char *GetValueAsCString();
455 virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
456 std::string &destination);
458 bool GetValueAsCString(lldb::Format format, std::string &destination);
460 virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
461 bool *success = nullptr);
463 virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
465 virtual bool SetValueFromCString(const char *value_str, Error &error);
467 // Return the module associated with this value object in case the
468 // value is from an executable file and might have its data in
469 // sections of the file. This can be used for variables.
470 virtual lldb::ModuleSP GetModule();
472 ValueObject *GetRoot();
474 // Given a ValueObject, loop over itself and its parent, and its parent's
476 // until either the given callback returns false, or you end up at a null
478 ValueObject *FollowParentChain(std::function<bool(ValueObject *)>);
480 virtual bool GetDeclaration(Declaration &decl);
482 //------------------------------------------------------------------
483 // The functions below should NOT be modified by subclasses
484 //------------------------------------------------------------------
485 const Error &GetError();
487 const ConstString &GetName() const;
489 virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
491 // this will always create the children if necessary
492 lldb::ValueObjectSP GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
493 size_t *index_of_error = nullptr);
496 GetChildAtIndexPath(llvm::ArrayRef<std::pair<size_t, bool>> idxs,
497 size_t *index_of_error = nullptr);
499 // this will always create the children if necessary
500 lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef<ConstString> names,
501 ConstString *name_of_error = nullptr);
504 GetChildAtNamePath(llvm::ArrayRef<std::pair<ConstString, bool>> names,
505 ConstString *name_of_error = nullptr);
507 virtual lldb::ValueObjectSP GetChildMemberWithName(const ConstString &name,
510 virtual size_t GetIndexOfChildWithName(const ConstString &name);
512 size_t GetNumChildren(uint32_t max = UINT32_MAX);
514 const Value &GetValue() const;
518 virtual bool ResolveValue(Scalar &scalar);
520 // return 'false' whenever you set the error, otherwise
521 // callers may assume true means everything is OK - this will
522 // break breakpoint conditions among potentially a few others
523 virtual bool IsLogicalTrue(Error &error);
525 virtual const char *GetLocationAsCString();
528 GetSummaryAsCString(lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
531 GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
532 lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
534 bool GetSummaryAsCString(std::string &destination,
535 const TypeSummaryOptions &options);
537 bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
538 std::string &destination,
539 const TypeSummaryOptions &options);
541 std::pair<TypeValidatorResult, std::string> GetValidationStatus();
543 const char *GetObjectDescription();
545 bool HasSpecialPrintableRepresentation(
546 ValueObjectRepresentationStyle val_obj_display,
547 lldb::Format custom_format);
549 enum class PrintableRepresentationSpecialCases : bool {
555 DumpPrintableRepresentation(Stream &s,
556 ValueObjectRepresentationStyle val_obj_display =
557 eValueObjectRepresentationStyleSummary,
558 lldb::Format custom_format = lldb::eFormatInvalid,
559 PrintableRepresentationSpecialCases special =
560 PrintableRepresentationSpecialCases::eAllow,
561 bool do_dump_error = true);
562 bool GetValueIsValid() const;
564 // If you call this on a newly created ValueObject, it will always return
566 bool GetValueDidChange();
568 bool UpdateValueIfNeeded(bool update_format = true);
570 bool UpdateFormatsIfNeeded();
572 lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
574 // Change the name of the current ValueObject. Should *not* be used from a
575 // synthetic child provider as it would change the name of the non synthetic
577 void SetName(const ConstString &name);
579 virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
580 AddressType *address_type = nullptr);
582 lldb::addr_t GetPointerValue(AddressType *address_type = nullptr);
584 lldb::ValueObjectSP GetSyntheticChild(const ConstString &key) const;
586 lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
588 lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
591 lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression,
594 virtual lldb::ValueObjectSP
595 GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
597 ConstString name_const_str = ConstString());
599 virtual lldb::ValueObjectSP
600 GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
601 ConstString name_const_str = ConstString());
603 virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType);
605 lldb::DynamicValueType GetDynamicValueType();
607 virtual lldb::ValueObjectSP GetStaticValue();
609 virtual lldb::ValueObjectSP GetNonSyntheticValue();
611 lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic = true);
613 virtual bool HasSyntheticValue();
615 virtual bool IsSynthetic() { return false; }
618 GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue,
621 virtual lldb::ValueObjectSP CreateConstantValue(const ConstString &name);
623 virtual lldb::ValueObjectSP Dereference(Error &error);
625 // Creates a copy of the ValueObject with a new name and setting the current
626 // ValueObject as its parent. It should be used when we want to change the
627 // name of a ValueObject without modifying the actual ValueObject itself
628 // (e.g. sythetic child provider).
629 virtual lldb::ValueObjectSP Clone(const ConstString &new_name);
631 virtual lldb::ValueObjectSP AddressOf(Error &error);
633 virtual lldb::addr_t GetLiveAddress() { return LLDB_INVALID_ADDRESS; }
635 virtual void SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
636 AddressType address_type = eAddressTypeLoad) {}
638 // Find the address of the C++ vtable pointer
639 virtual lldb::addr_t GetCPPVTableAddress(AddressType &address_type);
641 virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
643 virtual lldb::ValueObjectSP CastPointerType(const char *name,
644 CompilerType &ast_type);
646 virtual lldb::ValueObjectSP CastPointerType(const char *name,
647 lldb::TypeSP &type_sp);
649 // The backing bits of this value object were updated, clear any
650 // descriptive string, so we know we have to refetch them
651 virtual void ValueUpdated() {
652 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
653 eClearUserVisibleDataItemsSummary |
654 eClearUserVisibleDataItemsDescription);
657 virtual bool IsDynamic() { return false; }
659 virtual bool DoesProvideSyntheticValue() { return false; }
661 virtual bool IsSyntheticChildrenGenerated();
663 virtual void SetSyntheticChildrenGenerated(bool b);
665 virtual SymbolContextScope *GetSymbolContextScope();
667 void Dump(Stream &s);
669 void Dump(Stream &s, const DumpValueObjectOptions &options);
671 static lldb::ValueObjectSP
672 CreateValueObjectFromExpression(llvm::StringRef name,
673 llvm::StringRef expression,
674 const ExecutionContext &exe_ctx);
676 static lldb::ValueObjectSP
677 CreateValueObjectFromExpression(llvm::StringRef name,
678 llvm::StringRef expression,
679 const ExecutionContext &exe_ctx,
680 const EvaluateExpressionOptions &options);
682 static lldb::ValueObjectSP
683 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
684 const ExecutionContext &exe_ctx,
687 static lldb::ValueObjectSP
688 CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
689 const ExecutionContext &exe_ctx, CompilerType type);
691 void LogValueObject(Log *log);
693 void LogValueObject(Log *log, const DumpValueObjectOptions &options);
695 lldb::ValueObjectSP Persist();
697 // returns true if this is a char* or a char[]
698 // if it is a char* and check_pointer is true,
699 // it also checks that the pointer is valid
700 bool IsCStringContainer(bool check_pointer = false);
702 std::pair<size_t, bool>
703 ReadPointedString(lldb::DataBufferSP &buffer_sp, Error &error,
704 uint32_t max_length = 0, bool honor_array = true,
705 lldb::Format item_format = lldb::eFormatCharArray);
707 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
708 uint32_t item_count = 1);
710 virtual uint64_t GetData(DataExtractor &data, Error &error);
712 virtual bool SetData(DataExtractor &data, Error &error);
714 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
716 bool NeedsUpdating() {
717 const bool accept_invalid_exe_ctx =
718 (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
719 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
722 void SetIsConstant() { m_update_point.SetIsConstant(); }
724 lldb::Format GetFormat() const;
726 virtual void SetFormat(lldb::Format format) {
727 if (format != m_format)
728 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
732 virtual lldb::LanguageType GetPreferredDisplayLanguage();
734 void SetPreferredDisplayLanguage(lldb::LanguageType);
736 lldb::TypeSummaryImplSP GetSummaryFormat() {
737 UpdateFormatsIfNeeded();
738 return m_type_summary_sp;
741 void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
742 m_type_summary_sp = format;
743 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
746 lldb::TypeValidatorImplSP GetValidator() {
747 UpdateFormatsIfNeeded();
748 return m_type_validator_sp;
751 void SetValidator(lldb::TypeValidatorImplSP format) {
752 m_type_validator_sp = format;
753 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
756 void SetValueFormat(lldb::TypeFormatImplSP format) {
757 m_type_format_sp = format;
758 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
761 lldb::TypeFormatImplSP GetValueFormat() {
762 UpdateFormatsIfNeeded();
763 return m_type_format_sp;
766 void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
767 if (synth_sp.get() == m_synthetic_children_sp.get())
769 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
770 m_synthetic_children_sp = synth_sp;
773 lldb::SyntheticChildrenSP GetSyntheticChildren() {
774 UpdateFormatsIfNeeded();
775 return m_synthetic_children_sp;
778 // Use GetParent for display purposes, but if you want to tell the parent to
780 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct
782 // displaying, they are really siblings, so for display it needs to route
783 // through to its grandparent.
784 virtual ValueObject *GetParent() { return m_parent; }
786 virtual const ValueObject *GetParent() const { return m_parent; }
788 ValueObject *GetNonBaseClassParent();
790 void SetAddressTypeOfChildren(AddressType at) {
791 m_address_type_of_ptr_or_ref_children = at;
794 AddressType GetAddressTypeOfChildren();
796 void SetHasCompleteType() { m_did_calculate_complete_objc_class_type = true; }
798 //------------------------------------------------------------------
799 /// Find out if a ValueObject might have children.
801 /// This call is much more efficient than CalculateNumChildren() as
802 /// it doesn't need to complete the underlying type. This is designed
803 /// to be used in a UI environment in order to detect if the
804 /// disclosure triangle should be displayed or not.
806 /// This function returns true for class, union, structure,
807 /// pointers, references, arrays and more. Again, it does so without
808 /// doing any expensive type completion.
811 /// Returns \b true if the ValueObject might have children, or \b
813 //------------------------------------------------------------------
814 virtual bool MightHaveChildren();
816 virtual lldb::VariableSP GetVariable() { return nullptr; }
818 virtual bool IsRuntimeSupportValue();
820 virtual uint64_t GetLanguageFlags();
822 virtual void SetLanguageFlags(uint64_t flags);
825 typedef ClusterManager<ValueObject> ValueObjectManager;
827 class ChildrenManager {
829 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
831 bool HasChildAtIndex(size_t idx) {
832 std::lock_guard<std::recursive_mutex> guard(m_mutex);
833 return (m_children.find(idx) != m_children.end());
836 ValueObject *GetChildAtIndex(size_t idx) {
837 std::lock_guard<std::recursive_mutex> guard(m_mutex);
838 const auto iter = m_children.find(idx);
839 return ((iter == m_children.end()) ? nullptr : iter->second);
842 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
843 // we do not need to be mutex-protected to make a pair
844 ChildrenPair pair(idx, valobj);
845 std::lock_guard<std::recursive_mutex> guard(m_mutex);
846 m_children.insert(pair);
849 void SetChildrenCount(size_t count) { Clear(count); }
851 size_t GetChildrenCount() { return m_children_count; }
853 void Clear(size_t new_count = 0) {
854 std::lock_guard<std::recursive_mutex> guard(m_mutex);
855 m_children_count = new_count;
860 typedef std::map<size_t, ValueObject *> ChildrenMap;
861 typedef ChildrenMap::iterator ChildrenIterator;
862 typedef ChildrenMap::value_type ChildrenPair;
863 std::recursive_mutex m_mutex;
864 ChildrenMap m_children;
865 size_t m_children_count;
868 //------------------------------------------------------------------
869 // Classes that inherit from ValueObject can see and modify these
870 //------------------------------------------------------------------
872 *m_parent; // The parent value object, or nullptr if this has no parent
873 ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
874 // nullptr if never calculated)
875 EvaluationPoint m_update_point; // Stores both the stop id and the full
876 // context at which this value was last
877 // updated. When we are asked to update the value object, we check whether
878 // the context & stop id are the same before updating.
879 ConstString m_name; // The name of this object
881 m_data; // A data extractor that can be used to extract the value.
883 Error m_error; // An error object that can describe any errors that occur when
885 std::string m_value_str; // Cached value string that will get cleared if/when
886 // the value is updated.
887 std::string m_old_value_str; // Cached old value string from the last time the
889 std::string m_location_str; // Cached location string that will get cleared
890 // if/when the value is updated.
891 std::string m_summary_str; // Cached summary string that will get cleared
892 // if/when the value is updated.
893 std::string m_object_desc_str; // Cached result of the "object printer". This
894 // differs from the summary
895 // in that the summary is consed up by us, the object_desc_string is builtin.
897 llvm::Optional<std::pair<TypeValidatorResult, std::string>>
900 CompilerType m_override_type; // If the type of the value object should be
901 // overridden, the type to impose.
903 ValueObjectManager *m_manager; // This object is managed by the root object
904 // (any ValueObject that gets created
905 // without a parent.) The manager gets passed through all the generations of
906 // dependent objects, and will keep the whole cluster of objects alive as long
907 // as a shared pointer to any of them has been handed out. Shared pointers to
908 // value objects must always be made with the GetSP method.
910 ChildrenManager m_children;
911 std::map<ConstString, ValueObject *> m_synthetic_children;
913 ValueObject *m_dynamic_value;
914 ValueObject *m_synthetic_value;
915 ValueObject *m_deref_valobj;
917 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
918 // pointer to this one because it is
920 // as an independent ValueObjectConstResult, which isn't managed by us.
922 lldb::Format m_format;
923 lldb::Format m_last_format;
924 uint32_t m_last_format_mgr_revision;
925 lldb::TypeSummaryImplSP m_type_summary_sp;
926 lldb::TypeFormatImplSP m_type_format_sp;
927 lldb::SyntheticChildrenSP m_synthetic_children_sp;
928 lldb::TypeValidatorImplSP m_type_validator_sp;
929 ProcessModID m_user_id_of_forced_summary;
930 AddressType m_address_type_of_ptr_or_ref_children;
932 llvm::SmallVector<uint8_t, 16> m_value_checksum;
934 lldb::LanguageType m_preferred_display_language;
936 uint64_t m_language_flags;
938 bool m_value_is_valid : 1, m_value_did_change : 1, m_children_count_valid : 1,
939 m_old_value_valid : 1, m_is_deref_of_parent : 1,
940 m_is_array_item_for_pointer : 1, m_is_bitfield_for_scalar : 1,
941 m_is_child_at_offset : 1, m_is_getting_summary : 1,
942 m_did_calculate_complete_objc_class_type : 1,
943 m_is_synthetic_children_generated : 1;
945 friend class ValueObjectChild;
946 friend class ClangExpressionDeclMap; // For GetValue
947 friend class ExpressionVariable; // For SetName
948 friend class Target; // For SetName
949 friend class ValueObjectConstResultImpl;
950 friend class ValueObjectSynthetic; // For ClearUserVisibleData
952 //------------------------------------------------------------------
953 // Constructors and Destructors
954 //------------------------------------------------------------------
956 // Use the no-argument constructor to make a constant variable object (with no
957 // ExecutionContextScope.)
961 // Use this constructor to create a "root variable object". The ValueObject
962 // will be locked to this context
963 // through-out its lifespan.
965 ValueObject(ExecutionContextScope *exe_scope,
966 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
968 // Use this constructor to create a ValueObject owned by another ValueObject.
969 // It will inherit the ExecutionContext
972 ValueObject(ValueObject &parent);
974 ValueObjectManager *GetManager() { return m_manager; }
976 virtual bool UpdateValue() = 0;
978 virtual LazyBool CanUpdateWithInvalidExecutionContext() {
979 return eLazyBoolCalculate;
982 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
984 virtual lldb::DynamicValueType GetDynamicValueTypeImpl() {
985 return lldb::eNoDynamicValues;
988 virtual bool HasDynamicValueTypeInfo() { return false; }
990 virtual void CalculateSyntheticValue(bool use_synthetic = true);
992 // Should only be called by ValueObject::GetChildAtIndex()
993 // Returns a ValueObject managed by this ValueObject's manager.
994 virtual ValueObject *CreateChildAtIndex(size_t idx,
995 bool synthetic_array_member,
996 int32_t synthetic_index);
998 // Should only be called by ValueObject::GetNumChildren()
999 virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
1001 void SetNumChildren(size_t num_children);
1003 void SetValueDidChange(bool value_changed);
1005 void SetValueIsValid(bool valid);
1007 void ClearUserVisibleData(
1008 uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1010 void AddSyntheticChild(const ConstString &key, ValueObject *valobj);
1012 DataExtractor &GetDataExtractor();
1014 void ClearDynamicTypeInformation();
1016 //------------------------------------------------------------------
1017 // Subclasses must implement the functions below.
1018 //------------------------------------------------------------------
1020 virtual CompilerType GetCompilerTypeImpl() = 0;
1022 const char *GetLocationAsCStringImpl(const Value &value,
1023 const DataExtractor &data);
1025 bool IsChecksumEmpty();
1027 void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
1030 virtual CompilerType MaybeCalculateCompleteType();
1032 lldb::ValueObjectSP GetValueForExpressionPath_Impl(
1033 llvm::StringRef expression_cstr,
1034 ExpressionPathScanEndReason *reason_to_stop,
1035 ExpressionPathEndResultType *final_value_type,
1036 const GetValueForExpressionPathOptions &options,
1037 ExpressionPathAftermath *final_task_on_target);
1039 DISALLOW_COPY_AND_ASSIGN(ValueObject);
1042 //------------------------------------------------------------------------------
1043 // A value object manager class that is seeded with the static variable value
1044 // and it vends the user facing value object. If the type is dynamic it can
1045 // vend the dynamic type. If this user type also has a synthetic type associated
1046 // with it, it will vend the synthetic type. The class watches the process' stop
1047 // ID and will update the user type when needed.
1048 //------------------------------------------------------------------------------
1049 class ValueObjectManager {
1050 // The root value object is the static typed variable object.
1051 lldb::ValueObjectSP m_root_valobj_sp;
1052 // The user value object is the value object the user wants to see.
1053 lldb::ValueObjectSP m_user_valobj_sp;
1054 lldb::DynamicValueType m_use_dynamic;
1055 uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1056 bool m_use_synthetic;
1059 ValueObjectManager() {}
1061 ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1062 lldb::DynamicValueType use_dynamic, bool use_synthetic);
1064 bool IsValid() const;
1066 lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1068 // Gets the correct value object from the root object for a given process
1069 // stop ID. If dynamic values are enabled, or if synthetic children are
1070 // enabled, the value object that the user wants to see might change while
1072 lldb::ValueObjectSP GetSP();
1074 void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1075 void SetUseSynthetic(bool use_synthetic);
1076 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1077 bool GetUseSynthetic() const { return m_use_synthetic; }
1078 lldb::TargetSP GetTargetSP() const;
1079 lldb::ProcessSP GetProcessSP() const;
1080 lldb::ThreadSP GetThreadSP() const;
1081 lldb::StackFrameSP GetFrameSP() const;
1084 } // namespace lldb_private
1086 #endif // liblldb_ValueObject_h_