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