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 liblldb_ValueObject_h_
10 #define liblldb_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"
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-forward.h"
26 #include "lldb/lldb-types.h"
27 
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/Optional.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/StringRef.h"
32 
33 #include <functional>
34 #include <initializer_list>
35 #include <map>
36 #include <mutex>
37 #include <string>
38 #include <utility>
39 
40 #include <stddef.h>
41 #include <stdint.h>
42 namespace lldb_private {
43 class Declaration;
44 }
45 namespace lldb_private {
46 class DumpValueObjectOptions;
47 }
48 namespace lldb_private {
49 class EvaluateExpressionOptions;
50 }
51 namespace lldb_private {
52 class ExecutionContextScope;
53 }
54 namespace lldb_private {
55 class Log;
56 }
57 namespace lldb_private {
58 class Scalar;
59 }
60 namespace lldb_private {
61 class Stream;
62 }
63 namespace lldb_private {
64 class SymbolContextScope;
65 }
66 namespace lldb_private {
67 class TypeFormatImpl;
68 }
69 namespace lldb_private {
70 class TypeSummaryImpl;
71 }
72 namespace lldb_private {
73 class TypeSummaryOptions;
74 }
75 namespace lldb_private {
76 
77 /// ValueObject:
78 ///
79 /// This abstract class provides an interface to a particular value, be it a
80 /// register, a local or global variable,
81 /// that is evaluated in some particular scope. The ValueObject also has the
82 /// capability of being the "child" of
83 /// some other variable object, and in turn of having children.
84 /// If a ValueObject is a root variable object - having no parent - then it must
85 /// be constructed with respect to some
86 /// particular ExecutionContextScope. If it is a child, it inherits the
87 /// ExecutionContextScope from its parent.
88 /// The ValueObject will update itself if necessary before fetching its value,
89 /// summary, object description, etc.
90 /// But it will always update itself in the ExecutionContextScope with which it
91 /// was originally created.
92 
93 /// A brief note on life cycle management for ValueObjects. This is a little
94 /// tricky because a ValueObject can contain
95 /// various other ValueObjects - the Dynamic Value, its children, the
96 /// dereference value, etc. Any one of these can be
97 /// handed out as a shared pointer, but for that contained value object to be
98 /// valid, the root object and potentially other
99 /// of the value objects need to stay around.
100 /// We solve this problem by handing out shared pointers to the Value Object and
101 /// any of its dependents using a shared
102 /// ClusterManager. This treats each shared pointer handed out for the entire
103 /// cluster as a reference to the whole
104 /// cluster. The whole cluster will stay around until the last reference is
105 /// released.
106 ///
107 /// The ValueObject mostly handle this automatically, if a value object is made
108 /// with a Parent ValueObject, then it adds
109 /// itself to the ClusterManager of the parent.
110 
111 /// It does mean that external to the ValueObjects we should only ever make
112 /// available ValueObjectSP's, never ValueObjects
113 /// or pointers to them. So all the "Root level" ValueObject derived
114 /// constructors should be private, and
115 /// should implement a Create function that new's up object and returns a Shared
116 /// Pointer that it gets from the GetSP() method.
117 ///
118 /// However, if you are making an derived ValueObject that will be contained in
119 /// a parent value object, you should just
120 /// hold onto a pointer to it internally, and by virtue of passing the parent
121 /// ValueObject into its constructor, it will
122 /// be added to the ClusterManager for the parent. Then if you ever hand out a
123 /// Shared Pointer to the contained ValueObject,
124 /// just do so by calling GetSP() on the contained object.
125 
126 class ValueObject : public UserID {
127 public:
131  };
132 
142  };
143 
145  eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse
146  eExpressionPathScanEndReasonNoSuchChild, // child element not found
148  // element not found
150  // arrays
152  // used
154  // used
156  // not allowed
158  // options
160  // other than scalars,
161  // pointers or arrays
163  // but I cannot parse it
165  // bitfields, but I
166  // cannot parse after
167  // it
168  eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in
169  // the expression
171  // operator
173  // operator
175  // VOList
177  // children failed
179  };
180 
182  eExpressionPathEndResultTypePlain = 1, // anything but...
186  eExpressionPathEndResultTypeValueObjectList, // several items in a VOList
188  };
189 
191  eExpressionPathAftermathNothing = 1, // just return it
192  eExpressionPathAftermathDereference, // dereference the target
193  eExpressionPathAftermathTakeAddress // take target's address
194  };
195 
209  };
210 
213  None,
214  ToSynthetic,
216  Both
217  };
218 
223 
225  bool dot = false, bool no_ivar = false, bool bitfield = true,
226  SyntheticChildrenTraversal synth_traverse =
228  : m_check_dot_vs_arrow_syntax(dot), m_no_fragile_ivar(no_ivar),
229  m_allow_bitfields_syntax(bitfield),
230  m_synthetic_children_traversal(synth_traverse) {}
231 
233  m_check_dot_vs_arrow_syntax = true;
234  return *this;
235  }
236 
238  m_check_dot_vs_arrow_syntax = false;
239  return *this;
240  }
241 
243  m_no_fragile_ivar = false;
244  return *this;
245  }
246 
248  m_no_fragile_ivar = true;
249  return *this;
250  }
251 
253  m_allow_bitfields_syntax = true;
254  return *this;
255  }
256 
258  m_allow_bitfields_syntax = false;
259  return *this;
260  }
261 
264  m_synthetic_children_traversal = traverse;
265  return *this;
266  }
267 
269  static GetValueForExpressionPathOptions g_default_options;
270 
271  return g_default_options;
272  }
273  };
274 
276  public:
277  EvaluationPoint();
278 
280  bool use_selected = false);
281 
282  EvaluationPoint(const EvaluationPoint &rhs);
283 
284  ~EvaluationPoint();
285 
287  return m_exe_ctx_ref;
288  }
289 
290  // Set the EvaluationPoint to the values in exe_scope, Return true if the
291  // Evaluation Point changed. Since the ExecutionContextScope is always
292  // going to be valid currently, the Updated Context will also always be
293  // valid.
294 
295  // bool
296  // SetContext (ExecutionContextScope *exe_scope);
297 
298  void SetIsConstant() {
299  SetUpdated();
300  m_mod_id.SetInvalid();
301  }
302 
303  bool IsConstant() const { return !m_mod_id.IsValid(); }
304 
305  ProcessModID GetModID() const { return m_mod_id; }
306 
307  void SetUpdateID(ProcessModID new_id) { m_mod_id = new_id; }
308 
309  void SetNeedsUpdate() { m_needs_update = true; }
310 
311  void SetUpdated();
312 
313  bool NeedsUpdating(bool accept_invalid_exe_ctx) {
314  SyncWithProcessState(accept_invalid_exe_ctx);
315  return m_needs_update;
316  }
317 
318  bool IsValid() {
319  const bool accept_invalid_exe_ctx = false;
320  if (!m_mod_id.IsValid())
321  return false;
322  else if (SyncWithProcessState(accept_invalid_exe_ctx)) {
323  if (!m_mod_id.IsValid())
324  return false;
325  }
326  return true;
327  }
328 
329  void SetInvalid() {
330  // Use the stop id to mark us as invalid, leave the thread id and the
331  // stack id around for logging and history purposes.
332  m_mod_id.SetInvalid();
333 
334  // Can't update an invalid state.
335  m_needs_update = false;
336  }
337 
338  private:
339  bool SyncWithProcessState(bool accept_invalid_exe_ctx);
340 
341  ProcessModID m_mod_id; // This is the stop id when this ValueObject was last
342  // evaluated.
343  ExecutionContextRef m_exe_ctx_ref;
344  bool m_needs_update;
345  };
346 
347  virtual ~ValueObject();
348 
349  const EvaluationPoint &GetUpdatePoint() const { return m_update_point; }
350 
352 
355  }
356 
357  lldb::TargetSP GetTargetSP() const {
359  }
360 
361  lldb::ProcessSP GetProcessSP() const {
363  }
364 
365  lldb::ThreadSP GetThreadSP() const {
367  }
368 
369  lldb::StackFrameSP GetFrameSP() const {
371  }
372 
373  void SetNeedsUpdate();
374 
376 
377  // this vends a TypeImpl that is useful at the SB API layer
378  virtual TypeImpl GetTypeImpl();
379 
380  virtual bool CanProvideValue();
381 
382  // Subclasses must implement the functions below.
383  virtual uint64_t GetByteSize() = 0;
384 
385  virtual lldb::ValueType GetValueType() const = 0;
386 
387  // Subclasses can implement the functions below.
388  virtual ConstString GetTypeName();
389 
391 
393 
395 
396  virtual uint32_t
397  GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr);
398 
399  virtual bool IsPointerType();
400 
401  virtual bool IsArrayType();
402 
403  virtual bool IsScalarType();
404 
405  virtual bool IsPointerOrReferenceType();
406 
407  virtual bool IsPossibleDynamicType();
408 
409  bool IsNilReference();
410 
412 
413  virtual bool IsBaseClass() { return false; }
414 
415  bool IsBaseClass(uint32_t &depth);
416 
417  virtual bool IsDereferenceOfParent() { return false; }
418 
419  bool IsIntegerType(bool &is_signed);
420 
421  virtual bool GetBaseClassPath(Stream &s);
422 
423  virtual void GetExpressionPath(
424  Stream &s, bool qualify_cxx_base_classes,
426 
427  lldb::ValueObjectSP GetValueForExpressionPath(
428  llvm::StringRef expression,
429  ExpressionPathScanEndReason *reason_to_stop = nullptr,
430  ExpressionPathEndResultType *final_value_type = nullptr,
431  const GetValueForExpressionPathOptions &options =
433  ExpressionPathAftermath *final_task_on_target = nullptr);
434 
435  virtual bool IsInScope() { return true; }
436 
437  virtual lldb::offset_t GetByteOffset() { return 0; }
438 
439  virtual uint32_t GetBitfieldBitSize() { return 0; }
440 
441  virtual uint32_t GetBitfieldBitOffset() { return 0; }
442 
443  bool IsBitfield() {
444  return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
445  }
446 
448 
449  virtual const char *GetValueAsCString();
450 
451  virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl &format,
452  std::string &destination);
453 
454  bool GetValueAsCString(lldb::Format format, std::string &destination);
455 
456  virtual uint64_t GetValueAsUnsigned(uint64_t fail_value,
457  bool *success = nullptr);
458 
459  virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr);
460 
461  virtual bool SetValueFromCString(const char *value_str, Status &error);
462 
463  // Return the module associated with this value object in case the value is
464  // from an executable file and might have its data in sections of the file.
465  // This can be used for variables.
466  virtual lldb::ModuleSP GetModule();
467 
468  ValueObject *GetRoot();
469 
470  // Given a ValueObject, loop over itself and its parent, and its parent's
471  // parent, .. until either the given callback returns false, or you end up at
472  // a null pointer
473  ValueObject *FollowParentChain(std::function<bool(ValueObject *)>);
474 
475  virtual bool GetDeclaration(Declaration &decl);
476 
477  // The functions below should NOT be modified by subclasses
478  const Status &GetError();
479 
480  ConstString GetName() const;
481 
482  virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
483 
484  // this will always create the children if necessary
485  lldb::ValueObjectSP GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
486  size_t *index_of_error = nullptr);
487 
488  lldb::ValueObjectSP
489  GetChildAtIndexPath(llvm::ArrayRef<std::pair<size_t, bool>> idxs,
490  size_t *index_of_error = nullptr);
491 
492  // this will always create the children if necessary
493  lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef<ConstString> names,
494  ConstString *name_of_error = nullptr);
495 
496  lldb::ValueObjectSP
497  GetChildAtNamePath(llvm::ArrayRef<std::pair<ConstString, bool>> names,
498  ConstString *name_of_error = nullptr);
499 
500  virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name,
501  bool can_create);
502 
503  virtual size_t GetIndexOfChildWithName(ConstString name);
504 
505  size_t GetNumChildren(uint32_t max = UINT32_MAX);
506 
507  const Value &GetValue() const;
508 
509  Value &GetValue();
510 
511  virtual bool ResolveValue(Scalar &scalar);
512 
513  // return 'false' whenever you set the error, otherwise callers may assume
514  // true means everything is OK - this will break breakpoint conditions among
515  // potentially a few others
516  virtual bool IsLogicalTrue(Status &error);
517 
518  virtual const char *GetLocationAsCString();
519 
520  const char *
522 
523  bool
524  GetSummaryAsCString(TypeSummaryImpl *summary_ptr, std::string &destination,
526 
527  bool GetSummaryAsCString(std::string &destination,
528  const TypeSummaryOptions &options);
529 
530  bool GetSummaryAsCString(TypeSummaryImpl *summary_ptr,
531  std::string &destination,
532  const TypeSummaryOptions &options);
533 
534  std::pair<TypeValidatorResult, std::string> GetValidationStatus();
535 
536  const char *GetObjectDescription();
537 
539  ValueObjectRepresentationStyle val_obj_display,
540  lldb::Format custom_format);
541 
543  eDisable = false,
544  eAllow = true
545  };
546 
547  bool
549  ValueObjectRepresentationStyle val_obj_display =
551  lldb::Format custom_format = lldb::eFormatInvalid,
554  bool do_dump_error = true);
555  bool GetValueIsValid() const;
556 
557  // If you call this on a newly created ValueObject, it will always return
558  // false.
559  bool GetValueDidChange();
560 
561  bool UpdateValueIfNeeded(bool update_format = true);
562 
563  bool UpdateFormatsIfNeeded();
564 
565  lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); }
566 
567  // Change the name of the current ValueObject. Should *not* be used from a
568  // synthetic child provider as it would change the name of the non synthetic
569  // child as well.
570  void SetName(ConstString name);
571 
572  virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
573  AddressType *address_type = nullptr);
574 
575  lldb::addr_t GetPointerValue(AddressType *address_type = nullptr);
576 
577  lldb::ValueObjectSP GetSyntheticChild(ConstString key) const;
578 
579  lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create);
580 
581  lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
582  bool can_create);
583 
584  lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression,
585  bool can_create);
586 
587  virtual lldb::ValueObjectSP
588  GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type,
589  bool can_create,
590  ConstString name_const_str = ConstString());
591 
592  virtual lldb::ValueObjectSP
593  GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create,
594  ConstString name_const_str = ConstString());
595 
596  virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType);
597 
599 
600  virtual lldb::ValueObjectSP GetStaticValue();
601 
602  virtual lldb::ValueObjectSP GetNonSyntheticValue();
603 
604  lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic = true);
605 
606  virtual bool HasSyntheticValue();
607 
608  virtual bool IsSynthetic() { return false; }
609 
610  lldb::ValueObjectSP
612  bool synthValue);
613 
614  virtual lldb::ValueObjectSP CreateConstantValue(ConstString name);
615 
616  virtual lldb::ValueObjectSP Dereference(Status &error);
617 
618  // Creates a copy of the ValueObject with a new name and setting the current
619  // ValueObject as its parent. It should be used when we want to change the
620  // name of a ValueObject without modifying the actual ValueObject itself
621  // (e.g. sythetic child provider).
622  virtual lldb::ValueObjectSP Clone(ConstString new_name);
623 
624  virtual lldb::ValueObjectSP AddressOf(Status &error);
625 
627 
629  AddressType address_type = eAddressTypeLoad) {}
630 
631  virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type);
632 
633  virtual lldb::ValueObjectSP CastPointerType(const char *name,
634  CompilerType &ast_type);
635 
636  virtual lldb::ValueObjectSP CastPointerType(const char *name,
637  lldb::TypeSP &type_sp);
638 
639  // The backing bits of this value object were updated, clear any descriptive
640  // string, so we know we have to refetch them
641  virtual void ValueUpdated() {
645  }
646 
647  virtual bool IsDynamic() { return false; }
648 
649  virtual bool DoesProvideSyntheticValue() { return false; }
650 
651  virtual bool IsSyntheticChildrenGenerated();
652 
653  virtual void SetSyntheticChildrenGenerated(bool b);
654 
656 
657  void Dump(Stream &s);
658 
659  void Dump(Stream &s, const DumpValueObjectOptions &options);
660 
661  static lldb::ValueObjectSP
662  CreateValueObjectFromExpression(llvm::StringRef name,
663  llvm::StringRef expression,
664  const ExecutionContext &exe_ctx);
665 
666  static lldb::ValueObjectSP
667  CreateValueObjectFromExpression(llvm::StringRef name,
668  llvm::StringRef expression,
669  const ExecutionContext &exe_ctx,
670  const EvaluateExpressionOptions &options);
671 
672  static lldb::ValueObjectSP
673  CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address,
674  const ExecutionContext &exe_ctx,
675  CompilerType type);
676 
677  static lldb::ValueObjectSP
678  CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data,
679  const ExecutionContext &exe_ctx, CompilerType type);
680 
681  void LogValueObject(Log *log);
682 
683  void LogValueObject(Log *log, const DumpValueObjectOptions &options);
684 
685  lldb::ValueObjectSP Persist();
686 
687  // returns true if this is a char* or a char[] if it is a char* and
688  // check_pointer is true, it also checks that the pointer is valid
689  bool IsCStringContainer(bool check_pointer = false);
690 
691  std::pair<size_t, bool>
692  ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error,
693  uint32_t max_length = 0, bool honor_array = true,
694  lldb::Format item_format = lldb::eFormatCharArray);
695 
696  virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
697  uint32_t item_count = 1);
698 
699  virtual uint64_t GetData(DataExtractor &data, Status &error);
700 
701  virtual bool SetData(DataExtractor &data, Status &error);
702 
703  virtual bool GetIsConstant() const { return m_update_point.IsConstant(); }
704 
705  bool NeedsUpdating() {
706  const bool accept_invalid_exe_ctx =
708  return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
709  }
710 
712 
713  lldb::Format GetFormat() const;
714 
715  virtual void SetFormat(lldb::Format format) {
716  if (format != m_format)
718  m_format = format;
719  }
720 
722 
724 
725  lldb::TypeSummaryImplSP GetSummaryFormat() {
727  return m_type_summary_sp;
728  }
729 
730  void SetSummaryFormat(lldb::TypeSummaryImplSP format) {
731  m_type_summary_sp = format;
733  }
734 
735  lldb::TypeValidatorImplSP GetValidator() {
737  return m_type_validator_sp;
738  }
739 
740  void SetValidator(lldb::TypeValidatorImplSP format) {
741  m_type_validator_sp = format;
743  }
744 
745  void SetValueFormat(lldb::TypeFormatImplSP format) {
746  m_type_format_sp = format;
748  }
749 
750  lldb::TypeFormatImplSP GetValueFormat() {
752  return m_type_format_sp;
753  }
754 
755  void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) {
756  if (synth_sp.get() == m_synthetic_children_sp.get())
757  return;
759  m_synthetic_children_sp = synth_sp;
760  }
761 
762  lldb::SyntheticChildrenSP GetSyntheticChildren() {
765  }
766 
767  // Use GetParent for display purposes, but if you want to tell the parent to
768  // update itself then use m_parent. The ValueObjectDynamicValue's parent is
769  // not the correct parent for displaying, they are really siblings, so for
770  // display it needs to route through to its grandparent.
771  virtual ValueObject *GetParent() { return m_parent; }
772 
773  virtual const ValueObject *GetParent() const { return m_parent; }
774 
776 
779  }
780 
782 
784 
785  /// Find out if a ValueObject might have children.
786  ///
787  /// This call is much more efficient than CalculateNumChildren() as
788  /// it doesn't need to complete the underlying type. This is designed
789  /// to be used in a UI environment in order to detect if the
790  /// disclosure triangle should be displayed or not.
791  ///
792  /// This function returns true for class, union, structure,
793  /// pointers, references, arrays and more. Again, it does so without
794  /// doing any expensive type completion.
795  ///
796  /// \return
797  /// Returns \b true if the ValueObject might have children, or \b
798  /// false otherwise.
799  virtual bool MightHaveChildren();
800 
801  virtual lldb::VariableSP GetVariable() { return nullptr; }
802 
803  virtual bool IsRuntimeSupportValue();
804 
805  virtual uint64_t GetLanguageFlags();
806 
807  virtual void SetLanguageFlags(uint64_t flags);
808 
809 protected:
811 
813  public:
814  ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {}
815 
816  bool HasChildAtIndex(size_t idx) {
817  std::lock_guard<std::recursive_mutex> guard(m_mutex);
818  return (m_children.find(idx) != m_children.end());
819  }
820 
822  std::lock_guard<std::recursive_mutex> guard(m_mutex);
823  const auto iter = m_children.find(idx);
824  return ((iter == m_children.end()) ? nullptr : iter->second);
825  }
826 
827  void SetChildAtIndex(size_t idx, ValueObject *valobj) {
828  // we do not need to be mutex-protected to make a pair
829  ChildrenPair pair(idx, valobj);
830  std::lock_guard<std::recursive_mutex> guard(m_mutex);
831  m_children.insert(pair);
832  }
833 
834  void SetChildrenCount(size_t count) { Clear(count); }
835 
836  size_t GetChildrenCount() { return m_children_count; }
837 
838  void Clear(size_t new_count = 0) {
839  std::lock_guard<std::recursive_mutex> guard(m_mutex);
840  m_children_count = new_count;
841  m_children.clear();
842  }
843 
844  private:
845  typedef std::map<size_t, ValueObject *> ChildrenMap;
846  typedef ChildrenMap::iterator ChildrenIterator;
847  typedef ChildrenMap::value_type ChildrenPair;
848  std::recursive_mutex m_mutex;
849  ChildrenMap m_children;
850  size_t m_children_count;
851  };
852 
853  // Classes that inherit from ValueObject can see and modify these
855  *m_parent; // The parent value object, or nullptr if this has no parent
856  ValueObject *m_root; // The root of the hierarchy for this ValueObject (or
857  // nullptr if never calculated)
858  EvaluationPoint m_update_point; // Stores both the stop id and the full
859  // context at which this value was last
860  // updated. When we are asked to update the value object, we check whether
861  // the context & stop id are the same before updating.
862  ConstString m_name; // The name of this object
864  m_data; // A data extractor that can be used to extract the value.
866  Status
867  m_error; // An error object that can describe any errors that occur when
868  // updating values.
869  std::string m_value_str; // Cached value string that will get cleared if/when
870  // the value is updated.
871  std::string m_old_value_str; // Cached old value string from the last time the
872  // value was gotten
873  std::string m_location_str; // Cached location string that will get cleared
874  // if/when the value is updated.
875  std::string m_summary_str; // Cached summary string that will get cleared
876  // if/when the value is updated.
877  std::string m_object_desc_str; // Cached result of the "object printer". This
878  // differs from the summary
879  // in that the summary is consed up by us, the object_desc_string is builtin.
880 
881  llvm::Optional<std::pair<TypeValidatorResult, std::string>>
883 
884  CompilerType m_override_type; // If the type of the value object should be
885  // overridden, the type to impose.
886 
887  ValueObjectManager *m_manager; // This object is managed by the root object
888  // (any ValueObject that gets created
889  // without a parent.) The manager gets passed through all the generations of
890  // dependent objects, and will keep the whole cluster of objects alive as
891  // long as a shared pointer to any of them has been handed out. Shared
892  // pointers to value objects must always be made with the GetSP method.
893 
895  std::map<ConstString, ValueObject *> m_synthetic_children;
896 
900 
901  lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared
902  // pointer to this one because it is
903  // created
904  // as an independent ValueObjectConstResult, which isn't managed by us.
905 
909  lldb::TypeSummaryImplSP m_type_summary_sp;
910  lldb::TypeFormatImplSP m_type_format_sp;
911  lldb::SyntheticChildrenSP m_synthetic_children_sp;
912  lldb::TypeValidatorImplSP m_type_validator_sp;
915 
916  llvm::SmallVector<uint8_t, 16> m_value_checksum;
917 
919 
921 
928 
929  friend class ValueObjectChild;
930  friend class ClangExpressionDeclMap; // For GetValue
931  friend class ExpressionVariable; // For SetName
932  friend class Target; // For SetName
934  friend class ValueObjectSynthetic; // For ClearUserVisibleData
935 
936  // Constructors and Destructors
937 
938  // Use the no-argument constructor to make a constant variable object (with
939  // no ExecutionContextScope.)
940 
941  ValueObject();
942 
943  // Use this constructor to create a "root variable object". The ValueObject
944  // will be locked to this context through-out its lifespan.
945 
947  AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
948 
949  // Use this constructor to create a ValueObject owned by another ValueObject.
950  // It will inherit the ExecutionContext of its parent.
951 
952  ValueObject(ValueObject &parent);
953 
954  ValueObjectManager *GetManager() { return m_manager; }
955 
956  virtual bool UpdateValue() = 0;
957 
959  return eLazyBoolCalculate;
960  }
961 
962  virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic);
963 
965  return lldb::eNoDynamicValues;
966  }
967 
968  virtual bool HasDynamicValueTypeInfo() { return false; }
969 
970  virtual void CalculateSyntheticValue(bool use_synthetic = true);
971 
972  // Should only be called by ValueObject::GetChildAtIndex() Returns a
973  // ValueObject managed by this ValueObject's manager.
974  virtual ValueObject *CreateChildAtIndex(size_t idx,
975  bool synthetic_array_member,
976  int32_t synthetic_index);
977 
978  // Should only be called by ValueObject::GetNumChildren()
979  virtual size_t CalculateNumChildren(uint32_t max = UINT32_MAX) = 0;
980 
981  void SetNumChildren(size_t num_children);
982 
983  void SetValueDidChange(bool value_changed);
984 
985  void SetValueIsValid(bool valid);
986 
989 
990  void AddSyntheticChild(ConstString key, ValueObject *valobj);
991 
993 
995 
996  // Subclasses must implement the functions below.
997 
998  virtual CompilerType GetCompilerTypeImpl() = 0;
999 
1000  const char *GetLocationAsCStringImpl(const Value &value,
1001  const DataExtractor &data);
1002 
1003  bool IsChecksumEmpty();
1004 
1006 
1007 private:
1008  virtual CompilerType MaybeCalculateCompleteType();
1009 
1010  lldb::ValueObjectSP GetValueForExpressionPath_Impl(
1011  llvm::StringRef expression_cstr,
1012  ExpressionPathScanEndReason *reason_to_stop,
1013  ExpressionPathEndResultType *final_value_type,
1014  const GetValueForExpressionPathOptions &options,
1015  ExpressionPathAftermath *final_task_on_target);
1016 
1017  DISALLOW_COPY_AND_ASSIGN(ValueObject);
1018 };
1019 
1020 // A value object manager class that is seeded with the static variable value
1021 // and it vends the user facing value object. If the type is dynamic it can
1022 // vend the dynamic type. If this user type also has a synthetic type
1023 // associated with it, it will vend the synthetic type. The class watches the
1024 // process' stop
1025 // ID and will update the user type when needed.
1027  // The root value object is the static typed variable object.
1028  lldb::ValueObjectSP m_root_valobj_sp;
1029  // The user value object is the value object the user wants to see.
1030  lldb::ValueObjectSP m_user_valobj_sp;
1031  lldb::DynamicValueType m_use_dynamic;
1032  uint32_t m_stop_id; // The stop ID that m_user_valobj_sp is valid for.
1033  bool m_use_synthetic;
1034 
1035 public:
1037 
1038  ValueObjectManager(lldb::ValueObjectSP in_valobj_sp,
1039  lldb::DynamicValueType use_dynamic, bool use_synthetic);
1040 
1041  bool IsValid() const;
1042 
1043  lldb::ValueObjectSP GetRootSP() const { return m_root_valobj_sp; }
1044 
1045  // Gets the correct value object from the root object for a given process
1046  // stop ID. If dynamic values are enabled, or if synthetic children are
1047  // enabled, the value object that the user wants to see might change while
1048  // debugging.
1049  lldb::ValueObjectSP GetSP();
1050 
1051  void SetUseDynamic(lldb::DynamicValueType use_dynamic);
1052  void SetUseSynthetic(bool use_synthetic);
1053  lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
1054  bool GetUseSynthetic() const { return m_use_synthetic; }
1055  lldb::TargetSP GetTargetSP() const;
1056  lldb::ProcessSP GetProcessSP() const;
1057  lldb::ThreadSP GetThreadSP() const;
1058  lldb::StackFrameSP GetFrameSP() const;
1059 };
1060 
1061 } // namespace lldb_private
1062 
1063 #endif // liblldb_ValueObject_h_
GetValueForExpressionPathOptions & DoAllowFragileIVar()
Definition: ValueObject.h:242
virtual bool IsBaseClass()
Definition: ValueObject.h:413
virtual void CalculateDynamicValue(lldb::DynamicValueType use_dynamic)
An data extractor class.
Definition: DataExtractor.h:47
CompilerType GetCompilerType()
virtual const char * GetValueAsCString()
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::ValueObjectSP GetSyntheticChild(ConstString key) const
virtual lldb::LanguageType GetPreferredDisplayLanguage()
ValueObject * GetNonBaseClassParent()
GetValueForExpressionPathOptions & SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse)
Definition: ValueObject.h:263
lldb_private::SharingPtr< T > GetSharedPointer(T *desired_object)
Definition: SharedCluster.h:63
virtual lldb::ValueObjectSP Dereference(Status &error)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name, bool can_create)
lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef< ConstString > names, ConstString *name_of_error=nullptr)
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
void Clear()
Clears the object state.
Definition: UserID.h:43
virtual ConstString GetTypeName()
GetValueForExpressionPathOptions & DontAllowBitfieldSyntax()
Definition: ValueObject.h:257
virtual ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index)
ConstString GetName() const
virtual bool SetValueFromCString(const char *value_str, Status &error)
virtual LazyBool CanUpdateWithInvalidExecutionContext()
Definition: ValueObject.h:958
void SetPreferredDisplayLanguage(lldb::LanguageType)
lldb::ValueObjectSP GetSyntheticExpressionPathChild(const char *expression, bool can_create)
virtual lldb::LanguageType GetObjectRuntimeLanguage()
virtual bool IsPointerOrReferenceType()
void LogValueObject(Log *log)
virtual lldb::addr_t GetLiveAddress()
Definition: ValueObject.h:626
lldb::ProcessSP GetProcessSP() const
Get accessor that creates a strong reference from the weak process reference contained in this object...
A mix in class that contains a generic user ID.
Definition: UserID.h:33
void SetValueDidChange(bool value_changed)
bool IsCStringContainer(bool check_pointer=false)
void SetChildAtIndex(size_t idx, ValueObject *valobj)
Definition: ValueObject.h:827
virtual const ValueObject * GetParent() const
Definition: ValueObject.h:773
virtual uint64_t GetLanguageFlags()
GetValueForExpressionPathOptions(bool dot=false, bool no_ivar=false, bool bitfield=true, SyntheticChildrenTraversal synth_traverse=SyntheticChildrenTraversal::ToSynthetic)
Definition: ValueObject.h:224
std::pair< size_t, bool > ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, uint32_t max_length=0, bool honor_array=true, lldb::Format item_format=lldb::eFormatCharArray)
virtual void CalculateSyntheticValue(bool use_synthetic=true)
lldb::ValueObjectSP GetSyntheticValue(bool use_synthetic=true)
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
virtual lldb::ValueObjectSP CreateConstantValue(ConstString name)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
virtual bool IsRuntimeSupportValue()
const char * GetLocationAsCStringImpl(const Value &value, const DataExtractor &data)
const Status & GetError()
AddressType m_address_type_of_ptr_or_ref_children
Definition: ValueObject.h:914
ValueObject * m_dynamic_value
Definition: ValueObject.h:897
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:357
virtual bool IsPointerType()
GetValueForExpressionPathOptions & DoCheckDotVsArrowSyntax()
Definition: ValueObject.h:232
ValueObjectManager * GetManager()
Definition: ValueObject.h:954
virtual void SetLiveAddress(lldb::addr_t addr=LLDB_INVALID_ADDRESS, AddressType address_type=eAddressTypeLoad)
Definition: ValueObject.h:628
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
const char * GetObjectDescription()
virtual size_t GetIndexOfChildWithName(ConstString name)
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)
bool IsIntegerType(bool &is_signed)
EvaluationPoint & GetUpdatePoint()
Definition: ValueObject.h:351
uint32_t m_last_format_mgr_revision
Definition: ValueObject.h:908
void SetAddressTypeOfChildren(AddressType at)
Definition: ValueObject.h:777
lldb::Format GetFormat() const
virtual bool IsArrayItemForPointer()
Definition: ValueObject.h:447
virtual lldb::ModuleSP GetModule()
const EvaluationPoint & GetUpdatePoint() const
Definition: ValueObject.h:349
virtual const char * GetLocationAsCString()
void SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
Definition: ValueObject.h:755
void SetNumChildren(size_t num_children)
lldb::LanguageType m_preferred_display_language
Definition: ValueObject.h:918
bool NeedsUpdating(bool accept_invalid_exe_ctx)
Definition: ValueObject.h:313
ValueObject * m_synthetic_value
Definition: ValueObject.h:898
void SetValidator(lldb::TypeValidatorImplSP format)
Definition: ValueObject.h:740
lldb::ThreadSP GetThreadSP() const
Get accessor that creates a strong reference from the weak thread reference contained in this object...
virtual ConstString GetQualifiedTypeName()
virtual bool SetData(DataExtractor &data, Status &error)
lldb::DynamicValueType GetUseDynamic() const
Definition: ValueObject.h:1053
#define UINT32_MAX
Definition: lldb-defines.h:31
virtual bool ResolveValue(Scalar &scalar)
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type)
lldb::ThreadSP GetThreadSP() const
Definition: ValueObject.h:365
virtual ValueObject * GetParent()
Definition: ValueObject.h:771
ClusterManager< ValueObject > ValueObjectManager
Definition: ValueObject.h:810
virtual size_t CalculateNumChildren(uint32_t max=UINT32_MAX)=0
lldb::SyntheticChildrenSP m_synthetic_children_sp
Definition: ValueObject.h:911
virtual TypeImpl GetTypeImpl()
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
ValueObject * GetChildAtIndex(size_t idx)
Definition: ValueObject.h:821
LanguageType
Programming language type.
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
virtual lldb::DynamicValueType GetDynamicValueTypeImpl()
Definition: ValueObject.h:964
virtual bool CanProvideValue()
uint64_t offset_t
Definition: lldb-types.h:87
llvm::Optional< std::pair< TypeValidatorResult, std::string > > m_validation_result
Definition: ValueObject.h:882
virtual void SetFormat(lldb::Format format)
Definition: ValueObject.h:715
virtual lldb::VariableSP GetVariable()
Definition: ValueObject.h:801
virtual lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
EvaluationPoint m_update_point
Definition: ValueObject.h:858
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
lldb::StackFrameSP GetFrameSP() const
Definition: ValueObject.h:369
lldb::Format m_last_format
Definition: ValueObject.h:907
virtual lldb::ValueObjectSP GetSyntheticBase(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
static const GetValueForExpressionPathOptions DefaultOptions()
Definition: ValueObject.h:268
virtual bool IsSynthetic()
Definition: ValueObject.h:608
virtual CompilerType GetCompilerTypeImpl()=0
virtual bool IsDereferenceOfParent()
Definition: ValueObject.h:417
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
void ClearUserVisibleData(uint32_t items=ValueObject::eClearUserVisibleDataItemsAllStrings)
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:353
GetValueForExpressionPathOptions & DontAllowFragileIVar()
Definition: ValueObject.h:247
AddressType GetAddressTypeOfChildren()
virtual bool IsDynamic()
Definition: ValueObject.h:647
virtual bool IsInScope()
Definition: ValueObject.h:435
Execution context objects refer to objects in the execution of the program that is being debugged...
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
ValueObject * FollowParentChain(std::function< bool(ValueObject *)>)
virtual lldb::ValueObjectSP GetDynamicValue(lldb::DynamicValueType valueType)
virtual bool IsPossibleDynamicType()
CompilerType m_override_type
Definition: ValueObject.h:884
virtual lldb::ValueObjectSP Clone(ConstString new_name)
virtual uint64_t GetByteSize()=0
lldb::ValueObjectSP GetChildAtIndexPath(llvm::ArrayRef< size_t > idxs, size_t *index_of_error=nullptr)
lldb::TargetSP GetTargetSP() const
Get accessor that creates a strong reference from the weak target reference contained in this object...
virtual uint64_t GetData(DataExtractor &data, Status &error)
virtual bool IsSyntheticChildrenGenerated()
virtual uint32_t GetBitfieldBitOffset()
Definition: ValueObject.h:441
lldb::TypeValidatorImplSP GetValidator()
Definition: ValueObject.h:735
virtual lldb::ValueObjectSP CastPointerType(const char *name, CompilerType &ast_type)
void SetValueIsValid(bool valid)
virtual bool GetBaseClassPath(Stream &s)
lldb::ValueObjectSP GetRootSP() const
Definition: ValueObject.h:1043
virtual lldb::ValueObjectSP AddressOf(Status &error)
GetValueForExpressionPathOptions & DoAllowBitfieldSyntax()
Definition: ValueObject.h:252
lldb::SyntheticChildrenSP GetSyntheticChildren()
Definition: ValueObject.h:762
virtual bool HasSyntheticValue()
virtual bool IsLogicalTrue(Status &error)
lldb::TypeFormatImplSP m_type_format_sp
Definition: ValueObject.h:910
ValueObjectManager * m_manager
Definition: ValueObject.h:887
std::string m_object_desc_str
Definition: ValueObject.h:877
std::map< ConstString, ValueObject * > m_synthetic_children
Definition: ValueObject.h:895
uint64_t addr_t
Definition: lldb-types.h:83
lldb::DynamicValueType GetDynamicValueType()
virtual lldb::ValueObjectSP GetStaticValue()
bool UpdateValueIfNeeded(bool update_format=true)
void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType)
virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx=0, uint32_t item_count=1)
virtual lldb::offset_t GetByteOffset()
Definition: ValueObject.h:437
A uniqued constant string class.
Definition: ConstString.h:38
lldb::TypeSummaryImplSP m_type_summary_sp
Definition: ValueObject.h:909
Unknown or invalid language value.
virtual bool GetDeclaration(Declaration &decl)
bool DumpPrintableRepresentation(Stream &s, ValueObjectRepresentationStyle val_obj_display=eValueObjectRepresentationStyleSummary, lldb::Format custom_format=lldb::eFormatInvalid, PrintableRepresentationSpecialCases special=PrintableRepresentationSpecialCases::eAllow, bool do_dump_error=true)
lldb::ProcessSP GetProcessSP() const
Definition: ValueObject.h:361
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success=nullptr)
lldb::TypeSummaryImplSP GetSummaryFormat()
Definition: ValueObject.h:725
virtual bool GetIsConstant() const
Definition: ValueObject.h:703
virtual void GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat=eGetExpressionPathFormatDereferencePointers)
lldb::ValueObjectSP GetSyntheticBitFieldChild(uint32_t from, uint32_t to, bool can_create)
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
lldb::TypeFormatImplSP GetValueFormat()
Definition: ValueObject.h:750
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:565
lldb::StackFrameSP GetFrameSP() const
Get accessor that creates a strong reference from the weak frame reference contained in this object...
lldb::ValueObjectSP m_addr_of_valobj_sp
Definition: ValueObject.h:901
virtual lldb::ValueType GetValueType() const =0
virtual bool UpdateValue()=0
virtual bool MightHaveChildren()
Find out if a ValueObject might have children.
const Value & GetValue() const
lldb::TypeValidatorImplSP m_type_validator_sp
Definition: ValueObject.h:912
size_t GetNumChildren(uint32_t max=UINT32_MAX)
virtual void SetLanguageFlags(uint64_t flags)
void SetSummaryFormat(lldb::TypeSummaryImplSP format)
Definition: ValueObject.h:730
ValueObject * m_deref_valobj
Definition: ValueObject.h:899
bool m_did_calculate_complete_objc_class_type
Definition: ValueObject.h:922
ChildrenManager m_children
Definition: ValueObject.h:894
virtual bool DoesProvideSyntheticValue()
Definition: ValueObject.h:649
lldb::ValueObjectSP Persist()
void SetName(ConstString name)
const char * GetSummaryAsCString(lldb::LanguageType lang=lldb::eLanguageTypeUnknown)
virtual SymbolContextScope * GetSymbolContextScope()
virtual void SetSyntheticChildrenGenerated(bool b)
lldb::ValueObjectSP GetSyntheticArrayMember(size_t index, bool can_create)
void SetUpdateID(ProcessModID new_id)
Definition: ValueObject.h:307
ProcessModID m_user_id_of_forced_summary
Definition: ValueObject.h:913
Address is an address as in the current target inferior process.
virtual ConstString GetDisplayTypeName()
DataExtractor & GetDataExtractor()
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:286
std::pair< TypeValidatorResult, std::string > GetValidationStatus()
virtual void ValueUpdated()
Definition: ValueObject.h:641
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
llvm::SmallVector< uint8_t, 16 > m_value_checksum
Definition: ValueObject.h:916
void SetValueFormat(lldb::TypeFormatImplSP format)
Definition: ValueObject.h:745
virtual uint32_t GetBitfieldBitSize()
Definition: ValueObject.h:439
"lldb/Expression/ClangExpressionDeclMap.h" Manages named entities that are defined in LLDB&#39;s debug in...
GetValueForExpressionPathOptions & DontCheckDotVsArrowSyntax()
Definition: ValueObject.h:237
virtual bool HasDynamicValueTypeInfo()
Definition: ValueObject.h:968
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create)
virtual lldb::ValueObjectSP GetNonSyntheticValue()
void AddSyntheticChild(ConstString key, ValueObject *valobj)
virtual lldb::ValueObjectSP Cast(const CompilerType &compiler_type)
An error handling class.
Definition: Status.h:44