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