ValueObject.h revision d6bcc0db2ffc5cf724460f8e260c5709e07ea642
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
665    GetValueIsValid () const;
666
667    bool
668    GetValueDidChange ();
669
670    bool
671    UpdateValueIfNeeded (bool update_format = true);
672
673    bool
674    UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true);
675
676    void
677    UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues);
678
679    DataExtractor &
680    GetDataExtractor ();
681
682    lldb::ValueObjectSP
683    GetSP ()
684    {
685        return m_manager->GetSharedPointer(this);
686    }
687
688protected:
689    void
690    AddSyntheticChild (const ConstString &key,
691                       ValueObject *valobj);
692public:
693    lldb::ValueObjectSP
694    GetSyntheticChild (const ConstString &key) const;
695
696    lldb::ValueObjectSP
697    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
698
699    lldb::ValueObjectSP
700    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
701
702    lldb::ValueObjectSP
703    GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
704
705    lldb::ValueObjectSP
706    GetSyntheticExpressionPathChild(const char* expression, bool can_create);
707
708    virtual lldb::ValueObjectSP
709    GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
710
711    lldb::ValueObjectSP
712    GetDynamicValue (lldb::DynamicValueType valueType);
713
714    lldb::ValueObjectSP
715    GetSyntheticValue (lldb::SyntheticValueType use_synthetic);
716
717    virtual bool
718    HasSyntheticValue();
719
720    virtual lldb::ValueObjectSP
721    CreateConstantValue (const ConstString &name);
722
723    virtual lldb::ValueObjectSP
724    Dereference (Error &error);
725
726    virtual lldb::ValueObjectSP
727    AddressOf (Error &error);
728
729    virtual lldb::ValueObjectSP
730    CastPointerType (const char *name,
731                     ClangASTType &ast_type);
732
733    virtual lldb::ValueObjectSP
734    CastPointerType (const char *name,
735                     lldb::TypeSP &type_sp);
736
737    // The backing bits of this value object were updated, clear any
738    // descriptive string, so we know we have to refetch them
739    virtual void
740    ValueUpdated ()
741    {
742        m_value_str.clear();
743        m_summary_str.clear();
744        m_object_desc_str.clear();
745    }
746
747    virtual bool
748    IsDynamic ()
749    {
750        return false;
751    }
752
753    static void
754    DumpValueObject (Stream &s,
755                     ValueObject *valobj)
756    {
757
758        if (!valobj)
759            return;
760
761        ValueObject::DumpValueObject(s,
762                                     valobj,
763                                     DumpValueObjectOptions::DefaultOptions());
764    }
765
766    static void
767    DumpValueObject (Stream &s,
768                     ValueObject *valobj,
769                     const char *root_valobj_name)
770    {
771
772        if (!valobj)
773            return;
774
775        ValueObject::DumpValueObject(s,
776                                     valobj,
777                                     root_valobj_name,
778                                     DumpValueObjectOptions::DefaultOptions());
779    }
780
781    static void
782    DumpValueObject (Stream &s,
783                     ValueObject *valobj,
784                     const DumpValueObjectOptions& options)
785    {
786
787        if (!valobj)
788            return;
789
790        ValueObject::DumpValueObject(s,
791                                     valobj,
792                                     valobj->GetName().AsCString(),
793                                     options.m_ptr_depth,
794                                     0,
795                                     options.m_max_depth,
796                                     options.m_show_types,
797                                     options.m_show_location,
798                                     options.m_use_objc,
799                                     options.m_use_dynamic,
800                                     options.m_use_synthetic,
801                                     options.m_scope_already_checked,
802                                     options.m_flat_output,
803                                     options.m_omit_summary_depth,
804                                     options.m_ignore_cap);
805    }
806
807    static void
808    DumpValueObject (Stream &s,
809                     ValueObject *valobj,
810                     const char *root_valobj_name,
811                     const DumpValueObjectOptions& options)
812    {
813
814        if (!valobj)
815            return;
816
817        ValueObject::DumpValueObject(s,
818                                     valobj,
819                                     root_valobj_name,
820                                     options.m_ptr_depth,
821                                     0,
822                                     options.m_max_depth,
823                                     options.m_show_types,
824                                     options.m_show_location,
825                                     options.m_use_objc,
826                                     options.m_use_dynamic,
827                                     options.m_use_synthetic,
828                                     options.m_scope_already_checked,
829                                     options.m_flat_output,
830                                     options.m_omit_summary_depth,
831                                     options.m_ignore_cap);
832    }
833
834    static void
835    DumpValueObject (Stream &s,
836                     ValueObject *valobj,
837                     const char *root_valobj_name,
838                     uint32_t ptr_depth,
839                     uint32_t curr_depth,
840                     uint32_t max_depth,
841                     bool show_types,
842                     bool show_location,
843                     bool use_objc,
844                     lldb::DynamicValueType use_dynamic,
845                     bool use_synthetic,
846                     bool scope_already_checked,
847                     bool flat_output,
848                     uint32_t omit_summary_depth,
849                     bool ignore_cap);
850
851    // returns true if this is a char* or a char[]
852    // if it is a char* and check_pointer is true,
853    // it also checks that the pointer is valid
854    bool
855    IsCStringContainer(bool check_pointer = false);
856
857    void
858    ReadPointedString(Stream& s,
859                      Error& error,
860                      uint32_t max_length = 0,
861                      bool honor_array = true,
862                      lldb::Format item_format = lldb::eFormatCharArray);
863
864    bool
865    GetIsConstant () const
866    {
867        return m_update_point.IsConstant();
868    }
869
870    void
871    SetIsConstant ()
872    {
873        m_update_point.SetIsConstant();
874    }
875
876    lldb::Format
877    GetFormat () const
878    {
879        if (m_parent && m_format == lldb::eFormatDefault)
880            return m_parent->GetFormat();
881        return m_format;
882    }
883
884    void
885    SetIsExpressionResult(bool expr)
886    {
887        m_is_expression_result = expr;
888    }
889
890    bool
891    GetIsExpressionResult()
892    {
893        return m_is_expression_result;
894    }
895
896    void
897    SetFormat (lldb::Format format)
898    {
899        if (format != m_format)
900            m_value_str.clear();
901        m_format = format;
902    }
903
904    void
905    SetCustomSummaryFormat(lldb::SummaryFormatSP format)
906    {
907        m_forced_summary_format = format;
908        m_user_id_of_forced_summary = m_update_point.GetModID();
909        m_summary_str.clear();
910    }
911
912    lldb::SummaryFormatSP
913    GetCustomSummaryFormat()
914    {
915        return m_forced_summary_format;
916    }
917
918    void
919    ClearCustomSummaryFormat()
920    {
921        m_forced_summary_format.reset();
922        m_summary_str.clear();
923    }
924
925    bool
926    HasCustomSummaryFormat()
927    {
928        return (m_forced_summary_format.get());
929    }
930
931    lldb::SummaryFormatSP
932    GetSummaryFormat()
933    {
934        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
935        if (HasCustomSummaryFormat())
936            return m_forced_summary_format;
937        return m_last_summary_format;
938    }
939
940    // Use GetParent for display purposes, but if you want to tell the parent to update itself
941    // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
942    // displaying, they are really siblings, so for display it needs to route through to its grandparent.
943    virtual ValueObject *
944    GetParent()
945    {
946        return m_parent;
947    }
948
949    virtual const ValueObject *
950    GetParent() const
951    {
952        return m_parent;
953    }
954
955    ValueObject *
956    GetNonBaseClassParent();
957
958    void
959    SetPointersPointToLoadAddrs (bool b)
960    {
961        m_pointers_point_to_load_addrs = b;
962    }
963
964protected:
965    typedef ClusterManager<ValueObject> ValueObjectManager;
966
967    //------------------------------------------------------------------
968    // Classes that inherit from ValueObject can see and modify these
969    //------------------------------------------------------------------
970    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
971    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last
972                                        // updated.  When we are asked to update the value object, we check whether
973                                        // the context & stop id are the same before updating.
974    ConstString         m_name;         // The name of this object
975    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
976    Value               m_value;
977    Error               m_error;        // An error object that can describe any errors that occur when updating values.
978    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
979    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
980    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
981    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
982    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
983                                              // in that the summary is consed up by us, the object_desc_string is builtin.
984
985    ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
986                                        // without a parent.)  The manager gets passed through all the generations of
987                                        // dependent objects, and will keep the whole cluster of objects alive as long
988                                        // as a shared pointer to any of them has been handed out.  Shared pointers to
989                                        // value objects must always be made with the GetSP method.
990
991    std::vector<ValueObject *> m_children;
992    std::map<ConstString, ValueObject *> m_synthetic_children;
993    ValueObject *m_dynamic_value;
994    ValueObject *m_synthetic_value;
995    lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
996                                             // as an independent ValueObjectConstResult, which isn't managed by us.
997    ValueObject *m_deref_valobj;
998
999    lldb::Format                m_format;
1000    uint32_t                    m_last_format_mgr_revision;
1001    lldb::DynamicValueType      m_last_format_mgr_dynamic;
1002    lldb::SummaryFormatSP       m_last_summary_format;
1003    lldb::SummaryFormatSP       m_forced_summary_format;
1004    lldb::ValueFormatSP         m_last_value_format;
1005    lldb::SyntheticChildrenSP   m_last_synthetic_filter;
1006    ProcessModID                m_user_id_of_forced_summary;
1007
1008    bool                m_value_is_valid:1,
1009                        m_value_did_change:1,
1010                        m_children_count_valid:1,
1011                        m_old_value_valid:1,
1012                        m_pointers_point_to_load_addrs:1,
1013                        m_is_deref_of_parent:1,
1014                        m_is_array_item_for_pointer:1,
1015                        m_is_bitfield_for_scalar:1,
1016                        m_is_expression_path_child:1,
1017                        m_is_child_at_offset:1,
1018                        m_is_expression_result:1;
1019
1020    // used to prevent endless looping into GetpPrintableRepresentation()
1021    uint32_t            m_dump_printable_counter;
1022    friend class ClangExpressionDeclMap;  // For GetValue
1023    friend class ClangExpressionVariable; // For SetName
1024    friend class Target;                  // For SetName
1025
1026    //------------------------------------------------------------------
1027    // Constructors and Destructors
1028    //------------------------------------------------------------------
1029
1030    // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1031
1032    ValueObject();
1033
1034    // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1035    // through-out its lifespan.
1036
1037    ValueObject (ExecutionContextScope *exe_scope);
1038
1039    // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1040    // of its parent.
1041
1042    ValueObject (ValueObject &parent);
1043
1044    ValueObjectManager *
1045    GetManager()
1046    {
1047        return m_manager;
1048    }
1049
1050    virtual bool
1051    UpdateValue () = 0;
1052
1053    virtual void
1054    CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1055
1056    virtual void
1057    CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic);
1058
1059    // Should only be called by ValueObject::GetChildAtIndex()
1060    // Returns a ValueObject managed by this ValueObject's manager.
1061    virtual ValueObject *
1062    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
1063
1064    // Should only be called by ValueObject::GetNumChildren()
1065    virtual uint32_t
1066    CalculateNumChildren() = 0;
1067
1068    void
1069    SetNumChildren (uint32_t num_children);
1070
1071    void
1072    SetValueDidChange (bool value_changed);
1073
1074    void
1075    SetValueIsValid (bool valid);
1076
1077    void
1078    ClearUserVisibleData();
1079
1080public:
1081
1082    void
1083    SetName (const ConstString &name);
1084
1085    lldb::addr_t
1086    GetPointerValue (AddressType &address_type,
1087                     bool scalar_is_load_address);
1088
1089    lldb::addr_t
1090    GetAddressOf (AddressType &address_type,
1091                  bool scalar_is_load_address);
1092private:
1093    //------------------------------------------------------------------
1094    // For ValueObject only
1095    //------------------------------------------------------------------
1096
1097    lldb::ValueObjectSP
1098    GetValueForExpressionPath_Impl(const char* expression_cstr,
1099                                   const char** first_unparsed,
1100                                   ExpressionPathScanEndReason* reason_to_stop,
1101                                   ExpressionPathEndResultType* final_value_type,
1102                                   const GetValueForExpressionPathOptions& options,
1103                                   ExpressionPathAftermath* final_task_on_target);
1104
1105    // this method will ONLY expand [] expressions into a VOList and return
1106    // the number of elements it added to the VOList
1107    // it will NOT loop through expanding the follow-up of the expression_cstr
1108    // for all objects in the list
1109    int
1110    ExpandArraySliceExpression(const char* expression_cstr,
1111                               const char** first_unparsed,
1112                               lldb::ValueObjectSP root,
1113                               lldb::ValueObjectListSP& list,
1114                               ExpressionPathScanEndReason* reason_to_stop,
1115                               ExpressionPathEndResultType* final_value_type,
1116                               const GetValueForExpressionPathOptions& options,
1117                               ExpressionPathAftermath* final_task_on_target);
1118
1119
1120    DISALLOW_COPY_AND_ASSIGN (ValueObject);
1121
1122};
1123
1124} // namespace lldb_private
1125
1126#endif  // liblldb_ValueObject_h_
1127