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