]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ValueObject.h
Merge ^/head r274961 through r276301.
[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 // 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 capability 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     // 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     const char *
611     GetObjectDescription ();
612     
613     bool
614     HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display,
615                                        lldb::Format custom_format);
616     
617     enum PrintableRepresentationSpecialCases
618     {
619         ePrintableRepresentationSpecialCasesDisable = 0,
620         ePrintableRepresentationSpecialCasesAllow = 1,
621         ePrintableRepresentationSpecialCasesOnly = 3
622     };
623     
624     bool
625     DumpPrintableRepresentation (Stream& s,
626                                  ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary,
627                                  lldb::Format custom_format = lldb::eFormatInvalid,
628                                  PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow,
629                                  bool do_dump_error = true);
630     bool
631     GetValueIsValid () const;
632
633     bool
634     GetValueDidChange ();
635
636     bool
637     UpdateValueIfNeeded (bool update_format = true);
638     
639     bool
640     UpdateFormatsIfNeeded();
641
642     lldb::ValueObjectSP
643     GetSP ()
644     {
645         return m_manager->GetSharedPointer(this);
646     }
647     
648     void
649     SetName (const ConstString &name);
650     
651     virtual lldb::addr_t
652     GetAddressOf (bool scalar_is_load_address = true,
653                   AddressType *address_type = NULL);
654     
655     lldb::addr_t
656     GetPointerValue (AddressType *address_type = NULL);
657     
658     lldb::ValueObjectSP
659     GetSyntheticChild (const ConstString &key) const;
660     
661     lldb::ValueObjectSP
662     GetSyntheticArrayMember (size_t index, bool can_create);
663
664     lldb::ValueObjectSP
665     GetSyntheticArrayMemberFromPointer (size_t index, bool can_create);
666     
667     lldb::ValueObjectSP
668     GetSyntheticArrayMemberFromArray (size_t index, bool can_create);
669     
670     lldb::ValueObjectSP
671     GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
672
673     lldb::ValueObjectSP
674     GetSyntheticExpressionPathChild(const char* expression, bool can_create);
675     
676     virtual lldb::ValueObjectSP
677     GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
678     
679     virtual lldb::ValueObjectSP
680     GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create);
681
682     virtual lldb::ValueObjectSP
683     GetDynamicValue (lldb::DynamicValueType valueType);
684     
685     lldb::DynamicValueType
686     GetDynamicValueType ();
687     
688     virtual lldb::ValueObjectSP
689     GetStaticValue ();
690     
691     virtual lldb::ValueObjectSP
692     GetNonSyntheticValue ();
693     
694     lldb::ValueObjectSP
695     GetSyntheticValue (bool use_synthetic = true);
696     
697     virtual bool
698     HasSyntheticValue();
699     
700     virtual bool
701     IsSynthetic() { return false; }
702     
703     virtual lldb::ValueObjectSP
704     CreateConstantValue (const ConstString &name);
705
706     virtual lldb::ValueObjectSP
707     Dereference (Error &error);
708     
709     virtual lldb::ValueObjectSP
710     AddressOf (Error &error);
711     
712     virtual lldb::addr_t
713     GetLiveAddress()
714     {
715         return LLDB_INVALID_ADDRESS;
716     }
717     
718     virtual void
719     SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
720                    AddressType address_type = eAddressTypeLoad)
721     {
722     }
723
724     // Find the address of the C++ vtable pointer
725     virtual lldb::addr_t
726     GetCPPVTableAddress(AddressType &address_type);
727     
728     virtual lldb::ValueObjectSP
729     Cast (const ClangASTType &clang_ast_type);
730     
731     virtual lldb::ValueObjectSP
732     CastPointerType (const char *name,
733                      ClangASTType &ast_type);
734
735     virtual lldb::ValueObjectSP
736     CastPointerType (const char *name,
737                      lldb::TypeSP &type_sp);
738
739     // The backing bits of this value object were updated, clear any
740     // descriptive string, so we know we have to refetch them
741     virtual void
742     ValueUpdated ()
743     {
744         ClearUserVisibleData(eClearUserVisibleDataItemsValue |
745                              eClearUserVisibleDataItemsSummary |
746                              eClearUserVisibleDataItemsDescription);
747     }
748
749     virtual bool
750     IsDynamic ()
751     {
752         return false;
753     }
754     
755     virtual SymbolContextScope *
756     GetSymbolContextScope();
757     
758     void
759     Dump (Stream &s);
760     
761     void
762     Dump (Stream &s,
763           const DumpValueObjectOptions& options);
764
765     static lldb::ValueObjectSP
766     CreateValueObjectFromExpression (const char* name,
767                                      const char* expression,
768                                      const ExecutionContext& exe_ctx);
769     
770     static lldb::ValueObjectSP
771     CreateValueObjectFromAddress (const char* name,
772                                   uint64_t address,
773                                   const ExecutionContext& exe_ctx,
774                                   ClangASTType type);
775     
776     static lldb::ValueObjectSP
777     CreateValueObjectFromData (const char* name,
778                                const DataExtractor& data,
779                                const ExecutionContext& exe_ctx,
780                                ClangASTType type);
781     
782     void
783     LogValueObject (Log *log);
784
785     void
786     LogValueObject (Log *log,
787                     const DumpValueObjectOptions& options);
788
789
790     // returns true if this is a char* or a char[]
791     // if it is a char* and check_pointer is true,
792     // it also checks that the pointer is valid
793     bool
794     IsCStringContainer (bool check_pointer = false);
795     
796     size_t
797     ReadPointedString (Stream& s,
798                        Error& error,
799                        uint32_t max_length = 0,
800                        bool honor_array = true,
801                        lldb::Format item_format = lldb::eFormatCharArray);
802     
803     virtual size_t
804     GetPointeeData (DataExtractor& data,
805                     uint32_t item_idx = 0,
806                                         uint32_t item_count = 1);
807     
808     virtual uint64_t
809     GetData (DataExtractor& data, Error &error);
810     
811     virtual bool
812     SetData (DataExtractor &data, Error &error);
813
814     bool
815     GetIsConstant () const
816     {
817         return m_update_point.IsConstant();
818     }
819     
820     void
821     SetIsConstant ()
822     {
823         m_update_point.SetIsConstant();
824     }
825
826     lldb::Format
827     GetFormat () const;
828     
829     void
830     SetFormat (lldb::Format format)
831     {
832         if (format != m_format)
833             ClearUserVisibleData(eClearUserVisibleDataItemsValue);
834         m_format = format;
835     }
836     
837     lldb::TypeSummaryImplSP
838     GetSummaryFormat()
839     {
840         UpdateFormatsIfNeeded();
841         return m_type_summary_sp;
842     }
843     
844     void
845     SetSummaryFormat(lldb::TypeSummaryImplSP format)
846     {
847         m_type_summary_sp = format;
848         ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
849     }
850     
851     void
852     SetValueFormat(lldb::TypeFormatImplSP format)
853     {
854         m_type_format_sp = format;
855         ClearUserVisibleData(eClearUserVisibleDataItemsValue);
856     }
857     
858     lldb::TypeFormatImplSP
859     GetValueFormat()
860     {
861         UpdateFormatsIfNeeded();
862         return m_type_format_sp;
863     }
864     
865     void
866     SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
867     {
868         if (synth_sp.get() == m_synthetic_children_sp.get())
869             return;
870         ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
871         m_synthetic_children_sp = synth_sp;
872     }
873     
874     lldb::SyntheticChildrenSP
875     GetSyntheticChildren()
876     {
877         UpdateFormatsIfNeeded();
878         return m_synthetic_children_sp;
879     }
880
881     // Use GetParent for display purposes, but if you want to tell the parent to update itself
882     // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
883     // displaying, they are really siblings, so for display it needs to route through to its grandparent.
884     virtual ValueObject *
885     GetParent()
886     {
887         return m_parent;
888     }
889
890     virtual const ValueObject *
891     GetParent() const
892     {
893         return m_parent;
894     }
895
896     ValueObject *
897     GetNonBaseClassParent();
898
899     void
900     SetAddressTypeOfChildren(AddressType at)
901     {
902         m_address_type_of_ptr_or_ref_children = at;
903     }
904     
905     AddressType
906     GetAddressTypeOfChildren();
907     
908     void
909     SetHasCompleteType()
910     {
911         m_did_calculate_complete_objc_class_type = true;
912     }
913     
914     //------------------------------------------------------------------
915     /// Find out if a ValueObject might have children.
916     ///
917     /// This call is much more efficient than CalculateNumChildren() as
918     /// it doesn't need to complete the underlying type. This is designed
919     /// to be used in a UI environment in order to detect if the
920     /// disclosure triangle should be displayed or not.
921     ///
922     /// This function returns true for class, union, structure,
923     /// pointers, references, arrays and more. Again, it does so without
924     /// doing any expensive type completion.
925     ///
926     /// @return
927     ///     Returns \b true if the ValueObject might have children, or \b
928     ///     false otherwise.
929     //------------------------------------------------------------------
930     virtual bool
931     MightHaveChildren();
932
933 protected:
934     typedef ClusterManager<ValueObject> ValueObjectManager;
935     
936     class ChildrenManager
937     {
938     public:
939         ChildrenManager() :
940             m_mutex(Mutex::eMutexTypeRecursive),
941             m_children(),
942             m_children_count(0)
943         {}
944         
945         bool
946         HasChildAtIndex (size_t idx)
947         {
948             Mutex::Locker locker(m_mutex);
949             ChildrenIterator iter = m_children.find(idx);
950             ChildrenIterator end = m_children.end();
951             return (iter != end);
952         }
953         
954         ValueObject*
955         GetChildAtIndex (size_t idx)
956         {
957             Mutex::Locker locker(m_mutex);
958             ChildrenIterator iter = m_children.find(idx);
959             ChildrenIterator end = m_children.end();
960             if (iter == end)
961                 return NULL;
962             else
963                 return iter->second;
964         }
965         
966         void
967         SetChildAtIndex (size_t idx, ValueObject* valobj)
968         {
969             ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair
970             Mutex::Locker locker(m_mutex);
971             m_children.insert(pair);
972         }
973         
974         void
975         SetChildrenCount (size_t count)
976         {
977             Clear(count);
978         }
979         
980         size_t
981         GetChildrenCount ()
982         {
983             return m_children_count;
984         }
985         
986         void
987         Clear(size_t new_count = 0)
988         {
989             Mutex::Locker locker(m_mutex);
990             m_children_count = new_count;
991             m_children.clear();
992         }
993         
994     private:
995         typedef std::map<size_t, ValueObject*> ChildrenMap;
996         typedef ChildrenMap::iterator ChildrenIterator;
997         typedef ChildrenMap::value_type ChildrenPair;
998         Mutex m_mutex;
999         ChildrenMap m_children;
1000         size_t m_children_count;
1001     };
1002
1003     //------------------------------------------------------------------
1004     // Classes that inherit from ValueObject can see and modify these
1005     //------------------------------------------------------------------
1006     ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
1007     ValueObject  *      m_root;         // The root of the hierarchy for this ValueObject (or NULL if never calculated)
1008     EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last 
1009                                         // updated.  When we are asked to update the value object, we check whether
1010                                         // the context & stop id are the same before updating.
1011     ConstString         m_name;         // The name of this object
1012     DataExtractor       m_data;         // A data extractor that can be used to extract the value.
1013     Value               m_value;
1014     Error               m_error;        // An error object that can describe any errors that occur when updating values.
1015     std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
1016     std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
1017     std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
1018     std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
1019     std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
1020                                               // in that the summary is consed up by us, the object_desc_string is builtin.
1021
1022     ClangASTType        m_override_type;// If the type of the value object should be overridden, the type to impose.
1023     
1024     ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
1025                                         // without a parent.)  The manager gets passed through all the generations of
1026                                         // dependent objects, and will keep the whole cluster of objects alive as long
1027                                         // as a shared pointer to any of them has been handed out.  Shared pointers to
1028                                         // value objects must always be made with the GetSP method.
1029
1030     ChildrenManager                      m_children;
1031     std::map<ConstString, ValueObject *> m_synthetic_children;
1032     
1033     ValueObject*                         m_dynamic_value;
1034     ValueObject*                         m_synthetic_value;
1035     ValueObject*                         m_deref_valobj;
1036     
1037     lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1038                                              // as an independent ValueObjectConstResult, which isn't managed by us.
1039
1040     lldb::Format                m_format;
1041     lldb::Format                m_last_format;
1042     uint32_t                    m_last_format_mgr_revision;
1043     lldb::TypeSummaryImplSP     m_type_summary_sp;
1044     lldb::TypeFormatImplSP      m_type_format_sp;
1045     lldb::SyntheticChildrenSP   m_synthetic_children_sp;
1046     ProcessModID                m_user_id_of_forced_summary;
1047     AddressType                 m_address_type_of_ptr_or_ref_children;
1048     
1049     bool                m_value_is_valid:1,
1050                         m_value_did_change:1,
1051                         m_children_count_valid:1,
1052                         m_old_value_valid:1,
1053                         m_is_deref_of_parent:1,
1054                         m_is_array_item_for_pointer:1,
1055                         m_is_bitfield_for_scalar:1,
1056                         m_is_child_at_offset:1,
1057                         m_is_getting_summary:1,
1058                         m_did_calculate_complete_objc_class_type:1;
1059     
1060     friend class ClangExpressionDeclMap;  // For GetValue
1061     friend class ClangExpressionVariable; // For SetName
1062     friend class Target;                  // For SetName
1063     friend class ValueObjectConstResultImpl;
1064
1065     //------------------------------------------------------------------
1066     // Constructors and Destructors
1067     //------------------------------------------------------------------
1068     
1069     // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1070     
1071     ValueObject();
1072     
1073     // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1074     // through-out its lifespan.
1075     
1076     ValueObject (ExecutionContextScope *exe_scope,
1077                  AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1078     
1079     // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1080     // of its parent.
1081     
1082     ValueObject (ValueObject &parent);
1083
1084     ValueObjectManager *
1085     GetManager()
1086     {
1087         return m_manager;
1088     }
1089     
1090     virtual bool
1091     UpdateValue () = 0;
1092
1093     virtual void
1094     CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1095     
1096     virtual lldb::DynamicValueType
1097     GetDynamicValueTypeImpl ()
1098     {
1099         return lldb::eNoDynamicValues;
1100     }
1101     
1102     virtual bool
1103     HasDynamicValueTypeInfo ()
1104     {
1105         return false;
1106     }
1107     
1108     virtual void
1109     CalculateSyntheticValue (bool use_synthetic = true);
1110     
1111     // Should only be called by ValueObject::GetChildAtIndex()
1112     // Returns a ValueObject managed by this ValueObject's manager.
1113     virtual ValueObject *
1114     CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index);
1115
1116     // Should only be called by ValueObject::GetNumChildren()
1117     virtual size_t
1118     CalculateNumChildren() = 0;
1119
1120     void
1121     SetNumChildren (size_t num_children);
1122
1123     void
1124     SetValueDidChange (bool value_changed);
1125
1126     void
1127     SetValueIsValid (bool valid);
1128     
1129     void
1130     ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1131     
1132     void
1133     AddSyntheticChild (const ConstString &key,
1134                        ValueObject *valobj);
1135     
1136     DataExtractor &
1137     GetDataExtractor ();
1138     
1139     void
1140     ClearDynamicTypeInformation ();
1141     
1142     //------------------------------------------------------------------
1143     // Subclasses must implement the functions below.
1144     //------------------------------------------------------------------
1145     
1146     virtual ClangASTType
1147     GetClangTypeImpl () = 0;
1148     
1149     const char *
1150     GetLocationAsCStringImpl (const Value& value,
1151                               const DataExtractor& data);
1152     
1153 private:
1154     //------------------------------------------------------------------
1155     // For ValueObject only
1156     //------------------------------------------------------------------
1157     
1158     virtual ClangASTType
1159     MaybeCalculateCompleteType ();
1160     
1161     lldb::ValueObjectSP
1162     GetValueForExpressionPath_Impl(const char* expression_cstr,
1163                                    const char** first_unparsed,
1164                                    ExpressionPathScanEndReason* reason_to_stop,
1165                                    ExpressionPathEndResultType* final_value_type,
1166                                    const GetValueForExpressionPathOptions& options,
1167                                    ExpressionPathAftermath* final_task_on_target);
1168         
1169     // this method will ONLY expand [] expressions into a VOList and return
1170     // the number of elements it added to the VOList
1171     // it will NOT loop through expanding the follow-up of the expression_cstr
1172     // for all objects in the list
1173     int
1174     ExpandArraySliceExpression(const char* expression_cstr,
1175                                const char** first_unparsed,
1176                                lldb::ValueObjectSP root,
1177                                lldb::ValueObjectListSP& list,
1178                                ExpressionPathScanEndReason* reason_to_stop,
1179                                ExpressionPathEndResultType* final_value_type,
1180                                const GetValueForExpressionPathOptions& options,
1181                                ExpressionPathAftermath* final_task_on_target);
1182                                
1183     
1184     DISALLOW_COPY_AND_ASSIGN (ValueObject);
1185
1186 };
1187
1188 } // namespace lldb_private
1189
1190 #endif  // liblldb_ValueObject_h_