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