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