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