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