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/Symbol/CompilerType.h"
15 #include "lldb/Symbol/Type.h" // for TypeImpl
16 #include "lldb/Target/ExecutionContext.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/DataExtractor.h"
20 #include "lldb/Utility/SharedCluster.h"
21 #include "lldb/Utility/Status.h"
22 #include "lldb/Utility/UserID.h"
23 #include "lldb/lldb-defines.h" // for LLDB_INVALID...
24 #include "lldb/lldb-enumerations.h" // for DynamicValue...
25 #include "lldb/lldb-forward.h" // for ValueObjectSP
26 #include "lldb/lldb-private-enumerations.h" // for AddressType
27 #include "lldb/lldb-types.h" // for addr_t, offs...
29 #include "llvm/ADT/ArrayRef.h"
30 #include "llvm/ADT/Optional.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringRef.h" // for StringRef
35 #include <initializer_list>
37 #include <mutex> // for recursive_mutex
38 #include <string> // for string
39 #include <utility> // for pair
41 #include <stddef.h> // for size_t
42 #include <stdint.h> // for uint32_t
43 namespace lldb_private {
46 namespace lldb_private {
47 class DumpValueObjectOptions;
49 namespace lldb_private {
50 class EvaluateExpressionOptions;
52 namespace lldb_private {
53 class ExecutionContextScope;
55 namespace lldb_private {
58 namespace lldb_private {
61 namespace lldb_private {
64 namespace lldb_private {
65 class SymbolContextScope;
67 namespace lldb_private {
70 namespace lldb_private {
71 class TypeSummaryImpl;
73 namespace lldb_private {
74 class TypeSummaryOptions;
76 namespace lldb_private {
80 /// This abstract class provides an interface to a particular value, be it a
81 /// register, a local or global variable,
82 /// that is evaluated in some particular scope. The ValueObject also has the
83 /// capability of being the "child" of
84 /// some other variable object, and in turn of having children.
85 /// If a ValueObject is a root variable object - having no parent - then it must
86 /// be constructed with respect to some
87 /// particular ExecutionContextScope. If it is a child, it inherits the
88 /// ExecutionContextScope from its parent.
89 /// The ValueObject will update itself if necessary before fetching its value,
90 /// summary, object description, etc.
91 /// But it will always update itself in the ExecutionContextScope with which it
92 /// was originally created.
94 /// A brief note on life cycle management for ValueObjects. This is a little
95 /// tricky because a ValueObject can contain
96 /// various other ValueObjects - the Dynamic Value, its children, the
97 /// dereference value, etc. Any one of these can be
98 /// handed out as a shared pointer, but for that contained value object to be
99 /// valid, the root object and potentially other
100 /// of the value objects need to stay around.
101 /// We solve this problem by handing out shared pointers to the Value Object and
102 /// any of its dependents using a shared
103 /// ClusterManager. This treats each shared pointer handed out for the entire
104 /// cluster as a reference to the whole
105 /// cluster. The whole cluster will stay around until the last reference is
108 /// The ValueObject mostly handle this automatically, if a value object is made
109 /// with a Parent ValueObject, then it adds
110 /// itself to the ClusterManager of the parent.
112 /// It does mean that external to the ValueObjects we should only ever make
113 /// available ValueObjectSP's, never ValueObjects
114 /// or pointers to them. So all the "Root level" ValueObject derived
115 /// constructors should be private, and
116 /// should implement a Create function that new's up object and returns a Shared
117 /// Pointer that it gets from the GetSP() method.
119 /// However, if you are making an derived ValueObject that will be contained in
120 /// a parent value object, you should just
121 /// hold onto a pointer to it internally, and by virtue of passing the parent
122 /// ValueObject into its constructor, it will
123 /// be added to the ClusterManager for the parent. Then if you ever hand out a
124 /// Shared Pointer to the contained ValueObject,
125 /// just do so by calling GetSP() on the contained object.
127 class ValueObject : public UserID {
129 enum GetExpressionPathFormat {
130 eGetExpressionPathFormatDereferencePointers = 1,
131 eGetExpressionPathFormatHonorPointers
134 enum ValueObjectRepresentationStyle {
135 eValueObjectRepresentationStyleValue = 1,
136 eValueObjectRepresentationStyleSummary,
137 eValueObjectRepresentationStyleLanguageSpecific,
138 eValueObjectRepresentationStyleLocation,
139 eValueObjectRepresentationStyleChildrenCount,
140 eValueObjectRepresentationStyleType,
141 eValueObjectRepresentationStyleName,
142 eValueObjectRepresentationStyleExpressionPath
145 enum ExpressionPathScanEndReason {
146 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
147 eExpressionPathScanEndReasonNoSuchChild, // child element not found
148 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child
150 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for
152 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be
154 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be
156 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion
158 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by
160 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects
161 // other than scalars,
162 // pointers or arrays
163 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays,
164 // but I cannot parse it
165 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for
167 // cannot parse after
169 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in
171 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply &
173 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply *
175 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a
177 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic
179 eExpressionPathScanEndReasonUnknown = 0xFFFF
182 enum ExpressionPathEndResultType {
183 eExpressionPathEndResultTypePlain = 1, // anything but...
184 eExpressionPathEndResultTypeBitfield, // a bitfield
185 eExpressionPathEndResultTypeBoundedRange, // a range [low-high]
186 eExpressionPathEndResultTypeUnboundedRange, // a range []
187 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
188 eExpressionPathEndResultTypeInvalid = 0xFFFF
191 enum ExpressionPathAftermath {
192 eExpressionPathAftermathNothing = 1, // just return it
193 eExpressionPathAftermathDereference, // dereference the target
194 eExpressionPathAftermathTakeAddress // take target's address
197 enum ClearUserVisibleDataItems {
198 eClearUserVisibleDataItemsNothing = 1u << 0,
199 eClearUserVisibleDataItemsValue = 1u << 1,
200 eClearUserVisibleDataItemsSummary = 1u << 2,
201 eClearUserVisibleDataItemsLocation = 1u << 3,
202 eClearUserVisibleDataItemsDescription = 1u << 4,
203 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
204 eClearUserVisibleDataItemsValidator = 1u << 6,
205 eClearUserVisibleDataItemsAllStrings =
206 eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary |
207 eClearUserVisibleDataItemsLocation |
208 eClearUserVisibleDataItemsDescription,
209 eClearUserVisibleDataItemsAll = 0xFFFF
212 struct GetValueForExpressionPathOptions {
213 enum class SyntheticChildrenTraversal {
220 bool m_check_dot_vs_arrow_syntax;
221 bool m_no_fragile_ivar;
222 bool m_allow_bitfields_syntax;
223 SyntheticChildrenTraversal m_synthetic_children_traversal;
225 GetValueForExpressionPathOptions(
226 bool dot = false, bool no_ivar = false, bool bitfield = true,
227 SyntheticChildrenTraversal synth_traverse =
228 SyntheticChildrenTraversal::ToSynthetic)
229 : m_check_dot_vs_arrow_syntax(dot), m_no_fragile_ivar(no_ivar),
230 m_allow_bitfields_syntax(bitfield),
231 m_synthetic_children_traversal(synth_traverse) {}
233 GetValueForExpressionPathOptions &DoCheckDotVsArrowSyntax() {
234 m_check_dot_vs_arrow_syntax = true;
238 GetValueForExpressionPathOptions &DontCheckDotVsArrowSyntax() {
239 m_check_dot_vs_arrow_syntax = false;
243 GetValueForExpressionPathOptions &DoAllowFragileIVar() {
244 m_no_fragile_ivar = false;
248 GetValueForExpressionPathOptions &DontAllowFragileIVar() {
249 m_no_fragile_ivar = true;
253 GetValueForExpressionPathOptions &DoAllowBitfieldSyntax() {
254 m_allow_bitfields_syntax = true;
258 GetValueForExpressionPathOptions &DontAllowBitfieldSyntax() {
259 m_allow_bitfields_syntax = false;
263 GetValueForExpressionPathOptions &
264 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse) {
265 m_synthetic_children_traversal = traverse;
269 static const GetValueForExpressionPathOptions DefaultOptions() {
270 static GetValueForExpressionPathOptions g_default_options;
272 return g_default_options;
276 class EvaluationPoint {
280 EvaluationPoint(ExecutionContextScope *exe_scope,
281 bool use_selected = false);
283 EvaluationPoint(const EvaluationPoint &rhs);
287 const ExecutionContextRef &GetExecutionContextRef() const {
288 return m_exe_ctx_ref;
291 // Set the EvaluationPoint to the values in exe_scope, Return true if the
292 // Evaluation Point changed. Since the ExecutionContextScope is always
293 // going to be valid currently, the Updated Context will also always be
297 // SetContext (ExecutionContextScope *exe_scope);
299 void SetIsConstant() {
301 m_mod_id.SetInvalid();
304 bool IsConstant() const { return !m_mod_id.IsValid(); }
306 ProcessModID GetModID() const { return m_mod_id; }
308 void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
310 void SetNeedsUpdate() { m_needs_update = true; }
314 bool NeedsUpdating(bool accept_invalid_exe_ctx) {
315 SyncWithProcessState(accept_invalid_exe_ctx);
316 return m_needs_update;
320 const bool accept_invalid_exe_ctx = false;
321 if (!m_mod_id.IsValid())
323 else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
324 if (!m_mod_id.IsValid())
331 // Use the stop id to mark us as invalid, leave the thread id and the
332 // stack id around for logging and history purposes.
333 m_mod_id.SetInvalid();
335 // Can't update an invalid state.
336 m_needs_update = false;
340 bool SyncWithProcessState(bool accept_invalid_exe_ctx);
342 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
344 ExecutionContextRef m_exe_ctx_ref;
348 virtual ~ValueObject();
350 const EvaluationPoint &GetUpdatePoint() const { return m_update_point; }
352 EvaluationPoint &GetUpdatePoint() { return m_update_point; }
354 const ExecutionContextRef &GetExecutionContextRef() const {
355 return m_update_point.GetExecutionContextRef();
358 lldb::TargetSP GetTargetSP() const {
359 return m_update_point.GetExecutionContextRef().GetTargetSP();
362 lldb::ProcessSP GetProcessSP() const {
363 return m_update_point.GetExecutionContextRef().GetProcessSP();
366 lldb::ThreadSP GetThreadSP() const {
367 return m_update_point.GetExecutionContextRef().GetThreadSP();
370 lldb::StackFrameSP GetFrameSP() const {
371 return m_update_point.GetExecutionContextRef().GetFrameSP();
374 void SetNeedsUpdate();
376 CompilerType GetCompilerType();
378 // this vends a TypeImpl that is useful at the SB API layer
379 virtual TypeImpl GetTypeImpl();
381 virtual bool CanProvideValue();
383 //------------------------------------------------------------------
384 // Subclasses must implement the functions below.
385 //------------------------------------------------------------------
386 virtual uint64_t GetByteSize() = 0;
388 virtual lldb::ValueType GetValueType() const = 0;
390 //------------------------------------------------------------------
391 // Subclasses can implement the functions below.
392 //------------------------------------------------------------------
393 virtual ConstString GetTypeName();
395 virtual ConstString GetDisplayTypeName();
397 virtual ConstString GetQualifiedTypeName();
399 virtual lldb::LanguageType GetObjectRuntimeLanguage();
402 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
404 virtual bool IsPointerType();
406 virtual bool IsArrayType();
408 virtual bool IsScalarType();
410 virtual bool IsPointerOrReferenceType();
412 virtual bool IsPossibleDynamicType();
414 bool IsNilReference();
416 bool IsUninitializedReference();
418 virtual bool IsBaseClass() { return false; }
420 bool IsBaseClass(uint32_t &depth);
422 virtual bool IsDereferenceOfParent() { return false; }
424 bool IsIntegerType(bool &is_signed);
426 virtual bool GetBaseClassPath(Stream &s);
428 virtual void GetExpressionPath(
429 Stream &s, bool qualify_cxx_base_classes,
430 GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
432 lldb::ValueObjectSP GetValueForExpressionPath(
433 llvm::StringRef expression,
434 ExpressionPathScanEndReason *reason_to_stop = nullptr,
435 ExpressionPathEndResultType *final_value_type = nullptr,
436 const GetValueForExpressionPathOptions &options =
437 GetValueForExpressionPathOptions::DefaultOptions(),
438 ExpressionPathAftermath *final_task_on_target = nullptr);
440 virtual bool IsInScope() { return true; }
442 virtual lldb::offset_t GetByteOffset() { return 0; }
444 virtual uint32_t GetBitfieldBitSize() { return 0; }
446 virtual uint32_t GetBitfieldBitOffset() { return 0; }
449 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
452 virtual bool IsArrayItemForPointer() { return m_is_array_item_for_pointer; }
454 virtual const char *GetValueAsCString();
456 virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
457 std::string &destination);
459 bool GetValueAsCString(lldb::Format format, std::string &destination);
461 virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
462 bool *success = nullptr);
464 virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
466 virtual bool SetValueFromCString(const char *value_str, Status &error);
468 // Return the module associated with this value object in case the value is
469 // from an executable file and might have its data in sections of the file.
470 // This can be used for variables.
471 virtual lldb::ModuleSP GetModule();
473 ValueObject *GetRoot();
475 // Given a ValueObject, loop over itself and its parent, and its parent's
476 // parent, .. until either the given callback returns false, or you end up at
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 Status &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 callers may assume
521 // true means everything is OK - this will break breakpoint conditions among
522 // potentially a few others
523 virtual bool IsLogicalTrue(Status &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(Status &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(Status &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 descriptive
650 // 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[] if it is a char* and
698 // check_pointer is true, it also checks that the pointer is valid
699 bool IsCStringContainer(bool check_pointer = false);
701 std::pair<size_t, bool>
702 ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error,
703 uint32_t max_length = 0, bool honor_array = true,
704 lldb::Format item_format = lldb::eFormatCharArray);
706 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
707 uint32_t item_count = 1);
709 virtual uint64_t GetData(DataExtractor &data, Status &error);
711 virtual bool SetData(DataExtractor &data, Status &error);
713 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
715 bool NeedsUpdating() {
716 const bool accept_invalid_exe_ctx =
717 (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
718 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
721 void SetIsConstant() { m_update_point.SetIsConstant(); }
723 lldb::Format GetFormat() const;
725 virtual void SetFormat(lldb::Format format) {
726 if (format != m_format)
727 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
731 virtual lldb::LanguageType GetPreferredDisplayLanguage();
733 void SetPreferredDisplayLanguage(lldb::LanguageType);
735 lldb::TypeSummaryImplSP GetSummaryFormat() {
736 UpdateFormatsIfNeeded();
737 return m_type_summary_sp;
740 void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
741 m_type_summary_sp = format;
742 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
745 lldb::TypeValidatorImplSP GetValidator() {
746 UpdateFormatsIfNeeded();
747 return m_type_validator_sp;
750 void SetValidator(lldb::TypeValidatorImplSP format) {
751 m_type_validator_sp = format;
752 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
755 void SetValueFormat(lldb::TypeFormatImplSP format) {
756 m_type_format_sp = format;
757 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
760 lldb::TypeFormatImplSP GetValueFormat() {
761 UpdateFormatsIfNeeded();
762 return m_type_format_sp;
765 void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
766 if (synth_sp.get() == m_synthetic_children_sp.get())
768 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
769 m_synthetic_children_sp = synth_sp;
772 lldb::SyntheticChildrenSP GetSyntheticChildren() {
773 UpdateFormatsIfNeeded();
774 return m_synthetic_children_sp;
777 // Use GetParent for display purposes, but if you want to tell the parent to
778 // update itself then use m_parent. The ValueObjectDynamicValue's parent is
779 // not the correct parent for displaying, they are really siblings, so for
780 // display it needs to route through to its grandparent.
781 virtual ValueObject *GetParent() { return m_parent; }
783 virtual const ValueObject *GetParent() const { return m_parent; }
785 ValueObject *GetNonBaseClassParent();
787 void SetAddressTypeOfChildren(AddressType at) {
788 m_address_type_of_ptr_or_ref_children = at;
791 AddressType GetAddressTypeOfChildren();
793 void SetHasCompleteType() { m_did_calculate_complete_objc_class_type = true; }
795 //------------------------------------------------------------------
796 /// Find out if a ValueObject might have children.
798 /// This call is much more efficient than CalculateNumChildren() as
799 /// it doesn't need to complete the underlying type. This is designed
800 /// to be used in a UI environment in order to detect if the
801 /// disclosure triangle should be displayed or not.
803 /// This function returns true for class, union, structure,
804 /// pointers, references, arrays and more. Again, it does so without
805 /// doing any expensive type completion.
808 /// Returns \b true if the ValueObject might have children, or \b
810 //------------------------------------------------------------------
811 virtual bool MightHaveChildren();
813 virtual lldb::VariableSP GetVariable() { return nullptr; }
815 virtual bool IsRuntimeSupportValue();
817 virtual uint64_t GetLanguageFlags();
819 virtual void SetLanguageFlags(uint64_t flags);
822 typedef ClusterManager<ValueObject> ValueObjectManager;
824 class ChildrenManager {
826 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
828 bool HasChildAtIndex(size_t idx) {
829 std::lock_guard<std::recursive_mutex> guard(m_mutex);
830 return (m_children.find(idx) != m_children.end());
833 ValueObject *GetChildAtIndex(size_t idx) {
834 std::lock_guard<std::recursive_mutex> guard(m_mutex);
835 const auto iter = m_children.find(idx);
836 return ((iter == m_children.end()) ? nullptr : iter->second);
839 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
840 // we do not need to be mutex-protected to make a pair
841 ChildrenPair pair(idx, valobj);
842 std::lock_guard<std::recursive_mutex> guard(m_mutex);
843 m_children.insert(pair);
846 void SetChildrenCount(size_t count) { Clear(count); }
848 size_t GetChildrenCount() { return m_children_count; }
850 void Clear(size_t new_count = 0) {
851 std::lock_guard<std::recursive_mutex> guard(m_mutex);
852 m_children_count = new_count;
857 typedef std::map<size_t, ValueObject *> ChildrenMap;
858 typedef ChildrenMap::iterator ChildrenIterator;
859 typedef ChildrenMap::value_type ChildrenPair;
860 std::recursive_mutex m_mutex;
861 ChildrenMap m_children;
862 size_t m_children_count;
865 //------------------------------------------------------------------
866 // Classes that inherit from ValueObject can see and modify these
867 //------------------------------------------------------------------
869 *m_parent; // The parent value object, or nullptr if this has no parent
870 ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
871 // nullptr if never calculated)
872 EvaluationPoint m_update_point; // Stores both the stop id and the full
873 // context at which this value was last
874 // updated. When we are asked to update the value object, we check whether
875 // the context & stop id are the same before updating.
876 ConstString m_name; // The name of this object
878 m_data; // A data extractor that can be used to extract the value.
881 m_error; // An error object that can describe any errors that occur when
883 std::string m_value_str; // Cached value string that will get cleared if/when
884 // the value is updated.
885 std::string m_old_value_str; // Cached old value string from the last time the
887 std::string m_location_str; // Cached location string that will get cleared
888 // if/when the value is updated.
889 std::string m_summary_str; // Cached summary string that will get cleared
890 // if/when the value is updated.
891 std::string m_object_desc_str; // Cached result of the "object printer". This
892 // differs from the summary
893 // in that the summary is consed up by us, the object_desc_string is builtin.
895 llvm::Optional<std::pair<TypeValidatorResult, std::string>>
898 CompilerType m_override_type; // If the type of the value object should be
899 // overridden, the type to impose.
901 ValueObjectManager *m_manager; // This object is managed by the root object
902 // (any ValueObject that gets created
903 // without a parent.) The manager gets passed through all the generations of
904 // dependent objects, and will keep the whole cluster of objects alive as
905 // long as a shared pointer to any of them has been handed out. Shared
906 // pointers to value objects must always be made with the GetSP method.
908 ChildrenManager m_children;
909 std::map<ConstString, ValueObject *> m_synthetic_children;
911 ValueObject *m_dynamic_value;
912 ValueObject *m_synthetic_value;
913 ValueObject *m_deref_valobj;
915 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
916 // pointer to this one because it is
918 // as an independent ValueObjectConstResult, which isn't managed by us.
920 lldb::Format m_format;
921 lldb::Format m_last_format;
922 uint32_t m_last_format_mgr_revision;
923 lldb::TypeSummaryImplSP m_type_summary_sp;
924 lldb::TypeFormatImplSP m_type_format_sp;
925 lldb::SyntheticChildrenSP m_synthetic_children_sp;
926 lldb::TypeValidatorImplSP m_type_validator_sp;
927 ProcessModID m_user_id_of_forced_summary;
928 AddressType m_address_type_of_ptr_or_ref_children;
930 llvm::SmallVector<uint8_t, 16> m_value_checksum;
932 lldb::LanguageType m_preferred_display_language;
934 uint64_t m_language_flags;
936 bool m_value_is_valid : 1, m_value_did_change : 1, m_children_count_valid : 1,
937 m_old_value_valid : 1, m_is_deref_of_parent : 1,
938 m_is_array_item_for_pointer : 1, m_is_bitfield_for_scalar : 1,
939 m_is_child_at_offset : 1, m_is_getting_summary : 1,
940 m_did_calculate_complete_objc_class_type : 1,
941 m_is_synthetic_children_generated : 1;
943 friend class ValueObjectChild;
944 friend class ClangExpressionDeclMap; // For GetValue
945 friend class ExpressionVariable; // For SetName
946 friend class Target; // For SetName
947 friend class ValueObjectConstResultImpl;
948 friend class ValueObjectSynthetic; // For ClearUserVisibleData
950 //------------------------------------------------------------------
951 // Constructors and Destructors
952 //------------------------------------------------------------------
954 // Use the no-argument constructor to make a constant variable object (with
955 // no ExecutionContextScope.)
959 // Use this constructor to create a "root variable object". The ValueObject
960 // will be locked to this context through-out its lifespan.
962 ValueObject(ExecutionContextScope *exe_scope,
963 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
965 // Use this constructor to create a ValueObject owned by another ValueObject.
966 // It will inherit the ExecutionContext of its parent.
968 ValueObject(ValueObject &parent);
970 ValueObjectManager *GetManager() { return m_manager; }
972 virtual bool UpdateValue() = 0;
974 virtual LazyBool CanUpdateWithInvalidExecutionContext() {
975 return eLazyBoolCalculate;
978 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
980 virtual lldb::DynamicValueType GetDynamicValueTypeImpl() {
981 return lldb::eNoDynamicValues;
984 virtual bool HasDynamicValueTypeInfo() { return false; }
986 virtual void CalculateSyntheticValue(bool use_synthetic = true);
988 // Should only be called by ValueObject::GetChildAtIndex() Returns a
989 // ValueObject managed by this ValueObject's manager.
990 virtual ValueObject *CreateChildAtIndex(size_t idx,
991 bool synthetic_array_member,
992 int32_t synthetic_index);
994 // Should only be called by ValueObject::GetNumChildren()
995 virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
997 void SetNumChildren(size_t num_children);
999 void SetValueDidChange(bool value_changed);
1001 void SetValueIsValid(bool valid);
1003 void ClearUserVisibleData(
1004 uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1006 void AddSyntheticChild(const ConstString &key, ValueObject *valobj);
1008 DataExtractor &GetDataExtractor();
1010 void ClearDynamicTypeInformation();
1012 //------------------------------------------------------------------
1013 // Subclasses must implement the functions below.
1014 //------------------------------------------------------------------
1016 virtual CompilerType GetCompilerTypeImpl() = 0;
1018 const char *GetLocationAsCStringImpl(const Value &value,
1019 const DataExtractor &data);
1021 bool IsChecksumEmpty();
1023 void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
1026 virtual CompilerType MaybeCalculateCompleteType();
1028 lldb::ValueObjectSP GetValueForExpressionPath_Impl(
1029 llvm::StringRef expression_cstr,
1030 ExpressionPathScanEndReason *reason_to_stop,
1031 ExpressionPathEndResultType *final_value_type,
1032 const GetValueForExpressionPathOptions &options,
1033 ExpressionPathAftermath *final_task_on_target);
1035 DISALLOW_COPY_AND_ASSIGN(ValueObject);
1038 //------------------------------------------------------------------------------
1039 // A value object manager class that is seeded with the static variable value
1040 // and it vends the user facing value object. If the type is dynamic it can
1041 // vend the dynamic type. If this user type also has a synthetic type
1042 // associated with it, it will vend the synthetic type. The class watches the
1044 // ID and will update the user type when needed.
1045 //------------------------------------------------------------------------------
1046 class ValueObjectManager {
1047 // The root value object is the static typed variable object.
1048 lldb::ValueObjectSP m_root_valobj_sp;
1049 // The user value object is the value object the user wants to see.
1050 lldb::ValueObjectSP m_user_valobj_sp;
1051 lldb::DynamicValueType m_use_dynamic;
1052 uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1053 bool m_use_synthetic;
1056 ValueObjectManager() {}
1058 ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1059 lldb::DynamicValueType use_dynamic, bool use_synthetic);
1061 bool IsValid() const;
1063 lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1065 // Gets the correct value object from the root object for a given process
1066 // stop ID. If dynamic values are enabled, or if synthetic children are
1067 // enabled, the value object that the user wants to see might change while
1069 lldb::ValueObjectSP GetSP();
1071 void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1072 void SetUseSynthetic(bool use_synthetic);
1073 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1074 bool GetUseSynthetic() const { return m_use_synthetic; }
1075 lldb::TargetSP GetTargetSP() const;
1076 lldb::ProcessSP GetProcessSP() const;
1077 lldb::ThreadSP GetThreadSP() const;
1078 lldb::StackFrameSP GetFrameSP() const;
1081 } // namespace lldb_private
1083 #endif // liblldb_ValueObject_h_