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