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