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