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