1 //===-- ValueObject.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ValueObject_h_
11 #define liblldb_ValueObject_h_
16 #include <initializer_list>
20 // Other libraries and framework includes
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/SmallVector.h"
25 #include "lldb/Core/ConstString.h"
26 #include "lldb/Core/DataExtractor.h"
27 #include "lldb/Core/Error.h"
28 #include "lldb/Core/Flags.h"
29 #include "lldb/Core/UserID.h"
30 #include "lldb/Core/Value.h"
31 #include "lldb/Symbol/CompilerType.h"
32 #include "lldb/Target/ExecutionContext.h"
33 #include "lldb/Target/ExecutionContextScope.h"
34 #include "lldb/Target/Process.h"
35 #include "lldb/Target/StackID.h"
36 #include "lldb/Utility/SharedCluster.h"
37 #include "lldb/lldb-private.h"
39 namespace lldb_private {
43 /// This abstract class provides an interface to a particular value, be it a
44 /// register, a local or global variable,
45 /// that is evaluated in some particular scope. The ValueObject also has the
46 /// capability of being the "child" of
47 /// some other variable object, and in turn of having children.
48 /// If a ValueObject is a root variable object - having no parent - then it must
49 /// be constructed with respect to some
50 /// particular ExecutionContextScope. If it is a child, it inherits the
51 /// ExecutionContextScope from its parent.
52 /// The ValueObject will update itself if necessary before fetching its value,
53 /// summary, object description, etc.
54 /// But it will always update itself in the ExecutionContextScope with which it
55 /// was originally created.
57 /// A brief note on life cycle management for ValueObjects. This is a little
58 /// tricky because a ValueObject can contain
59 /// various other ValueObjects - the Dynamic Value, its children, the
60 /// dereference value, etc. Any one of these can be
61 /// handed out as a shared pointer, but for that contained value object to be
62 /// valid, the root object and potentially other
63 /// of the value objects need to stay around.
64 /// We solve this problem by handing out shared pointers to the Value Object and
65 /// any of its dependents using a shared
66 /// ClusterManager. This treats each shared pointer handed out for the entire
67 /// cluster as a reference to the whole
68 /// cluster. The whole cluster will stay around until the last reference is
71 /// The ValueObject mostly handle this automatically, if a value object is made
72 /// with a Parent ValueObject, then it adds
73 /// itself to the ClusterManager of the parent.
75 /// It does mean that external to the ValueObjects we should only ever make
76 /// available ValueObjectSP's, never ValueObjects
77 /// or pointers to them. So all the "Root level" ValueObject derived
78 /// constructors should be private, and
79 /// should implement a Create function that new's up object and returns a Shared
80 /// Pointer that it gets from the GetSP() method.
82 /// However, if you are making an derived ValueObject that will be contained in
83 /// a parent value object, you should just
84 /// hold onto a pointer to it internally, and by virtue of passing the parent
85 /// ValueObject into its constructor, it will
86 /// be added to the ClusterManager for the parent. Then if you ever hand out a
87 /// Shared Pointer to the contained ValueObject,
88 /// just do so by calling GetSP() on the contained object.
90 class ValueObject : public UserID {
92 enum GetExpressionPathFormat {
93 eGetExpressionPathFormatDereferencePointers = 1,
94 eGetExpressionPathFormatHonorPointers
97 enum ValueObjectRepresentationStyle {
98 eValueObjectRepresentationStyleValue = 1,
99 eValueObjectRepresentationStyleSummary,
100 eValueObjectRepresentationStyleLanguageSpecific,
101 eValueObjectRepresentationStyleLocation,
102 eValueObjectRepresentationStyleChildrenCount,
103 eValueObjectRepresentationStyleType,
104 eValueObjectRepresentationStyleName,
105 eValueObjectRepresentationStyleExpressionPath
108 enum ExpressionPathScanEndReason {
109 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
110 eExpressionPathScanEndReasonNoSuchChild, // child element not found
111 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child
113 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for
115 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be
117 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be
119 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion
121 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by
123 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects
124 // other than scalars,
125 // pointers or arrays
126 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays,
127 // but I cannot parse it
128 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for
130 // cannot parse after
132 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in
134 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply &
136 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply *
138 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a
140 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic
142 eExpressionPathScanEndReasonUnknown = 0xFFFF
145 enum ExpressionPathEndResultType {
146 eExpressionPathEndResultTypePlain = 1, // anything but...
147 eExpressionPathEndResultTypeBitfield, // a bitfield
148 eExpressionPathEndResultTypeBoundedRange, // a range [low-high]
149 eExpressionPathEndResultTypeUnboundedRange, // a range []
150 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
151 eExpressionPathEndResultTypeInvalid = 0xFFFF
154 enum ExpressionPathAftermath {
155 eExpressionPathAftermathNothing = 1, // just return it
156 eExpressionPathAftermathDereference, // dereference the target
157 eExpressionPathAftermathTakeAddress // take target's address
160 enum ClearUserVisibleDataItems {
161 eClearUserVisibleDataItemsNothing = 1u << 0,
162 eClearUserVisibleDataItemsValue = 1u << 1,
163 eClearUserVisibleDataItemsSummary = 1u << 2,
164 eClearUserVisibleDataItemsLocation = 1u << 3,
165 eClearUserVisibleDataItemsDescription = 1u << 4,
166 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
167 eClearUserVisibleDataItemsValidator = 1u << 6,
168 eClearUserVisibleDataItemsAllStrings =
169 eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary |
170 eClearUserVisibleDataItemsLocation |
171 eClearUserVisibleDataItemsDescription,
172 eClearUserVisibleDataItemsAll = 0xFFFF
175 struct GetValueForExpressionPathOptions {
176 enum class SyntheticChildrenTraversal {
183 bool m_check_dot_vs_arrow_syntax;
184 bool m_no_fragile_ivar;
185 bool m_allow_bitfields_syntax;
186 SyntheticChildrenTraversal m_synthetic_children_traversal;
188 GetValueForExpressionPathOptions(
189 bool dot = false, bool no_ivar = false, bool bitfield = true,
190 SyntheticChildrenTraversal synth_traverse =
191 SyntheticChildrenTraversal::ToSynthetic)
192 : m_check_dot_vs_arrow_syntax(dot), m_no_fragile_ivar(no_ivar),
193 m_allow_bitfields_syntax(bitfield),
194 m_synthetic_children_traversal(synth_traverse) {}
196 GetValueForExpressionPathOptions &DoCheckDotVsArrowSyntax() {
197 m_check_dot_vs_arrow_syntax = true;
201 GetValueForExpressionPathOptions &DontCheckDotVsArrowSyntax() {
202 m_check_dot_vs_arrow_syntax = false;
206 GetValueForExpressionPathOptions &DoAllowFragileIVar() {
207 m_no_fragile_ivar = false;
211 GetValueForExpressionPathOptions &DontAllowFragileIVar() {
212 m_no_fragile_ivar = true;
216 GetValueForExpressionPathOptions &DoAllowBitfieldSyntax() {
217 m_allow_bitfields_syntax = true;
221 GetValueForExpressionPathOptions &DontAllowBitfieldSyntax() {
222 m_allow_bitfields_syntax = false;
226 GetValueForExpressionPathOptions &
227 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse) {
228 m_synthetic_children_traversal = traverse;
232 static const GetValueForExpressionPathOptions DefaultOptions() {
233 static GetValueForExpressionPathOptions g_default_options;
235 return g_default_options;
239 class EvaluationPoint {
243 EvaluationPoint(ExecutionContextScope *exe_scope,
244 bool use_selected = false);
246 EvaluationPoint(const EvaluationPoint &rhs);
250 const ExecutionContextRef &GetExecutionContextRef() const {
251 return m_exe_ctx_ref;
254 // Set the EvaluationPoint to the values in exe_scope,
255 // Return true if the Evaluation Point changed.
256 // Since the ExecutionContextScope is always going to be valid currently,
257 // the Updated Context will also always be valid.
260 // SetContext (ExecutionContextScope *exe_scope);
262 void SetIsConstant() {
264 m_mod_id.SetInvalid();
267 bool IsConstant() const { return !m_mod_id.IsValid(); }
269 ProcessModID GetModID() const { return m_mod_id; }
271 void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
273 void SetNeedsUpdate() { m_needs_update = true; }
277 bool NeedsUpdating(bool accept_invalid_exe_ctx) {
278 SyncWithProcessState(accept_invalid_exe_ctx);
279 return m_needs_update;
283 const bool accept_invalid_exe_ctx = false;
284 if (!m_mod_id.IsValid())
286 else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
287 if (!m_mod_id.IsValid())
294 // Use the stop id to mark us as invalid, leave the thread id and the
295 // stack id around for logging and
297 m_mod_id.SetInvalid();
299 // Can't update an invalid state.
300 m_needs_update = false;
304 bool SyncWithProcessState(bool accept_invalid_exe_ctx);
306 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
308 ExecutionContextRef m_exe_ctx_ref;
312 virtual ~ValueObject();
314 const EvaluationPoint &GetUpdatePoint() const { return m_update_point; }
316 EvaluationPoint &GetUpdatePoint() { return m_update_point; }
318 const ExecutionContextRef &GetExecutionContextRef() const {
319 return m_update_point.GetExecutionContextRef();
322 lldb::TargetSP GetTargetSP() const {
323 return m_update_point.GetExecutionContextRef().GetTargetSP();
326 lldb::ProcessSP GetProcessSP() const {
327 return m_update_point.GetExecutionContextRef().GetProcessSP();
330 lldb::ThreadSP GetThreadSP() const {
331 return m_update_point.GetExecutionContextRef().GetThreadSP();
334 lldb::StackFrameSP GetFrameSP() const {
335 return m_update_point.GetExecutionContextRef().GetFrameSP();
338 void SetNeedsUpdate();
340 CompilerType GetCompilerType();
342 // this vends a TypeImpl that is useful at the SB API layer
343 virtual TypeImpl GetTypeImpl();
345 virtual bool CanProvideValue();
347 //------------------------------------------------------------------
348 // Subclasses must implement the functions below.
349 //------------------------------------------------------------------
350 virtual uint64_t GetByteSize() = 0;
352 virtual lldb::ValueType GetValueType() const = 0;
354 //------------------------------------------------------------------
355 // Subclasses can implement the functions below.
356 //------------------------------------------------------------------
357 virtual ConstString GetTypeName();
359 virtual ConstString GetDisplayTypeName();
361 virtual ConstString GetQualifiedTypeName();
363 virtual lldb::LanguageType GetObjectRuntimeLanguage();
366 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
368 virtual bool IsPointerType();
370 virtual bool IsArrayType();
372 virtual bool IsScalarType();
374 virtual bool IsPointerOrReferenceType();
376 virtual bool IsPossibleDynamicType();
378 bool IsNilReference();
380 bool IsUninitializedReference();
382 virtual bool IsBaseClass() { return false; }
384 bool IsBaseClass(uint32_t &depth);
386 virtual bool IsDereferenceOfParent() { return false; }
388 bool IsIntegerType(bool &is_signed);
390 virtual bool GetBaseClassPath(Stream &s);
392 virtual void GetExpressionPath(
393 Stream &s, bool qualify_cxx_base_classes,
394 GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
396 lldb::ValueObjectSP GetValueForExpressionPath(
397 llvm::StringRef expression,
398 ExpressionPathScanEndReason *reason_to_stop = nullptr,
399 ExpressionPathEndResultType *final_value_type = nullptr,
400 const GetValueForExpressionPathOptions &options =
401 GetValueForExpressionPathOptions::DefaultOptions(),
402 ExpressionPathAftermath *final_task_on_target = nullptr);
404 virtual bool IsInScope() { return true; }
406 virtual lldb::offset_t GetByteOffset() { return 0; }
408 virtual uint32_t GetBitfieldBitSize() { return 0; }
410 virtual uint32_t GetBitfieldBitOffset() { return 0; }
413 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
416 virtual bool IsArrayItemForPointer() { return m_is_array_item_for_pointer; }
418 virtual const char *GetValueAsCString();
420 virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
421 std::string &destination);
423 bool GetValueAsCString(lldb::Format format, std::string &destination);
425 virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
426 bool *success = nullptr);
428 virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
430 virtual bool SetValueFromCString(const char *value_str, Error &error);
432 // Return the module associated with this value object in case the
433 // value is from an executable file and might have its data in
434 // sections of the file. This can be used for variables.
435 virtual lldb::ModuleSP GetModule();
437 ValueObject *GetRoot();
439 // Given a ValueObject, loop over itself and its parent, and its parent's
441 // until either the given callback returns false, or you end up at a null
443 ValueObject *FollowParentChain(std::function<bool(ValueObject *)>);
445 virtual bool GetDeclaration(Declaration &decl);
447 //------------------------------------------------------------------
448 // The functions below should NOT be modified by subclasses
449 //------------------------------------------------------------------
450 const Error &GetError();
452 const ConstString &GetName() const;
454 virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
456 // this will always create the children if necessary
458 GetChildAtIndexPath(const std::initializer_list<size_t> &idxs,
459 size_t *index_of_error = nullptr);
461 lldb::ValueObjectSP GetChildAtIndexPath(const std::vector<size_t> &idxs,
462 size_t *index_of_error = nullptr);
464 lldb::ValueObjectSP GetChildAtIndexPath(
465 const std::initializer_list<std::pair<size_t, bool>> &idxs,
466 size_t *index_of_error = nullptr);
469 GetChildAtIndexPath(const std::vector<std::pair<size_t, bool>> &idxs,
470 size_t *index_of_error = nullptr);
472 // this will always create the children if necessary
474 GetChildAtNamePath(const std::initializer_list<ConstString> &names,
475 ConstString *name_of_error = nullptr);
477 lldb::ValueObjectSP GetChildAtNamePath(const std::vector<ConstString> &names,
478 ConstString *name_of_error = nullptr);
480 lldb::ValueObjectSP GetChildAtNamePath(
481 const std::initializer_list<std::pair<ConstString, bool>> &names,
482 ConstString *name_of_error = nullptr);
485 GetChildAtNamePath(const std::vector<std::pair<ConstString, bool>> &names,
486 ConstString *name_of_error = nullptr);
488 virtual lldb::ValueObjectSP GetChildMemberWithName(const ConstString &name,
491 virtual size_t GetIndexOfChildWithName(const ConstString &name);
493 size_t GetNumChildren(uint32_t max = UINT32_MAX);
495 const Value &GetValue() const;
499 virtual bool ResolveValue(Scalar &scalar);
501 // return 'false' whenever you set the error, otherwise
502 // callers may assume true means everything is OK - this will
503 // break breakpoint conditions among potentially a few others
504 virtual bool IsLogicalTrue(Error &error);
506 virtual const char *GetLocationAsCString();
509 GetSummaryAsCString(lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
512 GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
513 lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
515 bool GetSummaryAsCString(std::string &destination,
516 const TypeSummaryOptions &options);
518 bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
519 std::string &destination,
520 const TypeSummaryOptions &options);
522 std::pair<TypeValidatorResult, std::string> GetValidationStatus();
524 const char *GetObjectDescription();
526 bool HasSpecialPrintableRepresentation(
527 ValueObjectRepresentationStyle val_obj_display,
528 lldb::Format custom_format);
530 enum class PrintableRepresentationSpecialCases : bool {
536 DumpPrintableRepresentation(Stream &s,
537 ValueObjectRepresentationStyle val_obj_display =
538 eValueObjectRepresentationStyleSummary,
539 lldb::Format custom_format = lldb::eFormatInvalid,
540 PrintableRepresentationSpecialCases special =
541 PrintableRepresentationSpecialCases::eAllow,
542 bool do_dump_error = true);
543 bool GetValueIsValid() const;
545 // If you call this on a newly created ValueObject, it will always return
547 bool GetValueDidChange();
549 bool UpdateValueIfNeeded(bool update_format = true);
551 bool UpdateFormatsIfNeeded();
553 lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
555 void SetName(const ConstString &name);
557 virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
558 AddressType *address_type = nullptr);
560 lldb::addr_t GetPointerValue(AddressType *address_type = nullptr);
562 lldb::ValueObjectSP GetSyntheticChild(const ConstString &key) const;
564 lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
566 lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
569 lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression,
572 virtual lldb::ValueObjectSP
573 GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
575 ConstString name_const_str = ConstString());
577 virtual lldb::ValueObjectSP
578 GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
579 ConstString name_const_str = ConstString());
581 virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType);
583 lldb::DynamicValueType GetDynamicValueType();
585 virtual lldb::ValueObjectSP GetStaticValue();
587 virtual lldb::ValueObjectSP GetNonSyntheticValue();
589 lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic = true);
591 virtual bool HasSyntheticValue();
593 virtual bool IsSynthetic() { return false; }
596 GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue,
599 virtual lldb::ValueObjectSP CreateConstantValue(const ConstString &name);
601 virtual lldb::ValueObjectSP Dereference(Error &error);
603 virtual lldb::ValueObjectSP AddressOf(Error &error);
605 virtual lldb::addr_t GetLiveAddress() { return LLDB_INVALID_ADDRESS; }
607 virtual void SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
608 AddressType address_type = eAddressTypeLoad) {}
610 // Find the address of the C++ vtable pointer
611 virtual lldb::addr_t GetCPPVTableAddress(AddressType &address_type);
613 virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
615 virtual lldb::ValueObjectSP CastPointerType(const char *name,
616 CompilerType &ast_type);
618 virtual lldb::ValueObjectSP CastPointerType(const char *name,
619 lldb::TypeSP &type_sp);
621 // The backing bits of this value object were updated, clear any
622 // descriptive string, so we know we have to refetch them
623 virtual void ValueUpdated() {
624 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
625 eClearUserVisibleDataItemsSummary |
626 eClearUserVisibleDataItemsDescription);
629 virtual bool IsDynamic() { return false; }
631 virtual bool DoesProvideSyntheticValue() { return false; }
633 virtual bool IsSyntheticChildrenGenerated();
635 virtual void SetSyntheticChildrenGenerated(bool b);
637 virtual SymbolContextScope *GetSymbolContextScope();
639 void Dump(Stream &s);
641 void Dump(Stream &s, const DumpValueObjectOptions &options);
643 static lldb::ValueObjectSP
644 CreateValueObjectFromExpression(llvm::StringRef name,
645 llvm::StringRef expression,
646 const ExecutionContext &exe_ctx);
648 static lldb::ValueObjectSP
649 CreateValueObjectFromExpression(llvm::StringRef name,
650 llvm::StringRef expression,
651 const ExecutionContext &exe_ctx,
652 const EvaluateExpressionOptions &options);
654 static lldb::ValueObjectSP
655 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
656 const ExecutionContext &exe_ctx,
659 static lldb::ValueObjectSP
660 CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
661 const ExecutionContext &exe_ctx, CompilerType type);
663 void LogValueObject(Log *log);
665 void LogValueObject(Log *log, const DumpValueObjectOptions &options);
667 lldb::ValueObjectSP Persist();
669 // returns true if this is a char* or a char[]
670 // if it is a char* and check_pointer is true,
671 // it also checks that the pointer is valid
672 bool IsCStringContainer(bool check_pointer = false);
674 std::pair<size_t, bool>
675 ReadPointedString(lldb::DataBufferSP &buffer_sp, Error &error,
676 uint32_t max_length = 0, bool honor_array = true,
677 lldb::Format item_format = lldb::eFormatCharArray);
679 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
680 uint32_t item_count = 1);
682 virtual uint64_t GetData(DataExtractor &data, Error &error);
684 virtual bool SetData(DataExtractor &data, Error &error);
686 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
688 bool NeedsUpdating() {
689 const bool accept_invalid_exe_ctx =
690 (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
691 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
694 void SetIsConstant() { m_update_point.SetIsConstant(); }
696 lldb::Format GetFormat() const;
698 virtual void SetFormat(lldb::Format format) {
699 if (format != m_format)
700 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
704 virtual lldb::LanguageType GetPreferredDisplayLanguage();
706 void SetPreferredDisplayLanguage(lldb::LanguageType);
708 lldb::TypeSummaryImplSP GetSummaryFormat() {
709 UpdateFormatsIfNeeded();
710 return m_type_summary_sp;
713 void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
714 m_type_summary_sp = format;
715 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
718 lldb::TypeValidatorImplSP GetValidator() {
719 UpdateFormatsIfNeeded();
720 return m_type_validator_sp;
723 void SetValidator(lldb::TypeValidatorImplSP format) {
724 m_type_validator_sp = format;
725 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
728 void SetValueFormat(lldb::TypeFormatImplSP format) {
729 m_type_format_sp = format;
730 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
733 lldb::TypeFormatImplSP GetValueFormat() {
734 UpdateFormatsIfNeeded();
735 return m_type_format_sp;
738 void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
739 if (synth_sp.get() == m_synthetic_children_sp.get())
741 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
742 m_synthetic_children_sp = synth_sp;
745 lldb::SyntheticChildrenSP GetSyntheticChildren() {
746 UpdateFormatsIfNeeded();
747 return m_synthetic_children_sp;
750 // Use GetParent for display purposes, but if you want to tell the parent to
752 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct
754 // displaying, they are really siblings, so for display it needs to route
755 // through to its grandparent.
756 virtual ValueObject *GetParent() { return m_parent; }
758 virtual const ValueObject *GetParent() const { return m_parent; }
760 ValueObject *GetNonBaseClassParent();
762 void SetAddressTypeOfChildren(AddressType at) {
763 m_address_type_of_ptr_or_ref_children = at;
766 AddressType GetAddressTypeOfChildren();
768 void SetHasCompleteType() { m_did_calculate_complete_objc_class_type = true; }
770 //------------------------------------------------------------------
771 /// Find out if a ValueObject might have children.
773 /// This call is much more efficient than CalculateNumChildren() as
774 /// it doesn't need to complete the underlying type. This is designed
775 /// to be used in a UI environment in order to detect if the
776 /// disclosure triangle should be displayed or not.
778 /// This function returns true for class, union, structure,
779 /// pointers, references, arrays and more. Again, it does so without
780 /// doing any expensive type completion.
783 /// Returns \b true if the ValueObject might have children, or \b
785 //------------------------------------------------------------------
786 virtual bool MightHaveChildren();
788 virtual lldb::VariableSP GetVariable() { return nullptr; }
790 virtual bool IsRuntimeSupportValue();
792 virtual uint64_t GetLanguageFlags();
794 virtual void SetLanguageFlags(uint64_t flags);
797 typedef ClusterManager<ValueObject> ValueObjectManager;
799 class ChildrenManager {
801 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
803 bool HasChildAtIndex(size_t idx) {
804 std::lock_guard<std::recursive_mutex> guard(m_mutex);
805 return (m_children.find(idx) != m_children.end());
808 ValueObject *GetChildAtIndex(size_t idx) {
809 std::lock_guard<std::recursive_mutex> guard(m_mutex);
810 const auto iter = m_children.find(idx);
811 return ((iter == m_children.end()) ? nullptr : iter->second);
814 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
815 // we do not need to be mutex-protected to make a pair
816 ChildrenPair pair(idx, valobj);
817 std::lock_guard<std::recursive_mutex> guard(m_mutex);
818 m_children.insert(pair);
821 void SetChildrenCount(size_t count) { Clear(count); }
823 size_t GetChildrenCount() { return m_children_count; }
825 void Clear(size_t new_count = 0) {
826 std::lock_guard<std::recursive_mutex> guard(m_mutex);
827 m_children_count = new_count;
832 typedef std::map<size_t, ValueObject *> ChildrenMap;
833 typedef ChildrenMap::iterator ChildrenIterator;
834 typedef ChildrenMap::value_type ChildrenPair;
835 std::recursive_mutex m_mutex;
836 ChildrenMap m_children;
837 size_t m_children_count;
840 //------------------------------------------------------------------
841 // Classes that inherit from ValueObject can see and modify these
842 //------------------------------------------------------------------
844 *m_parent; // The parent value object, or nullptr if this has no parent
845 ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
846 // nullptr if never calculated)
847 EvaluationPoint m_update_point; // Stores both the stop id and the full
848 // context at which this value was last
849 // updated. When we are asked to update the value object, we check whether
850 // the context & stop id are the same before updating.
851 ConstString m_name; // The name of this object
853 m_data; // A data extractor that can be used to extract the value.
855 Error m_error; // An error object that can describe any errors that occur when
857 std::string m_value_str; // Cached value string that will get cleared if/when
858 // the value is updated.
859 std::string m_old_value_str; // Cached old value string from the last time the
861 std::string m_location_str; // Cached location string that will get cleared
862 // if/when the value is updated.
863 std::string m_summary_str; // Cached summary string that will get cleared
864 // if/when the value is updated.
865 std::string m_object_desc_str; // Cached result of the "object printer". This
866 // differs from the summary
867 // in that the summary is consed up by us, the object_desc_string is builtin.
869 llvm::Optional<std::pair<TypeValidatorResult, std::string>>
872 CompilerType m_override_type; // If the type of the value object should be
873 // overridden, the type to impose.
875 ValueObjectManager *m_manager; // This object is managed by the root object
876 // (any ValueObject that gets created
877 // without a parent.) The manager gets passed through all the generations of
878 // dependent objects, and will keep the whole cluster of objects alive as long
879 // as a shared pointer to any of them has been handed out. Shared pointers to
880 // value objects must always be made with the GetSP method.
882 ChildrenManager m_children;
883 std::map<ConstString, ValueObject *> m_synthetic_children;
885 ValueObject *m_dynamic_value;
886 ValueObject *m_synthetic_value;
887 ValueObject *m_deref_valobj;
889 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
890 // pointer to this one because it is
892 // as an independent ValueObjectConstResult, which isn't managed by us.
894 lldb::Format m_format;
895 lldb::Format m_last_format;
896 uint32_t m_last_format_mgr_revision;
897 lldb::TypeSummaryImplSP m_type_summary_sp;
898 lldb::TypeFormatImplSP m_type_format_sp;
899 lldb::SyntheticChildrenSP m_synthetic_children_sp;
900 lldb::TypeValidatorImplSP m_type_validator_sp;
901 ProcessModID m_user_id_of_forced_summary;
902 AddressType m_address_type_of_ptr_or_ref_children;
904 llvm::SmallVector<uint8_t, 16> m_value_checksum;
906 lldb::LanguageType m_preferred_display_language;
908 uint64_t m_language_flags;
910 bool m_value_is_valid : 1, m_value_did_change : 1, m_children_count_valid : 1,
911 m_old_value_valid : 1, m_is_deref_of_parent : 1,
912 m_is_array_item_for_pointer : 1, m_is_bitfield_for_scalar : 1,
913 m_is_child_at_offset : 1, m_is_getting_summary : 1,
914 m_did_calculate_complete_objc_class_type : 1,
915 m_is_synthetic_children_generated : 1;
917 friend class ValueObjectChild;
918 friend class ClangExpressionDeclMap; // For GetValue
919 friend class ExpressionVariable; // For SetName
920 friend class Target; // For SetName
921 friend class ValueObjectConstResultImpl;
922 friend class ValueObjectSynthetic; // For ClearUserVisibleData
924 //------------------------------------------------------------------
925 // Constructors and Destructors
926 //------------------------------------------------------------------
928 // Use the no-argument constructor to make a constant variable object (with no
929 // ExecutionContextScope.)
933 // Use this constructor to create a "root variable object". The ValueObject
934 // will be locked to this context
935 // through-out its lifespan.
937 ValueObject(ExecutionContextScope *exe_scope,
938 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
940 // Use this constructor to create a ValueObject owned by another ValueObject.
941 // It will inherit the ExecutionContext
944 ValueObject(ValueObject &parent);
946 ValueObjectManager *GetManager() { return m_manager; }
948 virtual bool UpdateValue() = 0;
950 virtual LazyBool CanUpdateWithInvalidExecutionContext() {
951 return eLazyBoolCalculate;
954 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
956 virtual lldb::DynamicValueType GetDynamicValueTypeImpl() {
957 return lldb::eNoDynamicValues;
960 virtual bool HasDynamicValueTypeInfo() { return false; }
962 virtual void CalculateSyntheticValue(bool use_synthetic = true);
964 // Should only be called by ValueObject::GetChildAtIndex()
965 // Returns a ValueObject managed by this ValueObject's manager.
966 virtual ValueObject *CreateChildAtIndex(size_t idx,
967 bool synthetic_array_member,
968 int32_t synthetic_index);
970 // Should only be called by ValueObject::GetNumChildren()
971 virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
973 void SetNumChildren(size_t num_children);
975 void SetValueDidChange(bool value_changed);
977 void SetValueIsValid(bool valid);
979 void ClearUserVisibleData(
980 uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
982 void AddSyntheticChild(const ConstString &key, ValueObject *valobj);
984 DataExtractor &GetDataExtractor();
986 void ClearDynamicTypeInformation();
988 //------------------------------------------------------------------
989 // Subclasses must implement the functions below.
990 //------------------------------------------------------------------
992 virtual CompilerType GetCompilerTypeImpl() = 0;
994 const char *GetLocationAsCStringImpl(const Value &value,
995 const DataExtractor &data);
997 bool IsChecksumEmpty();
999 void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
1002 virtual CompilerType MaybeCalculateCompleteType();
1004 lldb::ValueObjectSP GetValueForExpressionPath_Impl(
1005 llvm::StringRef expression_cstr,
1006 ExpressionPathScanEndReason *reason_to_stop,
1007 ExpressionPathEndResultType *final_value_type,
1008 const GetValueForExpressionPathOptions &options,
1009 ExpressionPathAftermath *final_task_on_target);
1011 DISALLOW_COPY_AND_ASSIGN(ValueObject);
1014 //------------------------------------------------------------------------------
1015 // A value object manager class that is seeded with the static variable value
1016 // and it vends the user facing value object. If the type is dynamic it can
1017 // vend the dynamic type. If this user type also has a synthetic type associated
1018 // with it, it will vend the synthetic type. The class watches the process' stop
1019 // ID and will update the user type when needed.
1020 //------------------------------------------------------------------------------
1021 class ValueObjectManager {
1022 // The root value object is the static typed variable object.
1023 lldb::ValueObjectSP m_root_valobj_sp;
1024 // The user value object is the value object the user wants to see.
1025 lldb::ValueObjectSP m_user_valobj_sp;
1026 lldb::DynamicValueType m_use_dynamic;
1027 uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1028 bool m_use_synthetic;
1031 ValueObjectManager() {}
1033 ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1034 lldb::DynamicValueType use_dynamic, bool use_synthetic);
1036 bool IsValid() const;
1038 lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1040 // Gets the correct value object from the root object for a given process
1041 // stop ID. If dynamic values are enabled, or if synthetic children are
1042 // enabled, the value object that the user wants to see might change while
1044 lldb::ValueObjectSP GetSP();
1046 void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1047 void SetUseSynthetic(bool use_synthetic);
1048 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1049 bool GetUseSynthetic() const { return m_use_synthetic; }
1050 lldb::TargetSP GetTargetSP() const;
1051 lldb::ProcessSP GetProcessSP() const;
1052 lldb::ThreadSP GetThreadSP() const;
1053 lldb::StackFrameSP GetFrameSP() const;
1056 } // namespace lldb_private
1058 #endif // liblldb_ValueObject_h_