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