ValueObject.h revision 1c61743af946076e988d88baf725382e99d905de
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/PriorityPointerPair.h"
32#include "lldb/Utility/SharedCluster.h"
33
34namespace lldb_private {
35
36/// ValueObject:
37///
38/// This abstract class provides an interface to a particular value, be it a register, a local or global variable,
39/// that is evaluated in some particular scope.  The ValueObject also has the capibility of being the "child" of
40/// some other variable object, and in turn of having children.
41/// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some
42/// particular ExecutionContextScope.  If it is a child, it inherits the ExecutionContextScope from its parent.
43/// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc.
44/// But it will always update itself in the ExecutionContextScope with which it was originally created.
45
46/// A brief note on life cycle management for ValueObjects.  This is a little tricky because a ValueObject can contain
47/// various other ValueObjects - the Dynamic Value, its children, the dereference value, etc.  Any one of these can be
48/// handed out as a shared pointer, but for that contained value object to be valid, the root object and potentially other
49/// of the value objects need to stay around.
50/// We solve this problem by handing out shared pointers to the Value Object and any of its dependents using a shared
51/// ClusterManager.  This treats each shared pointer handed out for the entire cluster as a reference to the whole
52/// cluster.  The whole cluster will stay around until the last reference is released.
53///
54/// The ValueObject mostly handle this automatically, if a value object is made with a Parent ValueObject, then it adds
55/// itself to the ClusterManager of the parent.
56
57/// It does mean that external to the ValueObjects we should only ever make available ValueObjectSP's, never ValueObjects
58/// or pointers to them.  So all the "Root level" ValueObject derived constructors should be private, and
59/// should implement a Create function that new's up object and returns a Shared Pointer that it gets from the GetSP() method.
60///
61/// However, if you are making an derived ValueObject that will be contained in a parent value object, you should just
62/// hold onto a pointer to it internally, and by virtue of passing the parent ValueObject into its constructor, it will
63/// be added to the ClusterManager for the parent.  Then if you ever hand out a Shared Pointer to the contained ValueObject,
64/// just do so by calling GetSP() on the contained object.
65
66class ValueObject : public UserID
67{
68public:
69
70    enum GetExpressionPathFormat
71    {
72        eDereferencePointers = 1,
73        eHonorPointers
74    };
75
76    enum ValueObjectRepresentationStyle
77    {
78        eDisplayValue = 1,
79        eDisplaySummary,
80        eDisplayLanguageSpecific,
81        eDisplayLocation,
82        eDisplayChildrenCount,
83    };
84
85    enum ExpressionPathScanEndReason
86    {
87        eEndOfString = 1,           // out of data to parse
88        eNoSuchChild,               // child element not found
89        eEmptyRangeNotAllowed,      // [] only allowed for arrays
90        eDotInsteadOfArrow,         // . used when -> should be used
91        eArrowInsteadOfDot,         // -> used when . should be used
92        eFragileIVarNotAllowed,     // ObjC ivar expansion not allowed
93        eRangeOperatorNotAllowed,   // [] not allowed by options
94        eRangeOperatorInvalid,      // [] not valid on objects other than scalars, pointers or arrays
95        eArrayRangeOperatorMet,     // [] is good for arrays, but I cannot parse it
96        eBitfieldRangeOperatorMet,  // [] is good for bitfields, but I cannot parse after it
97        eUnexpectedSymbol,          // something is malformed in the expression
98        eTakingAddressFailed,       // impossible to apply & operator
99        eDereferencingFailed,       // impossible to apply * operator
100        eRangeOperatorExpanded,     // [] was expanded into a VOList
101        eUnknown = 0xFFFF
102    };
103
104    enum ExpressionPathEndResultType
105    {
106        ePlain = 1,                 // anything but...
107        eBitfield,                  // a bitfield
108        eBoundedRange,              // a range [low-high]
109        eUnboundedRange,            // a range []
110        eValueObjectList,           // several items in a VOList
111        eInvalid = 0xFFFF
112    };
113
114    enum ExpressionPathAftermath
115    {
116        eNothing = 1,               // just return it
117        eDereference,               // dereference the target
118        eTakeAddress                // take target's address
119    };
120
121    struct GetValueForExpressionPathOptions
122    {
123        bool m_check_dot_vs_arrow_syntax;
124        bool m_no_fragile_ivar;
125        bool m_allow_bitfields_syntax;
126        bool m_no_synthetic_children;
127
128        GetValueForExpressionPathOptions(bool dot = false,
129                                         bool no_ivar = false,
130                                         bool bitfield = true,
131                                         bool no_synth = false) :
132            m_check_dot_vs_arrow_syntax(dot),
133            m_no_fragile_ivar(no_ivar),
134            m_allow_bitfields_syntax(bitfield),
135            m_no_synthetic_children(no_synth)
136        {
137        }
138
139        GetValueForExpressionPathOptions&
140        DoCheckDotVsArrowSyntax()
141        {
142            m_check_dot_vs_arrow_syntax = true;
143            return *this;
144        }
145
146        GetValueForExpressionPathOptions&
147        DontCheckDotVsArrowSyntax()
148        {
149            m_check_dot_vs_arrow_syntax = false;
150            return *this;
151        }
152
153        GetValueForExpressionPathOptions&
154        DoAllowFragileIVar()
155        {
156            m_no_fragile_ivar = false;
157            return *this;
158        }
159
160        GetValueForExpressionPathOptions&
161        DontAllowFragileIVar()
162        {
163            m_no_fragile_ivar = true;
164            return *this;
165        }
166
167        GetValueForExpressionPathOptions&
168        DoAllowBitfieldSyntax()
169        {
170            m_allow_bitfields_syntax = true;
171            return *this;
172        }
173
174        GetValueForExpressionPathOptions&
175        DontAllowBitfieldSyntax()
176        {
177            m_allow_bitfields_syntax = false;
178            return *this;
179        }
180
181        GetValueForExpressionPathOptions&
182        DoAllowSyntheticChildren()
183        {
184            m_no_synthetic_children = false;
185            return *this;
186        }
187
188        GetValueForExpressionPathOptions&
189        DontAllowSyntheticChildren()
190        {
191            m_no_synthetic_children = true;
192            return *this;
193        }
194
195        static const GetValueForExpressionPathOptions
196        DefaultOptions()
197        {
198            static GetValueForExpressionPathOptions g_default_options;
199
200            return g_default_options;
201        }
202
203    };
204
205    struct DumpValueObjectOptions
206    {
207        uint32_t m_ptr_depth;
208        uint32_t m_max_depth;
209        bool m_show_types;
210        bool m_show_location;
211        bool m_use_objc;
212        lldb::DynamicValueType m_use_dynamic;
213        lldb::SyntheticValueType m_use_synthetic;
214        bool m_scope_already_checked;
215        bool m_flat_output;
216        uint32_t m_omit_summary_depth;
217        bool m_ignore_cap;
218
219        DumpValueObjectOptions() :
220        m_ptr_depth(0),
221        m_max_depth(UINT32_MAX),
222        m_show_types(false),
223        m_show_location(false),
224        m_use_objc(false),
225        m_use_dynamic(lldb::eNoDynamicValues),
226        m_use_synthetic(lldb::eUseSyntheticFilter),
227        m_scope_already_checked(false),
228        m_flat_output(false),
229        m_omit_summary_depth(0),
230        m_ignore_cap(false)
231        {}
232
233        static const DumpValueObjectOptions
234        DefaultOptions()
235        {
236            static DumpValueObjectOptions g_default_options;
237
238            return g_default_options;
239        }
240
241        DumpValueObjectOptions&
242        SetPointerDepth(uint32_t depth = 0)
243        {
244            m_ptr_depth = depth;
245            return *this;
246        }
247
248        DumpValueObjectOptions&
249        SetMaximumDepth(uint32_t depth = 0)
250        {
251            m_max_depth = depth;
252            return *this;
253        }
254
255        DumpValueObjectOptions&
256        SetShowTypes(bool show = false)
257        {
258            m_show_types = show;
259            return *this;
260        }
261
262        DumpValueObjectOptions&
263        SetShowLocation(bool show = false)
264        {
265            m_show_location = show;
266            return *this;
267        }
268
269        DumpValueObjectOptions&
270        SetUseObjectiveC(bool use = false)
271        {
272            m_use_objc = use;
273            return *this;
274        }
275
276        DumpValueObjectOptions&
277        SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues)
278        {
279            m_use_dynamic = dyn;
280            return *this;
281        }
282
283        DumpValueObjectOptions&
284        SetUseSyntheticValue(lldb::SyntheticValueType syn = lldb::eUseSyntheticFilter)
285        {
286            m_use_synthetic = syn;
287            return *this;
288        }
289
290        DumpValueObjectOptions&
291        SetScopeChecked(bool check = true)
292        {
293            m_scope_already_checked = check;
294            return *this;
295        }
296
297        DumpValueObjectOptions&
298        SetFlatOutput(bool flat = false)
299        {
300            m_flat_output = flat;
301            return *this;
302        }
303
304        DumpValueObjectOptions&
305        SetOmitSummaryDepth(uint32_t depth = 0)
306        {
307            m_omit_summary_depth = depth;
308            return *this;
309        }
310
311        DumpValueObjectOptions&
312        SetIgnoreCap(bool ignore = false)
313        {
314            m_ignore_cap = ignore;
315            return *this;
316        }
317
318        DumpValueObjectOptions&
319        SetRawDisplay(bool raw = false)
320        {
321            if (raw)
322            {
323                SetUseSyntheticValue(lldb::eNoSyntheticFilter);
324                SetOmitSummaryDepth(UINT32_MAX);
325                SetIgnoreCap(true);
326            }
327            else
328            {
329                SetUseSyntheticValue(lldb::eUseSyntheticFilter);
330                SetOmitSummaryDepth(0);
331                SetIgnoreCap(false);
332            }
333            return *this;
334        }
335
336    };
337
338    class EvaluationPoint
339    {
340    public:
341
342        EvaluationPoint ();
343
344        EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false);
345
346        EvaluationPoint (const EvaluationPoint &rhs);
347
348        ~EvaluationPoint ();
349
350        ExecutionContextScope *
351        GetExecutionContextScope ();
352
353        lldb::TargetSP
354        GetTargetSP () const
355        {
356            return m_target_sp;
357        }
358
359        lldb::ProcessSP
360        GetProcessSP () const
361        {
362            return m_process_sp;
363        }
364
365        // Set the EvaluationPoint to the values in exe_scope,
366        // Return true if the Evaluation Point changed.
367        // Since the ExecutionContextScope is always going to be valid currently,
368        // the Updated Context will also always be valid.
369
370        bool
371        SetContext (ExecutionContextScope *exe_scope);
372
373        void
374        SetIsConstant ()
375        {
376            SetUpdated();
377            m_mod_id.SetInvalid();
378        }
379
380        bool
381        IsConstant () const
382        {
383            return !m_mod_id.IsValid();
384        }
385
386        ProcessModID
387        GetModID () const
388        {
389            return m_mod_id;
390        }
391
392        void
393        SetUpdateID (ProcessModID new_id)
394        {
395            m_mod_id = new_id;
396        }
397
398        bool
399        IsFirstEvaluation () const
400        {
401            return m_first_update;
402        }
403
404        void
405        SetNeedsUpdate ()
406        {
407            m_needs_update = true;
408        }
409
410        void
411        SetUpdated ();
412
413        bool
414        NeedsUpdating()
415        {
416            SyncWithProcessState();
417            return m_needs_update;
418        }
419
420        bool
421        IsValid ()
422        {
423            if (!m_mod_id.IsValid())
424                return false;
425            else if (SyncWithProcessState ())
426            {
427                if (!m_mod_id.IsValid())
428                    return false;
429            }
430            return true;
431        }
432
433        void
434        SetInvalid ()
435        {
436            // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and
437            // history purposes.
438            m_mod_id.SetInvalid();
439
440            // Can't update an invalid state.
441            m_needs_update = false;
442
443        }
444
445    private:
446        bool
447        SyncWithProcessState ();
448
449        ExecutionContextScope *m_exe_scope;   // This is not the way to store the evaluation point state, it is just
450                                            // a cache of the lookup, and gets thrown away when we update.
451        bool             m_needs_update;
452        bool             m_first_update;
453
454        lldb::TargetSP   m_target_sp;
455        lldb::ProcessSP  m_process_sp;
456        lldb::user_id_t  m_thread_id;
457        StackID          m_stack_id;
458        ProcessModID     m_mod_id; // This is the stop id when this ValueObject was last evaluated.
459    };
460
461    const EvaluationPoint &
462    GetUpdatePoint () const
463    {
464        return m_update_point;
465    }
466
467    EvaluationPoint &
468    GetUpdatePoint ()
469    {
470        return m_update_point;
471    }
472
473    ExecutionContextScope *
474    GetExecutionContextScope ()
475    {
476        return m_update_point.GetExecutionContextScope();
477    }
478
479    void
480    SetNeedsUpdate ();
481
482    virtual ~ValueObject();
483
484    //------------------------------------------------------------------
485    // Sublasses must implement the functions below.
486    //------------------------------------------------------------------
487    virtual size_t
488    GetByteSize() = 0;
489
490    virtual clang::ASTContext *
491    GetClangAST () = 0;
492
493    virtual lldb::clang_type_t
494    GetClangType () = 0;
495
496    virtual lldb::ValueType
497    GetValueType() const = 0;
498
499    virtual ConstString
500    GetTypeName() = 0;
501
502    virtual lldb::LanguageType
503    GetObjectRuntimeLanguage();
504
505    virtual bool
506    IsPointerType ();
507
508    virtual bool
509    IsArrayType ();
510
511    virtual bool
512    IsScalarType ();
513
514    virtual bool
515    IsPointerOrReferenceType ();
516
517    virtual bool
518    IsPossibleCPlusPlusDynamicType ();
519
520    virtual bool
521    IsPossibleDynamicType ();
522
523    virtual bool
524    IsBaseClass ()
525    {
526        return false;
527    }
528
529    virtual bool
530    IsDereferenceOfParent ()
531    {
532        return false;
533    }
534
535    bool
536    IsIntegerType (bool &is_signed);
537
538    virtual bool
539    GetBaseClassPath (Stream &s);
540
541    virtual void
542    GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eDereferencePointers);
543
544    lldb::ValueObjectSP
545    GetValueForExpressionPath(const char* expression,
546                              const char** first_unparsed = NULL,
547                              ExpressionPathScanEndReason* reason_to_stop = NULL,
548                              ExpressionPathEndResultType* final_value_type = NULL,
549                              const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
550                              ExpressionPathAftermath* final_task_on_target = NULL);
551
552    int
553    GetValuesForExpressionPath(const char* expression,
554                               lldb::ValueObjectListSP& list,
555                               const char** first_unparsed = NULL,
556                               ExpressionPathScanEndReason* reason_to_stop = NULL,
557                               ExpressionPathEndResultType* final_value_type = NULL,
558                               const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
559                               ExpressionPathAftermath* final_task_on_target = NULL);
560
561    virtual bool
562    IsInScope ()
563    {
564        return true;
565    }
566
567    virtual off_t
568    GetByteOffset()
569    {
570        return 0;
571    }
572
573    virtual uint32_t
574    GetBitfieldBitSize()
575    {
576        return 0;
577    }
578
579    virtual uint32_t
580    GetBitfieldBitOffset()
581    {
582        return 0;
583    }
584
585    virtual bool
586    IsArrayItemForPointer()
587    {
588        return m_is_array_item_for_pointer;
589    }
590
591    virtual bool
592    SetClangAST (clang::ASTContext *ast)
593    {
594        return false;
595    }
596
597    virtual const char *
598    GetValueAsCString ();
599
600    virtual unsigned long long
601    GetValueAsUnsigned();
602
603    virtual bool
604    SetValueFromCString (const char *value_str);
605
606    // Return the module associated with this value object in case the
607    // value is from an executable file and might have its data in
608    // sections of the file. This can be used for variables.
609    virtual Module *
610    GetModule()
611    {
612        if (m_parent)
613            return m_parent->GetModule();
614        return NULL;
615    }
616    //------------------------------------------------------------------
617    // The functions below should NOT be modified by sublasses
618    //------------------------------------------------------------------
619    const Error &
620    GetError();
621
622    const ConstString &
623    GetName() const;
624
625    virtual lldb::ValueObjectSP
626    GetChildAtIndex (uint32_t idx, bool can_create);
627
628    virtual lldb::ValueObjectSP
629    GetChildMemberWithName (const ConstString &name, bool can_create);
630
631    virtual uint32_t
632    GetIndexOfChildWithName (const ConstString &name);
633
634    uint32_t
635    GetNumChildren ();
636
637    const Value &
638    GetValue() const;
639
640    Value &
641    GetValue();
642
643    virtual bool
644    ResolveValue (Scalar &scalar);
645
646    const char *
647    GetLocationAsCString ();
648
649    const char *
650    GetSummaryAsCString ();
651
652    const char *
653    GetObjectDescription ();
654
655    bool
656    GetPrintableRepresentation(Stream& s,
657                               ValueObjectRepresentationStyle val_obj_display = eDisplaySummary,
658                               lldb::Format custom_format = lldb::eFormatInvalid);
659
660    bool
661    DumpPrintableRepresentation(Stream& s,
662                                ValueObjectRepresentationStyle val_obj_display = eDisplaySummary,
663                                lldb::Format custom_format = lldb::eFormatInvalid,
664                                bool only_special = false);
665    bool
666    GetValueIsValid () const;
667
668    bool
669    GetValueDidChange ();
670
671    bool
672    UpdateValueIfNeeded (bool update_format = true);
673
674    bool
675    UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true);
676
677    void
678    UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues);
679
680    DataExtractor &
681    GetDataExtractor ();
682
683    lldb::ValueObjectSP
684    GetSP ()
685    {
686        return m_manager->GetSharedPointer(this);
687    }
688
689protected:
690    void
691    AddSyntheticChild (const ConstString &key,
692                       ValueObject *valobj);
693public:
694    lldb::ValueObjectSP
695    GetSyntheticChild (const ConstString &key) const;
696
697    lldb::ValueObjectSP
698    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
699
700    lldb::ValueObjectSP
701    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
702
703    lldb::ValueObjectSP
704    GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
705
706    lldb::ValueObjectSP
707    GetSyntheticExpressionPathChild(const char* expression, bool can_create);
708
709    virtual lldb::ValueObjectSP
710    GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
711
712    lldb::ValueObjectSP
713    GetDynamicValue (lldb::DynamicValueType valueType);
714
715    lldb::ValueObjectSP
716    GetSyntheticValue (lldb::SyntheticValueType use_synthetic);
717
718    virtual bool
719    HasSyntheticValue();
720
721    virtual lldb::ValueObjectSP
722    CreateConstantValue (const ConstString &name);
723
724    virtual lldb::ValueObjectSP
725    Dereference (Error &error);
726
727    virtual lldb::ValueObjectSP
728    AddressOf (Error &error);
729
730    virtual lldb::ValueObjectSP
731    CastPointerType (const char *name,
732                     ClangASTType &ast_type);
733
734    virtual lldb::ValueObjectSP
735    CastPointerType (const char *name,
736                     lldb::TypeSP &type_sp);
737
738    // The backing bits of this value object were updated, clear any
739    // descriptive string, so we know we have to refetch them
740    virtual void
741    ValueUpdated ()
742    {
743        m_value_str.clear();
744        m_summary_str.clear();
745        m_object_desc_str.clear();
746    }
747
748    virtual bool
749    IsDynamic ()
750    {
751        return false;
752    }
753
754    static void
755    DumpValueObject (Stream &s,
756                     ValueObject *valobj)
757    {
758
759        if (!valobj)
760            return;
761
762        ValueObject::DumpValueObject(s,
763                                     valobj,
764                                     DumpValueObjectOptions::DefaultOptions());
765    }
766
767    static void
768    DumpValueObject (Stream &s,
769                     ValueObject *valobj,
770                     const char *root_valobj_name)
771    {
772
773        if (!valobj)
774            return;
775
776        ValueObject::DumpValueObject(s,
777                                     valobj,
778                                     root_valobj_name,
779                                     DumpValueObjectOptions::DefaultOptions());
780    }
781
782    static void
783    DumpValueObject (Stream &s,
784                     ValueObject *valobj,
785                     const DumpValueObjectOptions& options)
786    {
787
788        if (!valobj)
789            return;
790
791        ValueObject::DumpValueObject(s,
792                                     valobj,
793                                     valobj->GetName().AsCString(),
794                                     options.m_ptr_depth,
795                                     0,
796                                     options.m_max_depth,
797                                     options.m_show_types,
798                                     options.m_show_location,
799                                     options.m_use_objc,
800                                     options.m_use_dynamic,
801                                     options.m_use_synthetic,
802                                     options.m_scope_already_checked,
803                                     options.m_flat_output,
804                                     options.m_omit_summary_depth,
805                                     options.m_ignore_cap);
806    }
807
808    static void
809    DumpValueObject (Stream &s,
810                     ValueObject *valobj,
811                     const char *root_valobj_name,
812                     const DumpValueObjectOptions& options)
813    {
814
815        if (!valobj)
816            return;
817
818        ValueObject::DumpValueObject(s,
819                                     valobj,
820                                     root_valobj_name,
821                                     options.m_ptr_depth,
822                                     0,
823                                     options.m_max_depth,
824                                     options.m_show_types,
825                                     options.m_show_location,
826                                     options.m_use_objc,
827                                     options.m_use_dynamic,
828                                     options.m_use_synthetic,
829                                     options.m_scope_already_checked,
830                                     options.m_flat_output,
831                                     options.m_omit_summary_depth,
832                                     options.m_ignore_cap);
833    }
834
835    static void
836    DumpValueObject (Stream &s,
837                     ValueObject *valobj,
838                     const char *root_valobj_name,
839                     uint32_t ptr_depth,
840                     uint32_t curr_depth,
841                     uint32_t max_depth,
842                     bool show_types,
843                     bool show_location,
844                     bool use_objc,
845                     lldb::DynamicValueType use_dynamic,
846                     bool use_synthetic,
847                     bool scope_already_checked,
848                     bool flat_output,
849                     uint32_t omit_summary_depth,
850                     bool ignore_cap);
851
852    // returns true if this is a char* or a char[]
853    // if it is a char* and check_pointer is true,
854    // it also checks that the pointer is valid
855    bool
856    IsCStringContainer(bool check_pointer = false);
857
858    void
859    ReadPointedString(Stream& s,
860                      Error& error,
861                      uint32_t max_length = 0,
862                      bool honor_array = true,
863                      lldb::Format item_format = lldb::eFormatCharArray);
864
865    bool
866    GetIsConstant () const
867    {
868        return m_update_point.IsConstant();
869    }
870
871    void
872    SetIsConstant ()
873    {
874        m_update_point.SetIsConstant();
875    }
876
877    lldb::Format
878    GetFormat () const
879    {
880        if (m_parent && m_format == lldb::eFormatDefault)
881            return m_parent->GetFormat();
882        return m_format;
883    }
884
885    void
886    SetIsExpressionResult(bool expr)
887    {
888        m_is_expression_result = expr;
889    }
890
891    bool
892    GetIsExpressionResult()
893    {
894        return m_is_expression_result;
895    }
896
897    void
898    SetFormat (lldb::Format format)
899    {
900        if (format != m_format)
901            m_value_str.clear();
902        m_format = format;
903    }
904
905    void
906    SetCustomSummaryFormat(lldb::SummaryFormatSP format)
907    {
908        m_forced_summary_format = format;
909        m_user_id_of_forced_summary = m_update_point.GetModID();
910        m_summary_str.clear();
911    }
912
913    lldb::SummaryFormatSP
914    GetCustomSummaryFormat()
915    {
916        return m_forced_summary_format;
917    }
918
919    void
920    ClearCustomSummaryFormat()
921    {
922        m_forced_summary_format.reset();
923        m_summary_str.clear();
924    }
925
926    bool
927    HasCustomSummaryFormat()
928    {
929        return (m_forced_summary_format.get());
930    }
931
932    lldb::SummaryFormatSP
933    GetSummaryFormat()
934    {
935        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
936        if (HasCustomSummaryFormat())
937            return m_forced_summary_format;
938        return m_last_summary_format;
939    }
940
941    // Use GetParent for display purposes, but if you want to tell the parent to update itself
942    // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
943    // displaying, they are really siblings, so for display it needs to route through to its grandparent.
944    virtual ValueObject *
945    GetParent()
946    {
947        return m_parent;
948    }
949
950    virtual const ValueObject *
951    GetParent() const
952    {
953        return m_parent;
954    }
955
956    ValueObject *
957    GetNonBaseClassParent();
958
959    void
960    SetPointersPointToLoadAddrs (bool b)
961    {
962        m_pointers_point_to_load_addrs = b;
963    }
964
965protected:
966    typedef ClusterManager<ValueObject> ValueObjectManager;
967
968    //------------------------------------------------------------------
969    // Classes that inherit from ValueObject can see and modify these
970    //------------------------------------------------------------------
971    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
972    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last
973                                        // updated.  When we are asked to update the value object, we check whether
974                                        // the context & stop id are the same before updating.
975    ConstString         m_name;         // The name of this object
976    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
977    Value               m_value;
978    Error               m_error;        // An error object that can describe any errors that occur when updating values.
979    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
980    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
981    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
982    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
983    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
984                                              // in that the summary is consed up by us, the object_desc_string is builtin.
985
986    ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
987                                        // without a parent.)  The manager gets passed through all the generations of
988                                        // dependent objects, and will keep the whole cluster of objects alive as long
989                                        // as a shared pointer to any of them has been handed out.  Shared pointers to
990                                        // value objects must always be made with the GetSP method.
991
992    std::vector<ValueObject *> m_children;
993    std::map<ConstString, ValueObject *> m_synthetic_children;
994    ValueObject *m_dynamic_value;
995    ValueObject *m_synthetic_value;
996    lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
997                                             // as an independent ValueObjectConstResult, which isn't managed by us.
998    ValueObject *m_deref_valobj;
999
1000    lldb::Format                m_format;
1001    uint32_t                    m_last_format_mgr_revision;
1002    lldb::DynamicValueType      m_last_format_mgr_dynamic;
1003    lldb::SummaryFormatSP       m_last_summary_format;
1004    lldb::SummaryFormatSP       m_forced_summary_format;
1005    lldb::ValueFormatSP         m_last_value_format;
1006    lldb::SyntheticChildrenSP   m_last_synthetic_filter;
1007    ProcessModID                m_user_id_of_forced_summary;
1008
1009    bool                m_value_is_valid:1,
1010                        m_value_did_change:1,
1011                        m_children_count_valid:1,
1012                        m_old_value_valid:1,
1013                        m_pointers_point_to_load_addrs:1,
1014                        m_is_deref_of_parent:1,
1015                        m_is_array_item_for_pointer:1,
1016                        m_is_bitfield_for_scalar:1,
1017                        m_is_expression_path_child:1,
1018                        m_is_child_at_offset:1,
1019                        m_is_expression_result:1;
1020
1021    // used to prevent endless looping into GetpPrintableRepresentation()
1022    uint32_t            m_dump_printable_counter;
1023    friend class ClangExpressionDeclMap;  // For GetValue
1024    friend class ClangExpressionVariable; // For SetName
1025    friend class Target;                  // For SetName
1026
1027    //------------------------------------------------------------------
1028    // Constructors and Destructors
1029    //------------------------------------------------------------------
1030
1031    // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1032
1033    ValueObject();
1034
1035    // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1036    // through-out its lifespan.
1037
1038    ValueObject (ExecutionContextScope *exe_scope);
1039
1040    // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1041    // of its parent.
1042
1043    ValueObject (ValueObject &parent);
1044
1045    ValueObjectManager *
1046    GetManager()
1047    {
1048        return m_manager;
1049    }
1050
1051    virtual bool
1052    UpdateValue () = 0;
1053
1054    virtual void
1055    CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1056
1057    virtual void
1058    CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic);
1059
1060    // Should only be called by ValueObject::GetChildAtIndex()
1061    // Returns a ValueObject managed by this ValueObject's manager.
1062    virtual ValueObject *
1063    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
1064
1065    // Should only be called by ValueObject::GetNumChildren()
1066    virtual uint32_t
1067    CalculateNumChildren() = 0;
1068
1069    void
1070    SetNumChildren (uint32_t num_children);
1071
1072    void
1073    SetValueDidChange (bool value_changed);
1074
1075    void
1076    SetValueIsValid (bool valid);
1077
1078    void
1079    ClearUserVisibleData();
1080
1081public:
1082
1083    void
1084    SetName (const ConstString &name);
1085
1086    lldb::addr_t
1087    GetPointerValue (AddressType &address_type,
1088                     bool scalar_is_load_address);
1089
1090    lldb::addr_t
1091    GetAddressOf (AddressType &address_type,
1092                  bool scalar_is_load_address);
1093private:
1094    //------------------------------------------------------------------
1095    // For ValueObject only
1096    //------------------------------------------------------------------
1097
1098    lldb::ValueObjectSP
1099    GetValueForExpressionPath_Impl(const char* expression_cstr,
1100                                   const char** first_unparsed,
1101                                   ExpressionPathScanEndReason* reason_to_stop,
1102                                   ExpressionPathEndResultType* final_value_type,
1103                                   const GetValueForExpressionPathOptions& options,
1104                                   ExpressionPathAftermath* final_task_on_target);
1105
1106    // this method will ONLY expand [] expressions into a VOList and return
1107    // the number of elements it added to the VOList
1108    // it will NOT loop through expanding the follow-up of the expression_cstr
1109    // for all objects in the list
1110    int
1111    ExpandArraySliceExpression(const char* expression_cstr,
1112                               const char** first_unparsed,
1113                               lldb::ValueObjectSP root,
1114                               lldb::ValueObjectListSP& list,
1115                               ExpressionPathScanEndReason* reason_to_stop,
1116                               ExpressionPathEndResultType* final_value_type,
1117                               const GetValueForExpressionPathOptions& options,
1118                               ExpressionPathAftermath* final_task_on_target);
1119
1120
1121    DISALLOW_COPY_AND_ASSIGN (ValueObject);
1122
1123};
1124
1125} // namespace lldb_private
1126
1127#endif  // liblldb_ValueObject_h_
1128