ValueObject.h revision b6985793ce97364e6fa86643b942326b218dcb3d
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    // this will always create the children if necessary
738    lldb::ValueObjectSP
739    GetChildAtIndexPath (const std::initializer_list<uint32_t> &idxs,
740                         uint32_t* index_of_error = NULL);
741
742    lldb::ValueObjectSP
743    GetChildAtIndexPath (const std::vector<uint32_t> &idxs,
744                         uint32_t* index_of_error = NULL);
745
746    lldb::ValueObjectSP
747    GetChildAtIndexPath (const std::initializer_list< std::pair<uint32_t, bool> > &idxs,
748                         uint32_t* index_of_error = NULL);
749
750    lldb::ValueObjectSP
751    GetChildAtIndexPath (const std::vector< std::pair<uint32_t, bool> > &idxs,
752                         uint32_t* index_of_error = NULL);
753
754    virtual lldb::ValueObjectSP
755    GetChildMemberWithName (const ConstString &name, bool can_create);
756
757    virtual uint32_t
758    GetIndexOfChildWithName (const ConstString &name);
759
760    uint32_t
761    GetNumChildren ();
762
763    const Value &
764    GetValue() const;
765
766    Value &
767    GetValue();
768
769    virtual bool
770    ResolveValue (Scalar &scalar);
771
772    const char *
773    GetLocationAsCString ();
774
775    const char *
776    GetSummaryAsCString ();
777
778    bool
779    GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
780                         std::string& destination);
781
782    const char *
783    GetObjectDescription ();
784
785    bool
786    HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display,
787                                       lldb::Format custom_format);
788
789    enum PrintableRepresentationSpecialCases
790    {
791        ePrintableRepresentationSpecialCasesDisable = 0,
792        ePrintableRepresentationSpecialCasesAllow = 1,
793        ePrintableRepresentationSpecialCasesOnly = 3
794    };
795
796    bool
797    DumpPrintableRepresentation (Stream& s,
798                                 ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary,
799                                 lldb::Format custom_format = lldb::eFormatInvalid,
800                                 PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow);
801    bool
802    GetValueIsValid () const;
803
804    bool
805    GetValueDidChange ();
806
807    bool
808    UpdateValueIfNeeded (bool update_format = true);
809
810    bool
811    UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true);
812
813    bool
814    UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues);
815
816    lldb::ValueObjectSP
817    GetSP ()
818    {
819        return m_manager->GetSharedPointer(this);
820    }
821
822    void
823    SetName (const ConstString &name);
824
825    virtual lldb::addr_t
826    GetAddressOf (bool scalar_is_load_address = true,
827                  AddressType *address_type = NULL);
828
829    lldb::addr_t
830    GetPointerValue (AddressType *address_type = NULL);
831
832    lldb::ValueObjectSP
833    GetSyntheticChild (const ConstString &key) const;
834
835    lldb::ValueObjectSP
836    GetSyntheticArrayMember (int32_t index, bool can_create);
837
838    lldb::ValueObjectSP
839    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
840
841    lldb::ValueObjectSP
842    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
843
844    lldb::ValueObjectSP
845    GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
846
847    lldb::ValueObjectSP
848    GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create);
849
850    lldb::ValueObjectSP
851    GetSyntheticExpressionPathChild(const char* expression, bool can_create);
852
853    virtual lldb::ValueObjectSP
854    GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
855
856    virtual lldb::ValueObjectSP
857    GetDynamicValue (lldb::DynamicValueType valueType);
858
859    virtual lldb::ValueObjectSP
860    GetStaticValue ();
861
862    virtual lldb::ValueObjectSP
863    GetNonSyntheticValue ();
864
865    lldb::ValueObjectSP
866    GetSyntheticValue (bool use_synthetic = true);
867
868    virtual bool
869    HasSyntheticValue();
870
871    virtual bool
872    IsSynthetic() { return false; }
873
874    virtual lldb::ValueObjectSP
875    CreateConstantValue (const ConstString &name);
876
877    virtual lldb::ValueObjectSP
878    Dereference (Error &error);
879
880    virtual lldb::ValueObjectSP
881    AddressOf (Error &error);
882
883    virtual lldb::addr_t
884    GetLiveAddress()
885    {
886        return LLDB_INVALID_ADDRESS;
887    }
888
889    virtual void
890    SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
891                   AddressType address_type = eAddressTypeLoad)
892    {
893    }
894
895    virtual lldb::ValueObjectSP
896    Cast (const ClangASTType &clang_ast_type);
897
898    virtual lldb::ValueObjectSP
899    CastPointerType (const char *name,
900                     ClangASTType &ast_type);
901
902    virtual lldb::ValueObjectSP
903    CastPointerType (const char *name,
904                     lldb::TypeSP &type_sp);
905
906    // The backing bits of this value object were updated, clear any
907    // descriptive string, so we know we have to refetch them
908    virtual void
909    ValueUpdated ()
910    {
911        ClearUserVisibleData(eClearUserVisibleDataItemsValue |
912                             eClearUserVisibleDataItemsSummary |
913                             eClearUserVisibleDataItemsDescription);
914    }
915
916    virtual bool
917    IsDynamic ()
918    {
919        return false;
920    }
921
922    virtual SymbolContextScope *
923    GetSymbolContextScope();
924
925    static void
926    DumpValueObject (Stream &s,
927                     ValueObject *valobj);
928    static void
929    DumpValueObject (Stream &s,
930                     ValueObject *valobj,
931                     const DumpValueObjectOptions& options);
932
933    static lldb::ValueObjectSP
934    CreateValueObjectFromExpression (const char* name,
935                                     const char* expression,
936                                     const ExecutionContext& exe_ctx);
937
938    static lldb::ValueObjectSP
939    CreateValueObjectFromAddress (const char* name,
940                                  uint64_t address,
941                                  const ExecutionContext& exe_ctx,
942                                  ClangASTType type);
943
944    static lldb::ValueObjectSP
945    CreateValueObjectFromData (const char* name,
946                               DataExtractor& data,
947                               const ExecutionContext& exe_ctx,
948                               ClangASTType type);
949
950    static void
951    LogValueObject (Log *log,
952                    ValueObject *valobj);
953
954    static void
955    LogValueObject (Log *log,
956                    ValueObject *valobj,
957                    const DumpValueObjectOptions& options);
958
959
960    // returns true if this is a char* or a char[]
961    // if it is a char* and check_pointer is true,
962    // it also checks that the pointer is valid
963    bool
964    IsCStringContainer (bool check_pointer = false);
965
966    void
967    ReadPointedString (Stream& s,
968                       Error& error,
969                       uint32_t max_length = 0,
970                       bool honor_array = true,
971                       lldb::Format item_format = lldb::eFormatCharArray);
972
973    virtual size_t
974    GetPointeeData (DataExtractor& data,
975                    uint32_t item_idx = 0,
976					uint32_t item_count = 1);
977
978    virtual size_t
979    GetData (DataExtractor& data);
980
981    bool
982    GetIsConstant () const
983    {
984        return m_update_point.IsConstant();
985    }
986
987    void
988    SetIsConstant ()
989    {
990        m_update_point.SetIsConstant();
991    }
992
993    lldb::Format
994    GetFormat () const
995    {
996        if (m_parent && m_format == lldb::eFormatDefault)
997            return m_parent->GetFormat();
998        return m_format;
999    }
1000
1001    void
1002    SetFormat (lldb::Format format)
1003    {
1004        if (format != m_format)
1005            ClearUserVisibleData(eClearUserVisibleDataItemsValue);
1006        m_format = format;
1007    }
1008
1009    lldb::TypeSummaryImplSP
1010    GetSummaryFormat()
1011    {
1012        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1013        return m_type_summary_sp;
1014    }
1015
1016    void
1017    SetSummaryFormat(lldb::TypeSummaryImplSP format)
1018    {
1019        m_type_summary_sp = format;
1020        ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
1021    }
1022
1023    void
1024    SetValueFormat(lldb::TypeFormatImplSP format)
1025    {
1026        m_type_format_sp = format;
1027        ClearUserVisibleData(eClearUserVisibleDataItemsValue);
1028    }
1029
1030    lldb::TypeFormatImplSP
1031    GetValueFormat()
1032    {
1033        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1034        return m_type_format_sp;
1035    }
1036
1037    void
1038    SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
1039    {
1040        if (synth_sp.get() == m_synthetic_children_sp.get())
1041            return;
1042        ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
1043        m_synthetic_children_sp = synth_sp;
1044    }
1045
1046    lldb::SyntheticChildrenSP
1047    GetSyntheticChildren()
1048    {
1049        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1050        return m_synthetic_children_sp;
1051    }
1052
1053    // Use GetParent for display purposes, but if you want to tell the parent to update itself
1054    // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
1055    // displaying, they are really siblings, so for display it needs to route through to its grandparent.
1056    virtual ValueObject *
1057    GetParent()
1058    {
1059        return m_parent;
1060    }
1061
1062    virtual const ValueObject *
1063    GetParent() const
1064    {
1065        return m_parent;
1066    }
1067
1068    ValueObject *
1069    GetNonBaseClassParent();
1070
1071    void
1072    SetAddressTypeOfChildren(AddressType at)
1073    {
1074        m_address_type_of_ptr_or_ref_children = at;
1075    }
1076
1077    AddressType
1078    GetAddressTypeOfChildren()
1079    {
1080        if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
1081        {
1082            if (m_parent)
1083                return m_parent->GetAddressTypeOfChildren();
1084        }
1085        return m_address_type_of_ptr_or_ref_children;
1086    }
1087
1088    void
1089    SetHasCompleteType()
1090    {
1091        m_did_calculate_complete_objc_class_type = true;
1092    }
1093
1094    //------------------------------------------------------------------
1095    /// Find out if a SBValue might have children.
1096    ///
1097    /// This call is much more efficient than CalculateNumChildren() as
1098    /// it doesn't need to complete the underlying type. This is designed
1099    /// to be used in a UI environment in order to detect if the
1100    /// disclosure triangle should be displayed or not.
1101    ///
1102    /// This function returns true for class, union, structure,
1103    /// pointers, references, arrays and more. Again, it does so without
1104    /// doing any expensive type completion.
1105    ///
1106    /// @return
1107    ///     Returns \b true if the SBValue might have children, or \b
1108    ///     false otherwise.
1109    //------------------------------------------------------------------
1110    virtual bool
1111    MightHaveChildren();
1112
1113protected:
1114    typedef ClusterManager<ValueObject> ValueObjectManager;
1115
1116    class ChildrenManager
1117    {
1118    public:
1119        ChildrenManager() :
1120        m_mutex(Mutex::eMutexTypeRecursive),
1121        m_children(),
1122        m_children_count(0)
1123        {}
1124
1125        bool
1126        HasChildAtIndex (uint32_t idx)
1127        {
1128            Mutex::Locker locker(m_mutex);
1129            ChildrenIterator iter = m_children.find(idx);
1130            ChildrenIterator end = m_children.end();
1131            return (iter != end);
1132        }
1133
1134        ValueObject*
1135        GetChildAtIndex (uint32_t idx)
1136        {
1137            Mutex::Locker locker(m_mutex);
1138            ChildrenIterator iter = m_children.find(idx);
1139            ChildrenIterator end = m_children.end();
1140            if (iter == end)
1141                return NULL;
1142            else
1143                return iter->second;
1144        }
1145
1146        void
1147        SetChildAtIndex (uint32_t idx, ValueObject* valobj)
1148        {
1149            ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair
1150            Mutex::Locker locker(m_mutex);
1151            m_children.insert(pair);
1152        }
1153
1154        void
1155        SetChildrenCount (uint32_t count)
1156        {
1157            m_children_count = count;
1158        }
1159
1160        uint32_t
1161        GetChildrenCount ()
1162        {
1163            return m_children_count;
1164        }
1165
1166        void
1167        Clear()
1168        {
1169            m_children_count = 0;
1170            Mutex::Locker locker(m_mutex);
1171            m_children.clear();
1172        }
1173
1174    private:
1175        typedef std::map<uint32_t, ValueObject*> ChildrenMap;
1176        typedef ChildrenMap::iterator ChildrenIterator;
1177        typedef ChildrenMap::value_type ChildrenPair;
1178        Mutex m_mutex;
1179        ChildrenMap m_children;
1180        uint32_t m_children_count;
1181    };
1182
1183    //------------------------------------------------------------------
1184    // Classes that inherit from ValueObject can see and modify these
1185    //------------------------------------------------------------------
1186    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
1187    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last
1188                                        // updated.  When we are asked to update the value object, we check whether
1189                                        // the context & stop id are the same before updating.
1190    ConstString         m_name;         // The name of this object
1191    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
1192    Value               m_value;
1193    Error               m_error;        // An error object that can describe any errors that occur when updating values.
1194    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
1195    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
1196    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
1197    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
1198    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
1199                                              // in that the summary is consed up by us, the object_desc_string is builtin.
1200
1201    ClangASTType        m_override_type;// If the type of the value object should be overridden, the type to impose.
1202
1203    ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
1204                                        // without a parent.)  The manager gets passed through all the generations of
1205                                        // dependent objects, and will keep the whole cluster of objects alive as long
1206                                        // as a shared pointer to any of them has been handed out.  Shared pointers to
1207                                        // value objects must always be made with the GetSP method.
1208
1209    ChildrenManager                      m_children;
1210    std::map<ConstString, ValueObject *> m_synthetic_children;
1211
1212    ValueObject*                         m_dynamic_value;
1213    ValueObject*                         m_synthetic_value;
1214    ValueObject*                         m_deref_valobj;
1215
1216    lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1217                                             // as an independent ValueObjectConstResult, which isn't managed by us.
1218
1219    lldb::Format                m_format;
1220    uint32_t                    m_last_format_mgr_revision;
1221    lldb::DynamicValueType      m_last_format_mgr_dynamic;
1222    lldb::TypeSummaryImplSP     m_type_summary_sp;
1223    lldb::TypeFormatImplSP      m_type_format_sp;
1224    lldb::SyntheticChildrenSP   m_synthetic_children_sp;
1225    ProcessModID                m_user_id_of_forced_summary;
1226    AddressType                 m_address_type_of_ptr_or_ref_children;
1227
1228    bool                m_value_is_valid:1,
1229                        m_value_did_change:1,
1230                        m_children_count_valid:1,
1231                        m_old_value_valid:1,
1232                        m_is_deref_of_parent:1,
1233                        m_is_array_item_for_pointer:1,
1234                        m_is_bitfield_for_scalar:1,
1235                        m_is_expression_path_child:1,
1236                        m_is_child_at_offset:1,
1237                        m_is_getting_summary:1,
1238                        m_did_calculate_complete_objc_class_type:1;
1239
1240    friend class ClangExpressionDeclMap;  // For GetValue
1241    friend class ClangExpressionVariable; // For SetName
1242    friend class Target;                  // For SetName
1243    friend class ValueObjectConstResultImpl;
1244
1245    //------------------------------------------------------------------
1246    // Constructors and Destructors
1247    //------------------------------------------------------------------
1248
1249    // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1250
1251    ValueObject();
1252
1253    // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1254    // through-out its lifespan.
1255
1256    ValueObject (ExecutionContextScope *exe_scope,
1257                 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1258
1259    // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1260    // of its parent.
1261
1262    ValueObject (ValueObject &parent);
1263
1264    ValueObjectManager *
1265    GetManager()
1266    {
1267        return m_manager;
1268    }
1269
1270    virtual bool
1271    UpdateValue () = 0;
1272
1273    virtual void
1274    CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1275
1276    virtual void
1277    CalculateSyntheticValue (bool use_synthetic = true);
1278
1279    // Should only be called by ValueObject::GetChildAtIndex()
1280    // Returns a ValueObject managed by this ValueObject's manager.
1281    virtual ValueObject *
1282    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
1283
1284    // Should only be called by ValueObject::GetNumChildren()
1285    virtual uint32_t
1286    CalculateNumChildren() = 0;
1287
1288    void
1289    SetNumChildren (uint32_t num_children);
1290
1291    void
1292    SetValueDidChange (bool value_changed);
1293
1294    void
1295    SetValueIsValid (bool valid);
1296
1297    void
1298    ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1299
1300    void
1301    AddSyntheticChild (const ConstString &key,
1302                       ValueObject *valobj);
1303
1304    DataExtractor &
1305    GetDataExtractor ();
1306
1307    void
1308    ClearDynamicTypeInformation ();
1309
1310    //------------------------------------------------------------------
1311    // Sublasses must implement the functions below.
1312    //------------------------------------------------------------------
1313
1314    virtual clang::ASTContext *
1315    GetClangASTImpl () = 0;
1316
1317    virtual lldb::clang_type_t
1318    GetClangTypeImpl () = 0;
1319
1320private:
1321    //------------------------------------------------------------------
1322    // For ValueObject only
1323    //------------------------------------------------------------------
1324
1325    virtual ClangASTType
1326    MaybeCalculateCompleteType ();
1327
1328    lldb::ValueObjectSP
1329    GetValueForExpressionPath_Impl(const char* expression_cstr,
1330                                   const char** first_unparsed,
1331                                   ExpressionPathScanEndReason* reason_to_stop,
1332                                   ExpressionPathEndResultType* final_value_type,
1333                                   const GetValueForExpressionPathOptions& options,
1334                                   ExpressionPathAftermath* final_task_on_target);
1335
1336    // this method will ONLY expand [] expressions into a VOList and return
1337    // the number of elements it added to the VOList
1338    // it will NOT loop through expanding the follow-up of the expression_cstr
1339    // for all objects in the list
1340    int
1341    ExpandArraySliceExpression(const char* expression_cstr,
1342                               const char** first_unparsed,
1343                               lldb::ValueObjectSP root,
1344                               lldb::ValueObjectListSP& list,
1345                               ExpressionPathScanEndReason* reason_to_stop,
1346                               ExpressionPathEndResultType* final_value_type,
1347                               const GetValueForExpressionPathOptions& options,
1348                               ExpressionPathAftermath* final_task_on_target);
1349
1350
1351    DISALLOW_COPY_AND_ASSIGN (ValueObject);
1352
1353};
1354
1355} // namespace lldb_private
1356
1357#endif  // liblldb_ValueObject_h_
1358