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