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