LLDB mainline
ValueObject.h
Go to the documentation of this file.
1//===-- ValueObject.h -------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_VALUEOBJECT_VALUEOBJECT_H
10#define LLDB_VALUEOBJECT_VALUEOBJECT_H
11
12#include "lldb/Core/Value.h"
14#include "lldb/Symbol/Type.h"
16#include "lldb/Target/Process.h"
20#include "lldb/Utility/Status.h"
21#include "lldb/Utility/UserID.h"
22#include "lldb/lldb-defines.h"
24#include "lldb/lldb-forward.h"
26#include "lldb/lldb-types.h"
27
28#include "llvm/ADT/ArrayRef.h"
29#include "llvm/ADT/SmallVector.h"
30#include "llvm/ADT/StringRef.h"
31
32#include <functional>
33#include <initializer_list>
34#include <map>
35#include <mutex>
36#include <optional>
37#include <string>
38#include <utility>
39
40#include <cstddef>
41#include <cstdint>
42
43namespace lldb_private {
44class Declaration;
48class Log;
49class Scalar;
50class Stream;
52class TypeFormatImpl;
53class TypeSummaryImpl;
55
56/// ValueObject:
57///
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.
71
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
84/// released.
85///
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.
89
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.
96///
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.
104
106public:
111
122
124 /// Out of data to parse.
126 /// Child element not found.
128 /// (Synthetic) child element not found.
130 /// [] only allowed for arrays.
132 /// . used when -> should be used.
134 /// -> used when . should be used.
136 /// ObjC ivar expansion not allowed.
138 /// [] not allowed by options.
140 /// [] not valid on objects other than scalars, pointers or arrays.
142 /// [] is good for arrays, but I cannot parse it.
144 /// [] is good for bitfields, but I cannot parse after it.
146 /// Something is malformed in he expression.
148 /// Impossible to apply & operator.
150 /// Impossible to apply * operator.
152 /// [] was expanded into a VOList.
154 /// getting the synthetic children failed.
157 };
158
172
174 /// Just return it.
176 /// Dereference the target.
178 /// Take target's address.
180 };
181
195
203
208
210 bool dot = false, bool no_ivar = false, bool bitfield = true,
211 SyntheticChildrenTraversal synth_traverse =
214 m_allow_bitfields_syntax(bitfield),
215 m_synthetic_children_traversal(synth_traverse) {}
216
221
226
231
236
241
246
252
254 static GetValueForExpressionPathOptions g_default_options;
255
256 return g_default_options;
257 }
258 };
259
261 public:
263
265 bool use_selected = false);
266
268
270
272 return m_exe_ctx_ref;
273 }
274
276 SetUpdated();
277 m_mod_id.SetInvalid();
278 }
279
280 bool IsConstant() const { return !m_mod_id.IsValid(); }
281
282 ProcessModID GetModID() const { return m_mod_id; }
283
284 void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
285
287
288 void SetUpdated();
289
290 bool NeedsUpdating(bool accept_invalid_exe_ctx) {
291 SyncWithProcessState(accept_invalid_exe_ctx);
292 return m_needs_update;
293 }
294
295 bool IsValid() {
296 const bool accept_invalid_exe_ctx = false;
297 if (!m_mod_id.IsValid())
298 return false;
299 else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
300 if (!m_mod_id.IsValid())
301 return false;
302 }
303 return true;
304 }
305
306 void SetInvalid() {
307 // Use the stop id to mark us as invalid, leave the thread id and the
308 // stack id around for logging and history purposes.
309 m_mod_id.SetInvalid();
310
311 // Can't update an invalid state.
312 m_needs_update = false;
313 }
314
315 private:
316 bool SyncWithProcessState(bool accept_invalid_exe_ctx);
317
318 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
319 // evaluated.
321 bool m_needs_update = true;
322 };
323
324 virtual ~ValueObject();
325
327
329
331 return m_update_point.GetExecutionContextRef();
332 }
333
335 return m_update_point.GetExecutionContextRef().GetTargetSP();
336 }
337
339 return m_update_point.GetExecutionContextRef().GetProcessSP();
340 }
341
343 return m_update_point.GetExecutionContextRef().GetThreadSP();
344 }
345
347 return m_update_point.GetExecutionContextRef().GetFrameSP();
348 }
349
350 void SetNeedsUpdate();
351
353
354 // this vends a TypeImpl that is useful at the SB API layer
356
357 virtual bool CanProvideValue();
358
359 // Subclasses must implement the functions below.
360 virtual llvm::Expected<uint64_t> GetByteSize() = 0;
361
362 virtual lldb::ValueType GetValueType() const = 0;
363
364 // Subclasses can implement the functions below.
366
368
372
376
377 uint32_t
378 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) {
379 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type);
380 }
381
383
385
387
391
393
394 bool IsNilReference();
395
397
398 virtual bool IsBaseClass() { return false; }
399
400 bool IsBaseClass(uint32_t &depth);
401
402 virtual bool IsDereferenceOfParent() { return false; }
403
404 bool IsIntegerType(bool &is_signed) {
405 return GetCompilerType().IsIntegerType(is_signed);
406 }
407
408 virtual void GetExpressionPath(
409 Stream &s,
411
413 llvm::StringRef expression,
414 ExpressionPathScanEndReason *reason_to_stop = nullptr,
415 ExpressionPathEndResultType *final_value_type = nullptr,
416 const GetValueForExpressionPathOptions &options =
418 ExpressionPathAftermath *final_task_on_target = nullptr);
419
420 virtual bool IsInScope() { return true; }
421
422 virtual lldb::offset_t GetByteOffset() { return 0; }
423
424 virtual uint32_t GetBitfieldBitSize() { return 0; }
425
426 virtual uint32_t GetBitfieldBitOffset() { return 0; }
427
428 bool IsBitfield() {
429 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
430 }
431
432 virtual const char *GetValueAsCString();
433
434 virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
435 std::string &destination);
436
437 bool GetValueAsCString(lldb::Format format, std::string &destination);
438
439 virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
440 bool *success = nullptr);
441
442 virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
443
444 /// If the current ValueObject is of an appropriate type, convert the
445 /// value to an APSInt and return that. Otherwise return an error.
446 llvm::Expected<llvm::APSInt> GetValueAsAPSInt();
447
448 /// If the current ValueObject is of an appropriate type, convert the
449 /// value to an APFloat and return that. Otherwise return an error.
450 llvm::Expected<llvm::APFloat> GetValueAsAPFloat();
451
452 /// If the current ValueObject is of an appropriate type, convert the
453 /// value to a boolean and return that. Otherwise return an error.
454 llvm::Expected<bool> GetValueAsBool();
455
456 /// Update an existing integer ValueObject with a new integer value. This
457 /// is only intended to be used with 'temporary' ValueObjects, i.e. ones that
458 /// are not associated with program variables. It does not update program
459 /// memory, registers, stack, etc.
460 void SetValueFromInteger(const llvm::APInt &value, Status &error);
461
462 /// Update an existing integer ValueObject with an integer value created
463 /// frome 'new_val_sp'. This is only intended to be used with 'temporary'
464 /// ValueObjects, i.e. ones that are not associated with program variables.
465 /// It does not update program memory, registers, stack, etc.
467
468 virtual bool SetValueFromCString(const char *value_str, Status &error);
469
470 /// Return the module associated with this value object in case the value is
471 /// from an executable file and might have its data in sections of the file.
472 /// This can be used for variables.
473 virtual lldb::ModuleSP GetModule();
474
476
477 /// Given a ValueObject, loop over itself and its parent, and its parent's
478 /// parent, .. until either the given callback returns false, or you end up at
479 /// a null pointer
480 ValueObject *FollowParentChain(std::function<bool(ValueObject *)>);
481
482 virtual bool GetDeclaration(Declaration &decl);
483
484 // The functions below should NOT be modified by subclasses
485 const Status &GetError();
486
487 ConstString GetName() const { return m_name; }
488
489 /// Returns a unique id for this ValueObject.
490 lldb::user_id_t GetID() const { return m_id.GetID(); }
491
492 virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx,
493 bool can_create = true);
494
495 // The method always creates missing children in the path, if necessary.
496 lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef<llvm::StringRef> names);
497
498 virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name,
499 bool can_create = true);
500
501 virtual llvm::Expected<size_t> GetIndexOfChildWithName(llvm::StringRef name);
502
503 llvm::Expected<uint32_t> GetNumChildren(uint32_t max = UINT32_MAX);
504 /// Like \c GetNumChildren but returns 0 on error. You probably
505 /// shouldn't be using this function. It exists primarily to ease the
506 /// transition to more pervasive error handling while not all APIs
507 /// have been updated.
508 uint32_t GetNumChildrenIgnoringErrors(uint32_t max = UINT32_MAX);
510
511 const Value &GetValue() const { return m_value; }
512
513 Value &GetValue() { return m_value; }
514
515 virtual bool ResolveValue(Scalar &scalar);
516
517 // return 'false' whenever you set the error, otherwise callers may assume
518 // true means everything is OK - this will break breakpoint conditions among
519 // potentially a few others
520 virtual bool IsLogicalTrue(Status &error);
521
522 virtual const char *GetLocationAsCString() {
524 }
525
526 const char *
528
529 bool
530 GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
532
533 bool GetSummaryAsCString(std::string &destination,
534 const TypeSummaryOptions &options);
535
536 bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
537 std::string &destination,
538 const TypeSummaryOptions &options);
539
540 llvm::Expected<std::string> GetObjectDescription();
541
543 ValueObjectRepresentationStyle val_obj_display,
544 lldb::Format custom_format);
545
547 eDisable = false,
548 eAllow = true
549 };
550
551 bool
553 ValueObjectRepresentationStyle val_obj_display =
555 lldb::Format custom_format = lldb::eFormatInvalid,
558 bool do_dump_error = true);
559 bool GetValueIsValid() const { return m_flags.m_value_is_valid; }
560
561 // If you call this on a newly created ValueObject, it will always return
562 // false.
563 bool GetValueDidChange() { return m_flags.m_value_did_change; }
564
565 bool UpdateValueIfNeeded(bool update_format = true);
566
568
569 lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
570
571 /// Change the name of the current ValueObject. Should *not* be used from a
572 /// synthetic child provider as it would change the name of the non synthetic
573 /// child as well.
574 void SetName(ConstString name) { m_name = name; }
575
580
581 virtual AddrAndType GetAddressOf(bool scalar_is_load_address = true);
582
584
586
587 lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
588
589 lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
590 bool can_create);
591
593 bool can_create);
594
595 virtual lldb::ValueObjectSP
596 GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
597 bool can_create,
598 ConstString name_const_str = ConstString());
599
600 virtual lldb::ValueObjectSP
601 GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
602 ConstString name_const_str = ConstString());
603
605
607
609
611
613
614 virtual bool HasSyntheticValue();
615
616 virtual bool IsSynthetic() { return false; }
617
620 bool synthValue);
621
623
625
626 /// Creates a copy of the ValueObject with a new name and setting the current
627 /// ValueObject as its parent. It should be used when we want to change the
628 /// name of a ValueObject without modifying the actual ValueObject itself
629 /// (e.g. sythetic child provider).
630 virtual lldb::ValueObjectSP Clone(ConstString new_name);
631
633
635
638
639 lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
640
641 virtual lldb::ValueObjectSP DoCast(const CompilerType &compiler_type);
642
643 virtual lldb::ValueObjectSP CastPointerType(const char *name,
644 CompilerType &ast_type);
645
646 virtual lldb::ValueObjectSP CastPointerType(const char *name,
647 lldb::TypeSP &type_sp);
648
649 /// Return the target load address associated with this value object.
651
652 /// Take a ValueObject whose type is an inherited class, and cast it to
653 /// 'type', which should be one of its base classes. 'base_type_indices'
654 /// contains the indices of direct base classes on the path from the
655 /// ValueObject's current type to 'type'
656 llvm::Expected<lldb::ValueObjectSP>
658 const llvm::ArrayRef<uint32_t> &base_type_indices);
659
660 /// Take a ValueObject whose type is a base class, and cast it to 'type',
661 /// which should be one of its derived classes. 'base_type_indices'
662 /// contains the indices of direct base classes on the path from the
663 /// ValueObject's current type to 'type'
664 llvm::Expected<lldb::ValueObjectSP> CastBaseToDerivedType(CompilerType type,
665 uint64_t offset);
666
667 // Take a ValueObject that contains a scalar, enum or pointer type, and
668 // cast it to a "basic" type (integer, float or boolean).
670
671 // Take a ValueObject that contain an integer, float or enum, and cast it
672 // to an enum.
674
675 /// If this object represents a C++ class with a vtable, return an object
676 /// that represents the virtual function table. If the object isn't a class
677 /// with a vtable, return a valid ValueObject with the error set correctly.
679 // The backing bits of this value object were updated, clear any descriptive
680 // string, so we know we have to refetch them.
686
687 virtual bool IsDynamic() { return false; }
688
689 virtual bool DoesProvideSyntheticValue() { return false; }
690
692 return m_flags.m_is_synthetic_children_generated;
693 }
694
695 virtual void SetSyntheticChildrenGenerated(bool b) {
696 m_flags.m_is_synthetic_children_generated = b;
697 }
698
700
701 llvm::Error Dump(Stream &s);
702
703 llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
704
706 CreateValueObjectFromExpression(llvm::StringRef name,
707 llvm::StringRef expression,
708 const ExecutionContext &exe_ctx);
709
711 CreateValueObjectFromExpression(llvm::StringRef name,
712 llvm::StringRef expression,
713 const ExecutionContext &exe_ctx,
714 const EvaluateExpressionOptions &options);
715
716 /// Given an address either create a value object containing the value at
717 /// that address, or create a value object containing the address itself
718 /// (pointer value), depending on whether the parameter 'do_deref' is true or
719 /// false.
721 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
722 const ExecutionContext &exe_ctx,
723 CompilerType type, bool do_deref = true);
724
726 CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
727 const ExecutionContext &exe_ctx, CompilerType type);
728
729 /// Create a value object containing the given APInt value.
731 const llvm::APInt &v,
732 CompilerType type,
733 llvm::StringRef name);
734
735 /// Create a value object containing the given APFloat value.
737 CreateValueObjectFromAPFloat(lldb::TargetSP target, const llvm::APFloat &v,
738 CompilerType type, llvm::StringRef name);
739
740 /// Create a value object containing the given Scalar value.
742 Scalar &s,
743 CompilerType type,
744 llvm::StringRef name);
745
746 /// Create a value object containing the given boolean value.
748 bool value,
749 llvm::StringRef name);
750
751 /// Create a nullptr value object with the specified type (must be a
752 /// nullptr type).
754 CompilerType type,
755 llvm::StringRef name);
756
758
759 /// Returns true if this is a char* or a char[] if it is a char* and
760 /// check_pointer is true, it also checks that the pointer is valid.
761 bool IsCStringContainer(bool check_pointer = false);
762
763 std::pair<size_t, bool>
765 bool honor_array);
766
767 virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
768 uint32_t item_count = 1);
769
770 virtual uint64_t GetData(DataExtractor &data, Status &error);
771
772 virtual bool SetData(DataExtractor &data, Status &error);
773
774 virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
775
777 const bool accept_invalid_exe_ctx =
779 return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
780 }
781
782 void SetIsConstant() { m_update_point.SetIsConstant(); }
783
784 lldb::Format GetFormat() const;
785
786 virtual void SetFormat(lldb::Format format) {
787 if (format != m_format)
789 m_format = format;
790 }
791
793
797
802
807
808 void SetDerefValobj(ValueObject *deref) { m_deref_valobj = deref; }
809
811
816
821
828
833
834 // Use GetParent for display purposes, but if you want to tell the parent to
835 // update itself then use m_parent. The ValueObjectDynamicValue's parent is
836 // not the correct parent for displaying, they are really siblings, so for
837 // display it needs to route through to its grandparent.
838 virtual ValueObject *GetParent() { return m_parent; }
839
840 virtual const ValueObject *GetParent() const { return m_parent; }
841
843
847
849
851 m_flags.m_did_calculate_complete_objc_class_type = true;
852 }
853
854 /// Find out if a ValueObject might have children.
855 ///
856 /// This call is much more efficient than CalculateNumChildren() as
857 /// it doesn't need to complete the underlying type. This is designed
858 /// to be used in a UI environment in order to detect if the
859 /// disclosure triangle should be displayed or not.
860 ///
861 /// This function returns true for class, union, structure,
862 /// pointers, references, arrays and more. Again, it does so without
863 /// doing any expensive type completion.
864 ///
865 /// \return
866 /// Returns \b true if the ValueObject might have children, or \b
867 /// false otherwise.
868 virtual bool MightHaveChildren();
869
870 virtual lldb::VariableSP GetVariable() { return nullptr; }
871
872 virtual bool IsRuntimeSupportValue();
873
874 virtual uint64_t GetLanguageFlags() { return m_language_flags; }
875
876 virtual void SetLanguageFlags(uint64_t flags) { m_language_flags = flags; }
877
878 /// Returns the local buffer that this ValueObject points to if it's
879 /// available.
880 /// \return
881 /// The local buffer if this value object's value points to a
882 /// host address, and if that buffer can be determined. Otherwise, returns
883 /// an empty ArrayRef.
884 ///
885 /// TODO: Because a ValueObject's Value can point to any arbitrary memory
886 /// location, it is possible that we can't find what what buffer we're
887 /// pointing to, and thus also can't know its size. See the comment in
888 /// Value::m_value for a more thorough explanation of why that is.
889 llvm::ArrayRef<uint8_t> GetLocalBuffer() const;
890
891protected:
893
895 public:
896 ChildrenManager() = default;
897
898 bool HasChildAtIndex(size_t idx) {
899 std::lock_guard<std::recursive_mutex> guard(m_mutex);
900 return (m_children.find(idx) != m_children.end());
901 }
902
904 std::lock_guard<std::recursive_mutex> guard(m_mutex);
905 const auto iter = m_children.find(idx);
906 return ((iter == m_children.end()) ? nullptr : iter->second);
907 }
908
909 void SetChildAtIndex(size_t idx, ValueObject *valobj) {
910 // we do not need to be mutex-protected to make a pair
911 ChildrenPair pair(idx, valobj);
912 std::lock_guard<std::recursive_mutex> guard(m_mutex);
913 m_children.insert(pair);
914 }
915
916 void SetChildrenCount(size_t count) { Clear(count); }
917
919
920 void Clear(size_t new_count = 0) {
921 std::lock_guard<std::recursive_mutex> guard(m_mutex);
922 m_children_count = new_count;
923 m_children.clear();
924 }
925
926 private:
927 typedef std::map<size_t, ValueObject *> ChildrenMap;
928 typedef ChildrenMap::iterator ChildrenIterator;
929 typedef ChildrenMap::value_type ChildrenPair;
930 std::recursive_mutex m_mutex;
933 };
934
935 // Classes that inherit from ValueObject can see and modify these
936
937 /// The parent value object, or nullptr if this has no parent.
939 /// The root of the hierarchy for this ValueObject (or nullptr if never
940 /// calculated).
941 ValueObject *m_root = nullptr;
942 /// Stores both the stop id and the full context at which this value was last
943 /// updated. When we are asked to update the value object, we check whether
944 /// the context & stop id are the same before updating.
946 /// The name of this object.
948 /// A data extractor that can be used to extract the value.
951 /// An error object that can describe any errors that occur when updating
952 /// values.
954 /// Cached value string that will get cleared if/when the value is updated.
955 std::string m_value_str;
956 /// Cached old value string from the last time the value was gotten
957 std::string m_old_value_str;
958 /// Cached location string that will get cleared if/when the value is updated.
959 std::string m_location_str;
960 /// Cached summary string that will get cleared if/when the value is updated.
961 std::string m_summary_str;
962 /// Cached result of the "object printer". This differs from the summary
963 /// in that the summary is consed up by us, the object_desc_string is builtin.
964 std::string m_object_desc_str;
965 /// If the type of the value object should be overridden, the type to impose.
967
968 /// This object is managed by the root object (any ValueObject that gets
969 /// created without a parent.) The manager gets passed through all the
970 /// generations of dependent objects, and will keep the whole cluster of
971 /// objects alive as long as a shared pointer to any of them has been handed
972 /// out. Shared pointers to value objects must always be made with the GetSP
973 /// method.
975
977 std::map<ConstString, ValueObject *> m_synthetic_children;
978
982
983 /// We have to hold onto a shared pointer to this one because it is created
984 /// as an independent ValueObjectConstResult, which isn't managed by us.
986
995
996 llvm::SmallVector<uint8_t, 16> m_value_checksum;
997
999
1000 uint64_t m_language_flags = 0;
1001
1002 /// Unique identifier for every value object.
1004
1005 // Utility class for initializing all bitfields in ValueObject's constructors.
1006 // FIXME: This could be done via default initializers once we have C++20.
1028
1029 friend class ValueObjectChild;
1030 friend class ExpressionVariable; // For SetName
1031 friend class Target; // For SetName
1033 friend class ValueObjectSynthetic; // For ClearUserVisibleData
1034
1035 /// Use this constructor to create a "root variable object". The ValueObject
1036 /// will be locked to this context through-out its lifespan.
1038 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1039
1040 /// Use this constructor to create a ValueObject owned by another ValueObject.
1041 /// It will inherit the ExecutionContext of its parent.
1042 ValueObject(ValueObject &parent);
1043
1045
1046 virtual bool UpdateValue() = 0;
1047
1051
1052 virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
1053
1057
1058 virtual bool HasDynamicValueTypeInfo() { return false; }
1059
1060 virtual void CalculateSyntheticValue();
1061
1062 /// Should only be called by ValueObject::GetChildAtIndex().
1063 ///
1064 /// \return A ValueObject managed by this ValueObject's manager.
1065 virtual ValueObject *CreateChildAtIndex(size_t idx);
1066
1067 /// Should only be called by ValueObject::GetSyntheticArrayMember().
1068 ///
1069 /// \return A ValueObject managed by this ValueObject's manager.
1070 virtual ValueObject *CreateSyntheticArrayMember(size_t idx);
1071
1072 /// Should only be called by ValueObject::GetNumChildren().
1073 virtual llvm::Expected<uint32_t>
1075
1076 void SetNumChildren(uint32_t num_children);
1077
1078 void SetValueDidChange(bool value_changed) {
1079 m_flags.m_value_did_change = value_changed;
1080 }
1081
1082 void SetValueIsValid(bool valid) { m_flags.m_value_is_valid = valid; }
1083
1086
1087 void AddSyntheticChild(ConstString key, ValueObject *valobj);
1088
1090
1092
1093 // Subclasses must implement the functions below.
1094
1096
1097 const char *GetLocationAsCStringImpl(const Value &value,
1098 const DataExtractor &data);
1099
1100 bool IsChecksumEmpty() { return m_value_checksum.empty(); }
1101
1103
1104protected:
1106
1107private:
1112
1114 llvm::StringRef expression_cstr,
1115 ExpressionPathScanEndReason *reason_to_stop,
1116 ExpressionPathEndResultType *final_value_type,
1117 const GetValueForExpressionPathOptions &options,
1118 ExpressionPathAftermath *final_task_on_target);
1119
1120 ValueObject(const ValueObject &) = delete;
1121 const ValueObject &operator=(const ValueObject &) = delete;
1122};
1123
1124} // namespace lldb_private
1125
1126#endif // LLDB_VALUEOBJECT_VALUEOBJECT_H
static llvm::raw_ostream & error(Stream &strm)
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
ConstString GetTypeName(bool BaseOnly=false) const
bool IsIntegerType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
ValueObject * GetChildAtIndex(uint32_t idx)
void SetChildAtIndex(size_t idx, ValueObject *valobj)
std::map< size_t, ValueObject * > ChildrenMap
bool SyncWithProcessState(bool accept_invalid_exe_ctx)
void SetUpdateID(ProcessModID new_id)
const ExecutionContextRef & GetExecutionContextRef() const
bool NeedsUpdating(bool accept_invalid_exe_ctx)
AddressType m_address_type_of_ptr_or_ref_children
void SetValueIsValid(bool valid)
lldb::TypeFormatImplSP GetValueFormat()
EvaluationPoint m_update_point
Stores both the stop id and the full context at which this value was last updated.
lldb::TypeSummaryImplSP GetSummaryFormat()
llvm::SmallVector< uint8_t, 16 > m_value_checksum
llvm::Expected< llvm::APFloat > GetValueAsAPFloat()
If the current ValueObject is of an appropriate type, convert the value to an APFloat and return that...
virtual uint32_t GetBitfieldBitSize()
void ClearUserVisibleData(uint32_t items=ValueObject::eClearUserVisibleDataItemsAllStrings)
ValueObject * FollowParentChain(std::function< bool(ValueObject *)>)
Given a ValueObject, loop over itself and its parent, and its parent's parent, .
CompilerType m_override_type
If the type of the value object should be overridden, the type to impose.
lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
const EvaluationPoint & GetUpdatePoint() const
void AddSyntheticChild(ConstString key, ValueObject *valobj)
virtual uint64_t GetData(DataExtractor &data, Status &error)
EvaluationPoint & GetUpdatePoint()
friend class ValueObjectSynthetic
bool DumpPrintableRepresentation(Stream &s, ValueObjectRepresentationStyle val_obj_display=eValueObjectRepresentationStyleSummary, lldb::Format custom_format=lldb::eFormatInvalid, PrintableRepresentationSpecialCases special=PrintableRepresentationSpecialCases::eAllow, bool do_dump_error=true)
ValueObject * m_deref_valobj
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual lldb::DynamicValueType GetDynamicValueTypeImpl()
const ValueObject & operator=(const ValueObject &)=delete
static lldb::ValueObjectSP CreateValueObjectFromBool(lldb::TargetSP target, bool value, llvm::StringRef name)
Create a value object containing the given boolean value.
virtual bool GetIsConstant() const
virtual bool MightHaveChildren()
Find out if a ValueObject might have children.
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
virtual bool IsDereferenceOfParent()
CompilerType GetCompilerType()
virtual llvm::Expected< size_t > GetIndexOfChildWithName(llvm::StringRef name)
virtual ValueObject * CreateSyntheticArrayMember(size_t idx)
Should only be called by ValueObject::GetSyntheticArrayMember().
virtual const ValueObject * GetParent() const
void SetValueFormat(lldb::TypeFormatImplSP format)
virtual lldb::addr_t GetLiveAddress()
virtual void CalculateSyntheticValue()
void SetPreferredDisplayLanguage(lldb::LanguageType lt)
struct lldb_private::ValueObject::Bitflags m_flags
ClusterManager< ValueObject > ValueObjectManager
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
std::string m_summary_str
Cached summary string that will get cleared if/when the value is updated.
virtual lldb::ValueObjectSP DoCast(const CompilerType &compiler_type)
lldb::TypeSummaryImplSP m_type_summary_sp
lldb::ValueObjectSP GetSP()
ChildrenManager m_children
virtual void SetLanguageFlags(uint64_t flags)
virtual lldb::ValueObjectSP CastPointerType(const char *name, CompilerType &ast_type)
Status m_error
An error object that can describe any errors that occur when updating values.
virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1)
lldb::ValueObjectSP GetSyntheticValue()
static lldb::ValueObjectSP CreateValueObjectFromAPFloat(lldb::TargetSP target, const llvm::APFloat &v, CompilerType type, llvm::StringRef name)
Create a value object containing the given APFloat value.
ValueObjectManager * m_manager
This object is managed by the root object (any ValueObject that gets created without a parent....
lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to, bool can_create)
lldb::ProcessSP GetProcessSP() const
lldb::ValueObjectSP GetSyntheticChild(ConstString key) const
@ eExpressionPathScanEndReasonArrowInsteadOfDot
-> used when . should be used.
@ eExpressionPathScanEndReasonDereferencingFailed
Impossible to apply * operator.
@ eExpressionPathScanEndReasonNoSuchSyntheticChild
(Synthetic) child element not found.
@ eExpressionPathScanEndReasonNoSuchChild
Child element not found.
@ eExpressionPathScanEndReasonDotInsteadOfArrow
. used when -> should be used.
@ eExpressionPathScanEndReasonEndOfString
Out of data to parse.
@ eExpressionPathScanEndReasonBitfieldRangeOperatorMet
[] is good for bitfields, but I cannot parse after it.
@ eExpressionPathScanEndReasonRangeOperatorNotAllowed
[] not allowed by options.
@ eExpressionPathScanEndReasonEmptyRangeNotAllowed
[] only allowed for arrays.
@ eExpressionPathScanEndReasonRangeOperatorExpanded
[] was expanded into a VOList.
@ eExpressionPathScanEndReasonRangeOperatorInvalid
[] not valid on objects other than scalars, pointers or arrays.
@ eExpressionPathScanEndReasonUnexpectedSymbol
Something is malformed in he expression.
@ eExpressionPathScanEndReasonArrayRangeOperatorMet
[] is good for arrays, but I cannot parse it.
@ eExpressionPathScanEndReasonSyntheticValueMissing
getting the synthetic children failed.
@ eExpressionPathScanEndReasonTakingAddressFailed
Impossible to apply & operator.
@ eExpressionPathScanEndReasonFragileIVarNotAllowed
ObjC ivar expansion not allowed.
virtual bool UpdateValue()=0
lldb::Format GetFormat() const
virtual uint64_t GetLanguageFlags()
virtual lldb::VariableSP GetVariable()
friend class ExpressionVariable
@ eExpressionPathAftermathNothing
Just return it.
@ eExpressionPathAftermathDereference
Dereference the target.
@ eExpressionPathAftermathTakeAddress
Take target's address.
lldb::ValueObjectSP CastToBasicType(CompilerType type)
virtual void SetSyntheticChildrenGenerated(bool b)
lldb::user_id_t GetID() const
Returns a unique id for this ValueObject.
virtual void DoUpdateChildrenAddressType(ValueObject &valobj)
ValueObject * GetNonBaseClassParent()
virtual ValueObject * CreateChildAtIndex(size_t idx)
Should only be called by ValueObject::GetChildAtIndex().
lldb::ValueObjectSP GetValueForExpressionPath(llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop=nullptr, ExpressionPathEndResultType *final_value_type=nullptr, const GetValueForExpressionPathOptions &options=GetValueForExpressionPathOptions::DefaultOptions(), ExpressionPathAftermath *final_task_on_target=nullptr)
virtual lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic)
DataExtractor m_data
A data extractor that can be used to extract the value.
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
virtual llvm::Expected< uint64_t > GetByteSize()=0
virtual CompilerType GetCompilerTypeImpl()=0
virtual lldb::ValueObjectSP GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
lldb::ValueObjectSP CastToEnumType(CompilerType type)
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
virtual lldb::ValueType GetValueType() const =0
virtual void GetExpressionPath(Stream &s, GetExpressionPathFormat=eGetExpressionPathFormatDereferencePointers)
virtual bool HasSyntheticValue()
lldb::StackFrameSP GetFrameSP() const
lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef< llvm::StringRef > names)
void SetSummaryFormat(lldb::TypeSummaryImplSP format)
virtual bool IsRuntimeSupportValue()
virtual ConstString GetTypeName()
DataExtractor & GetDataExtractor()
virtual LazyBool CanUpdateWithInvalidExecutionContext()
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
void SetValueDidChange(bool value_changed)
lldb::ThreadSP GetThreadSP() const
ValueObjectManager * GetManager()
ValueObject * m_root
The root of the hierarchy for this ValueObject (or nullptr if never calculated).
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
static lldb::ValueObjectSP CreateValueObjectFromScalar(lldb::TargetSP target, Scalar &s, CompilerType type, llvm::StringRef name)
Create a value object containing the given Scalar value.
virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType)
ValueObject * GetDerefValobj()
virtual ConstString GetDisplayTypeName()
llvm::Expected< lldb::ValueObjectSP > CastDerivedToBaseType(CompilerType type, const llvm::ArrayRef< uint32_t > &base_type_indices)
Take a ValueObject whose type is an inherited class, and cast it to 'type', which should be one of it...
virtual lldb::ValueObjectSP AddressOf(Status &error)
lldb::DynamicValueType GetDynamicValueType()
llvm::Expected< lldb::ValueObjectSP > CastBaseToDerivedType(CompilerType type, uint64_t offset)
Take a ValueObject whose type is a base class, and cast it to 'type', which should be one of its deri...
lldb::SyntheticChildrenSP GetSyntheticChildren()
lldb::LanguageType m_preferred_display_language
void SetDerefValobj(ValueObject *deref)
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
virtual llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max=UINT32_MAX)=0
Should only be called by ValueObject::GetNumChildren().
lldb::LanguageType GetObjectRuntimeLanguage()
virtual lldb::ValueObjectSP CreateConstantValue(ConstString name)
virtual bool IsLogicalTrue(Status &error)
virtual SymbolContextScope * GetSymbolContextScope()
virtual bool HasDynamicValueTypeInfo()
static lldb::ValueObjectSP CreateValueObjectFromNullptr(lldb::TargetSP target, CompilerType type, llvm::StringRef name)
Create a nullptr value object with the specified type (must be a nullptr type).
ValueObject * m_synthetic_value
void SetNumChildren(uint32_t num_children)
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
virtual bool IsBaseClass()
llvm::Expected< bool > GetValueAsBool()
If the current ValueObject is of an appropriate type, convert the value to a boolean and return that.
virtual bool GetDeclaration(Declaration &decl)
virtual lldb::ValueObjectSP Clone(ConstString new_name)
Creates a copy of the ValueObject with a new name and setting the current ValueObject as its parent.
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
virtual bool IsSyntheticChildrenGenerated()
lldb::ValueObjectSP m_addr_of_valobj_sp
We have to hold onto a shared pointer to this one because it is created as an independent ValueObject...
std::pair< size_t, bool > ReadPointedString(lldb::WritableDataBufferSP &buffer_sp, Status &error, bool honor_array)
ValueObject(const ValueObject &)=delete
llvm::Error Dump(Stream &s)
bool UpdateValueIfNeeded(bool update_format=true)
static lldb::ValueObjectSP CreateValueObjectFromAPInt(lldb::TargetSP target, const llvm::APInt &v, CompilerType type, llvm::StringRef name)
Create a value object containing the given APInt value.
void SetName(ConstString name)
Change the name of the current ValueObject.
AddressType GetAddressTypeOfChildren()
const Status & GetError()
lldb::TypeFormatImplSP m_type_format_sp
lldb::TargetSP GetTargetSP() const
@ eExpressionPathEndResultTypePlain
Anything but...
@ eExpressionPathEndResultTypeBoundedRange
A range [low-high].
@ eExpressionPathEndResultTypeBitfield
A bitfield.
@ eExpressionPathEndResultTypeValueObjectList
Several items in a VOList.
@ eExpressionPathEndResultTypeUnboundedRange
A range [].
virtual lldb::ValueObjectSP Dereference(Status &error)
void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType)
virtual const char * GetValueAsCString()
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual const char * GetLocationAsCString()
ConstString GetName() const
std::string m_location_str
Cached location string that will get cleared if/when the value is updated.
lldb::ValueObjectSP GetVTable()
If this object represents a C++ class with a vtable, return an object that represents the virtual fun...
virtual bool SetValueFromCString(const char *value_str, Status &error)
virtual lldb::ValueObjectSP GetStaticValue()
lldb::ValueObjectSP Persist()
std::string m_object_desc_str
Cached result of the "object printer".
friend class ValueObjectConstResultImpl
virtual ValueObject * GetParent()
virtual ConstString GetQualifiedTypeName()
virtual bool DoesProvideSyntheticValue()
virtual CompilerType MaybeCalculateCompleteType()
lldb::SyntheticChildrenSP m_synthetic_children_sp
virtual uint32_t GetBitfieldBitOffset()
llvm::Expected< std::string > GetObjectDescription()
std::string m_old_value_str
Cached old value string from the last time the value was gotten.
virtual lldb::ValueObjectSP GetNonSyntheticValue()
lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression, bool can_create)
virtual bool SetData(DataExtractor &data, Status &error)
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success=nullptr)
void SetValueFromInteger(const llvm::APInt &value, Status &error)
Update an existing integer ValueObject with a new integer value.
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
std::string m_value_str
Cached value string that will get cleared if/when the value is updated.
bool IsIntegerType(bool &is_signed)
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
virtual bool ResolveValue(Scalar &scalar)
llvm::Expected< llvm::APSInt > GetValueAsAPSInt()
If the current ValueObject is of an appropriate type, convert the value to an APSInt and return that.
void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
ConstString m_name
The name of this object.
const char * GetLocationAsCStringImpl(const Value &value, const DataExtractor &data)
virtual void SetFormat(lldb::Format format)
ValueObject * m_dynamic_value
ProcessModID m_user_id_of_forced_summary
virtual TypeImpl GetTypeImpl()
bool IsCStringContainer(bool check_pointer=false)
Returns true if this is a char* or a char[] if it is a char* and check_pointer is true,...
virtual bool IsSynthetic()
std::map< ConstString, ValueObject * > m_synthetic_children
llvm::ArrayRef< uint8_t > GetLocalBuffer() const
Returns the local buffer that this ValueObject points to if it's available.
const ExecutionContextRef & GetExecutionContextRef() const
virtual AddrAndType GetAddressOf(bool scalar_is_load_address=true)
uint32_t GetNumChildrenIgnoringErrors(uint32_t max=UINT32_MAX)
Like GetNumChildren but returns 0 on error.
UserID m_id
Unique identifier for every value object.
const Value & GetValue() const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
virtual void SetLiveAddress(lldb::addr_t addr=LLDB_INVALID_ADDRESS, AddressType address_type=eAddressTypeLoad)
void SetAddressTypeOfChildren(AddressType at)
virtual lldb::offset_t GetByteOffset()
lldb::ValueObjectSP GetValueForExpressionPath_Impl(llvm::StringRef expression_cstr, ExpressionPathScanEndReason *reason_to_stop, ExpressionPathEndResultType *final_value_type, const GetValueForExpressionPathOptions &options, ExpressionPathAftermath *final_task_on_target)
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Format
Display format definitions.
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
A mix in class that contains a generic user ID.
Definition UserID.h:31
GetValueForExpressionPathOptions & DontAllowFragileIVar()
GetValueForExpressionPathOptions & SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse)
GetValueForExpressionPathOptions & DoAllowFragileIVar()
GetValueForExpressionPathOptions(bool dot=false, bool no_ivar=false, bool bitfield=true, SyntheticChildrenTraversal synth_traverse=SyntheticChildrenTraversal::ToSynthetic)
static const GetValueForExpressionPathOptions DefaultOptions()
GetValueForExpressionPathOptions & DontCheckDotVsArrowSyntax()
GetValueForExpressionPathOptions & DontAllowBitfieldSyntax()
GetValueForExpressionPathOptions & DoCheckDotVsArrowSyntax()
GetValueForExpressionPathOptions & DoAllowBitfieldSyntax()