1 //===-- ValueObject.h -------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ValueObject_h_
10 #define liblldb_ValueObject_h_
12 #include "lldb/Core/Value.h"
13 #include "lldb/Symbol/CompilerType.h"
14 #include "lldb/Symbol/Type.h"
15 #include "lldb/Target/ExecutionContext.h"
16 #include "lldb/Target/Process.h"
17 #include "lldb/Utility/ConstString.h"
18 #include "lldb/Utility/DataExtractor.h"
19 #include "lldb/Utility/SharedCluster.h"
20 #include "lldb/Utility/Status.h"
21 #include "lldb/Utility/UserID.h"
22 #include "lldb/lldb-defines.h"
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-forward.h"
25 #include "lldb/lldb-private-enumerations.h"
26 #include "lldb/lldb-types.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/Optional.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/StringRef.h"
34 #include <initializer_list>
43 namespace lldb_private {
45 class DumpValueObjectOptions;
46 class EvaluateExpressionOptions;
47 class ExecutionContextScope;
51 class SymbolContextScope;
53 class TypeSummaryImpl;
54 class TypeSummaryOptions;
58 /// This abstract class provides an interface to a particular value, be it a
59 /// register, a local or global variable,
60 /// that is evaluated in some particular scope. The ValueObject also has the
61 /// capability of being the "child" of
62 /// some other variable object, and in turn of having children.
63 /// If a ValueObject is a root variable object - having no parent - then it must
64 /// be constructed with respect to some
65 /// particular ExecutionContextScope. If it is a child, it inherits the
66 /// ExecutionContextScope from its parent.
67 /// The ValueObject will update itself if necessary before fetching its value,
68 /// summary, object description, etc.
69 /// But it will always update itself in the ExecutionContextScope with which it
70 /// was originally created.
72 /// A brief note on life cycle management for ValueObjects. This is a little
73 /// tricky because a ValueObject can contain
74 /// various other ValueObjects - the Dynamic Value, its children, the
75 /// dereference value, etc. Any one of these can be
76 /// handed out as a shared pointer, but for that contained value object to be
77 /// valid, the root object and potentially other
78 /// of the value objects need to stay around.
79 /// We solve this problem by handing out shared pointers to the Value Object and
80 /// any of its dependents using a shared
81 /// ClusterManager. This treats each shared pointer handed out for the entire
82 /// cluster as a reference to the whole
83 /// cluster. The whole cluster will stay around until the last reference is
86 /// The ValueObject mostly handle this automatically, if a value object is made
87 /// with a Parent ValueObject, then it adds
88 /// itself to the ClusterManager of the parent.
90 /// It does mean that external to the ValueObjects we should only ever make
91 /// available ValueObjectSP's, never ValueObjects
92 /// or pointers to them. So all the "Root level" ValueObject derived
93 /// constructors should be private, and
94 /// should implement a Create function that new's up object and returns a Shared
95 /// Pointer that it gets from the GetSP() method.
97 /// However, if you are making an derived ValueObject that will be contained in
98 /// a parent value object, you should just
99 /// hold onto a pointer to it internally, and by virtue of passing the parent
100 /// ValueObject into its constructor, it will
101 /// be added to the ClusterManager for the parent. Then if you ever hand out a
102 /// Shared Pointer to the contained ValueObject,
103 /// just do so by calling GetSP() on the contained object.
105 class ValueObject : public UserID {
107 enum GetExpressionPathFormat {
108 eGetExpressionPathFormatDereferencePointers = 1,
109 eGetExpressionPathFormatHonorPointers
112 enum ValueObjectRepresentationStyle {
113 eValueObjectRepresentationStyleValue = 1,
114 eValueObjectRepresentationStyleSummary,
115 eValueObjectRepresentationStyleLanguageSpecific,
116 eValueObjectRepresentationStyleLocation,
117 eValueObjectRepresentationStyleChildrenCount,
118 eValueObjectRepresentationStyleType,
119 eValueObjectRepresentationStyleName,
120 eValueObjectRepresentationStyleExpressionPath
123 enum ExpressionPathScanEndReason {
124 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
125 eExpressionPathScanEndReasonNoSuchChild, // child element not found
126 eExpressionPathScanEndReasonNoSuchSyntheticChild, // (synthetic) child
128 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for
130 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be
132 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be
134 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion
136 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by
138 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects
139 // other than scalars,
140 // pointers or arrays
141 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays,
142 // but I cannot parse it
143 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for
145 // cannot parse after
147 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in
149 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply &
151 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply *
153 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a
155 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic
157 eExpressionPathScanEndReasonUnknown = 0xFFFF
160 enum ExpressionPathEndResultType {
161 eExpressionPathEndResultTypePlain = 1, // anything but...
162 eExpressionPathEndResultTypeBitfield, // a bitfield
163 eExpressionPathEndResultTypeBoundedRange, // a range [low-high]
164 eExpressionPathEndResultTypeUnboundedRange, // a range []
165 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
166 eExpressionPathEndResultTypeInvalid = 0xFFFF
169 enum ExpressionPathAftermath {
170 eExpressionPathAftermathNothing = 1, // just return it
171 eExpressionPathAftermathDereference, // dereference the target
172 eExpressionPathAftermathTakeAddress // take target's address
175 enum ClearUserVisibleDataItems {
176 eClearUserVisibleDataItemsNothing = 1u << 0,
177 eClearUserVisibleDataItemsValue = 1u << 1,
178 eClearUserVisibleDataItemsSummary = 1u << 2,
179 eClearUserVisibleDataItemsLocation = 1u << 3,
180 eClearUserVisibleDataItemsDescription = 1u << 4,
181 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
182 eClearUserVisibleDataItemsValidator = 1u << 6,
183 eClearUserVisibleDataItemsAllStrings =
184 eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary |
185 eClearUserVisibleDataItemsLocation |
186 eClearUserVisibleDataItemsDescription,
187 eClearUserVisibleDataItemsAll = 0xFFFF
190 struct GetValueForExpressionPathOptions {
191 enum class SyntheticChildrenTraversal {
198 bool m_check_dot_vs_arrow_syntax;
199 bool m_no_fragile_ivar;
200 bool m_allow_bitfields_syntax;
201 SyntheticChildrenTraversal m_synthetic_children_traversal;
203 GetValueForExpressionPathOptions(
204 bool dot = false, bool no_ivar = false, bool bitfield = true,
205 SyntheticChildrenTraversal synth_traverse =
206 SyntheticChildrenTraversal::ToSynthetic)
207 : m_check_dot_vs_arrow_syntax(dot), m_no_fragile_ivar(no_ivar),
208 m_allow_bitfields_syntax(bitfield),
209 m_synthetic_children_traversal(synth_traverse) {}
211 GetValueForExpressionPathOptions &DoCheckDotVsArrowSyntax() {
212 m_check_dot_vs_arrow_syntax = true;
216 GetValueForExpressionPathOptions &DontCheckDotVsArrowSyntax() {
217 m_check_dot_vs_arrow_syntax = false;
221 GetValueForExpressionPathOptions &DoAllowFragileIVar() {
222 m_no_fragile_ivar = false;
226 GetValueForExpressionPathOptions &DontAllowFragileIVar() {
227 m_no_fragile_ivar = true;
231 GetValueForExpressionPathOptions &DoAllowBitfieldSyntax() {
232 m_allow_bitfields_syntax = true;
236 GetValueForExpressionPathOptions &DontAllowBitfieldSyntax() {
237 m_allow_bitfields_syntax = false;
241 GetValueForExpressionPathOptions &
242 SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse) {
243 m_synthetic_children_traversal = traverse;
247 static const GetValueForExpressionPathOptions DefaultOptions() {
248 static GetValueForExpressionPathOptions g_default_options;
250 return g_default_options;
254 class EvaluationPoint {
258 EvaluationPoint(ExecutionContextScope *exe_scope,
259 bool use_selected = false);
261 EvaluationPoint(const EvaluationPoint &rhs);
265 const ExecutionContextRef &GetExecutionContextRef() const {
266 return m_exe_ctx_ref;
269 // Set the EvaluationPoint to the values in exe_scope, Return true if the
270 // Evaluation Point changed. Since the ExecutionContextScope is always
271 // going to be valid currently, the Updated Context will also always be
275 // SetContext (ExecutionContextScope *exe_scope);
277 void SetIsConstant() {
279 m_mod_id.SetInvalid();
282 bool IsConstant() const { return !m_mod_id.IsValid(); }
284 ProcessModID GetModID() const { return m_mod_id; }
286 void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
288 void SetNeedsUpdate() { m_needs_update = true; }
292 bool NeedsUpdating(bool accept_invalid_exe_ctx) {
293 SyncWithProcessState(accept_invalid_exe_ctx);
294 return m_needs_update;
298 const bool accept_invalid_exe_ctx = false;
299 if (!m_mod_id.IsValid())
301 else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
302 if (!m_mod_id.IsValid())
309 // Use the stop id to mark us as invalid, leave the thread id and the
310 // stack id around for logging and history purposes.
311 m_mod_id.SetInvalid();
313 // Can't update an invalid state.
314 m_needs_update = false;
318 bool SyncWithProcessState(bool accept_invalid_exe_ctx);
320 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
322 ExecutionContextRef m_exe_ctx_ref;
326 virtual ~ValueObject();
328 const EvaluationPoint &GetUpdatePoint() const { return m_update_point; }
330 EvaluationPoint &GetUpdatePoint() { return m_update_point; }
332 const ExecutionContextRef &GetExecutionContextRef() const {
333 return m_update_point.GetExecutionContextRef();
336 lldb::TargetSP GetTargetSP() const {
337 return m_update_point.GetExecutionContextRef().GetTargetSP();
340 lldb::ProcessSP GetProcessSP() const {
341 return m_update_point.GetExecutionContextRef().GetProcessSP();
344 lldb::ThreadSP GetThreadSP() const {
345 return m_update_point.GetExecutionContextRef().GetThreadSP();
348 lldb::StackFrameSP GetFrameSP() const {
349 return m_update_point.GetExecutionContextRef().GetFrameSP();
352 void SetNeedsUpdate();
354 CompilerType GetCompilerType();
356 // this vends a TypeImpl that is useful at the SB API layer
357 virtual TypeImpl GetTypeImpl();
359 virtual bool CanProvideValue();
361 // Subclasses must implement the functions below.
362 virtual uint64_t GetByteSize() = 0;
364 virtual lldb::ValueType GetValueType() const = 0;
366 // Subclasses can implement the functions below.
367 virtual ConstString GetTypeName();
369 virtual ConstString GetDisplayTypeName();
371 virtual ConstString GetQualifiedTypeName();
373 virtual lldb::LanguageType GetObjectRuntimeLanguage();
376 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
378 virtual bool IsPointerType();
380 virtual bool IsArrayType();
382 virtual bool IsScalarType();
384 virtual bool IsPointerOrReferenceType();
386 virtual bool IsPossibleDynamicType();
388 bool IsNilReference();
390 bool IsUninitializedReference();
392 virtual bool IsBaseClass() { return false; }
394 bool IsBaseClass(uint32_t &depth);
396 virtual bool IsDereferenceOfParent() { return false; }
398 bool IsIntegerType(bool &is_signed);
400 virtual bool GetBaseClassPath(Stream &s);
402 virtual void GetExpressionPath(
403 Stream &s, bool qualify_cxx_base_classes,
404 GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
406 lldb::ValueObjectSP GetValueForExpressionPath(
407 llvm::StringRef expression,
408 ExpressionPathScanEndReason *reason_to_stop = nullptr,
409 ExpressionPathEndResultType *final_value_type = nullptr,
410 const GetValueForExpressionPathOptions &options =
411 GetValueForExpressionPathOptions::DefaultOptions(),
412 ExpressionPathAftermath *final_task_on_target = nullptr);
414 virtual bool IsInScope() { return true; }
416 virtual lldb::offset_t GetByteOffset() { return 0; }
418 virtual uint32_t GetBitfieldBitSize() { return 0; }
420 virtual uint32_t GetBitfieldBitOffset() { return 0; }
423 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
426 virtual bool IsArrayItemForPointer() { return m_is_array_item_for_pointer; }
428 virtual const char *GetValueAsCString();
430 virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
431 std::string &destination);
433 bool GetValueAsCString(lldb::Format format, std::string &destination);
435 virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
436 bool *success = nullptr);
438 virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
440 virtual bool SetValueFromCString(const char *value_str, Status &error);
442 // Return the module associated with this value object in case the value is
443 // from an executable file and might have its data in sections of the file.
444 // This can be used for variables.
445 virtual lldb::ModuleSP GetModule();
447 ValueObject *GetRoot();
449 // Given a ValueObject, loop over itself and its parent, and its parent's
450 // parent, .. until either the given callback returns false, or you end up at
452 ValueObject *FollowParentChain(std::function<bool(ValueObject *)>);
454 virtual bool GetDeclaration(Declaration &decl);
456 // The functions below should NOT be modified by subclasses
457 const Status &GetError();
459 ConstString GetName() const;
461 virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
463 // this will always create the children if necessary
464 lldb::ValueObjectSP GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
465 size_t *index_of_error = nullptr);
468 GetChildAtIndexPath(llvm::ArrayRef<std::pair<size_t, bool>> idxs,
469 size_t *index_of_error = nullptr);
471 // this will always create the children if necessary
472 lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef<ConstString> names,
473 ConstString *name_of_error = nullptr);
476 GetChildAtNamePath(llvm::ArrayRef<std::pair<ConstString, bool>> names,
477 ConstString *name_of_error = nullptr);
479 virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name,
482 virtual size_t GetIndexOfChildWithName(ConstString name);
484 size_t GetNumChildren(uint32_t max = UINT32_MAX);
486 const Value &GetValue() const;
490 virtual bool ResolveValue(Scalar &scalar);
492 // return 'false' whenever you set the error, otherwise callers may assume
493 // true means everything is OK - this will break breakpoint conditions among
494 // potentially a few others
495 virtual bool IsLogicalTrue(Status &error);
497 virtual const char *GetLocationAsCString();
500 GetSummaryAsCString(lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
503 GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
504 lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
506 bool GetSummaryAsCString(std::string &destination,
507 const TypeSummaryOptions &options);
509 bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
510 std::string &destination,
511 const TypeSummaryOptions &options);
513 std::pair<TypeValidatorResult, std::string> GetValidationStatus();
515 const char *GetObjectDescription();
517 bool HasSpecialPrintableRepresentation(
518 ValueObjectRepresentationStyle val_obj_display,
519 lldb::Format custom_format);
521 enum class PrintableRepresentationSpecialCases : bool {
527 DumpPrintableRepresentation(Stream &s,
528 ValueObjectRepresentationStyle val_obj_display =
529 eValueObjectRepresentationStyleSummary,
530 lldb::Format custom_format = lldb::eFormatInvalid,
531 PrintableRepresentationSpecialCases special =
532 PrintableRepresentationSpecialCases::eAllow,
533 bool do_dump_error = true);
534 bool GetValueIsValid() const;
536 // If you call this on a newly created ValueObject, it will always return
538 bool GetValueDidChange();
540 bool UpdateValueIfNeeded(bool update_format = true);
542 bool UpdateFormatsIfNeeded();
544 lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
546 // Change the name of the current ValueObject. Should *not* be used from a
547 // synthetic child provider as it would change the name of the non synthetic
549 void SetName(ConstString name);
551 virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
552 AddressType *address_type = nullptr);
554 lldb::addr_t GetPointerValue(AddressType *address_type = nullptr);
556 lldb::ValueObjectSP GetSyntheticChild(ConstString key) const;
558 lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
560 lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
563 lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression,
566 virtual lldb::ValueObjectSP
567 GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
569 ConstString name_const_str = ConstString());
571 virtual lldb::ValueObjectSP
572 GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
573 ConstString name_const_str = ConstString());
575 virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType);
577 lldb::DynamicValueType GetDynamicValueType();
579 virtual lldb::ValueObjectSP GetStaticValue();
581 virtual lldb::ValueObjectSP GetNonSyntheticValue();
583 lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic = true);
585 virtual bool HasSyntheticValue();
587 virtual bool IsSynthetic() { return false; }
590 GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue,
593 virtual lldb::ValueObjectSP CreateConstantValue(ConstString name);
595 virtual lldb::ValueObjectSP Dereference(Status &error);
597 // Creates a copy of the ValueObject with a new name and setting the current
598 // ValueObject as its parent. It should be used when we want to change the
599 // name of a ValueObject without modifying the actual ValueObject itself
600 // (e.g. sythetic child provider).
601 virtual lldb::ValueObjectSP Clone(ConstString new_name);
603 virtual lldb::ValueObjectSP AddressOf(Status &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 virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
612 virtual lldb::ValueObjectSP CastPointerType(const char *name,
613 CompilerType &ast_type);
615 virtual lldb::ValueObjectSP CastPointerType(const char *name,
616 lldb::TypeSP &type_sp);
618 // The backing bits of this value object were updated, clear any descriptive
619 // string, so we know we have to refetch them
620 virtual void ValueUpdated() {
621 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
622 eClearUserVisibleDataItemsSummary |
623 eClearUserVisibleDataItemsDescription);
626 virtual bool IsDynamic() { return false; }
628 virtual bool DoesProvideSyntheticValue() { return false; }
630 virtual bool IsSyntheticChildrenGenerated();
632 virtual void SetSyntheticChildrenGenerated(bool b);
634 virtual SymbolContextScope *GetSymbolContextScope();
636 void Dump(Stream &s);
638 void Dump(Stream &s, const DumpValueObjectOptions &options);
640 static lldb::ValueObjectSP
641 CreateValueObjectFromExpression(llvm::StringRef name,
642 llvm::StringRef expression,
643 const ExecutionContext &exe_ctx);
645 static lldb::ValueObjectSP
646 CreateValueObjectFromExpression(llvm::StringRef name,
647 llvm::StringRef expression,
648 const ExecutionContext &exe_ctx,
649 const EvaluateExpressionOptions &options);
651 static lldb::ValueObjectSP
652 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
653 const ExecutionContext &exe_ctx,
656 static lldb::ValueObjectSP
657 CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
658 const ExecutionContext &exe_ctx, CompilerType type);
660 void LogValueObject(Log *log);
662 void LogValueObject(Log *log, const DumpValueObjectOptions &options);
664 lldb::ValueObjectSP Persist();
666 // returns true if this is a char* or a char[] if it is a char* and
667 // check_pointer is true, it also checks that the pointer is valid
668 bool IsCStringContainer(bool check_pointer = false);
670 std::pair<size_t, bool>
671 ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error,
672 uint32_t max_length = 0, bool honor_array = true,
673 lldb::Format item_format = lldb::eFormatCharArray);
675 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
676 uint32_t item_count = 1);
678 virtual uint64_t GetData(DataExtractor &data, Status &error);
680 virtual bool SetData(DataExtractor &data, Status &error);
682 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
684 bool NeedsUpdating() {
685 const bool accept_invalid_exe_ctx =
686 (CanUpdateWithInvalidExecutionContext() == eLazyBoolYes);
687 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
690 void SetIsConstant() { m_update_point.SetIsConstant(); }
692 lldb::Format GetFormat() const;
694 virtual void SetFormat(lldb::Format format) {
695 if (format != m_format)
696 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
700 virtual lldb::LanguageType GetPreferredDisplayLanguage();
702 void SetPreferredDisplayLanguage(lldb::LanguageType);
704 lldb::TypeSummaryImplSP GetSummaryFormat() {
705 UpdateFormatsIfNeeded();
706 return m_type_summary_sp;
709 void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
710 m_type_summary_sp = format;
711 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
714 lldb::TypeValidatorImplSP GetValidator() {
715 UpdateFormatsIfNeeded();
716 return m_type_validator_sp;
719 void SetValidator(lldb::TypeValidatorImplSP format) {
720 m_type_validator_sp = format;
721 ClearUserVisibleData(eClearUserVisibleDataItemsValidator);
724 void SetValueFormat(lldb::TypeFormatImplSP format) {
725 m_type_format_sp = format;
726 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
729 lldb::TypeFormatImplSP GetValueFormat() {
730 UpdateFormatsIfNeeded();
731 return m_type_format_sp;
734 void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
735 if (synth_sp.get() == m_synthetic_children_sp.get())
737 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
738 m_synthetic_children_sp = synth_sp;
741 lldb::SyntheticChildrenSP GetSyntheticChildren() {
742 UpdateFormatsIfNeeded();
743 return m_synthetic_children_sp;
746 // Use GetParent for display purposes, but if you want to tell the parent to
747 // update itself then use m_parent. The ValueObjectDynamicValue's parent is
748 // not the correct parent for displaying, they are really siblings, so for
749 // display it needs to route through to its grandparent.
750 virtual ValueObject *GetParent() { return m_parent; }
752 virtual const ValueObject *GetParent() const { return m_parent; }
754 ValueObject *GetNonBaseClassParent();
756 void SetAddressTypeOfChildren(AddressType at) {
757 m_address_type_of_ptr_or_ref_children = at;
760 AddressType GetAddressTypeOfChildren();
762 void SetHasCompleteType() { m_did_calculate_complete_objc_class_type = true; }
764 /// Find out if a ValueObject might have children.
766 /// This call is much more efficient than CalculateNumChildren() as
767 /// it doesn't need to complete the underlying type. This is designed
768 /// to be used in a UI environment in order to detect if the
769 /// disclosure triangle should be displayed or not.
771 /// This function returns true for class, union, structure,
772 /// pointers, references, arrays and more. Again, it does so without
773 /// doing any expensive type completion.
776 /// Returns \b true if the ValueObject might have children, or \b
778 virtual bool MightHaveChildren();
780 virtual lldb::VariableSP GetVariable() { return nullptr; }
782 virtual bool IsRuntimeSupportValue();
784 virtual uint64_t GetLanguageFlags();
786 virtual void SetLanguageFlags(uint64_t flags);
789 typedef ClusterManager<ValueObject> ValueObjectManager;
791 class ChildrenManager {
793 ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
795 bool HasChildAtIndex(size_t idx) {
796 std::lock_guard<std::recursive_mutex> guard(m_mutex);
797 return (m_children.find(idx) != m_children.end());
800 ValueObject *GetChildAtIndex(size_t idx) {
801 std::lock_guard<std::recursive_mutex> guard(m_mutex);
802 const auto iter = m_children.find(idx);
803 return ((iter == m_children.end()) ? nullptr : iter->second);
806 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
807 // we do not need to be mutex-protected to make a pair
808 ChildrenPair pair(idx, valobj);
809 std::lock_guard<std::recursive_mutex> guard(m_mutex);
810 m_children.insert(pair);
813 void SetChildrenCount(size_t count) { Clear(count); }
815 size_t GetChildrenCount() { return m_children_count; }
817 void Clear(size_t new_count = 0) {
818 std::lock_guard<std::recursive_mutex> guard(m_mutex);
819 m_children_count = new_count;
824 typedef std::map<size_t, ValueObject *> ChildrenMap;
825 typedef ChildrenMap::iterator ChildrenIterator;
826 typedef ChildrenMap::value_type ChildrenPair;
827 std::recursive_mutex m_mutex;
828 ChildrenMap m_children;
829 size_t m_children_count;
832 // Classes that inherit from ValueObject can see and modify these
834 *m_parent; // The parent value object, or nullptr if this has no parent
835 ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
836 // nullptr if never calculated)
837 EvaluationPoint m_update_point; // Stores both the stop id and the full
838 // context at which this value was last
839 // updated. When we are asked to update the value object, we check whether
840 // the context & stop id are the same before updating.
841 ConstString m_name; // The name of this object
843 m_data; // A data extractor that can be used to extract the value.
846 m_error; // An error object that can describe any errors that occur when
848 std::string m_value_str; // Cached value string that will get cleared if/when
849 // the value is updated.
850 std::string m_old_value_str; // Cached old value string from the last time the
852 std::string m_location_str; // Cached location string that will get cleared
853 // if/when the value is updated.
854 std::string m_summary_str; // Cached summary string that will get cleared
855 // if/when the value is updated.
856 std::string m_object_desc_str; // Cached result of the "object printer". This
857 // differs from the summary
858 // in that the summary is consed up by us, the object_desc_string is builtin.
860 llvm::Optional<std::pair<TypeValidatorResult, std::string>>
863 CompilerType m_override_type; // If the type of the value object should be
864 // overridden, the type to impose.
866 ValueObjectManager *m_manager; // This object is managed by the root object
867 // (any ValueObject that gets created
868 // without a parent.) The manager gets passed through all the generations of
869 // dependent objects, and will keep the whole cluster of objects alive as
870 // long as a shared pointer to any of them has been handed out. Shared
871 // pointers to value objects must always be made with the GetSP method.
873 ChildrenManager m_children;
874 std::map<ConstString, ValueObject *> m_synthetic_children;
876 ValueObject *m_dynamic_value;
877 ValueObject *m_synthetic_value;
878 ValueObject *m_deref_valobj;
880 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
881 // pointer to this one because it is
883 // as an independent ValueObjectConstResult, which isn't managed by us.
885 lldb::Format m_format;
886 lldb::Format m_last_format;
887 uint32_t m_last_format_mgr_revision;
888 lldb::TypeSummaryImplSP m_type_summary_sp;
889 lldb::TypeFormatImplSP m_type_format_sp;
890 lldb::SyntheticChildrenSP m_synthetic_children_sp;
891 lldb::TypeValidatorImplSP m_type_validator_sp;
892 ProcessModID m_user_id_of_forced_summary;
893 AddressType m_address_type_of_ptr_or_ref_children;
895 llvm::SmallVector<uint8_t, 16> m_value_checksum;
897 lldb::LanguageType m_preferred_display_language;
899 uint64_t m_language_flags;
901 bool m_value_is_valid : 1, m_value_did_change : 1, m_children_count_valid : 1,
902 m_old_value_valid : 1, m_is_deref_of_parent : 1,
903 m_is_array_item_for_pointer : 1, m_is_bitfield_for_scalar : 1,
904 m_is_child_at_offset : 1, m_is_getting_summary : 1,
905 m_did_calculate_complete_objc_class_type : 1,
906 m_is_synthetic_children_generated : 1;
908 friend class ValueObjectChild;
909 friend class ClangExpressionDeclMap; // For GetValue
910 friend class ExpressionVariable; // For SetName
911 friend class Target; // For SetName
912 friend class ValueObjectConstResultImpl;
913 friend class ValueObjectSynthetic; // For ClearUserVisibleData
915 // Constructors and Destructors
917 // Use the no-argument constructor to make a constant variable object (with
918 // no ExecutionContextScope.)
922 // Use this constructor to create a "root variable object". The ValueObject
923 // will be locked to this context through-out its lifespan.
925 ValueObject(ExecutionContextScope *exe_scope,
926 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
928 // Use this constructor to create a ValueObject owned by another ValueObject.
929 // It will inherit the ExecutionContext of its parent.
931 ValueObject(ValueObject &parent);
933 ValueObjectManager *GetManager() { return m_manager; }
935 virtual bool UpdateValue() = 0;
937 virtual LazyBool CanUpdateWithInvalidExecutionContext() {
938 return eLazyBoolCalculate;
941 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
943 virtual lldb::DynamicValueType GetDynamicValueTypeImpl() {
944 return lldb::eNoDynamicValues;
947 virtual bool HasDynamicValueTypeInfo() { return false; }
949 virtual void CalculateSyntheticValue(bool use_synthetic = true);
951 // Should only be called by ValueObject::GetChildAtIndex() Returns a
952 // ValueObject managed by this ValueObject's manager.
953 virtual ValueObject *CreateChildAtIndex(size_t idx,
954 bool synthetic_array_member,
955 int32_t synthetic_index);
957 // Should only be called by ValueObject::GetNumChildren()
958 virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
960 void SetNumChildren(size_t num_children);
962 void SetValueDidChange(bool value_changed);
964 void SetValueIsValid(bool valid);
966 void ClearUserVisibleData(
967 uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
969 void AddSyntheticChild(ConstString key, ValueObject *valobj);
971 DataExtractor &GetDataExtractor();
973 void ClearDynamicTypeInformation();
975 // Subclasses must implement the functions below.
977 virtual CompilerType GetCompilerTypeImpl() = 0;
979 const char *GetLocationAsCStringImpl(const Value &value,
980 const DataExtractor &data);
982 bool IsChecksumEmpty();
984 void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
987 virtual CompilerType MaybeCalculateCompleteType();
989 lldb::ValueObjectSP GetValueForExpressionPath_Impl(
990 llvm::StringRef expression_cstr,
991 ExpressionPathScanEndReason *reason_to_stop,
992 ExpressionPathEndResultType *final_value_type,
993 const GetValueForExpressionPathOptions &options,
994 ExpressionPathAftermath *final_task_on_target);
996 DISALLOW_COPY_AND_ASSIGN(ValueObject);
999 // A value object manager class that is seeded with the static variable value
1000 // and it vends the user facing value object. If the type is dynamic it can
1001 // vend the dynamic type. If this user type also has a synthetic type
1002 // associated with it, it will vend the synthetic type. The class watches the
1004 // ID and will update the user type when needed.
1005 class ValueObjectManager {
1006 // The root value object is the static typed variable object.
1007 lldb::ValueObjectSP m_root_valobj_sp;
1008 // The user value object is the value object the user wants to see.
1009 lldb::ValueObjectSP m_user_valobj_sp;
1010 lldb::DynamicValueType m_use_dynamic;
1011 uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1012 bool m_use_synthetic;
1015 ValueObjectManager() {}
1017 ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1018 lldb::DynamicValueType use_dynamic, bool use_synthetic);
1020 bool IsValid() const;
1022 lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1024 // Gets the correct value object from the root object for a given process
1025 // stop ID. If dynamic values are enabled, or if synthetic children are
1026 // enabled, the value object that the user wants to see might change while
1028 lldb::ValueObjectSP GetSP();
1030 void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1031 void SetUseSynthetic(bool use_synthetic);
1032 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1033 bool GetUseSynthetic() const { return m_use_synthetic; }
1034 lldb::TargetSP GetTargetSP() const;
1035 lldb::ProcessSP GetProcessSP() const;
1036 lldb::ThreadSP GetThreadSP() const;
1037 lldb::StackFrameSP GetFrameSP() const;
1040 } // namespace lldb_private
1042 #endif // liblldb_ValueObject_h_