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/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
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
493 GetChildAtIndexPath(const std::initializer_list<size_t> &idxs,
494 size_t *index_of_error = nullptr);
496 lldb::ValueObjectSP GetChildAtIndexPath(const std::vector<size_t> &idxs,
497 size_t *index_of_error = nullptr);
499 lldb::ValueObjectSP GetChildAtIndexPath(
500 const std::initializer_list<std::pair<size_t, bool>> &idxs,
501 size_t *index_of_error = nullptr);
504 GetChildAtIndexPath(const std::vector<std::pair<size_t, bool>> &idxs,
505 size_t *index_of_error = nullptr);
507 // this will always create the children if necessary
509 GetChildAtNamePath(const std::initializer_list<ConstString> &names,
510 ConstString *name_of_error = nullptr);
512 lldb::ValueObjectSP GetChildAtNamePath(const std::vector<ConstString> &names,
513 ConstString *name_of_error = nullptr);
515 lldb::ValueObjectSP GetChildAtNamePath(
516 const std::initializer_list<std::pair<ConstString, bool>> &names,
517 ConstString *name_of_error = nullptr);
520 GetChildAtNamePath(const std::vector<std::pair<ConstString, bool>> &names,
521 ConstString *name_of_error = nullptr);
523 virtual lldb::ValueObjectSP GetChildMemberWithName(const ConstString &name,
526 virtual size_t GetIndexOfChildWithName(const ConstString &name);
528 size_t GetNumChildren(uint32_t max = UINT32_MAX);
530 const Value &GetValue() const;
534 virtual bool ResolveValue(Scalar &scalar);
536 // return 'false' whenever you set the error, otherwise
537 // callers may assume true means everything is OK - this will
538 // break breakpoint conditions among potentially a few others
539 virtual bool IsLogicalTrue(Error &error);
541 virtual const char *GetLocationAsCString();
544 GetSummaryAsCString(lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
547 GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
548 lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
550 bool GetSummaryAsCString(std::string &destination,
551 const TypeSummaryOptions &options);
553 bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
554 std::string &destination,
555 const TypeSummaryOptions &options);
557 std::pair<TypeValidatorResult, std::string> GetValidationStatus();
559 const char *GetObjectDescription();
561 bool HasSpecialPrintableRepresentation(
562 ValueObjectRepresentationStyle val_obj_display,
563 lldb::Format custom_format);
565 enum class PrintableRepresentationSpecialCases : bool {
571 DumpPrintableRepresentation(Stream &s,
572 ValueObjectRepresentationStyle val_obj_display =
573 eValueObjectRepresentationStyleSummary,
574 lldb::Format custom_format = lldb::eFormatInvalid,
575 PrintableRepresentationSpecialCases special =
576 PrintableRepresentationSpecialCases::eAllow,
577 bool do_dump_error = true);
578 bool GetValueIsValid() const;
580 // If you call this on a newly created ValueObject, it will always return
582 bool GetValueDidChange();
584 bool UpdateValueIfNeeded(bool update_format = true);
586 bool UpdateFormatsIfNeeded();
588 lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
590 // Change the name of the current ValueObject. Should *not* be used from a
591 // synthetic child provider as it would change the name of the non synthetic
593 void SetName(const ConstString &name);
595 virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
596 AddressType *address_type = nullptr);
598 lldb::addr_t GetPointerValue(AddressType *address_type = nullptr);
600 lldb::ValueObjectSP GetSyntheticChild(const ConstString &key) const;
602 lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
604 lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
607 lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression,
610 virtual lldb::ValueObjectSP
611 GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
613 ConstString name_const_str = ConstString());
615 virtual lldb::ValueObjectSP
616 GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
617 ConstString name_const_str = ConstString());
619 virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType);
621 lldb::DynamicValueType GetDynamicValueType();
623 virtual lldb::ValueObjectSP GetStaticValue();
625 virtual lldb::ValueObjectSP GetNonSyntheticValue();
627 lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic = true);
629 virtual bool HasSyntheticValue();
631 virtual bool IsSynthetic() { return false; }
634 GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue,
637 virtual lldb::ValueObjectSP CreateConstantValue(const ConstString &name);
639 virtual lldb::ValueObjectSP Dereference(Error &error);
641 // Creates a copy of the ValueObject with a new name and setting the current
642 // ValueObject as its parent. It should be used when we want to change the
643 // name of a ValueObject without modifying the actual ValueObject itself
644 // (e.g. sythetic child provider).
645 virtual lldb::ValueObjectSP Clone(const ConstString &new_name);
647 virtual lldb::ValueObjectSP AddressOf(Error &error);
649 virtual lldb::addr_t GetLiveAddress() { return LLDB_INVALID_ADDRESS; }
651 virtual void SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
652 AddressType address_type = eAddressTypeLoad) {}
654 // Find the address of the C++ vtable pointer
655 virtual lldb::addr_t GetCPPVTableAddress(AddressType &address_type);
657 virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
659 virtual lldb::ValueObjectSP CastPointerType(const char *name,
660 CompilerType &ast_type);
662 virtual lldb::ValueObjectSP CastPointerType(const char *name,
663 lldb::TypeSP &type_sp);
665 // The backing bits of this value object were updated, clear any
666 // descriptive string, so we know we have to refetch them
667 virtual void ValueUpdated() {
668 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
669 eClearUserVisibleDataItemsSummary |
670 eClearUserVisibleDataItemsDescription);
673 virtual bool IsDynamic() { return false; }
675 virtual bool DoesProvideSyntheticValue() { return false; }
677 virtual bool IsSyntheticChildrenGenerated();
679 virtual void SetSyntheticChildrenGenerated(bool b);
681 virtual SymbolContextScope *GetSymbolContextScope();
683 void Dump(Stream &s);
685 void Dump(Stream &s, const DumpValueObjectOptions &options);
687 static lldb::ValueObjectSP
688 CreateValueObjectFromExpression(llvm::StringRef name,
689 llvm::StringRef expression,
690 const ExecutionContext &exe_ctx);
692 static lldb::ValueObjectSP
693 CreateValueObjectFromExpression(llvm::StringRef name,
694 llvm::StringRef expression,
695 const ExecutionContext &exe_ctx,
696 const EvaluateExpressionOptions &options);
698 static lldb::ValueObjectSP
699 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
700 const ExecutionContext &exe_ctx,
703 static lldb::ValueObjectSP
704 CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
705 const ExecutionContext &exe_ctx, CompilerType type);
707 void LogValueObject(Log *log);
709 void LogValueObject(Log *log, const DumpValueObjectOptions &options);
711 lldb::ValueObjectSP Persist();
713 // returns true if this is a char* or a char[]
714 // if it is a char* and check_pointer is true,
715 // it also checks that the pointer is valid
716 bool IsCStringContainer(bool check_pointer = false);
718 std::pair<size_t, bool>
719 ReadPointedString(lldb::DataBufferSP &buffer_sp, Error &error,
720 uint32_t max_length = 0, bool honor_array = true,
721 lldb::Format item_format = lldb::eFormatCharArray);
723 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
724 uint32_t item_count = 1);
726 virtual uint64_t GetData(DataExtractor &data, Error &error);
728 virtual bool SetData(DataExtractor &data, Error &error);
730 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
732 bool NeedsUpdating() {
733 const bool accept_invalid_exe_ctx =
734 (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
735 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
738 void SetIsConstant() { m_update_point.SetIsConstant(); }
740 lldb::Format GetFormat() const;
742 virtual void SetFormat(lldb::Format format) {
743 if (format != m_format)
744 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
748 virtual lldb::LanguageType GetPreferredDisplayLanguage();
750 void SetPreferredDisplayLanguage(lldb::LanguageType);
752 lldb::TypeSummaryImplSP GetSummaryFormat() {
753 UpdateFormatsIfNeeded();
754 return m_type_summary_sp;
757 void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
758 m_type_summary_sp = format;
759 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
762 lldb::TypeValidatorImplSP GetValidator() {
763 UpdateFormatsIfNeeded();
764 return m_type_validator_sp;
767 void SetValidator(lldb::TypeValidatorImplSP format) {
768 m_type_validator_sp = format;
769 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
772 void SetValueFormat(lldb::TypeFormatImplSP format) {
773 m_type_format_sp = format;
774 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
777 lldb::TypeFormatImplSP GetValueFormat() {
778 UpdateFormatsIfNeeded();
779 return m_type_format_sp;
782 void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
783 if (synth_sp.get() == m_synthetic_children_sp.get())
785 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
786 m_synthetic_children_sp = synth_sp;
789 lldb::SyntheticChildrenSP GetSyntheticChildren() {
790 UpdateFormatsIfNeeded();
791 return m_synthetic_children_sp;
794 // Use GetParent for display purposes, but if you want to tell the parent to
796 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct
798 // displaying, they are really siblings, so for display it needs to route
799 // through to its grandparent.
800 virtual ValueObject *GetParent() { return m_parent; }
802 virtual const ValueObject *GetParent() const { return m_parent; }
804 ValueObject *GetNonBaseClassParent();
806 void SetAddressTypeOfChildren(AddressType at) {
807 m_address_type_of_ptr_or_ref_children = at;
810 AddressType GetAddressTypeOfChildren();
812 void SetHasCompleteType() { m_did_calculate_complete_objc_class_type = true; }
814 //------------------------------------------------------------------
815 /// Find out if a ValueObject might have children.
817 /// This call is much more efficient than CalculateNumChildren() as
818 /// it doesn't need to complete the underlying type. This is designed
819 /// to be used in a UI environment in order to detect if the
820 /// disclosure triangle should be displayed or not.
822 /// This function returns true for class, union, structure,
823 /// pointers, references, arrays and more. Again, it does so without
824 /// doing any expensive type completion.
827 /// Returns \b true if the ValueObject might have children, or \b
829 //------------------------------------------------------------------
830 virtual bool MightHaveChildren();
832 virtual lldb::VariableSP GetVariable() { return nullptr; }
834 virtual bool IsRuntimeSupportValue();
836 virtual uint64_t GetLanguageFlags();
838 virtual void SetLanguageFlags(uint64_t flags);
841 typedef ClusterManager<ValueObject> ValueObjectManager;
843 class ChildrenManager {
845 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
847 bool HasChildAtIndex(size_t idx) {
848 std::lock_guard<std::recursive_mutex> guard(m_mutex);
849 return (m_children.find(idx) != m_children.end());
852 ValueObject *GetChildAtIndex(size_t idx) {
853 std::lock_guard<std::recursive_mutex> guard(m_mutex);
854 const auto iter = m_children.find(idx);
855 return ((iter == m_children.end()) ? nullptr : iter->second);
858 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
859 // we do not need to be mutex-protected to make a pair
860 ChildrenPair pair(idx, valobj);
861 std::lock_guard<std::recursive_mutex> guard(m_mutex);
862 m_children.insert(pair);
865 void SetChildrenCount(size_t count) { Clear(count); }
867 size_t GetChildrenCount() { return m_children_count; }
869 void Clear(size_t new_count = 0) {
870 std::lock_guard<std::recursive_mutex> guard(m_mutex);
871 m_children_count = new_count;
876 typedef std::map<size_t, ValueObject *> ChildrenMap;
877 typedef ChildrenMap::iterator ChildrenIterator;
878 typedef ChildrenMap::value_type ChildrenPair;
879 std::recursive_mutex m_mutex;
880 ChildrenMap m_children;
881 size_t m_children_count;
884 //------------------------------------------------------------------
885 // Classes that inherit from ValueObject can see and modify these
886 //------------------------------------------------------------------
888 *m_parent; // The parent value object, or nullptr if this has no parent
889 ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
890 // nullptr if never calculated)
891 EvaluationPoint m_update_point; // Stores both the stop id and the full
892 // context at which this value was last
893 // updated. When we are asked to update the value object, we check whether
894 // the context & stop id are the same before updating.
895 ConstString m_name; // The name of this object
897 m_data; // A data extractor that can be used to extract the value.
899 Error m_error; // An error object that can describe any errors that occur when
901 std::string m_value_str; // Cached value string that will get cleared if/when
902 // the value is updated.
903 std::string m_old_value_str; // Cached old value string from the last time the
905 std::string m_location_str; // Cached location string that will get cleared
906 // if/when the value is updated.
907 std::string m_summary_str; // Cached summary string that will get cleared
908 // if/when the value is updated.
909 std::string m_object_desc_str; // Cached result of the "object printer". This
910 // differs from the summary
911 // in that the summary is consed up by us, the object_desc_string is builtin.
913 llvm::Optional<std::pair<TypeValidatorResult, std::string>>
916 CompilerType m_override_type; // If the type of the value object should be
917 // overridden, the type to impose.
919 ValueObjectManager *m_manager; // This object is managed by the root object
920 // (any ValueObject that gets created
921 // without a parent.) The manager gets passed through all the generations of
922 // dependent objects, and will keep the whole cluster of objects alive as long
923 // as a shared pointer to any of them has been handed out. Shared pointers to
924 // value objects must always be made with the GetSP method.
926 ChildrenManager m_children;
927 std::map<ConstString, ValueObject *> m_synthetic_children;
929 ValueObject *m_dynamic_value;
930 ValueObject *m_synthetic_value;
931 ValueObject *m_deref_valobj;
933 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
934 // pointer to this one because it is
936 // as an independent ValueObjectConstResult, which isn't managed by us.
938 lldb::Format m_format;
939 lldb::Format m_last_format;
940 uint32_t m_last_format_mgr_revision;
941 lldb::TypeSummaryImplSP m_type_summary_sp;
942 lldb::TypeFormatImplSP m_type_format_sp;
943 lldb::SyntheticChildrenSP m_synthetic_children_sp;
944 lldb::TypeValidatorImplSP m_type_validator_sp;
945 ProcessModID m_user_id_of_forced_summary;
946 AddressType m_address_type_of_ptr_or_ref_children;
948 llvm::SmallVector<uint8_t, 16> m_value_checksum;
950 lldb::LanguageType m_preferred_display_language;
952 uint64_t m_language_flags;
954 bool m_value_is_valid : 1, m_value_did_change : 1, m_children_count_valid : 1,
955 m_old_value_valid : 1, m_is_deref_of_parent : 1,
956 m_is_array_item_for_pointer : 1, m_is_bitfield_for_scalar : 1,
957 m_is_child_at_offset : 1, m_is_getting_summary : 1,
958 m_did_calculate_complete_objc_class_type : 1,
959 m_is_synthetic_children_generated : 1;
961 friend class ValueObjectChild;
962 friend class ClangExpressionDeclMap; // For GetValue
963 friend class ExpressionVariable; // For SetName
964 friend class Target; // For SetName
965 friend class ValueObjectConstResultImpl;
966 friend class ValueObjectSynthetic; // For ClearUserVisibleData
968 //------------------------------------------------------------------
969 // Constructors and Destructors
970 //------------------------------------------------------------------
972 // Use the no-argument constructor to make a constant variable object (with no
973 // ExecutionContextScope.)
977 // Use this constructor to create a "root variable object". The ValueObject
978 // will be locked to this context
979 // through-out its lifespan.
981 ValueObject(ExecutionContextScope *exe_scope,
982 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
984 // Use this constructor to create a ValueObject owned by another ValueObject.
985 // It will inherit the ExecutionContext
988 ValueObject(ValueObject &parent);
990 ValueObjectManager *GetManager() { return m_manager; }
992 virtual bool UpdateValue() = 0;
994 virtual LazyBool CanUpdateWithInvalidExecutionContext() {
995 return eLazyBoolCalculate;
998 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
1000 virtual lldb::DynamicValueType GetDynamicValueTypeImpl() {
1001 return lldb::eNoDynamicValues;
1004 virtual bool HasDynamicValueTypeInfo() { return false; }
1006 virtual void CalculateSyntheticValue(bool use_synthetic = true);
1008 // Should only be called by ValueObject::GetChildAtIndex()
1009 // Returns a ValueObject managed by this ValueObject's manager.
1010 virtual ValueObject *CreateChildAtIndex(size_t idx,
1011 bool synthetic_array_member,
1012 int32_t synthetic_index);
1014 // Should only be called by ValueObject::GetNumChildren()
1015 virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
1017 void SetNumChildren(size_t num_children);
1019 void SetValueDidChange(bool value_changed);
1021 void SetValueIsValid(bool valid);
1023 void ClearUserVisibleData(
1024 uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1026 void AddSyntheticChild(const ConstString &key, ValueObject *valobj);
1028 DataExtractor &GetDataExtractor();
1030 void ClearDynamicTypeInformation();
1032 //------------------------------------------------------------------
1033 // Subclasses must implement the functions below.
1034 //------------------------------------------------------------------
1036 virtual CompilerType GetCompilerTypeImpl() = 0;
1038 const char *GetLocationAsCStringImpl(const Value &value,
1039 const DataExtractor &data);
1041 bool IsChecksumEmpty();
1043 void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
1046 virtual CompilerType MaybeCalculateCompleteType();
1048 lldb::ValueObjectSP GetValueForExpressionPath_Impl(
1049 llvm::StringRef expression_cstr,
1050 ExpressionPathScanEndReason *reason_to_stop,
1051 ExpressionPathEndResultType *final_value_type,
1052 const GetValueForExpressionPathOptions &options,
1053 ExpressionPathAftermath *final_task_on_target);
1055 DISALLOW_COPY_AND_ASSIGN(ValueObject);
1058 //------------------------------------------------------------------------------
1059 // A value object manager class that is seeded with the static variable value
1060 // and it vends the user facing value object. If the type is dynamic it can
1061 // vend the dynamic type. If this user type also has a synthetic type associated
1062 // with it, it will vend the synthetic type. The class watches the process' stop
1063 // ID and will update the user type when needed.
1064 //------------------------------------------------------------------------------
1065 class ValueObjectManager {
1066 // The root value object is the static typed variable object.
1067 lldb::ValueObjectSP m_root_valobj_sp;
1068 // The user value object is the value object the user wants to see.
1069 lldb::ValueObjectSP m_user_valobj_sp;
1070 lldb::DynamicValueType m_use_dynamic;
1071 uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1072 bool m_use_synthetic;
1075 ValueObjectManager() {}
1077 ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1078 lldb::DynamicValueType use_dynamic, bool use_synthetic);
1080 bool IsValid() const;
1082 lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1084 // Gets the correct value object from the root object for a given process
1085 // stop ID. If dynamic values are enabled, or if synthetic children are
1086 // enabled, the value object that the user wants to see might change while
1088 lldb::ValueObjectSP GetSP();
1090 void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1091 void SetUseSynthetic(bool use_synthetic);
1092 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1093 bool GetUseSynthetic() const { return m_use_synthetic; }
1094 lldb::TargetSP GetTargetSP() const;
1095 lldb::ProcessSP GetProcessSP() const;
1096 lldb::ThreadSP GetThreadSP() const;
1097 lldb::StackFrameSP GetFrameSP() const;
1100 } // namespace lldb_private
1102 #endif // liblldb_ValueObject_h_