ValueObject.h revision 7c53768e700f9181082072017976472e3ad9cc37
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
220        DumpValueObjectOptions() :
221        m_ptr_depth(0),
222        m_max_depth(UINT32_MAX),
223        m_show_types(false),
224        m_show_location(false),
225        m_use_objc(false),
226        m_use_dynamic(lldb::eNoDynamicValues),
227        m_use_synthetic(lldb::eUseSyntheticFilter),
228        m_scope_already_checked(false),
229        m_flat_output(false),
230        m_omit_summary_depth(0),
231        m_ignore_cap(false)
232        {}
233
234        static const DumpValueObjectOptions
235        DefaultOptions()
236        {
237            static DumpValueObjectOptions g_default_options;
238
239            return g_default_options;
240        }
241
242        DumpValueObjectOptions&
243        SetPointerDepth(uint32_t depth = 0)
244        {
245            m_ptr_depth = depth;
246            return *this;
247        }
248
249        DumpValueObjectOptions&
250        SetMaximumDepth(uint32_t depth = 0)
251        {
252            m_max_depth = depth;
253            return *this;
254        }
255
256        DumpValueObjectOptions&
257        SetShowTypes(bool show = false)
258        {
259            m_show_types = show;
260            return *this;
261        }
262
263        DumpValueObjectOptions&
264        SetShowLocation(bool show = false)
265        {
266            m_show_location = show;
267            return *this;
268        }
269
270        DumpValueObjectOptions&
271        SetUseObjectiveC(bool use = false)
272        {
273            m_use_objc = use;
274            return *this;
275        }
276
277        DumpValueObjectOptions&
278        SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues)
279        {
280            m_use_dynamic = dyn;
281            return *this;
282        }
283
284        DumpValueObjectOptions&
285        SetUseSyntheticValue(lldb::SyntheticValueType syn = lldb::eUseSyntheticFilter)
286        {
287            m_use_synthetic = syn;
288            return *this;
289        }
290
291        DumpValueObjectOptions&
292        SetScopeChecked(bool check = true)
293        {
294            m_scope_already_checked = check;
295            return *this;
296        }
297
298        DumpValueObjectOptions&
299        SetFlatOutput(bool flat = false)
300        {
301            m_flat_output = flat;
302            return *this;
303        }
304
305        DumpValueObjectOptions&
306        SetOmitSummaryDepth(uint32_t depth = 0)
307        {
308            m_omit_summary_depth = depth;
309            return *this;
310        }
311
312        DumpValueObjectOptions&
313        SetIgnoreCap(bool ignore = false)
314        {
315            m_ignore_cap = ignore;
316            return *this;
317        }
318
319        DumpValueObjectOptions&
320        SetRawDisplay(bool raw = false)
321        {
322            if (raw)
323            {
324                SetUseSyntheticValue(lldb::eNoSyntheticFilter);
325                SetOmitSummaryDepth(UINT32_MAX);
326                SetIgnoreCap(true);
327            }
328            else
329            {
330                SetUseSyntheticValue(lldb::eUseSyntheticFilter);
331                SetOmitSummaryDepth(0);
332                SetIgnoreCap(false);
333            }
334            return *this;
335        }
336
337    };
338
339    class EvaluationPoint
340    {
341    public:
342
343        EvaluationPoint ();
344
345        EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false);
346
347        EvaluationPoint (const EvaluationPoint &rhs);
348
349        ~EvaluationPoint ();
350
351        ExecutionContextScope *
352        GetExecutionContextScope ();
353
354        const lldb::TargetSP &
355        GetTargetSP () const
356        {
357            return m_target_sp;
358        }
359
360        const lldb::ProcessSP &
361        GetProcessSP () const
362        {
363            return m_process_sp;
364        }
365
366        // Set the EvaluationPoint to the values in exe_scope,
367        // Return true if the Evaluation Point changed.
368        // Since the ExecutionContextScope is always going to be valid currently,
369        // the Updated Context will also always be valid.
370
371        bool
372        SetContext (ExecutionContextScope *exe_scope);
373
374        void
375        SetIsConstant ()
376        {
377            SetUpdated();
378            m_mod_id.SetInvalid();
379        }
380
381        bool
382        IsConstant () const
383        {
384            return !m_mod_id.IsValid();
385        }
386
387        ProcessModID
388        GetModID () const
389        {
390            return m_mod_id;
391        }
392
393        void
394        SetUpdateID (ProcessModID new_id)
395        {
396            m_mod_id = new_id;
397        }
398
399        bool
400        IsFirstEvaluation () const
401        {
402            return m_first_update;
403        }
404
405        void
406        SetNeedsUpdate ()
407        {
408            m_needs_update = true;
409        }
410
411        void
412        SetUpdated ();
413
414        bool
415        NeedsUpdating()
416        {
417            SyncWithProcessState();
418            return m_needs_update;
419        }
420
421        bool
422        IsValid ()
423        {
424            if (!m_mod_id.IsValid())
425                return false;
426            else if (SyncWithProcessState ())
427            {
428                if (!m_mod_id.IsValid())
429                    return false;
430            }
431            return true;
432        }
433
434        void
435        SetInvalid ()
436        {
437            // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and
438            // history purposes.
439            m_mod_id.SetInvalid();
440
441            // Can't update an invalid state.
442            m_needs_update = false;
443
444        }
445
446    private:
447        bool
448        SyncWithProcessState ()
449        {
450            ExecutionContextScope *exe_scope;
451            return SyncWithProcessState(exe_scope);
452        }
453
454        bool
455        SyncWithProcessState (ExecutionContextScope *&exe_scope);
456
457        bool             m_needs_update;
458        bool             m_first_update;
459
460        lldb::TargetSP   m_target_sp;
461        lldb::ProcessSP  m_process_sp;
462        lldb::user_id_t  m_thread_id;
463        StackID          m_stack_id;
464        ProcessModID     m_mod_id; // This is the stop id when this ValueObject was last evaluated.
465    };
466
467    const EvaluationPoint &
468    GetUpdatePoint () const
469    {
470        return m_update_point;
471    }
472
473    EvaluationPoint &
474    GetUpdatePoint ()
475    {
476        return m_update_point;
477    }
478
479    ExecutionContextScope *
480    GetExecutionContextScope ()
481    {
482        return m_update_point.GetExecutionContextScope();
483    }
484
485    void
486    SetNeedsUpdate ();
487
488    virtual ~ValueObject();
489
490    //------------------------------------------------------------------
491    // Sublasses must implement the functions below.
492    //------------------------------------------------------------------
493    virtual size_t
494    GetByteSize() = 0;
495
496    virtual clang::ASTContext *
497    GetClangAST () = 0;
498
499    virtual lldb::clang_type_t
500    GetClangType () = 0;
501
502    virtual lldb::ValueType
503    GetValueType() const = 0;
504
505    virtual ConstString
506    GetTypeName() = 0;
507
508    virtual lldb::LanguageType
509    GetObjectRuntimeLanguage();
510
511    virtual bool
512    IsPointerType ();
513
514    virtual bool
515    IsArrayType ();
516
517    virtual bool
518    IsScalarType ();
519
520    virtual bool
521    IsPointerOrReferenceType ();
522
523    virtual bool
524    IsPossibleCPlusPlusDynamicType ();
525
526    virtual bool
527    IsPossibleDynamicType ();
528
529    virtual bool
530    IsBaseClass ()
531    {
532        return false;
533    }
534
535    virtual bool
536    IsDereferenceOfParent ()
537    {
538        return false;
539    }
540
541    bool
542    IsIntegerType (bool &is_signed);
543
544    virtual bool
545    GetBaseClassPath (Stream &s);
546
547    virtual void
548    GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eDereferencePointers);
549
550    lldb::ValueObjectSP
551    GetValueForExpressionPath(const char* expression,
552                              const char** first_unparsed = NULL,
553                              ExpressionPathScanEndReason* reason_to_stop = NULL,
554                              ExpressionPathEndResultType* final_value_type = NULL,
555                              const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
556                              ExpressionPathAftermath* final_task_on_target = NULL);
557
558    int
559    GetValuesForExpressionPath(const char* expression,
560                               lldb::ValueObjectListSP& list,
561                               const char** first_unparsed = NULL,
562                               ExpressionPathScanEndReason* reason_to_stop = NULL,
563                               ExpressionPathEndResultType* final_value_type = NULL,
564                               const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
565                               ExpressionPathAftermath* final_task_on_target = NULL);
566
567    virtual bool
568    IsInScope ()
569    {
570        return true;
571    }
572
573    virtual off_t
574    GetByteOffset()
575    {
576        return 0;
577    }
578
579    virtual uint32_t
580    GetBitfieldBitSize()
581    {
582        return 0;
583    }
584
585    virtual uint32_t
586    GetBitfieldBitOffset()
587    {
588        return 0;
589    }
590
591    virtual bool
592    IsArrayItemForPointer()
593    {
594        return m_is_array_item_for_pointer;
595    }
596
597    virtual bool
598    SetClangAST (clang::ASTContext *ast)
599    {
600        return false;
601    }
602
603    virtual const char *
604    GetValueAsCString ();
605
606    virtual uint64_t
607    GetValueAsUnsigned (uint64_t fail_value);
608
609    virtual bool
610    SetValueFromCString (const char *value_str);
611
612    // Return the module associated with this value object in case the
613    // value is from an executable file and might have its data in
614    // sections of the file. This can be used for variables.
615    virtual Module *
616    GetModule()
617    {
618        if (m_parent)
619            return m_parent->GetModule();
620        return NULL;
621    }
622    //------------------------------------------------------------------
623    // The functions below should NOT be modified by sublasses
624    //------------------------------------------------------------------
625    const Error &
626    GetError();
627
628    const ConstString &
629    GetName() const;
630
631    virtual lldb::ValueObjectSP
632    GetChildAtIndex (uint32_t idx, bool can_create);
633
634    virtual lldb::ValueObjectSP
635    GetChildMemberWithName (const ConstString &name, bool can_create);
636
637    virtual uint32_t
638    GetIndexOfChildWithName (const ConstString &name);
639
640    uint32_t
641    GetNumChildren ();
642
643    const Value &
644    GetValue() const;
645
646    Value &
647    GetValue();
648
649    virtual bool
650    ResolveValue (Scalar &scalar);
651
652    const char *
653    GetLocationAsCString ();
654
655    const char *
656    GetSummaryAsCString ();
657
658    const char *
659    GetObjectDescription ();
660
661    bool
662    GetPrintableRepresentation(Stream& s,
663                               ValueObjectRepresentationStyle val_obj_display = eDisplaySummary,
664                               lldb::Format custom_format = lldb::eFormatInvalid);
665
666    bool
667    HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
668                                              lldb::Format custom_format);
669
670    bool
671    DumpPrintableRepresentation(Stream& s,
672                                ValueObjectRepresentationStyle val_obj_display = eDisplaySummary,
673                                lldb::Format custom_format = lldb::eFormatInvalid,
674                                bool only_special = false);
675    bool
676    GetValueIsValid () const;
677
678    bool
679    GetValueDidChange ();
680
681    bool
682    UpdateValueIfNeeded (bool update_format = true);
683
684    bool
685    UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true);
686
687    bool
688    UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues);
689
690    lldb::ValueObjectSP
691    GetSP ()
692    {
693        return m_manager->GetSharedPointer(this);
694    }
695
696    void
697    SetName (const ConstString &name);
698
699    lldb::addr_t
700    GetAddressOf (bool scalar_is_load_address = true,
701                  AddressType *address_type = NULL);
702
703    lldb::addr_t
704    GetPointerValue (AddressType *address_type = NULL);
705
706    lldb::ValueObjectSP
707    GetSyntheticChild (const ConstString &key) const;
708
709    lldb::ValueObjectSP
710    GetSyntheticArrayMember (int32_t index, bool can_create);
711
712    lldb::ValueObjectSP
713    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
714
715    lldb::ValueObjectSP
716    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
717
718    lldb::ValueObjectSP
719    GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
720
721    lldb::ValueObjectSP
722    GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create);
723
724    lldb::ValueObjectSP
725    GetSyntheticExpressionPathChild(const char* expression, bool can_create);
726
727    virtual lldb::ValueObjectSP
728    GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
729
730    lldb::ValueObjectSP
731    GetDynamicValue (lldb::DynamicValueType valueType);
732
733    virtual lldb::ValueObjectSP
734    GetStaticValue ();
735
736    lldb::ValueObjectSP
737    GetSyntheticValue (lldb::SyntheticValueType use_synthetic);
738
739    virtual bool
740    HasSyntheticValue();
741
742    virtual lldb::ValueObjectSP
743    CreateConstantValue (const ConstString &name);
744
745    virtual lldb::ValueObjectSP
746    Dereference (Error &error);
747
748    virtual lldb::ValueObjectSP
749    AddressOf (Error &error);
750
751    virtual lldb::ValueObjectSP
752    CastPointerType (const char *name,
753                     ClangASTType &ast_type);
754
755    virtual lldb::ValueObjectSP
756    CastPointerType (const char *name,
757                     lldb::TypeSP &type_sp);
758
759    // The backing bits of this value object were updated, clear any
760    // descriptive string, so we know we have to refetch them
761    virtual void
762    ValueUpdated ()
763    {
764        m_value_str.clear();
765        m_summary_str.clear();
766        m_object_desc_str.clear();
767    }
768
769    virtual bool
770    IsDynamic ()
771    {
772        return false;
773    }
774
775    virtual SymbolContextScope *
776    GetSymbolContextScope();
777
778    static void
779    DumpValueObject (Stream &s,
780                     ValueObject *valobj)
781    {
782
783        if (!valobj)
784            return;
785
786        ValueObject::DumpValueObject(s,
787                                     valobj,
788                                     DumpValueObjectOptions::DefaultOptions());
789    }
790
791    static void
792    DumpValueObject (Stream &s,
793                     ValueObject *valobj,
794                     const char *root_valobj_name)
795    {
796
797        if (!valobj)
798            return;
799
800        ValueObject::DumpValueObject(s,
801                                     valobj,
802                                     root_valobj_name,
803                                     DumpValueObjectOptions::DefaultOptions());
804    }
805
806    static void
807    DumpValueObject (Stream &s,
808                     ValueObject *valobj,
809                     const DumpValueObjectOptions& options)
810    {
811
812        if (!valobj)
813            return;
814
815        ValueObject::DumpValueObject(s,
816                                     valobj,
817                                     valobj->GetName().AsCString(),
818                                     options.m_ptr_depth,
819                                     0,
820                                     options.m_max_depth,
821                                     options.m_show_types,
822                                     options.m_show_location,
823                                     options.m_use_objc,
824                                     options.m_use_dynamic,
825                                     options.m_use_synthetic,
826                                     options.m_scope_already_checked,
827                                     options.m_flat_output,
828                                     options.m_omit_summary_depth,
829                                     options.m_ignore_cap);
830    }
831
832    static void
833    DumpValueObject (Stream &s,
834                     ValueObject *valobj,
835                     const char *root_valobj_name,
836                     const DumpValueObjectOptions& options)
837    {
838
839        if (!valobj)
840            return;
841
842        ValueObject::DumpValueObject(s,
843                                     valobj,
844                                     root_valobj_name,
845                                     options.m_ptr_depth,
846                                     0,
847                                     options.m_max_depth,
848                                     options.m_show_types,
849                                     options.m_show_location,
850                                     options.m_use_objc,
851                                     options.m_use_dynamic,
852                                     options.m_use_synthetic,
853                                     options.m_scope_already_checked,
854                                     options.m_flat_output,
855                                     options.m_omit_summary_depth,
856                                     options.m_ignore_cap);
857    }
858
859    static void
860    DumpValueObject (Stream &s,
861                     ValueObject *valobj,
862                     const char *root_valobj_name,
863                     uint32_t ptr_depth,
864                     uint32_t curr_depth,
865                     uint32_t max_depth,
866                     bool show_types,
867                     bool show_location,
868                     bool use_objc,
869                     lldb::DynamicValueType use_dynamic,
870                     bool use_synthetic,
871                     bool scope_already_checked,
872                     bool flat_output,
873                     uint32_t omit_summary_depth,
874                     bool ignore_cap);
875
876    // returns true if this is a char* or a char[]
877    // if it is a char* and check_pointer is true,
878    // it also checks that the pointer is valid
879    bool
880    IsCStringContainer (bool check_pointer = false);
881
882    void
883    ReadPointedString (Stream& s,
884                       Error& error,
885                       uint32_t max_length = 0,
886                       bool honor_array = true,
887                       lldb::Format item_format = lldb::eFormatCharArray);
888
889    virtual size_t
890    GetPointeeData (DataExtractor& data,
891                    uint32_t item_idx = 0,
892					uint32_t item_count = 1);
893
894    virtual size_t
895    GetData (DataExtractor& data);
896
897    bool
898    GetIsConstant () const
899    {
900        return m_update_point.IsConstant();
901    }
902
903    void
904    SetIsConstant ()
905    {
906        m_update_point.SetIsConstant();
907    }
908
909    lldb::Format
910    GetFormat () const
911    {
912        if (m_parent && m_format == lldb::eFormatDefault)
913            return m_parent->GetFormat();
914        return m_format;
915    }
916
917    void
918    SetFormat (lldb::Format format)
919    {
920        if (format != m_format)
921            m_value_str.clear();
922        m_format = format;
923    }
924
925    void
926    SetCustomSummaryFormat(lldb::SummaryFormatSP format)
927    {
928        m_forced_summary_format = format;
929        m_user_id_of_forced_summary = m_update_point.GetModID();
930        m_summary_str.clear();
931        m_trying_summary_already = false;
932    }
933
934    lldb::SummaryFormatSP
935    GetCustomSummaryFormat()
936    {
937        return m_forced_summary_format;
938    }
939
940    void
941    ClearCustomSummaryFormat()
942    {
943        m_forced_summary_format.reset();
944        m_summary_str.clear();
945    }
946
947    bool
948    HasCustomSummaryFormat()
949    {
950        return (m_forced_summary_format.get());
951    }
952
953    lldb::SummaryFormatSP
954    GetSummaryFormat()
955    {
956        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
957        if (HasCustomSummaryFormat())
958            return m_forced_summary_format;
959        return m_last_summary_format;
960    }
961
962    void
963    SetSummaryFormat(lldb::SummaryFormatSP format)
964    {
965        m_last_summary_format = format;
966        m_summary_str.clear();
967        m_trying_summary_already = false;
968    }
969
970    void
971    SetValueFormat(lldb::ValueFormatSP format)
972    {
973        m_last_value_format = format;
974        m_value_str.clear();
975    }
976
977    lldb::ValueFormatSP
978    GetValueFormat()
979    {
980        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
981        return m_last_value_format;
982    }
983
984    void
985    SetSyntheticChildren(lldb::SyntheticChildrenSP synth)
986    {
987        m_last_synthetic_filter = synth;
988        m_synthetic_value = NULL;
989    }
990
991    lldb::SyntheticChildrenSP
992    GetSyntheticChildren()
993    {
994        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
995        return m_last_synthetic_filter;
996    }
997
998    // Use GetParent for display purposes, but if you want to tell the parent to update itself
999    // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
1000    // displaying, they are really siblings, so for display it needs to route through to its grandparent.
1001    virtual ValueObject *
1002    GetParent()
1003    {
1004        return m_parent;
1005    }
1006
1007    virtual const ValueObject *
1008    GetParent() const
1009    {
1010        return m_parent;
1011    }
1012
1013    ValueObject *
1014    GetNonBaseClassParent();
1015
1016    void
1017    SetAddressTypeOfChildren(AddressType at)
1018    {
1019        m_address_type_of_ptr_or_ref_children = at;
1020    }
1021
1022    AddressType
1023    GetAddressTypeOfChildren()
1024    {
1025        if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
1026        {
1027            if (m_parent)
1028                return m_parent->GetAddressTypeOfChildren();
1029        }
1030        return m_address_type_of_ptr_or_ref_children;
1031    }
1032
1033protected:
1034    typedef ClusterManager<ValueObject> ValueObjectManager;
1035
1036    //------------------------------------------------------------------
1037    // Classes that inherit from ValueObject can see and modify these
1038    //------------------------------------------------------------------
1039    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
1040    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last
1041                                        // updated.  When we are asked to update the value object, we check whether
1042                                        // the context & stop id are the same before updating.
1043    ConstString         m_name;         // The name of this object
1044    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
1045    Value               m_value;
1046    Error               m_error;        // An error object that can describe any errors that occur when updating values.
1047    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
1048    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
1049    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
1050    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
1051    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
1052                                              // in that the summary is consed up by us, the object_desc_string is builtin.
1053
1054    ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
1055                                        // without a parent.)  The manager gets passed through all the generations of
1056                                        // dependent objects, and will keep the whole cluster of objects alive as long
1057                                        // as a shared pointer to any of them has been handed out.  Shared pointers to
1058                                        // value objects must always be made with the GetSP method.
1059
1060    std::vector<ValueObject *>           m_children;
1061    std::map<ConstString, ValueObject *> m_synthetic_children;
1062
1063    ValueObject*                         m_dynamic_value;
1064    ValueObject*                         m_synthetic_value;
1065    ValueObject*                         m_deref_valobj;
1066
1067    lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1068                                             // as an independent ValueObjectConstResult, which isn't managed by us.
1069
1070    lldb::Format                m_format;
1071    uint32_t                    m_last_format_mgr_revision;
1072    lldb::DynamicValueType      m_last_format_mgr_dynamic;
1073    lldb::SummaryFormatSP       m_last_summary_format;
1074    lldb::SummaryFormatSP       m_forced_summary_format;
1075    lldb::ValueFormatSP         m_last_value_format;
1076    lldb::SyntheticChildrenSP   m_last_synthetic_filter;
1077    ProcessModID                m_user_id_of_forced_summary;
1078    AddressType                 m_address_type_of_ptr_or_ref_children;
1079
1080    bool                m_value_is_valid:1,
1081                        m_value_did_change:1,
1082                        m_children_count_valid:1,
1083                        m_old_value_valid:1,
1084                        m_is_deref_of_parent:1,
1085                        m_is_array_item_for_pointer:1,
1086                        m_is_bitfield_for_scalar:1,
1087                        m_is_expression_path_child:1,
1088                        m_is_child_at_offset:1,
1089                        m_trying_summary_already:1; // used to prevent endless recursion in printing summaries
1090
1091    friend class ClangExpressionDeclMap;  // For GetValue
1092    friend class ClangExpressionVariable; // For SetName
1093    friend class Target;                  // For SetName
1094    friend class ValueObjectConstResultImpl;
1095
1096    //------------------------------------------------------------------
1097    // Constructors and Destructors
1098    //------------------------------------------------------------------
1099
1100    // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1101
1102    ValueObject();
1103
1104    // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1105    // through-out its lifespan.
1106
1107    ValueObject (ExecutionContextScope *exe_scope,
1108                 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1109
1110    // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1111    // of its parent.
1112
1113    ValueObject (ValueObject &parent);
1114
1115    ValueObjectManager *
1116    GetManager()
1117    {
1118        return m_manager;
1119    }
1120
1121    virtual bool
1122    UpdateValue () = 0;
1123
1124    virtual void
1125    CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1126
1127    virtual void
1128    CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic);
1129
1130    // Should only be called by ValueObject::GetChildAtIndex()
1131    // Returns a ValueObject managed by this ValueObject's manager.
1132    virtual ValueObject *
1133    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
1134
1135    // Should only be called by ValueObject::GetNumChildren()
1136    virtual uint32_t
1137    CalculateNumChildren() = 0;
1138
1139    void
1140    SetNumChildren (uint32_t num_children);
1141
1142    void
1143    SetValueDidChange (bool value_changed);
1144
1145    void
1146    SetValueIsValid (bool valid);
1147
1148    void
1149    ClearUserVisibleData();
1150
1151    void
1152    AddSyntheticChild (const ConstString &key,
1153                       ValueObject *valobj);
1154
1155    DataExtractor &
1156    GetDataExtractor ();
1157
1158private:
1159    //------------------------------------------------------------------
1160    // For ValueObject only
1161    //------------------------------------------------------------------
1162
1163    lldb::ValueObjectSP
1164    GetValueForExpressionPath_Impl(const char* expression_cstr,
1165                                   const char** first_unparsed,
1166                                   ExpressionPathScanEndReason* reason_to_stop,
1167                                   ExpressionPathEndResultType* final_value_type,
1168                                   const GetValueForExpressionPathOptions& options,
1169                                   ExpressionPathAftermath* final_task_on_target);
1170
1171    // this method will ONLY expand [] expressions into a VOList and return
1172    // the number of elements it added to the VOList
1173    // it will NOT loop through expanding the follow-up of the expression_cstr
1174    // for all objects in the list
1175    int
1176    ExpandArraySliceExpression(const char* expression_cstr,
1177                               const char** first_unparsed,
1178                               lldb::ValueObjectSP root,
1179                               lldb::ValueObjectListSP& list,
1180                               ExpressionPathScanEndReason* reason_to_stop,
1181                               ExpressionPathEndResultType* final_value_type,
1182                               const GetValueForExpressionPathOptions& options,
1183                               ExpressionPathAftermath* final_task_on_target);
1184
1185
1186    DISALLOW_COPY_AND_ASSIGN (ValueObject);
1187
1188};
1189
1190} // namespace lldb_private
1191
1192#endif  // liblldb_ValueObject_h_
1193