1 //===-- ValueObject.cpp -----------------------------------------*- 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 #include "lldb/lldb-python.h"
11 
12 #include "lldb/Core/ValueObject.h"
13 
14 // C Includes
15 #include <stdlib.h>
16 
17 // C++ Includes
18 // Other libraries and framework includes
19 #include "llvm/Support/raw_ostream.h"
20 #include "clang/AST/Type.h"
21 
22 // Project includes
23 #include "lldb/Core/DataBufferHeap.h"
24 #include "lldb/Core/Debugger.h"
25 #include "lldb/Core/Log.h"
26 #include "lldb/Core/Module.h"
27 #include "lldb/Core/StreamString.h"
28 #include "lldb/Core/ValueObjectCast.h"
29 #include "lldb/Core/ValueObjectChild.h"
30 #include "lldb/Core/ValueObjectConstResult.h"
31 #include "lldb/Core/ValueObjectDynamicValue.h"
32 #include "lldb/Core/ValueObjectList.h"
33 #include "lldb/Core/ValueObjectMemory.h"
34 #include "lldb/Core/ValueObjectSyntheticFilter.h"
35 
36 #include "lldb/DataFormatters/DataVisualization.h"
37 #include "lldb/DataFormatters/StringPrinter.h"
38 #include "lldb/DataFormatters/ValueObjectPrinter.h"
39 
40 #include "lldb/Expression/ClangExpressionVariable.h"
41 #include "lldb/Expression/ClangPersistentVariables.h"
42 
43 #include "lldb/Host/Endian.h"
44 
45 #include "lldb/Interpreter/CommandInterpreter.h"
46 #include "lldb/Interpreter/ScriptInterpreterPython.h"
47 
48 #include "lldb/Symbol/ClangASTType.h"
49 #include "lldb/Symbol/ClangASTContext.h"
50 #include "lldb/Symbol/CompileUnit.h"
51 #include "lldb/Symbol/Type.h"
52 
53 #include "lldb/Target/ExecutionContext.h"
54 #include "lldb/Target/LanguageRuntime.h"
55 #include "lldb/Target/ObjCLanguageRuntime.h"
56 #include "lldb/Target/Process.h"
57 #include "lldb/Target/RegisterContext.h"
58 #include "lldb/Target/SectionLoadList.h"
59 #include "lldb/Target/Target.h"
60 #include "lldb/Target/Thread.h"
61 
62 using namespace lldb;
63 using namespace lldb_private;
64 using namespace lldb_utility;
65 
66 static user_id_t g_value_obj_uid = 0;
67 
68 //----------------------------------------------------------------------
69 // ValueObject constructor
70 //----------------------------------------------------------------------
71 ValueObject::ValueObject (ValueObject &parent) :
72     UserID (++g_value_obj_uid), // Unique identifier for every value object
73     m_parent (&parent),
74     m_root (NULL),
75     m_update_point (parent.GetUpdatePoint ()),
76     m_name (),
77     m_data (),
78     m_value (),
79     m_error (),
80     m_value_str (),
81     m_old_value_str (),
82     m_location_str (),
83     m_summary_str (),
84     m_object_desc_str (),
85     m_validation_result(),
86     m_manager(parent.GetManager()),
87     m_children (),
88     m_synthetic_children (),
89     m_dynamic_value (NULL),
90     m_synthetic_value(NULL),
91     m_deref_valobj(NULL),
92     m_format (eFormatDefault),
93     m_last_format (eFormatDefault),
94     m_last_format_mgr_revision(0),
95     m_type_summary_sp(),
96     m_type_format_sp(),
97     m_synthetic_children_sp(),
98     m_type_validator_sp(),
99     m_user_id_of_forced_summary(),
100     m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
101     m_value_is_valid (false),
102     m_value_did_change (false),
103     m_children_count_valid (false),
104     m_old_value_valid (false),
105     m_is_deref_of_parent (false),
106     m_is_array_item_for_pointer(false),
107     m_is_bitfield_for_scalar(false),
108     m_is_child_at_offset(false),
109     m_is_getting_summary(false),
110     m_did_calculate_complete_objc_class_type(false)
111 {
112     m_manager->ManageObject(this);
113 }
114 
115 //----------------------------------------------------------------------
116 // ValueObject constructor
117 //----------------------------------------------------------------------
118 ValueObject::ValueObject (ExecutionContextScope *exe_scope,
119                           AddressType child_ptr_or_ref_addr_type) :
120     UserID (++g_value_obj_uid), // Unique identifier for every value object
121     m_parent (NULL),
122     m_root (NULL),
123     m_update_point (exe_scope),
124     m_name (),
125     m_data (),
126     m_value (),
127     m_error (),
128     m_value_str (),
129     m_old_value_str (),
130     m_location_str (),
131     m_summary_str (),
132     m_object_desc_str (),
133     m_validation_result(),
134     m_manager(),
135     m_children (),
136     m_synthetic_children (),
137     m_dynamic_value (NULL),
138     m_synthetic_value(NULL),
139     m_deref_valobj(NULL),
140     m_format (eFormatDefault),
141     m_last_format (eFormatDefault),
142     m_last_format_mgr_revision(0),
143     m_type_summary_sp(),
144     m_type_format_sp(),
145     m_synthetic_children_sp(),
146     m_type_validator_sp(),
147     m_user_id_of_forced_summary(),
148     m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
149     m_value_is_valid (false),
150     m_value_did_change (false),
151     m_children_count_valid (false),
152     m_old_value_valid (false),
153     m_is_deref_of_parent (false),
154     m_is_array_item_for_pointer(false),
155     m_is_bitfield_for_scalar(false),
156     m_is_child_at_offset(false),
157     m_is_getting_summary(false),
158     m_did_calculate_complete_objc_class_type(false)
159 {
160     m_manager = new ValueObjectManager();
161     m_manager->ManageObject (this);
162 }
163 
164 //----------------------------------------------------------------------
165 // Destructor
166 //----------------------------------------------------------------------
167 ValueObject::~ValueObject ()
168 {
169 }
170 
171 bool
172 ValueObject::UpdateValueIfNeeded (bool update_format)
173 {
174 
175     bool did_change_formats = false;
176 
177     if (update_format)
178         did_change_formats = UpdateFormatsIfNeeded();
179 
180     // If this is a constant value, then our success is predicated on whether
181     // we have an error or not
182     if (GetIsConstant())
183     {
184         // if you are constant, things might still have changed behind your back
185         // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
186         // in this case, your value has not changed, but "computed" entries might have, so you might now have
187         // a different summary, or a different object description. clear these so we will recompute them
188         if (update_format && !did_change_formats)
189             ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
190         return m_error.Success();
191     }
192 
193     bool first_update = m_update_point.IsFirstEvaluation();
194 
195     if (m_update_point.NeedsUpdating())
196     {
197         m_update_point.SetUpdated();
198 
199         // Save the old value using swap to avoid a string copy which
200         // also will clear our m_value_str
201         if (m_value_str.empty())
202         {
203             m_old_value_valid = false;
204         }
205         else
206         {
207             m_old_value_valid = true;
208             m_old_value_str.swap (m_value_str);
209             ClearUserVisibleData(eClearUserVisibleDataItemsValue);
210         }
211 
212         ClearUserVisibleData();
213 
214         if (IsInScope())
215         {
216             const bool value_was_valid = GetValueIsValid();
217             SetValueDidChange (false);
218 
219             m_error.Clear();
220 
221             // Call the pure virtual function to update the value
222             bool success = UpdateValue ();
223 
224             SetValueIsValid (success);
225 
226             if (first_update)
227                 SetValueDidChange (false);
228             else if (!m_value_did_change && success == false)
229             {
230                 // The value wasn't gotten successfully, so we mark this
231                 // as changed if the value used to be valid and now isn't
232                 SetValueDidChange (value_was_valid);
233             }
234         }
235         else
236         {
237             m_error.SetErrorString("out of scope");
238         }
239     }
240     return m_error.Success();
241 }
242 
243 bool
244 ValueObject::UpdateFormatsIfNeeded()
245 {
246     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
247     if (log)
248         log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
249                     GetName().GetCString(), static_cast<void*>(this),
250                     m_last_format_mgr_revision,
251                     DataVisualization::GetCurrentRevision());
252 
253     bool any_change = false;
254 
255     if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
256     {
257         m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
258         any_change = true;
259 
260         SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
261         SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
262 #ifndef LLDB_DISABLE_PYTHON
263         SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
264 #endif
265         SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
266     }
267 
268     return any_change;
269 }
270 
271 void
272 ValueObject::SetNeedsUpdate ()
273 {
274     m_update_point.SetNeedsUpdate();
275     // We have to clear the value string here so ConstResult children will notice if their values are
276     // changed by hand (i.e. with SetValueAsCString).
277     ClearUserVisibleData(eClearUserVisibleDataItemsValue);
278 }
279 
280 void
281 ValueObject::ClearDynamicTypeInformation ()
282 {
283     m_children_count_valid = false;
284     m_did_calculate_complete_objc_class_type = false;
285     m_last_format_mgr_revision = 0;
286     m_override_type = ClangASTType();
287     SetValueFormat(lldb::TypeFormatImplSP());
288     SetSummaryFormat(lldb::TypeSummaryImplSP());
289     SetSyntheticChildren(lldb::SyntheticChildrenSP());
290 }
291 
292 ClangASTType
293 ValueObject::MaybeCalculateCompleteType ()
294 {
295     ClangASTType clang_type(GetClangTypeImpl());
296 
297     if (m_did_calculate_complete_objc_class_type)
298     {
299         if (m_override_type.IsValid())
300             return m_override_type;
301         else
302             return clang_type;
303     }
304 
305     ClangASTType class_type;
306     bool is_pointer_type = false;
307 
308     if (clang_type.IsObjCObjectPointerType(&class_type))
309     {
310         is_pointer_type = true;
311     }
312     else if (clang_type.IsObjCObjectOrInterfaceType())
313     {
314         class_type = clang_type;
315     }
316     else
317     {
318         return clang_type;
319     }
320 
321     m_did_calculate_complete_objc_class_type = true;
322 
323     if (class_type)
324     {
325         ConstString class_name (class_type.GetConstTypeName());
326 
327         if (class_name)
328         {
329             ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
330 
331             if (process_sp)
332             {
333                 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
334 
335                 if (objc_language_runtime)
336                 {
337                     TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
338 
339                     if (complete_objc_class_type_sp)
340                     {
341                         ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
342 
343                         if (complete_class.GetCompleteType())
344                         {
345                             if (is_pointer_type)
346                             {
347                                 m_override_type = complete_class.GetPointerType();
348                             }
349                             else
350                             {
351                                 m_override_type = complete_class;
352                             }
353 
354                             if (m_override_type.IsValid())
355                                 return m_override_type;
356                         }
357                     }
358                 }
359             }
360         }
361     }
362     return clang_type;
363 }
364 
365 ClangASTType
366 ValueObject::GetClangType ()
367 {
368     return MaybeCalculateCompleteType();
369 }
370 
371 TypeImpl
372 ValueObject::GetTypeImpl ()
373 {
374     return TypeImpl(GetClangType());
375 }
376 
377 DataExtractor &
378 ValueObject::GetDataExtractor ()
379 {
380     UpdateValueIfNeeded(false);
381     return m_data;
382 }
383 
384 const Error &
385 ValueObject::GetError()
386 {
387     UpdateValueIfNeeded(false);
388     return m_error;
389 }
390 
391 const ConstString &
392 ValueObject::GetName() const
393 {
394     return m_name;
395 }
396 
397 const char *
398 ValueObject::GetLocationAsCString ()
399 {
400     return GetLocationAsCStringImpl(m_value,
401                                     m_data);
402 }
403 
404 const char *
405 ValueObject::GetLocationAsCStringImpl (const Value& value,
406                                        const DataExtractor& data)
407 {
408     if (UpdateValueIfNeeded(false))
409     {
410         if (m_location_str.empty())
411         {
412             StreamString sstr;
413 
414             Value::ValueType value_type = value.GetValueType();
415 
416             switch (value_type)
417             {
418             case Value::eValueTypeScalar:
419             case Value::eValueTypeVector:
420                 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
421                 {
422                     RegisterInfo *reg_info = value.GetRegisterInfo();
423                     if (reg_info)
424                     {
425                         if (reg_info->name)
426                             m_location_str = reg_info->name;
427                         else if (reg_info->alt_name)
428                             m_location_str = reg_info->alt_name;
429                         if (m_location_str.empty())
430                             m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
431                     }
432                 }
433                 if (m_location_str.empty())
434                     m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
435                 break;
436 
437             case Value::eValueTypeLoadAddress:
438             case Value::eValueTypeFileAddress:
439             case Value::eValueTypeHostAddress:
440                 {
441                     uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
442                     sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
443                     m_location_str.swap(sstr.GetString());
444                 }
445                 break;
446             }
447         }
448     }
449     return m_location_str.c_str();
450 }
451 
452 Value &
453 ValueObject::GetValue()
454 {
455     return m_value;
456 }
457 
458 const Value &
459 ValueObject::GetValue() const
460 {
461     return m_value;
462 }
463 
464 bool
465 ValueObject::ResolveValue (Scalar &scalar)
466 {
467     if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
468     {
469         ExecutionContext exe_ctx (GetExecutionContextRef());
470         Value tmp_value(m_value);
471         scalar = tmp_value.ResolveValue(&exe_ctx);
472         if (scalar.IsValid())
473         {
474             const uint32_t bitfield_bit_size = GetBitfieldBitSize();
475             if (bitfield_bit_size)
476                 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
477             return true;
478         }
479     }
480     return false;
481 }
482 
483 bool
484 ValueObject::GetValueIsValid () const
485 {
486     return m_value_is_valid;
487 }
488 
489 
490 void
491 ValueObject::SetValueIsValid (bool b)
492 {
493     m_value_is_valid = b;
494 }
495 
496 bool
497 ValueObject::GetValueDidChange ()
498 {
499     GetValueAsCString ();
500     return m_value_did_change;
501 }
502 
503 void
504 ValueObject::SetValueDidChange (bool value_changed)
505 {
506     m_value_did_change = value_changed;
507 }
508 
509 ValueObjectSP
510 ValueObject::GetChildAtIndex (size_t idx, bool can_create)
511 {
512     ValueObjectSP child_sp;
513     // We may need to update our value if we are dynamic
514     if (IsPossibleDynamicType ())
515         UpdateValueIfNeeded(false);
516     if (idx < GetNumChildren())
517     {
518         // Check if we have already made the child value object?
519         if (can_create && !m_children.HasChildAtIndex(idx))
520         {
521             // No we haven't created the child at this index, so lets have our
522             // subclass do it and cache the result for quick future access.
523             m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
524         }
525 
526         ValueObject* child = m_children.GetChildAtIndex(idx);
527         if (child != NULL)
528             return child->GetSP();
529     }
530     return child_sp;
531 }
532 
533 ValueObjectSP
534 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
535                                   size_t* index_of_error)
536 {
537     if (idxs.size() == 0)
538         return GetSP();
539     ValueObjectSP root(GetSP());
540     for (size_t idx : idxs)
541     {
542         root = root->GetChildAtIndex(idx, true);
543         if (!root)
544         {
545             if (index_of_error)
546                 *index_of_error = idx;
547             return root;
548         }
549     }
550     return root;
551 }
552 
553 ValueObjectSP
554 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
555                                   size_t* index_of_error)
556 {
557     if (idxs.size() == 0)
558         return GetSP();
559     ValueObjectSP root(GetSP());
560     for (std::pair<size_t, bool> idx : idxs)
561     {
562         root = root->GetChildAtIndex(idx.first, idx.second);
563         if (!root)
564         {
565             if (index_of_error)
566                 *index_of_error = idx.first;
567             return root;
568         }
569     }
570     return root;
571 }
572 
573 lldb::ValueObjectSP
574 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
575                                   size_t* index_of_error)
576 {
577     if (idxs.size() == 0)
578         return GetSP();
579     ValueObjectSP root(GetSP());
580     for (size_t idx : idxs)
581     {
582         root = root->GetChildAtIndex(idx, true);
583         if (!root)
584         {
585             if (index_of_error)
586                 *index_of_error = idx;
587             return root;
588         }
589     }
590     return root;
591 }
592 
593 lldb::ValueObjectSP
594 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
595                                   size_t* index_of_error)
596 {
597     if (idxs.size() == 0)
598         return GetSP();
599     ValueObjectSP root(GetSP());
600     for (std::pair<size_t, bool> idx : idxs)
601     {
602         root = root->GetChildAtIndex(idx.first, idx.second);
603         if (!root)
604         {
605             if (index_of_error)
606                 *index_of_error = idx.first;
607             return root;
608         }
609     }
610     return root;
611 }
612 
613 lldb::ValueObjectSP
614 ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
615                                  ConstString* name_of_error)
616 {
617     if (names.size() == 0)
618         return GetSP();
619     ValueObjectSP root(GetSP());
620     for (ConstString name : names)
621     {
622         root = root->GetChildMemberWithName(name, true);
623         if (!root)
624         {
625             if (name_of_error)
626                 *name_of_error = name;
627             return root;
628         }
629     }
630     return root;
631 }
632 
633 lldb::ValueObjectSP
634 ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
635                                  ConstString* name_of_error)
636 {
637     if (names.size() == 0)
638         return GetSP();
639     ValueObjectSP root(GetSP());
640     for (ConstString name : names)
641     {
642         root = root->GetChildMemberWithName(name, true);
643         if (!root)
644         {
645             if (name_of_error)
646                 *name_of_error = name;
647             return root;
648         }
649     }
650     return root;
651 }
652 
653 lldb::ValueObjectSP
654 ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
655                                  ConstString* name_of_error)
656 {
657     if (names.size() == 0)
658         return GetSP();
659     ValueObjectSP root(GetSP());
660     for (std::pair<ConstString, bool> name : names)
661     {
662         root = root->GetChildMemberWithName(name.first, name.second);
663         if (!root)
664         {
665             if (name_of_error)
666                 *name_of_error = name.first;
667             return root;
668         }
669     }
670     return root;
671 }
672 
673 lldb::ValueObjectSP
674 ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
675                                  ConstString* name_of_error)
676 {
677     if (names.size() == 0)
678         return GetSP();
679         ValueObjectSP root(GetSP());
680         for (std::pair<ConstString, bool> name : names)
681         {
682             root = root->GetChildMemberWithName(name.first, name.second);
683             if (!root)
684             {
685                 if (name_of_error)
686                     *name_of_error = name.first;
687                     return root;
688             }
689         }
690     return root;
691 }
692 
693 size_t
694 ValueObject::GetIndexOfChildWithName (const ConstString &name)
695 {
696     bool omit_empty_base_classes = true;
697     return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
698 }
699 
700 ValueObjectSP
701 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
702 {
703     // when getting a child by name, it could be buried inside some base
704     // classes (which really aren't part of the expression path), so we
705     // need a vector of indexes that can get us down to the correct child
706     ValueObjectSP child_sp;
707 
708     // We may need to update our value if we are dynamic
709     if (IsPossibleDynamicType ())
710         UpdateValueIfNeeded(false);
711 
712     std::vector<uint32_t> child_indexes;
713     bool omit_empty_base_classes = true;
714     const size_t num_child_indexes =  GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
715                                                                                     omit_empty_base_classes,
716                                                                                     child_indexes);
717     if (num_child_indexes > 0)
718     {
719         std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
720         std::vector<uint32_t>::const_iterator end = child_indexes.end ();
721 
722         child_sp = GetChildAtIndex(*pos, can_create);
723         for (++pos; pos != end; ++pos)
724         {
725             if (child_sp)
726             {
727                 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
728                 child_sp = new_child_sp;
729             }
730             else
731             {
732                 child_sp.reset();
733             }
734 
735         }
736     }
737     return child_sp;
738 }
739 
740 
741 size_t
742 ValueObject::GetNumChildren ()
743 {
744     UpdateValueIfNeeded();
745     if (!m_children_count_valid)
746     {
747         SetNumChildren (CalculateNumChildren());
748     }
749     return m_children.GetChildrenCount();
750 }
751 
752 bool
753 ValueObject::MightHaveChildren()
754 {
755     bool has_children = false;
756     const uint32_t type_info = GetTypeInfo();
757     if (type_info)
758     {
759         if (type_info & (eTypeHasChildren |
760                          eTypeIsPointer |
761                          eTypeIsReference))
762             has_children = true;
763     }
764     else
765     {
766         has_children = GetNumChildren () > 0;
767     }
768     return has_children;
769 }
770 
771 // Should only be called by ValueObject::GetNumChildren()
772 void
773 ValueObject::SetNumChildren (size_t num_children)
774 {
775     m_children_count_valid = true;
776     m_children.SetChildrenCount(num_children);
777 }
778 
779 void
780 ValueObject::SetName (const ConstString &name)
781 {
782     m_name = name;
783 }
784 
785 ValueObject *
786 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
787 {
788     ValueObject *valobj = NULL;
789 
790     bool omit_empty_base_classes = true;
791     bool ignore_array_bounds = synthetic_array_member;
792     std::string child_name_str;
793     uint32_t child_byte_size = 0;
794     int32_t child_byte_offset = 0;
795     uint32_t child_bitfield_bit_size = 0;
796     uint32_t child_bitfield_bit_offset = 0;
797     bool child_is_base_class = false;
798     bool child_is_deref_of_parent = false;
799 
800     const bool transparent_pointers = synthetic_array_member == false;
801     ClangASTType child_clang_type;
802 
803     ExecutionContext exe_ctx (GetExecutionContextRef());
804 
805     child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
806                                                                 idx,
807                                                                 transparent_pointers,
808                                                                 omit_empty_base_classes,
809                                                                 ignore_array_bounds,
810                                                                 child_name_str,
811                                                                 child_byte_size,
812                                                                 child_byte_offset,
813                                                                 child_bitfield_bit_size,
814                                                                 child_bitfield_bit_offset,
815                                                                 child_is_base_class,
816                                                                 child_is_deref_of_parent,
817                                                                 this);
818     if (child_clang_type)
819     {
820         if (synthetic_index)
821             child_byte_offset += child_byte_size * synthetic_index;
822 
823         ConstString child_name;
824         if (!child_name_str.empty())
825             child_name.SetCString (child_name_str.c_str());
826 
827         valobj = new ValueObjectChild (*this,
828                                        child_clang_type,
829                                        child_name,
830                                        child_byte_size,
831                                        child_byte_offset,
832                                        child_bitfield_bit_size,
833                                        child_bitfield_bit_offset,
834                                        child_is_base_class,
835                                        child_is_deref_of_parent,
836                                        eAddressTypeInvalid);
837         //if (valobj)
838         //    valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
839    }
840 
841     return valobj;
842 }
843 
844 bool
845 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
846                                   std::string& destination)
847 {
848     return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
849 }
850 
851 bool
852 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
853                                   std::string& destination,
854                                   const TypeSummaryOptions& options)
855 {
856     destination.clear();
857 
858     // ideally we would like to bail out if passing NULL, but if we do so
859     // we end up not providing the summary for function pointers anymore
860     if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
861         return false;
862 
863     m_is_getting_summary = true;
864 
865     // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
866     // information that we might care to see in a crash log. might be useful in very specific situations though.
867     /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
868                                         GetTypeName().GetCString(),
869                                         GetName().GetCString(),
870                                         summary_ptr->GetDescription().c_str());*/
871 
872     if (UpdateValueIfNeeded (false))
873     {
874         if (summary_ptr)
875         {
876             if (HasSyntheticValue())
877                 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
878             summary_ptr->FormatObject(this, destination, options);
879         }
880         else
881         {
882             ClangASTType clang_type = GetClangType();
883 
884             // Do some default printout for function pointers
885             if (clang_type)
886             {
887                 if (clang_type.IsFunctionPointerType ())
888                 {
889                     StreamString sstr;
890                     AddressType func_ptr_address_type = eAddressTypeInvalid;
891                     addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
892                     if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
893                     {
894                         switch (func_ptr_address_type)
895                         {
896                             case eAddressTypeInvalid:
897                             case eAddressTypeFile:
898                                 break;
899 
900                             case eAddressTypeLoad:
901                             {
902                                 ExecutionContext exe_ctx (GetExecutionContextRef());
903 
904                                 Address so_addr;
905                                 Target *target = exe_ctx.GetTargetPtr();
906                                 if (target && target->GetSectionLoadList().IsEmpty() == false)
907                                 {
908                                     if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
909                                     {
910                                         so_addr.Dump (&sstr,
911                                                       exe_ctx.GetBestExecutionContextScope(),
912                                                       Address::DumpStyleResolvedDescription,
913                                                       Address::DumpStyleSectionNameOffset);
914                                     }
915                                 }
916                             }
917                                 break;
918 
919                             case eAddressTypeHost:
920                                 break;
921                         }
922                     }
923                     if (sstr.GetSize() > 0)
924                     {
925                         destination.assign (1, '(');
926                         destination.append (sstr.GetData(), sstr.GetSize());
927                         destination.append (1, ')');
928                     }
929                 }
930             }
931         }
932     }
933     m_is_getting_summary = false;
934     return !destination.empty();
935 }
936 
937 const char *
938 ValueObject::GetSummaryAsCString ()
939 {
940     if (UpdateValueIfNeeded(true) && m_summary_str.empty())
941     {
942         GetSummaryAsCString(GetSummaryFormat().get(),
943                             m_summary_str,
944                             TypeSummaryOptions());
945     }
946     if (m_summary_str.empty())
947         return NULL;
948     return m_summary_str.c_str();
949 }
950 
951 bool
952 ValueObject::GetSummaryAsCString (std::string& destination,
953                                   const TypeSummaryOptions& options)
954 {
955     return GetSummaryAsCString(GetSummaryFormat().get(),
956                         destination,
957                         options);
958 }
959 
960 bool
961 ValueObject::IsCStringContainer(bool check_pointer)
962 {
963     ClangASTType pointee_or_element_clang_type;
964     const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
965     bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
966                           pointee_or_element_clang_type.IsCharType ());
967     if (!is_char_arr_ptr)
968         return false;
969     if (!check_pointer)
970         return true;
971     if (type_flags.Test(eTypeIsArray))
972         return true;
973     addr_t cstr_address = LLDB_INVALID_ADDRESS;
974     AddressType cstr_address_type = eAddressTypeInvalid;
975     cstr_address = GetAddressOf (true, &cstr_address_type);
976     return (cstr_address != LLDB_INVALID_ADDRESS);
977 }
978 
979 size_t
980 ValueObject::GetPointeeData (DataExtractor& data,
981                              uint32_t item_idx,
982                              uint32_t item_count)
983 {
984     ClangASTType pointee_or_element_clang_type;
985     const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
986     const bool is_pointer_type = type_info & eTypeIsPointer;
987     const bool is_array_type = type_info & eTypeIsArray;
988     if (!(is_pointer_type || is_array_type))
989         return 0;
990 
991     if (item_count == 0)
992         return 0;
993 
994     const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
995     const uint64_t bytes = item_count * item_type_size;
996     const uint64_t offset = item_idx * item_type_size;
997 
998     if (item_idx == 0 && item_count == 1) // simply a deref
999     {
1000         if (is_pointer_type)
1001         {
1002             Error error;
1003             ValueObjectSP pointee_sp = Dereference(error);
1004             if (error.Fail() || pointee_sp.get() == NULL)
1005                 return 0;
1006             return pointee_sp->GetData(data, error);
1007         }
1008         else
1009         {
1010             ValueObjectSP child_sp = GetChildAtIndex(0, true);
1011             if (child_sp.get() == NULL)
1012                 return 0;
1013             Error error;
1014             return child_sp->GetData(data, error);
1015         }
1016         return true;
1017     }
1018     else /* (items > 1) */
1019     {
1020         Error error;
1021         lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1022         lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1023 
1024         AddressType addr_type;
1025         lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
1026 
1027         switch (addr_type)
1028         {
1029             case eAddressTypeFile:
1030                 {
1031                     ModuleSP module_sp (GetModule());
1032                     if (module_sp)
1033                     {
1034                         addr = addr + offset;
1035                         Address so_addr;
1036                         module_sp->ResolveFileAddress(addr, so_addr);
1037                         ExecutionContext exe_ctx (GetExecutionContextRef());
1038                         Target* target = exe_ctx.GetTargetPtr();
1039                         if (target)
1040                         {
1041                             heap_buf_ptr->SetByteSize(bytes);
1042                             size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1043                             if (error.Success())
1044                             {
1045                                 data.SetData(data_sp);
1046                                 return bytes_read;
1047                             }
1048                         }
1049                     }
1050                 }
1051                 break;
1052             case eAddressTypeLoad:
1053                 {
1054                     ExecutionContext exe_ctx (GetExecutionContextRef());
1055                     Process *process = exe_ctx.GetProcessPtr();
1056                     if (process)
1057                     {
1058                         heap_buf_ptr->SetByteSize(bytes);
1059                         size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
1060                         if (error.Success() || bytes_read > 0)
1061                         {
1062                             data.SetData(data_sp);
1063                             return bytes_read;
1064                         }
1065                     }
1066                 }
1067                 break;
1068             case eAddressTypeHost:
1069                 {
1070                     const uint64_t max_bytes = GetClangType().GetByteSize();
1071                     if (max_bytes > offset)
1072                     {
1073                         size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1074                         heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1075                         data.SetData(data_sp);
1076                         return bytes_read;
1077                     }
1078                 }
1079                 break;
1080             case eAddressTypeInvalid:
1081                 break;
1082         }
1083     }
1084     return 0;
1085 }
1086 
1087 uint64_t
1088 ValueObject::GetData (DataExtractor& data, Error &error)
1089 {
1090     UpdateValueIfNeeded(false);
1091     ExecutionContext exe_ctx (GetExecutionContextRef());
1092     error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
1093     if (error.Fail())
1094     {
1095         if (m_data.GetByteSize())
1096         {
1097             data = m_data;
1098             return data.GetByteSize();
1099         }
1100         else
1101         {
1102             return 0;
1103         }
1104     }
1105     data.SetAddressByteSize(m_data.GetAddressByteSize());
1106     data.SetByteOrder(m_data.GetByteOrder());
1107     return data.GetByteSize();
1108 }
1109 
1110 bool
1111 ValueObject::SetData (DataExtractor &data, Error &error)
1112 {
1113     error.Clear();
1114     // Make sure our value is up to date first so that our location and location
1115     // type is valid.
1116     if (!UpdateValueIfNeeded(false))
1117     {
1118         error.SetErrorString("unable to read value");
1119         return false;
1120     }
1121 
1122     uint64_t count = 0;
1123     const Encoding encoding = GetClangType().GetEncoding(count);
1124 
1125     const size_t byte_size = GetByteSize();
1126 
1127     Value::ValueType value_type = m_value.GetValueType();
1128 
1129     switch (value_type)
1130     {
1131     case Value::eValueTypeScalar:
1132         {
1133             Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1134 
1135             if (!set_error.Success())
1136             {
1137                 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1138                 return false;
1139             }
1140         }
1141         break;
1142     case Value::eValueTypeLoadAddress:
1143         {
1144             // If it is a load address, then the scalar value is the storage location
1145             // of the data, and we have to shove this value down to that load location.
1146             ExecutionContext exe_ctx (GetExecutionContextRef());
1147             Process *process = exe_ctx.GetProcessPtr();
1148             if (process)
1149             {
1150                 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1151                 size_t bytes_written = process->WriteMemory(target_addr,
1152                                                             data.GetDataStart(),
1153                                                             byte_size,
1154                                                             error);
1155                 if (!error.Success())
1156                     return false;
1157                 if (bytes_written != byte_size)
1158                 {
1159                     error.SetErrorString("unable to write value to memory");
1160                     return false;
1161                 }
1162             }
1163         }
1164         break;
1165     case Value::eValueTypeHostAddress:
1166         {
1167             // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1168             DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1169             m_data.SetData(buffer_sp, 0);
1170             data.CopyByteOrderedData (0,
1171                                       byte_size,
1172                                       const_cast<uint8_t *>(m_data.GetDataStart()),
1173                                       byte_size,
1174                                       m_data.GetByteOrder());
1175             m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1176         }
1177         break;
1178     case Value::eValueTypeFileAddress:
1179     case Value::eValueTypeVector:
1180         break;
1181     }
1182 
1183     // If we have reached this point, then we have successfully changed the value.
1184     SetNeedsUpdate();
1185     return true;
1186 }
1187 
1188 // will compute strlen(str), but without consuming more than
1189 // maxlen bytes out of str (this serves the purpose of reading
1190 // chunks of a string without having to worry about
1191 // missing NULL terminators in the chunk)
1192 // of course, if strlen(str) > maxlen, the function will return
1193 // maxlen_value (which should be != maxlen, because that allows you
1194 // to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1195 static uint32_t
1196 strlen_or_inf (const char* str,
1197                uint32_t maxlen,
1198                uint32_t maxlen_value)
1199 {
1200     uint32_t len = 0;
1201     if (str)
1202     {
1203         while(*str)
1204         {
1205             len++;str++;
1206             if (len >= maxlen)
1207                 return maxlen_value;
1208         }
1209     }
1210     return len;
1211 }
1212 
1213 static bool
1214 CopyStringDataToBufferSP(const StreamString& source,
1215                          lldb::DataBufferSP& destination)
1216 {
1217     destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1218     memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1219     return true;
1220 }
1221 
1222 size_t
1223 ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
1224                                 Error& error,
1225                                 uint32_t max_length,
1226                                 bool honor_array,
1227                                 Format item_format)
1228 {
1229     StreamString s;
1230     ExecutionContext exe_ctx (GetExecutionContextRef());
1231     Target* target = exe_ctx.GetTargetPtr();
1232 
1233     if (!target)
1234     {
1235         s << "<no target to read from>";
1236         error.SetErrorString("no target to read from");
1237         CopyStringDataToBufferSP(s, buffer_sp);
1238         return 0;
1239     }
1240 
1241     if (max_length == 0)
1242         max_length = target->GetMaximumSizeOfStringSummary();
1243 
1244     size_t bytes_read = 0;
1245     size_t total_bytes_read = 0;
1246 
1247     ClangASTType clang_type = GetClangType();
1248     ClangASTType elem_or_pointee_clang_type;
1249     const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
1250     if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
1251         elem_or_pointee_clang_type.IsCharType ())
1252     {
1253         addr_t cstr_address = LLDB_INVALID_ADDRESS;
1254         AddressType cstr_address_type = eAddressTypeInvalid;
1255 
1256         size_t cstr_len = 0;
1257         bool capped_data = false;
1258         if (type_flags.Test (eTypeIsArray))
1259         {
1260             // We have an array
1261             uint64_t array_size = 0;
1262             if (clang_type.IsArrayType(NULL, &array_size, NULL))
1263             {
1264                 cstr_len = array_size;
1265                 if (cstr_len > max_length)
1266                 {
1267                     capped_data = true;
1268                     cstr_len = max_length;
1269                 }
1270             }
1271             cstr_address = GetAddressOf (true, &cstr_address_type);
1272         }
1273         else
1274         {
1275             // We have a pointer
1276             cstr_address = GetPointerValue (&cstr_address_type);
1277         }
1278 
1279         if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1280         {
1281             s << "<invalid address>";
1282             error.SetErrorString("invalid address");
1283             CopyStringDataToBufferSP(s, buffer_sp);
1284             return 0;
1285         }
1286 
1287         Address cstr_so_addr (cstr_address);
1288         DataExtractor data;
1289         if (cstr_len > 0 && honor_array)
1290         {
1291             // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1292             // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1293             GetPointeeData(data, 0, cstr_len);
1294 
1295             if ((bytes_read = data.GetByteSize()) > 0)
1296             {
1297                 total_bytes_read = bytes_read;
1298                 for (size_t offset = 0; offset < bytes_read; offset++)
1299                     s.Printf("%c", *data.PeekData(offset, 1));
1300                 if (capped_data)
1301                     s << "...";
1302             }
1303         }
1304         else
1305         {
1306             cstr_len = max_length;
1307             const size_t k_max_buf_size = 64;
1308 
1309             size_t offset = 0;
1310 
1311             int cstr_len_displayed = -1;
1312             bool capped_cstr = false;
1313             // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1314             // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1315             while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
1316             {
1317                 total_bytes_read += bytes_read;
1318                 const char *cstr = data.PeekCStr(0);
1319                 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1320                 if (len > k_max_buf_size)
1321                     len = k_max_buf_size;
1322 
1323                 if (cstr_len_displayed < 0)
1324                     cstr_len_displayed = len;
1325 
1326                 if (len == 0)
1327                     break;
1328                 cstr_len_displayed += len;
1329                 if (len > bytes_read)
1330                     len = bytes_read;
1331                 if (len > cstr_len)
1332                     len = cstr_len;
1333 
1334                 for (size_t offset = 0; offset < bytes_read; offset++)
1335                     s.Printf("%c", *data.PeekData(offset, 1));
1336 
1337                 if (len < k_max_buf_size)
1338                     break;
1339 
1340                 if (len >= cstr_len)
1341                 {
1342                     capped_cstr = true;
1343                     break;
1344                 }
1345 
1346                 cstr_len -= len;
1347                 offset += len;
1348             }
1349 
1350             if (cstr_len_displayed >= 0)
1351             {
1352                 if (capped_cstr)
1353                     s << "...";
1354             }
1355         }
1356     }
1357     else
1358     {
1359         error.SetErrorString("not a string object");
1360         s << "<not a string object>";
1361     }
1362     CopyStringDataToBufferSP(s, buffer_sp);
1363     return total_bytes_read;
1364 }
1365 
1366 std::pair<TypeValidatorResult, std::string>
1367 ValueObject::GetValidationStatus ()
1368 {
1369     if (!UpdateValueIfNeeded(true))
1370         return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1371 
1372     if (m_validation_result.hasValue())
1373         return m_validation_result.getValue();
1374 
1375     if (!m_type_validator_sp)
1376         return {TypeValidatorResult::Success,""}; // no validator no failure
1377 
1378     auto outcome = m_type_validator_sp->FormatObject(this);
1379 
1380     return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1381 }
1382 
1383 const char *
1384 ValueObject::GetObjectDescription ()
1385 {
1386 
1387     if (!UpdateValueIfNeeded (true))
1388         return NULL;
1389 
1390     if (!m_object_desc_str.empty())
1391         return m_object_desc_str.c_str();
1392 
1393     ExecutionContext exe_ctx (GetExecutionContextRef());
1394     Process *process = exe_ctx.GetProcessPtr();
1395     if (process == NULL)
1396         return NULL;
1397 
1398     StreamString s;
1399 
1400     LanguageType language = GetObjectRuntimeLanguage();
1401     LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1402 
1403     if (runtime == NULL)
1404     {
1405         // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
1406         ClangASTType clang_type = GetClangType();
1407         if (clang_type)
1408         {
1409             bool is_signed;
1410             if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
1411             {
1412                 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
1413             }
1414         }
1415     }
1416 
1417     if (runtime && runtime->GetObjectDescription(s, *this))
1418     {
1419         m_object_desc_str.append (s.GetData());
1420     }
1421 
1422     if (m_object_desc_str.empty())
1423         return NULL;
1424     else
1425         return m_object_desc_str.c_str();
1426 }
1427 
1428 bool
1429 ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1430                                 std::string& destination)
1431 {
1432     if (UpdateValueIfNeeded(false))
1433         return format.FormatObject(this,destination);
1434     else
1435         return false;
1436 }
1437 
1438 bool
1439 ValueObject::GetValueAsCString (lldb::Format format,
1440                                 std::string& destination)
1441 {
1442     return GetValueAsCString(TypeFormatImpl_Format(format),destination);
1443 }
1444 
1445 const char *
1446 ValueObject::GetValueAsCString ()
1447 {
1448     if (UpdateValueIfNeeded(true))
1449     {
1450         lldb::TypeFormatImplSP format_sp;
1451         lldb::Format my_format = GetFormat();
1452         if (my_format == lldb::eFormatDefault)
1453         {
1454             if (m_type_format_sp)
1455                 format_sp = m_type_format_sp;
1456             else
1457             {
1458                 if (m_is_bitfield_for_scalar)
1459                     my_format = eFormatUnsigned;
1460                 else
1461                 {
1462                     if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
1463                     {
1464                         const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1465                         if (reg_info)
1466                             my_format = reg_info->format;
1467                     }
1468                     else
1469                     {
1470                         my_format = GetValue().GetClangType().GetFormat();
1471                     }
1472                 }
1473             }
1474         }
1475         if (my_format != m_last_format || m_value_str.empty())
1476         {
1477             m_last_format = my_format;
1478             if (!format_sp)
1479                 format_sp.reset(new TypeFormatImpl_Format(my_format));
1480             if (GetValueAsCString(*format_sp.get(), m_value_str))
1481             {
1482                 if (!m_value_did_change && m_old_value_valid)
1483                 {
1484                     // The value was gotten successfully, so we consider the
1485                     // value as changed if the value string differs
1486                     SetValueDidChange (m_old_value_str != m_value_str);
1487                 }
1488             }
1489         }
1490     }
1491     if (m_value_str.empty())
1492         return NULL;
1493     return m_value_str.c_str();
1494 }
1495 
1496 // if > 8bytes, 0 is returned. this method should mostly be used
1497 // to read address values out of pointers
1498 uint64_t
1499 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
1500 {
1501     // If our byte size is zero this is an aggregate type that has children
1502     if (CanProvideValue())
1503     {
1504         Scalar scalar;
1505         if (ResolveValue (scalar))
1506         {
1507             if (success)
1508                 *success = true;
1509             return scalar.ULongLong(fail_value);
1510         }
1511         // fallthrough, otherwise...
1512     }
1513 
1514     if (success)
1515         *success = false;
1516     return fail_value;
1517 }
1518 
1519 int64_t
1520 ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1521 {
1522     // If our byte size is zero this is an aggregate type that has children
1523     if (CanProvideValue())
1524     {
1525         Scalar scalar;
1526         if (ResolveValue (scalar))
1527         {
1528             if (success)
1529                 *success = true;
1530                 return scalar.SLongLong(fail_value);
1531         }
1532         // fallthrough, otherwise...
1533     }
1534 
1535     if (success)
1536         *success = false;
1537         return fail_value;
1538 }
1539 
1540 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1541 // this call up to date by returning true for your new special cases. We will eventually move
1542 // to checking this call result before trying to display special cases
1543 bool
1544 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1545                                                Format custom_format)
1546 {
1547     Flags flags(GetTypeInfo());
1548     if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
1549         && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1550     {
1551         if (IsCStringContainer(true) &&
1552             (custom_format == eFormatCString ||
1553              custom_format == eFormatCharArray ||
1554              custom_format == eFormatChar ||
1555              custom_format == eFormatVectorOfChar))
1556             return true;
1557 
1558         if (flags.Test(eTypeIsArray))
1559         {
1560             if ((custom_format == eFormatBytes) ||
1561                 (custom_format == eFormatBytesWithASCII))
1562                 return true;
1563 
1564             if ((custom_format == eFormatVectorOfChar) ||
1565                 (custom_format == eFormatVectorOfFloat32) ||
1566                 (custom_format == eFormatVectorOfFloat64) ||
1567                 (custom_format == eFormatVectorOfSInt16) ||
1568                 (custom_format == eFormatVectorOfSInt32) ||
1569                 (custom_format == eFormatVectorOfSInt64) ||
1570                 (custom_format == eFormatVectorOfSInt8) ||
1571                 (custom_format == eFormatVectorOfUInt128) ||
1572                 (custom_format == eFormatVectorOfUInt16) ||
1573                 (custom_format == eFormatVectorOfUInt32) ||
1574                 (custom_format == eFormatVectorOfUInt64) ||
1575                 (custom_format == eFormatVectorOfUInt8))
1576                 return true;
1577         }
1578     }
1579     return false;
1580 }
1581 
1582 bool
1583 ValueObject::DumpPrintableRepresentation(Stream& s,
1584                                          ValueObjectRepresentationStyle val_obj_display,
1585                                          Format custom_format,
1586                                          PrintableRepresentationSpecialCases special,
1587                                          bool do_dump_error)
1588 {
1589 
1590     Flags flags(GetTypeInfo());
1591 
1592     bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1593     bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1594 
1595     if (allow_special)
1596     {
1597         if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
1598              && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1599         {
1600             // when being asked to get a printable display an array or pointer type directly,
1601             // try to "do the right thing"
1602 
1603             if (IsCStringContainer(true) &&
1604                 (custom_format == eFormatCString ||
1605                  custom_format == eFormatCharArray ||
1606                  custom_format == eFormatChar ||
1607                  custom_format == eFormatVectorOfChar)) // print char[] & char* directly
1608             {
1609                 Error error;
1610                 lldb::DataBufferSP buffer_sp;
1611                 ReadPointedString(buffer_sp,
1612                                   error,
1613                                   0,
1614                                   (custom_format == eFormatVectorOfChar) ||
1615                                   (custom_format == eFormatCharArray));
1616                 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
1617                 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1618                 options.SetStream(&s);
1619                 options.SetPrefixToken(0);
1620                 options.SetQuote('"');
1621                 options.SetSourceSize(buffer_sp->GetByteSize());
1622                 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
1623                 return !error.Fail();
1624             }
1625 
1626             if (custom_format == eFormatEnum)
1627                 return false;
1628 
1629             // this only works for arrays, because I have no way to know when
1630             // the pointed memory ends, and no special \0 end of data marker
1631             if (flags.Test(eTypeIsArray))
1632             {
1633                 if ((custom_format == eFormatBytes) ||
1634                     (custom_format == eFormatBytesWithASCII))
1635                 {
1636                     const size_t count = GetNumChildren();
1637 
1638                     s << '[';
1639                     for (size_t low = 0; low < count; low++)
1640                     {
1641 
1642                         if (low)
1643                             s << ',';
1644 
1645                         ValueObjectSP child = GetChildAtIndex(low,true);
1646                         if (!child.get())
1647                         {
1648                             s << "<invalid child>";
1649                             continue;
1650                         }
1651                         child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1652                     }
1653 
1654                     s << ']';
1655 
1656                     return true;
1657                 }
1658 
1659                 if ((custom_format == eFormatVectorOfChar) ||
1660                     (custom_format == eFormatVectorOfFloat32) ||
1661                     (custom_format == eFormatVectorOfFloat64) ||
1662                     (custom_format == eFormatVectorOfSInt16) ||
1663                     (custom_format == eFormatVectorOfSInt32) ||
1664                     (custom_format == eFormatVectorOfSInt64) ||
1665                     (custom_format == eFormatVectorOfSInt8) ||
1666                     (custom_format == eFormatVectorOfUInt128) ||
1667                     (custom_format == eFormatVectorOfUInt16) ||
1668                     (custom_format == eFormatVectorOfUInt32) ||
1669                     (custom_format == eFormatVectorOfUInt64) ||
1670                     (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1671                 {
1672                     const size_t count = GetNumChildren();
1673 
1674                     Format format = FormatManager::GetSingleItemFormat(custom_format);
1675 
1676                     s << '[';
1677                     for (size_t low = 0; low < count; low++)
1678                     {
1679 
1680                         if (low)
1681                             s << ',';
1682 
1683                         ValueObjectSP child = GetChildAtIndex(low,true);
1684                         if (!child.get())
1685                         {
1686                             s << "<invalid child>";
1687                             continue;
1688                         }
1689                         child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1690                     }
1691 
1692                     s << ']';
1693 
1694                     return true;
1695                 }
1696             }
1697 
1698             if ((custom_format == eFormatBoolean) ||
1699                 (custom_format == eFormatBinary) ||
1700                 (custom_format == eFormatChar) ||
1701                 (custom_format == eFormatCharPrintable) ||
1702                 (custom_format == eFormatComplexFloat) ||
1703                 (custom_format == eFormatDecimal) ||
1704                 (custom_format == eFormatHex) ||
1705                 (custom_format == eFormatHexUppercase) ||
1706                 (custom_format == eFormatFloat) ||
1707                 (custom_format == eFormatOctal) ||
1708                 (custom_format == eFormatOSType) ||
1709                 (custom_format == eFormatUnicode16) ||
1710                 (custom_format == eFormatUnicode32) ||
1711                 (custom_format == eFormatUnsigned) ||
1712                 (custom_format == eFormatPointer) ||
1713                 (custom_format == eFormatComplexInteger) ||
1714                 (custom_format == eFormatComplex) ||
1715                 (custom_format == eFormatDefault)) // use the [] operator
1716                 return false;
1717         }
1718     }
1719 
1720     if (only_special)
1721         return false;
1722 
1723     bool var_success = false;
1724 
1725     {
1726         const char *cstr = NULL;
1727 
1728          // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1729         // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1730         // area for cases where our desired output is not backed by some other longer-term storage
1731         StreamString strm;
1732 
1733         if (custom_format != eFormatInvalid)
1734             SetFormat(custom_format);
1735 
1736         switch(val_obj_display)
1737         {
1738             case eValueObjectRepresentationStyleValue:
1739                 cstr = GetValueAsCString();
1740                 break;
1741 
1742             case eValueObjectRepresentationStyleSummary:
1743                 cstr = GetSummaryAsCString();
1744                 break;
1745 
1746             case eValueObjectRepresentationStyleLanguageSpecific:
1747                 cstr = GetObjectDescription();
1748                 break;
1749 
1750             case eValueObjectRepresentationStyleLocation:
1751                 cstr = GetLocationAsCString();
1752                 break;
1753 
1754             case eValueObjectRepresentationStyleChildrenCount:
1755                 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
1756                 cstr = strm.GetString().c_str();
1757                 break;
1758 
1759             case eValueObjectRepresentationStyleType:
1760                 cstr = GetTypeName().AsCString();
1761                 break;
1762 
1763             case eValueObjectRepresentationStyleName:
1764                 cstr = GetName().AsCString();
1765                 break;
1766 
1767             case eValueObjectRepresentationStyleExpressionPath:
1768                 GetExpressionPath(strm, false);
1769                 cstr = strm.GetString().c_str();
1770                 break;
1771         }
1772 
1773         if (!cstr)
1774         {
1775             if (val_obj_display == eValueObjectRepresentationStyleValue)
1776                 cstr = GetSummaryAsCString();
1777             else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1778             {
1779                 if (!CanProvideValue())
1780                 {
1781                     strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1782                     cstr = strm.GetString().c_str();
1783                 }
1784                 else
1785                     cstr = GetValueAsCString();
1786             }
1787         }
1788 
1789         if (cstr)
1790             s.PutCString(cstr);
1791         else
1792         {
1793             if (m_error.Fail())
1794             {
1795                 if (do_dump_error)
1796                     s.Printf("<%s>", m_error.AsCString());
1797                 else
1798                     return false;
1799             }
1800             else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1801                 s.PutCString("<no summary available>");
1802             else if (val_obj_display == eValueObjectRepresentationStyleValue)
1803                 s.PutCString("<no value available>");
1804             else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1805                 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1806             else
1807                 s.PutCString("<no printable representation>");
1808         }
1809 
1810         // we should only return false here if we could not do *anything*
1811         // even if we have an error message as output, that's a success
1812         // from our callers' perspective, so return true
1813         var_success = true;
1814 
1815         if (custom_format != eFormatInvalid)
1816             SetFormat(eFormatDefault);
1817     }
1818 
1819     return var_success;
1820 }
1821 
1822 addr_t
1823 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
1824 {
1825     if (!UpdateValueIfNeeded(false))
1826         return LLDB_INVALID_ADDRESS;
1827 
1828     switch (m_value.GetValueType())
1829     {
1830     case Value::eValueTypeScalar:
1831     case Value::eValueTypeVector:
1832         if (scalar_is_load_address)
1833         {
1834             if(address_type)
1835                 *address_type = eAddressTypeLoad;
1836             return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1837         }
1838         break;
1839 
1840     case Value::eValueTypeLoadAddress:
1841     case Value::eValueTypeFileAddress:
1842     case Value::eValueTypeHostAddress:
1843         {
1844             if(address_type)
1845                 *address_type = m_value.GetValueAddressType ();
1846             return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1847         }
1848         break;
1849     }
1850     if (address_type)
1851         *address_type = eAddressTypeInvalid;
1852     return LLDB_INVALID_ADDRESS;
1853 }
1854 
1855 addr_t
1856 ValueObject::GetPointerValue (AddressType *address_type)
1857 {
1858     addr_t address = LLDB_INVALID_ADDRESS;
1859     if(address_type)
1860         *address_type = eAddressTypeInvalid;
1861 
1862     if (!UpdateValueIfNeeded(false))
1863         return address;
1864 
1865     switch (m_value.GetValueType())
1866     {
1867     case Value::eValueTypeScalar:
1868     case Value::eValueTypeVector:
1869         address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1870         break;
1871 
1872     case Value::eValueTypeHostAddress:
1873     case Value::eValueTypeLoadAddress:
1874     case Value::eValueTypeFileAddress:
1875         {
1876             lldb::offset_t data_offset = 0;
1877             address = m_data.GetPointer(&data_offset);
1878         }
1879         break;
1880     }
1881 
1882     if (address_type)
1883         *address_type = GetAddressTypeOfChildren();
1884 
1885     return address;
1886 }
1887 
1888 bool
1889 ValueObject::SetValueFromCString (const char *value_str, Error& error)
1890 {
1891     error.Clear();
1892     // Make sure our value is up to date first so that our location and location
1893     // type is valid.
1894     if (!UpdateValueIfNeeded(false))
1895     {
1896         error.SetErrorString("unable to read value");
1897         return false;
1898     }
1899 
1900     uint64_t count = 0;
1901     const Encoding encoding = GetClangType().GetEncoding (count);
1902 
1903     const size_t byte_size = GetByteSize();
1904 
1905     Value::ValueType value_type = m_value.GetValueType();
1906 
1907     if (value_type == Value::eValueTypeScalar)
1908     {
1909         // If the value is already a scalar, then let the scalar change itself:
1910         m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1911     }
1912     else if (byte_size <= Scalar::GetMaxByteSize())
1913     {
1914         // If the value fits in a scalar, then make a new scalar and again let the
1915         // scalar code do the conversion, then figure out where to put the new value.
1916         Scalar new_scalar;
1917         error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1918         if (error.Success())
1919         {
1920             switch (value_type)
1921             {
1922             case Value::eValueTypeLoadAddress:
1923                 {
1924                     // If it is a load address, then the scalar value is the storage location
1925                     // of the data, and we have to shove this value down to that load location.
1926                     ExecutionContext exe_ctx (GetExecutionContextRef());
1927                     Process *process = exe_ctx.GetProcessPtr();
1928                     if (process)
1929                     {
1930                         addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1931                         size_t bytes_written = process->WriteScalarToMemory (target_addr,
1932                                                                              new_scalar,
1933                                                                              byte_size,
1934                                                                              error);
1935                         if (!error.Success())
1936                             return false;
1937                         if (bytes_written != byte_size)
1938                         {
1939                             error.SetErrorString("unable to write value to memory");
1940                             return false;
1941                         }
1942                     }
1943                 }
1944                 break;
1945             case Value::eValueTypeHostAddress:
1946                 {
1947                     // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1948                     DataExtractor new_data;
1949                     new_data.SetByteOrder (m_data.GetByteOrder());
1950 
1951                     DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1952                     m_data.SetData(buffer_sp, 0);
1953                     bool success = new_scalar.GetData(new_data);
1954                     if (success)
1955                     {
1956                         new_data.CopyByteOrderedData (0,
1957                                                       byte_size,
1958                                                       const_cast<uint8_t *>(m_data.GetDataStart()),
1959                                                       byte_size,
1960                                                       m_data.GetByteOrder());
1961                     }
1962                     m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1963 
1964                 }
1965                 break;
1966             case Value::eValueTypeFileAddress:
1967             case Value::eValueTypeScalar:
1968             case Value::eValueTypeVector:
1969                 break;
1970             }
1971         }
1972         else
1973         {
1974             return false;
1975         }
1976     }
1977     else
1978     {
1979         // We don't support setting things bigger than a scalar at present.
1980         error.SetErrorString("unable to write aggregate data type");
1981         return false;
1982     }
1983 
1984     // If we have reached this point, then we have successfully changed the value.
1985     SetNeedsUpdate();
1986     return true;
1987 }
1988 
1989 bool
1990 ValueObject::GetDeclaration (Declaration &decl)
1991 {
1992     decl.Clear();
1993     return false;
1994 }
1995 
1996 ConstString
1997 ValueObject::GetTypeName()
1998 {
1999     return GetClangType().GetConstTypeName();
2000 }
2001 
2002 ConstString
2003 ValueObject::GetDisplayTypeName()
2004 {
2005     return GetTypeName();
2006 }
2007 
2008 ConstString
2009 ValueObject::GetQualifiedTypeName()
2010 {
2011     return GetClangType().GetConstQualifiedTypeName();
2012 }
2013 
2014 
2015 LanguageType
2016 ValueObject::GetObjectRuntimeLanguage ()
2017 {
2018     return GetClangType().GetMinimumLanguage ();
2019 }
2020 
2021 void
2022 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
2023 {
2024     m_synthetic_children[key] = valobj;
2025 }
2026 
2027 ValueObjectSP
2028 ValueObject::GetSyntheticChild (const ConstString &key) const
2029 {
2030     ValueObjectSP synthetic_child_sp;
2031     std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
2032     if (pos != m_synthetic_children.end())
2033         synthetic_child_sp = pos->second->GetSP();
2034     return synthetic_child_sp;
2035 }
2036 
2037 uint32_t
2038 ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
2039 {
2040     return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
2041 }
2042 
2043 bool
2044 ValueObject::IsPointerType ()
2045 {
2046     return GetClangType().IsPointerType();
2047 }
2048 
2049 bool
2050 ValueObject::IsArrayType ()
2051 {
2052     return GetClangType().IsArrayType (NULL, NULL, NULL);
2053 }
2054 
2055 bool
2056 ValueObject::IsScalarType ()
2057 {
2058     return GetClangType().IsScalarType ();
2059 }
2060 
2061 bool
2062 ValueObject::IsIntegerType (bool &is_signed)
2063 {
2064     return GetClangType().IsIntegerType (is_signed);
2065 }
2066 
2067 bool
2068 ValueObject::IsPointerOrReferenceType ()
2069 {
2070     return GetClangType().IsPointerOrReferenceType ();
2071 }
2072 
2073 bool
2074 ValueObject::IsPossibleDynamicType ()
2075 {
2076     ExecutionContext exe_ctx (GetExecutionContextRef());
2077     Process *process = exe_ctx.GetProcessPtr();
2078     if (process)
2079         return process->IsPossibleDynamicValue(*this);
2080     else
2081         return GetClangType().IsPossibleDynamicType (NULL, true, true);
2082 }
2083 
2084 bool
2085 ValueObject::IsObjCNil ()
2086 {
2087     const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
2088     bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
2089     if (!isObjCpointer)
2090         return false;
2091     bool canReadValue = true;
2092     bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
2093     return canReadValue && isZero;
2094 }
2095 
2096 ValueObjectSP
2097 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
2098 {
2099     const uint32_t type_info = GetTypeInfo ();
2100     if (type_info & eTypeIsArray)
2101         return GetSyntheticArrayMemberFromArray(index, can_create);
2102 
2103     if (type_info & eTypeIsPointer)
2104         return GetSyntheticArrayMemberFromPointer(index, can_create);
2105 
2106     return ValueObjectSP();
2107 
2108 }
2109 
2110 ValueObjectSP
2111 ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
2112 {
2113     ValueObjectSP synthetic_child_sp;
2114     if (IsPointerType ())
2115     {
2116         char index_str[64];
2117         snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
2118         ConstString index_const_str(index_str);
2119         // Check if we have already created a synthetic array member in this
2120         // valid object. If we have we will re-use it.
2121         synthetic_child_sp = GetSyntheticChild (index_const_str);
2122         if (!synthetic_child_sp)
2123         {
2124             ValueObject *synthetic_child;
2125             // We haven't made a synthetic array member for INDEX yet, so
2126             // lets make one and cache it for any future reference.
2127             synthetic_child = CreateChildAtIndex(0, true, index);
2128 
2129             // Cache the value if we got one back...
2130             if (synthetic_child)
2131             {
2132                 AddSyntheticChild(index_const_str, synthetic_child);
2133                 synthetic_child_sp = synthetic_child->GetSP();
2134                 synthetic_child_sp->SetName(ConstString(index_str));
2135                 synthetic_child_sp->m_is_array_item_for_pointer = true;
2136             }
2137         }
2138     }
2139     return synthetic_child_sp;
2140 }
2141 
2142 // This allows you to create an array member using and index
2143 // that doesn't not fall in the normal bounds of the array.
2144 // Many times structure can be defined as:
2145 // struct Collection
2146 // {
2147 //     uint32_t item_count;
2148 //     Item item_array[0];
2149 // };
2150 // The size of the "item_array" is 1, but many times in practice
2151 // there are more items in "item_array".
2152 
2153 ValueObjectSP
2154 ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
2155 {
2156     ValueObjectSP synthetic_child_sp;
2157     if (IsArrayType ())
2158     {
2159         char index_str[64];
2160         snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
2161         ConstString index_const_str(index_str);
2162         // Check if we have already created a synthetic array member in this
2163         // valid object. If we have we will re-use it.
2164         synthetic_child_sp = GetSyntheticChild (index_const_str);
2165         if (!synthetic_child_sp)
2166         {
2167             ValueObject *synthetic_child;
2168             // We haven't made a synthetic array member for INDEX yet, so
2169             // lets make one and cache it for any future reference.
2170             synthetic_child = CreateChildAtIndex(0, true, index);
2171 
2172             // Cache the value if we got one back...
2173             if (synthetic_child)
2174             {
2175                 AddSyntheticChild(index_const_str, synthetic_child);
2176                 synthetic_child_sp = synthetic_child->GetSP();
2177                 synthetic_child_sp->SetName(ConstString(index_str));
2178                 synthetic_child_sp->m_is_array_item_for_pointer = true;
2179             }
2180         }
2181     }
2182     return synthetic_child_sp;
2183 }
2184 
2185 ValueObjectSP
2186 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2187 {
2188     ValueObjectSP synthetic_child_sp;
2189     if (IsScalarType ())
2190     {
2191         char index_str[64];
2192         snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2193         ConstString index_const_str(index_str);
2194         // Check if we have already created a synthetic array member in this
2195         // valid object. If we have we will re-use it.
2196         synthetic_child_sp = GetSyntheticChild (index_const_str);
2197         if (!synthetic_child_sp)
2198         {
2199             // We haven't made a synthetic array member for INDEX yet, so
2200             // lets make one and cache it for any future reference.
2201             ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2202                                                                       GetClangType(),
2203                                                                       index_const_str,
2204                                                                       GetByteSize(),
2205                                                                       0,
2206                                                                       to-from+1,
2207                                                                       from,
2208                                                                       false,
2209                                                                       false,
2210                                                                       eAddressTypeInvalid);
2211 
2212             // Cache the value if we got one back...
2213             if (synthetic_child)
2214             {
2215                 AddSyntheticChild(index_const_str, synthetic_child);
2216                 synthetic_child_sp = synthetic_child->GetSP();
2217                 synthetic_child_sp->SetName(ConstString(index_str));
2218                 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2219             }
2220         }
2221     }
2222     return synthetic_child_sp;
2223 }
2224 
2225 ValueObjectSP
2226 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2227 {
2228 
2229     ValueObjectSP synthetic_child_sp;
2230 
2231     char name_str[64];
2232     snprintf(name_str, sizeof(name_str), "@%i", offset);
2233     ConstString name_const_str(name_str);
2234 
2235     // Check if we have already created a synthetic array member in this
2236     // valid object. If we have we will re-use it.
2237     synthetic_child_sp = GetSyntheticChild (name_const_str);
2238 
2239     if (synthetic_child_sp.get())
2240         return synthetic_child_sp;
2241 
2242     if (!can_create)
2243         return ValueObjectSP();
2244 
2245     ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2246                                                              type,
2247                                                              name_const_str,
2248                                                              type.GetByteSize(),
2249                                                              offset,
2250                                                              0,
2251                                                              0,
2252                                                              false,
2253                                                              false,
2254                                                              eAddressTypeInvalid);
2255     if (synthetic_child)
2256     {
2257         AddSyntheticChild(name_const_str, synthetic_child);
2258         synthetic_child_sp = synthetic_child->GetSP();
2259         synthetic_child_sp->SetName(name_const_str);
2260         synthetic_child_sp->m_is_child_at_offset = true;
2261     }
2262     return synthetic_child_sp;
2263 }
2264 
2265 ValueObjectSP
2266 ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
2267 {
2268     ValueObjectSP synthetic_child_sp;
2269 
2270     char name_str[64];
2271     snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2272     ConstString name_const_str(name_str);
2273 
2274     // Check if we have already created a synthetic array member in this
2275     // valid object. If we have we will re-use it.
2276     synthetic_child_sp = GetSyntheticChild (name_const_str);
2277 
2278     if (synthetic_child_sp.get())
2279         return synthetic_child_sp;
2280 
2281     if (!can_create)
2282         return ValueObjectSP();
2283 
2284     const bool is_base_class = true;
2285 
2286     ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2287                                                              type,
2288                                                              name_const_str,
2289                                                              type.GetByteSize(),
2290                                                              offset,
2291                                                              0,
2292                                                              0,
2293                                                              is_base_class,
2294                                                              false,
2295                                                              eAddressTypeInvalid);
2296     if (synthetic_child)
2297     {
2298         AddSyntheticChild(name_const_str, synthetic_child);
2299         synthetic_child_sp = synthetic_child->GetSP();
2300         synthetic_child_sp->SetName(name_const_str);
2301     }
2302     return synthetic_child_sp;
2303 }
2304 
2305 
2306 // your expression path needs to have a leading . or ->
2307 // (unless it somehow "looks like" an array, in which case it has
2308 // a leading [ symbol). while the [ is meaningful and should be shown
2309 // to the user, . and -> are just parser design, but by no means
2310 // added information for the user.. strip them off
2311 static const char*
2312 SkipLeadingExpressionPathSeparators(const char* expression)
2313 {
2314     if (!expression || !expression[0])
2315         return expression;
2316     if (expression[0] == '.')
2317         return expression+1;
2318     if (expression[0] == '-' && expression[1] == '>')
2319         return expression+2;
2320     return expression;
2321 }
2322 
2323 ValueObjectSP
2324 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2325 {
2326     ValueObjectSP synthetic_child_sp;
2327     ConstString name_const_string(expression);
2328     // Check if we have already created a synthetic array member in this
2329     // valid object. If we have we will re-use it.
2330     synthetic_child_sp = GetSyntheticChild (name_const_string);
2331     if (!synthetic_child_sp)
2332     {
2333         // We haven't made a synthetic array member for expression yet, so
2334         // lets make one and cache it for any future reference.
2335         synthetic_child_sp = GetValueForExpressionPath(expression,
2336                                                        NULL, NULL, NULL,
2337                                                        GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
2338 
2339         // Cache the value if we got one back...
2340         if (synthetic_child_sp.get())
2341         {
2342             // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
2343             AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2344             synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
2345         }
2346     }
2347     return synthetic_child_sp;
2348 }
2349 
2350 void
2351 ValueObject::CalculateSyntheticValue (bool use_synthetic)
2352 {
2353     if (use_synthetic == false)
2354         return;
2355 
2356     TargetSP target_sp(GetTargetSP());
2357     if (target_sp && target_sp->GetEnableSyntheticValue() == false)
2358     {
2359         m_synthetic_value = NULL;
2360         return;
2361     }
2362 
2363     lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2364 
2365     if (!UpdateFormatsIfNeeded() && m_synthetic_value)
2366         return;
2367 
2368     if (m_synthetic_children_sp.get() == NULL)
2369         return;
2370 
2371     if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2372         return;
2373 
2374     m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
2375 }
2376 
2377 void
2378 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
2379 {
2380     if (use_dynamic == eNoDynamicValues)
2381         return;
2382 
2383     if (!m_dynamic_value && !IsDynamic())
2384     {
2385         ExecutionContext exe_ctx (GetExecutionContextRef());
2386         Process *process = exe_ctx.GetProcessPtr();
2387         if (process && process->IsPossibleDynamicValue(*this))
2388         {
2389             ClearDynamicTypeInformation ();
2390             m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2391         }
2392     }
2393 }
2394 
2395 ValueObjectSP
2396 ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
2397 {
2398     if (use_dynamic == eNoDynamicValues)
2399         return ValueObjectSP();
2400 
2401     if (!IsDynamic() && m_dynamic_value == NULL)
2402     {
2403         CalculateDynamicValue(use_dynamic);
2404     }
2405     if (m_dynamic_value)
2406         return m_dynamic_value->GetSP();
2407     else
2408         return ValueObjectSP();
2409 }
2410 
2411 ValueObjectSP
2412 ValueObject::GetStaticValue()
2413 {
2414     return GetSP();
2415 }
2416 
2417 lldb::ValueObjectSP
2418 ValueObject::GetNonSyntheticValue ()
2419 {
2420     return GetSP();
2421 }
2422 
2423 ValueObjectSP
2424 ValueObject::GetSyntheticValue (bool use_synthetic)
2425 {
2426     if (use_synthetic == false)
2427         return ValueObjectSP();
2428 
2429     CalculateSyntheticValue(use_synthetic);
2430 
2431     if (m_synthetic_value)
2432         return m_synthetic_value->GetSP();
2433     else
2434         return ValueObjectSP();
2435 }
2436 
2437 bool
2438 ValueObject::HasSyntheticValue()
2439 {
2440     UpdateFormatsIfNeeded();
2441 
2442     if (m_synthetic_children_sp.get() == NULL)
2443         return false;
2444 
2445     CalculateSyntheticValue(true);
2446 
2447     if (m_synthetic_value)
2448         return true;
2449     else
2450         return false;
2451 }
2452 
2453 bool
2454 ValueObject::GetBaseClassPath (Stream &s)
2455 {
2456     if (IsBaseClass())
2457     {
2458         bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
2459         ClangASTType clang_type = GetClangType();
2460         std::string cxx_class_name;
2461         bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
2462         if (this_had_base_class)
2463         {
2464             if (parent_had_base_class)
2465                 s.PutCString("::");
2466             s.PutCString(cxx_class_name.c_str());
2467         }
2468         return parent_had_base_class || this_had_base_class;
2469     }
2470     return false;
2471 }
2472 
2473 
2474 ValueObject *
2475 ValueObject::GetNonBaseClassParent()
2476 {
2477     if (GetParent())
2478     {
2479         if (GetParent()->IsBaseClass())
2480             return GetParent()->GetNonBaseClassParent();
2481         else
2482             return GetParent();
2483     }
2484     return NULL;
2485 }
2486 
2487 
2488 bool
2489 ValueObject::IsBaseClass (uint32_t& depth)
2490 {
2491     if (!IsBaseClass())
2492     {
2493         depth = 0;
2494         return false;
2495     }
2496     if (GetParent())
2497     {
2498         GetParent()->IsBaseClass(depth);
2499         depth = depth + 1;
2500         return true;
2501     }
2502     // TODO: a base of no parent? weird..
2503     depth = 1;
2504     return true;
2505 }
2506 
2507 void
2508 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
2509 {
2510     const bool is_deref_of_parent = IsDereferenceOfParent ();
2511 
2512     if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2513     {
2514         // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2515         // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2516         // the eHonorPointers mode is meant to produce strings in this latter format
2517         s.PutCString("*(");
2518     }
2519 
2520     ValueObject* parent = GetParent();
2521 
2522     if (parent)
2523         parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
2524 
2525     // if we are a deref_of_parent just because we are synthetic array
2526     // members made up to allow ptr[%d] syntax to work in variable
2527     // printing, then add our name ([%d]) to the expression path
2528     if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
2529         s.PutCString(m_name.AsCString());
2530 
2531     if (!IsBaseClass())
2532     {
2533         if (!is_deref_of_parent)
2534         {
2535             ValueObject *non_base_class_parent = GetNonBaseClassParent();
2536             if (non_base_class_parent)
2537             {
2538                 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2539                 if (non_base_class_parent_clang_type)
2540                 {
2541                     if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
2542                     {
2543                         s.PutCString("->");
2544                     }
2545                     else
2546                     {
2547                         const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2548 
2549                         if (non_base_class_parent_type_info & eTypeIsPointer)
2550                         {
2551                             s.PutCString("->");
2552                         }
2553                         else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2554                                  !(non_base_class_parent_type_info & eTypeIsArray))
2555                         {
2556                             s.PutChar('.');
2557                         }
2558                     }
2559                 }
2560             }
2561 
2562             const char *name = GetName().GetCString();
2563             if (name)
2564             {
2565                 if (qualify_cxx_base_classes)
2566                 {
2567                     if (GetBaseClassPath (s))
2568                         s.PutCString("::");
2569                 }
2570                 s.PutCString(name);
2571             }
2572         }
2573     }
2574 
2575     if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2576     {
2577         s.PutChar(')');
2578     }
2579 }
2580 
2581 ValueObjectSP
2582 ValueObject::GetValueForExpressionPath(const char* expression,
2583                                        const char** first_unparsed,
2584                                        ExpressionPathScanEndReason* reason_to_stop,
2585                                        ExpressionPathEndResultType* final_value_type,
2586                                        const GetValueForExpressionPathOptions& options,
2587                                        ExpressionPathAftermath* final_task_on_target)
2588 {
2589 
2590     const char* dummy_first_unparsed;
2591     ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2592     ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2593     ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2594 
2595     ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2596                                                            first_unparsed ? first_unparsed : &dummy_first_unparsed,
2597                                                            reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2598                                                            final_value_type ? final_value_type : &dummy_final_value_type,
2599                                                            options,
2600                                                            final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2601 
2602     if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2603         return ret_val;
2604 
2605     if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
2606     {
2607         if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
2608         {
2609             Error error;
2610             ValueObjectSP final_value = ret_val->Dereference(error);
2611             if (error.Fail() || !final_value.get())
2612             {
2613                 if (reason_to_stop)
2614                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2615                 if (final_value_type)
2616                     *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2617                 return ValueObjectSP();
2618             }
2619             else
2620             {
2621                 if (final_task_on_target)
2622                     *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2623                 return final_value;
2624             }
2625         }
2626         if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2627         {
2628             Error error;
2629             ValueObjectSP final_value = ret_val->AddressOf(error);
2630             if (error.Fail() || !final_value.get())
2631             {
2632                 if (reason_to_stop)
2633                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2634                 if (final_value_type)
2635                     *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2636                 return ValueObjectSP();
2637             }
2638             else
2639             {
2640                 if (final_task_on_target)
2641                     *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2642                 return final_value;
2643             }
2644         }
2645     }
2646     return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2647 }
2648 
2649 int
2650 ValueObject::GetValuesForExpressionPath(const char* expression,
2651                                         ValueObjectListSP& list,
2652                                         const char** first_unparsed,
2653                                         ExpressionPathScanEndReason* reason_to_stop,
2654                                         ExpressionPathEndResultType* final_value_type,
2655                                         const GetValueForExpressionPathOptions& options,
2656                                         ExpressionPathAftermath* final_task_on_target)
2657 {
2658     const char* dummy_first_unparsed;
2659     ExpressionPathScanEndReason dummy_reason_to_stop;
2660     ExpressionPathEndResultType dummy_final_value_type;
2661     ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2662 
2663     ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2664                                                            first_unparsed ? first_unparsed : &dummy_first_unparsed,
2665                                                            reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2666                                                            final_value_type ? final_value_type : &dummy_final_value_type,
2667                                                            options,
2668                                                            final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2669 
2670     if (!ret_val.get()) // if there are errors, I add nothing to the list
2671         return 0;
2672 
2673     if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
2674     {
2675         // I need not expand a range, just post-process the final value and return
2676         if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2677         {
2678             list->Append(ret_val);
2679             return 1;
2680         }
2681         if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
2682         {
2683             if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
2684             {
2685                 Error error;
2686                 ValueObjectSP final_value = ret_val->Dereference(error);
2687                 if (error.Fail() || !final_value.get())
2688                 {
2689                     if (reason_to_stop)
2690                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2691                     if (final_value_type)
2692                         *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2693                     return 0;
2694                 }
2695                 else
2696                 {
2697                     *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2698                     list->Append(final_value);
2699                     return 1;
2700                 }
2701             }
2702             if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2703             {
2704                 Error error;
2705                 ValueObjectSP final_value = ret_val->AddressOf(error);
2706                 if (error.Fail() || !final_value.get())
2707                 {
2708                     if (reason_to_stop)
2709                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2710                     if (final_value_type)
2711                         *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2712                     return 0;
2713                 }
2714                 else
2715                 {
2716                     *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2717                     list->Append(final_value);
2718                     return 1;
2719                 }
2720             }
2721         }
2722     }
2723     else
2724     {
2725         return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2726                                           first_unparsed ? first_unparsed : &dummy_first_unparsed,
2727                                           ret_val,
2728                                           list,
2729                                           reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2730                                           final_value_type ? final_value_type : &dummy_final_value_type,
2731                                           options,
2732                                           final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2733     }
2734     // in any non-covered case, just do the obviously right thing
2735     list->Append(ret_val);
2736     return 1;
2737 }
2738 
2739 ValueObjectSP
2740 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2741                                             const char** first_unparsed,
2742                                             ExpressionPathScanEndReason* reason_to_stop,
2743                                             ExpressionPathEndResultType* final_result,
2744                                             const GetValueForExpressionPathOptions& options,
2745                                             ExpressionPathAftermath* what_next)
2746 {
2747     ValueObjectSP root = GetSP();
2748 
2749     if (!root.get())
2750         return ValueObjectSP();
2751 
2752     *first_unparsed = expression_cstr;
2753 
2754     while (true)
2755     {
2756 
2757         const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2758 
2759         ClangASTType root_clang_type = root->GetClangType();
2760         ClangASTType pointee_clang_type;
2761         Flags pointee_clang_type_info;
2762 
2763         Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
2764         if (pointee_clang_type)
2765             pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
2766 
2767         if (!expression_cstr || *expression_cstr == '\0')
2768         {
2769             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2770             return root;
2771         }
2772 
2773         switch (*expression_cstr)
2774         {
2775             case '-':
2776             {
2777                 if (options.m_check_dot_vs_arrow_syntax &&
2778                     root_clang_type_info.Test(eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
2779                 {
2780                     *first_unparsed = expression_cstr;
2781                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2782                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2783                     return ValueObjectSP();
2784                 }
2785                 if (root_clang_type_info.Test(eTypeIsObjC) &&  // if yo are trying to extract an ObjC IVar when this is forbidden
2786                     root_clang_type_info.Test(eTypeIsPointer) &&
2787                     options.m_no_fragile_ivar)
2788                 {
2789                     *first_unparsed = expression_cstr;
2790                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2791                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2792                     return ValueObjectSP();
2793                 }
2794                 if (expression_cstr[1] != '>')
2795                 {
2796                     *first_unparsed = expression_cstr;
2797                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2798                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2799                     return ValueObjectSP();
2800                 }
2801                 expression_cstr++; // skip the -
2802             }
2803             case '.': // or fallthrough from ->
2804             {
2805                 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
2806                     root_clang_type_info.Test(eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
2807                 {
2808                     *first_unparsed = expression_cstr;
2809                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2810                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2811                     return ValueObjectSP();
2812                 }
2813                 expression_cstr++; // skip .
2814                 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2815                 ConstString child_name;
2816                 if (!next_separator) // if no other separator just expand this last layer
2817                 {
2818                     child_name.SetCString (expression_cstr);
2819                     ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2820 
2821                     if (child_valobj_sp.get()) // we know we are done, so just return
2822                     {
2823                         *first_unparsed = "";
2824                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2825                         *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2826                         return child_valobj_sp;
2827                     }
2828                     else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2829                     {
2830                         if (root->IsSynthetic())
2831                         {
2832                             *first_unparsed = expression_cstr;
2833                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
2834                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2835                             return ValueObjectSP();
2836                         }
2837 
2838                         child_valobj_sp = root->GetSyntheticValue();
2839                         if (child_valobj_sp.get())
2840                             child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2841                     }
2842 
2843                     // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2844                     // so we hit the "else" branch, and return an error
2845                     if(child_valobj_sp.get()) // if it worked, just return
2846                     {
2847                         *first_unparsed = "";
2848                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2849                         *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2850                         return child_valobj_sp;
2851                     }
2852                     else
2853                     {
2854                         *first_unparsed = expression_cstr;
2855                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2856                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2857                         return ValueObjectSP();
2858                     }
2859                 }
2860                 else // other layers do expand
2861                 {
2862                     child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2863                     ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2864                     if (child_valobj_sp.get()) // store the new root and move on
2865                     {
2866                         root = child_valobj_sp;
2867                         *first_unparsed = next_separator;
2868                         *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2869                         continue;
2870                     }
2871                     else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2872                     {
2873                         if (root->IsSynthetic())
2874                         {
2875                             *first_unparsed = expression_cstr;
2876                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2877                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2878                             return ValueObjectSP();
2879                         }
2880 
2881                         child_valobj_sp = root->GetSyntheticValue(true);
2882                         if (child_valobj_sp)
2883                             child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2884                     }
2885 
2886                     // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2887                     // so we hit the "else" branch, and return an error
2888                     if(child_valobj_sp.get()) // if it worked, move on
2889                     {
2890                         root = child_valobj_sp;
2891                         *first_unparsed = next_separator;
2892                         *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2893                         continue;
2894                     }
2895                     else
2896                     {
2897                         *first_unparsed = expression_cstr;
2898                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2899                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2900                         return ValueObjectSP();
2901                     }
2902                 }
2903                 break;
2904             }
2905             case '[':
2906             {
2907                 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer) && !root_clang_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
2908                 {
2909                     if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
2910                     {
2911                         if (options.m_no_synthetic_children) // ...only chance left is synthetic
2912                         {
2913                             *first_unparsed = expression_cstr;
2914                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2915                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2916                             return ValueObjectSP();
2917                         }
2918                     }
2919                     else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2920                     {
2921                         *first_unparsed = expression_cstr;
2922                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2923                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2924                         return ValueObjectSP();
2925                     }
2926                 }
2927                 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2928                 {
2929                     if (!root_clang_type_info.Test(eTypeIsArray))
2930                     {
2931                         *first_unparsed = expression_cstr;
2932                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2933                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2934                         return ValueObjectSP();
2935                     }
2936                     else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2937                     {
2938                         *first_unparsed = expression_cstr+2;
2939                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2940                         *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2941                         return root;
2942                     }
2943                 }
2944                 const char *separator_position = ::strchr(expression_cstr+1,'-');
2945                 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2946                 if (!close_bracket_position) // if there is no ], this is a syntax error
2947                 {
2948                     *first_unparsed = expression_cstr;
2949                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2950                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2951                     return ValueObjectSP();
2952                 }
2953                 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2954                 {
2955                     char *end = NULL;
2956                     unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2957                     if (!end || end != close_bracket_position) // if something weird is in our way return an error
2958                     {
2959                         *first_unparsed = expression_cstr;
2960                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2961                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2962                         return ValueObjectSP();
2963                     }
2964                     if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2965                     {
2966                         if (root_clang_type_info.Test(eTypeIsArray))
2967                         {
2968                             *first_unparsed = expression_cstr+2;
2969                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2970                             *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2971                             return root;
2972                         }
2973                         else
2974                         {
2975                             *first_unparsed = expression_cstr;
2976                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2977                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2978                             return ValueObjectSP();
2979                         }
2980                     }
2981                     // from here on we do have a valid index
2982                     if (root_clang_type_info.Test(eTypeIsArray))
2983                     {
2984                         ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2985                         if (!child_valobj_sp)
2986                             child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2987                         if (!child_valobj_sp)
2988                             if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2989                                 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2990                         if (child_valobj_sp)
2991                         {
2992                             root = child_valobj_sp;
2993                             *first_unparsed = end+1; // skip ]
2994                             *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2995                             continue;
2996                         }
2997                         else
2998                         {
2999                             *first_unparsed = expression_cstr;
3000                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3001                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3002                             return ValueObjectSP();
3003                         }
3004                     }
3005                     else if (root_clang_type_info.Test(eTypeIsPointer))
3006                     {
3007                         if (*what_next == ValueObject::eExpressionPathAftermathDereference &&  // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3008                             pointee_clang_type_info.Test(eTypeIsScalar))
3009                         {
3010                             Error error;
3011                             root = root->Dereference(error);
3012                             if (error.Fail() || !root.get())
3013                             {
3014                                 *first_unparsed = expression_cstr;
3015                                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3016                                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3017                                 return ValueObjectSP();
3018                             }
3019                             else
3020                             {
3021                                 *what_next = eExpressionPathAftermathNothing;
3022                                 continue;
3023                             }
3024                         }
3025                         else
3026                         {
3027                             if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
3028                                 && pointee_clang_type_info.AllClear(eTypeIsPointer)
3029                                 && root->HasSyntheticValue()
3030                                 && options.m_no_synthetic_children == false)
3031                             {
3032                                 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
3033                             }
3034                             else
3035                                 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3036                             if (!root.get())
3037                             {
3038                                 *first_unparsed = expression_cstr;
3039                                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3040                                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3041                                 return ValueObjectSP();
3042                             }
3043                             else
3044                             {
3045                                 *first_unparsed = end+1; // skip ]
3046                                 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3047                                 continue;
3048                             }
3049                         }
3050                     }
3051                     else if (root_clang_type_info.Test(eTypeIsScalar))
3052                     {
3053                         root = root->GetSyntheticBitFieldChild(index, index, true);
3054                         if (!root.get())
3055                         {
3056                             *first_unparsed = expression_cstr;
3057                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3058                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3059                             return ValueObjectSP();
3060                         }
3061                         else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3062                         {
3063                             *first_unparsed = end+1; // skip ]
3064                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3065                             *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3066                             return root;
3067                         }
3068                     }
3069                     else if (root_clang_type_info.Test(eTypeIsVector))
3070                     {
3071                         root = root->GetChildAtIndex(index, true);
3072                         if (!root.get())
3073                         {
3074                             *first_unparsed = expression_cstr;
3075                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3076                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3077                             return ValueObjectSP();
3078                         }
3079                         else
3080                         {
3081                             *first_unparsed = end+1; // skip ]
3082                             *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3083                             continue;
3084                         }
3085                     }
3086                     else if (options.m_no_synthetic_children == false)
3087                     {
3088                         if (root->HasSyntheticValue())
3089                             root = root->GetSyntheticValue();
3090                         else if (!root->IsSynthetic())
3091                         {
3092                             *first_unparsed = expression_cstr;
3093                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3094                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3095                             return ValueObjectSP();
3096                         }
3097                         // if we are here, then root itself is a synthetic VO.. should be good to go
3098 
3099                         if (!root.get())
3100                         {
3101                             *first_unparsed = expression_cstr;
3102                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3103                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3104                             return ValueObjectSP();
3105                         }
3106                         root = root->GetChildAtIndex(index, true);
3107                         if (!root.get())
3108                         {
3109                             *first_unparsed = expression_cstr;
3110                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3111                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3112                             return ValueObjectSP();
3113                         }
3114                         else
3115                         {
3116                             *first_unparsed = end+1; // skip ]
3117                             *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3118                             continue;
3119                         }
3120                     }
3121                     else
3122                     {
3123                         *first_unparsed = expression_cstr;
3124                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3125                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3126                         return ValueObjectSP();
3127                     }
3128                 }
3129                 else // we have a low and a high index
3130                 {
3131                     char *end = NULL;
3132                     unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3133                     if (!end || end != separator_position) // if something weird is in our way return an error
3134                     {
3135                         *first_unparsed = expression_cstr;
3136                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3137                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3138                         return ValueObjectSP();
3139                     }
3140                     unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3141                     if (!end || end != close_bracket_position) // if something weird is in our way return an error
3142                     {
3143                         *first_unparsed = expression_cstr;
3144                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3145                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3146                         return ValueObjectSP();
3147                     }
3148                     if (index_lower > index_higher) // swap indices if required
3149                     {
3150                         unsigned long temp = index_lower;
3151                         index_lower = index_higher;
3152                         index_higher = temp;
3153                     }
3154                     if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
3155                     {
3156                         root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3157                         if (!root.get())
3158                         {
3159                             *first_unparsed = expression_cstr;
3160                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3161                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3162                             return ValueObjectSP();
3163                         }
3164                         else
3165                         {
3166                             *first_unparsed = end+1; // skip ]
3167                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3168                             *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3169                             return root;
3170                         }
3171                     }
3172                     else if (root_clang_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3173                              *what_next == ValueObject::eExpressionPathAftermathDereference &&
3174                              pointee_clang_type_info.Test(eTypeIsScalar))
3175                     {
3176                         Error error;
3177                         root = root->Dereference(error);
3178                         if (error.Fail() || !root.get())
3179                         {
3180                             *first_unparsed = expression_cstr;
3181                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3182                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3183                             return ValueObjectSP();
3184                         }
3185                         else
3186                         {
3187                             *what_next = ValueObject::eExpressionPathAftermathNothing;
3188                             continue;
3189                         }
3190                     }
3191                     else
3192                     {
3193                         *first_unparsed = expression_cstr;
3194                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3195                         *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
3196                         return root;
3197                     }
3198                 }
3199                 break;
3200             }
3201             default: // some non-separator is in the way
3202             {
3203                 *first_unparsed = expression_cstr;
3204                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3205                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3206                 return ValueObjectSP();
3207                 break;
3208             }
3209         }
3210     }
3211 }
3212 
3213 int
3214 ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3215                                         const char** first_unparsed,
3216                                         ValueObjectSP root,
3217                                         ValueObjectListSP& list,
3218                                         ExpressionPathScanEndReason* reason_to_stop,
3219                                         ExpressionPathEndResultType* final_result,
3220                                         const GetValueForExpressionPathOptions& options,
3221                                         ExpressionPathAftermath* what_next)
3222 {
3223     if (!root.get())
3224         return 0;
3225 
3226     *first_unparsed = expression_cstr;
3227 
3228     while (true)
3229     {
3230 
3231         const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3232 
3233         ClangASTType root_clang_type = root->GetClangType();
3234         ClangASTType pointee_clang_type;
3235         Flags pointee_clang_type_info;
3236         Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
3237         if (pointee_clang_type)
3238             pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
3239 
3240         if (!expression_cstr || *expression_cstr == '\0')
3241         {
3242             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
3243             list->Append(root);
3244             return 1;
3245         }
3246 
3247         switch (*expression_cstr)
3248         {
3249             case '[':
3250             {
3251                 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
3252                 {
3253                     if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3254                     {
3255                         *first_unparsed = expression_cstr;
3256                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3257                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3258                         return 0;
3259                     }
3260                     else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3261                     {
3262                         *first_unparsed = expression_cstr;
3263                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3264                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3265                         return 0;
3266                     }
3267                 }
3268                 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3269                 {
3270                     if (!root_clang_type_info.Test(eTypeIsArray))
3271                     {
3272                         *first_unparsed = expression_cstr;
3273                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3274                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3275                         return 0;
3276                     }
3277                     else // expand this into list
3278                     {
3279                         const size_t max_index = root->GetNumChildren() - 1;
3280                         for (size_t index = 0; index < max_index; index++)
3281                         {
3282                             ValueObjectSP child =
3283                                 root->GetChildAtIndex(index, true);
3284                             list->Append(child);
3285                         }
3286                         *first_unparsed = expression_cstr+2;
3287                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3288                         *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3289                         return max_index; // tell me number of items I added to the VOList
3290                     }
3291                 }
3292                 const char *separator_position = ::strchr(expression_cstr+1,'-');
3293                 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3294                 if (!close_bracket_position) // if there is no ], this is a syntax error
3295                 {
3296                     *first_unparsed = expression_cstr;
3297                     *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3298                     *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3299                     return 0;
3300                 }
3301                 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3302                 {
3303                     char *end = NULL;
3304                     unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3305                     if (!end || end != close_bracket_position) // if something weird is in our way return an error
3306                     {
3307                         *first_unparsed = expression_cstr;
3308                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3309                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3310                         return 0;
3311                     }
3312                     if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3313                     {
3314                         if (root_clang_type_info.Test(eTypeIsArray))
3315                         {
3316                             const size_t max_index = root->GetNumChildren() - 1;
3317                             for (size_t index = 0; index < max_index; index++)
3318                             {
3319                                 ValueObjectSP child =
3320                                 root->GetChildAtIndex(index, true);
3321                                 list->Append(child);
3322                             }
3323                             *first_unparsed = expression_cstr+2;
3324                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3325                             *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3326                             return max_index; // tell me number of items I added to the VOList
3327                         }
3328                         else
3329                         {
3330                             *first_unparsed = expression_cstr;
3331                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3332                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3333                             return 0;
3334                         }
3335                     }
3336                     // from here on we do have a valid index
3337                     if (root_clang_type_info.Test(eTypeIsArray))
3338                     {
3339                         root = root->GetChildAtIndex(index, true);
3340                         if (!root.get())
3341                         {
3342                             *first_unparsed = expression_cstr;
3343                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3344                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3345                             return 0;
3346                         }
3347                         else
3348                         {
3349                             list->Append(root);
3350                             *first_unparsed = end+1; // skip ]
3351                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3352                             *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3353                             return 1;
3354                         }
3355                     }
3356                     else if (root_clang_type_info.Test(eTypeIsPointer))
3357                     {
3358                         if (*what_next == ValueObject::eExpressionPathAftermathDereference &&  // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3359                             pointee_clang_type_info.Test(eTypeIsScalar))
3360                         {
3361                             Error error;
3362                             root = root->Dereference(error);
3363                             if (error.Fail() || !root.get())
3364                             {
3365                                 *first_unparsed = expression_cstr;
3366                                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3367                                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3368                                 return 0;
3369                             }
3370                             else
3371                             {
3372                                 *what_next = eExpressionPathAftermathNothing;
3373                                 continue;
3374                             }
3375                         }
3376                         else
3377                         {
3378                             root = root->GetSyntheticArrayMemberFromPointer(index, true);
3379                             if (!root.get())
3380                             {
3381                                 *first_unparsed = expression_cstr;
3382                                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3383                                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3384                                 return 0;
3385                             }
3386                             else
3387                             {
3388                                 list->Append(root);
3389                                 *first_unparsed = end+1; // skip ]
3390                                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3391                                 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3392                                 return 1;
3393                             }
3394                         }
3395                     }
3396                     else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3397                     {
3398                         root = root->GetSyntheticBitFieldChild(index, index, true);
3399                         if (!root.get())
3400                         {
3401                             *first_unparsed = expression_cstr;
3402                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3403                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3404                             return 0;
3405                         }
3406                         else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3407                         {
3408                             list->Append(root);
3409                             *first_unparsed = end+1; // skip ]
3410                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3411                             *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3412                             return 1;
3413                         }
3414                     }
3415                 }
3416                 else // we have a low and a high index
3417                 {
3418                     char *end = NULL;
3419                     unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3420                     if (!end || end != separator_position) // if something weird is in our way return an error
3421                     {
3422                         *first_unparsed = expression_cstr;
3423                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3424                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3425                         return 0;
3426                     }
3427                     unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3428                     if (!end || end != close_bracket_position) // if something weird is in our way return an error
3429                     {
3430                         *first_unparsed = expression_cstr;
3431                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3432                         *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3433                         return 0;
3434                     }
3435                     if (index_lower > index_higher) // swap indices if required
3436                     {
3437                         unsigned long temp = index_lower;
3438                         index_lower = index_higher;
3439                         index_higher = temp;
3440                     }
3441                     if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
3442                     {
3443                         root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3444                         if (!root.get())
3445                         {
3446                             *first_unparsed = expression_cstr;
3447                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3448                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3449                             return 0;
3450                         }
3451                         else
3452                         {
3453                             list->Append(root);
3454                             *first_unparsed = end+1; // skip ]
3455                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3456                             *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3457                             return 1;
3458                         }
3459                     }
3460                     else if (root_clang_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3461                              *what_next == ValueObject::eExpressionPathAftermathDereference &&
3462                              pointee_clang_type_info.Test(eTypeIsScalar))
3463                     {
3464                         Error error;
3465                         root = root->Dereference(error);
3466                         if (error.Fail() || !root.get())
3467                         {
3468                             *first_unparsed = expression_cstr;
3469                             *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3470                             *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3471                             return 0;
3472                         }
3473                         else
3474                         {
3475                             *what_next = ValueObject::eExpressionPathAftermathNothing;
3476                             continue;
3477                         }
3478                     }
3479                     else
3480                     {
3481                         for (unsigned long index = index_lower;
3482                              index <= index_higher; index++)
3483                         {
3484                             ValueObjectSP child =
3485                                 root->GetChildAtIndex(index, true);
3486                             list->Append(child);
3487                         }
3488                         *first_unparsed = end+1;
3489                         *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3490                         *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3491                         return index_higher-index_lower+1; // tell me number of items I added to the VOList
3492                     }
3493                 }
3494                 break;
3495             }
3496             default: // some non-[ separator, or something entirely wrong, is in the way
3497             {
3498                 *first_unparsed = expression_cstr;
3499                 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3500                 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3501                 return 0;
3502                 break;
3503             }
3504         }
3505     }
3506 }
3507 
3508 void
3509 ValueObject::LogValueObject (Log *log)
3510 {
3511     if (log)
3512         return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
3513 }
3514 
3515 void
3516 ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
3517 {
3518     if (log)
3519     {
3520         StreamString s;
3521         Dump (s, options);
3522         if (s.GetSize())
3523             log->PutCString(s.GetData());
3524     }
3525 }
3526 
3527 void
3528 ValueObject::Dump (Stream &s)
3529 {
3530 
3531     ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3532     printer.PrintValueObject();
3533 }
3534 
3535 void
3536 ValueObject::Dump (Stream &s,
3537                    const DumpValueObjectOptions& options)
3538 {
3539     ValueObjectPrinter printer(this,&s,options);
3540     printer.PrintValueObject();
3541 }
3542 
3543 ValueObjectSP
3544 ValueObject::CreateConstantValue (const ConstString &name)
3545 {
3546     ValueObjectSP valobj_sp;
3547 
3548     if (UpdateValueIfNeeded(false) && m_error.Success())
3549     {
3550         ExecutionContext exe_ctx (GetExecutionContextRef());
3551 
3552         DataExtractor data;
3553         data.SetByteOrder (m_data.GetByteOrder());
3554         data.SetAddressByteSize(m_data.GetAddressByteSize());
3555 
3556         if (IsBitfield())
3557         {
3558             Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3559             m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3560         }
3561         else
3562             m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3563 
3564         valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3565                                                     GetClangType(),
3566                                                     name,
3567                                                     data,
3568                                                     GetAddressOf());
3569     }
3570 
3571     if (!valobj_sp)
3572     {
3573         ExecutionContext exe_ctx (GetExecutionContextRef());
3574         valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
3575     }
3576     return valobj_sp;
3577 }
3578 
3579 ValueObjectSP
3580 ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3581                                                     bool synthValue)
3582 {
3583     ValueObjectSP result_sp(GetSP());
3584 
3585     switch (dynValue)
3586     {
3587         case lldb::eDynamicCanRunTarget:
3588         case lldb::eDynamicDontRunTarget:
3589         {
3590             if (!result_sp->IsDynamic())
3591             {
3592                 if (result_sp->GetDynamicValue(dynValue))
3593                     result_sp = result_sp->GetDynamicValue(dynValue);
3594             }
3595         }
3596             break;
3597         case lldb::eNoDynamicValues:
3598         {
3599             if (result_sp->IsDynamic())
3600             {
3601                 if (result_sp->GetStaticValue())
3602                     result_sp = result_sp->GetStaticValue();
3603             }
3604         }
3605             break;
3606     }
3607 
3608     if (synthValue)
3609     {
3610         if (!result_sp->IsSynthetic())
3611         {
3612             if (result_sp->GetSyntheticValue())
3613                 result_sp = result_sp->GetSyntheticValue();
3614         }
3615     }
3616     else
3617     {
3618         if (result_sp->IsSynthetic())
3619         {
3620             if (result_sp->GetNonSyntheticValue())
3621                 result_sp = result_sp->GetNonSyntheticValue();
3622         }
3623     }
3624 
3625     return result_sp;
3626 }
3627 
3628 lldb::addr_t
3629 ValueObject::GetCPPVTableAddress (AddressType &address_type)
3630 {
3631     ClangASTType pointee_type;
3632     ClangASTType this_type(GetClangType());
3633     uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3634     if (type_info)
3635     {
3636         bool ptr_or_ref = false;
3637         if (type_info & (eTypeIsPointer | eTypeIsReference))
3638         {
3639             ptr_or_ref = true;
3640             type_info = pointee_type.GetTypeInfo();
3641         }
3642 
3643         const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
3644         if ((type_info & cpp_class) == cpp_class)
3645         {
3646             if (ptr_or_ref)
3647             {
3648                 address_type = GetAddressTypeOfChildren();
3649                 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3650             }
3651             else
3652                 return GetAddressOf (false, &address_type);
3653         }
3654     }
3655 
3656     address_type = eAddressTypeInvalid;
3657     return LLDB_INVALID_ADDRESS;
3658 }
3659 
3660 ValueObjectSP
3661 ValueObject::Dereference (Error &error)
3662 {
3663     if (m_deref_valobj)
3664         return m_deref_valobj->GetSP();
3665 
3666     const bool is_pointer_type = IsPointerType();
3667     if (is_pointer_type)
3668     {
3669         bool omit_empty_base_classes = true;
3670         bool ignore_array_bounds = false;
3671 
3672         std::string child_name_str;
3673         uint32_t child_byte_size = 0;
3674         int32_t child_byte_offset = 0;
3675         uint32_t child_bitfield_bit_size = 0;
3676         uint32_t child_bitfield_bit_offset = 0;
3677         bool child_is_base_class = false;
3678         bool child_is_deref_of_parent = false;
3679         const bool transparent_pointers = false;
3680         ClangASTType clang_type = GetClangType();
3681         ClangASTType child_clang_type;
3682 
3683         ExecutionContext exe_ctx (GetExecutionContextRef());
3684 
3685         child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3686                                                                 0,
3687                                                                 transparent_pointers,
3688                                                                 omit_empty_base_classes,
3689                                                                 ignore_array_bounds,
3690                                                                 child_name_str,
3691                                                                 child_byte_size,
3692                                                                 child_byte_offset,
3693                                                                 child_bitfield_bit_size,
3694                                                                 child_bitfield_bit_offset,
3695                                                                 child_is_base_class,
3696                                                                 child_is_deref_of_parent,
3697                                                                 this);
3698         if (child_clang_type && child_byte_size)
3699         {
3700             ConstString child_name;
3701             if (!child_name_str.empty())
3702                 child_name.SetCString (child_name_str.c_str());
3703 
3704             m_deref_valobj = new ValueObjectChild (*this,
3705                                                    child_clang_type,
3706                                                    child_name,
3707                                                    child_byte_size,
3708                                                    child_byte_offset,
3709                                                    child_bitfield_bit_size,
3710                                                    child_bitfield_bit_offset,
3711                                                    child_is_base_class,
3712                                                    child_is_deref_of_parent,
3713                                                    eAddressTypeInvalid);
3714         }
3715     }
3716 
3717     if (m_deref_valobj)
3718     {
3719         error.Clear();
3720         return m_deref_valobj->GetSP();
3721     }
3722     else
3723     {
3724         StreamString strm;
3725         GetExpressionPath(strm, true);
3726 
3727         if (is_pointer_type)
3728             error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3729         else
3730             error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3731         return ValueObjectSP();
3732     }
3733 }
3734 
3735 ValueObjectSP
3736 ValueObject::AddressOf (Error &error)
3737 {
3738     if (m_addr_of_valobj_sp)
3739         return m_addr_of_valobj_sp;
3740 
3741     AddressType address_type = eAddressTypeInvalid;
3742     const bool scalar_is_load_address = false;
3743     addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
3744     error.Clear();
3745     if (addr != LLDB_INVALID_ADDRESS)
3746     {
3747         switch (address_type)
3748         {
3749         case eAddressTypeInvalid:
3750             {
3751                 StreamString expr_path_strm;
3752                 GetExpressionPath(expr_path_strm, true);
3753                 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3754             }
3755             break;
3756 
3757         case eAddressTypeFile:
3758         case eAddressTypeLoad:
3759         case eAddressTypeHost:
3760             {
3761                 ClangASTType clang_type = GetClangType();
3762                 if (clang_type)
3763                 {
3764                     std::string name (1, '&');
3765                     name.append (m_name.AsCString(""));
3766                     ExecutionContext exe_ctx (GetExecutionContextRef());
3767                     m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3768                                                                           clang_type.GetPointerType(),
3769                                                                           ConstString (name.c_str()),
3770                                                                           addr,
3771                                                                           eAddressTypeInvalid,
3772                                                                           m_data.GetAddressByteSize());
3773                 }
3774             }
3775             break;
3776         }
3777     }
3778     else
3779     {
3780         StreamString expr_path_strm;
3781         GetExpressionPath(expr_path_strm, true);
3782         error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3783     }
3784 
3785     return m_addr_of_valobj_sp;
3786 }
3787 
3788 ValueObjectSP
3789 ValueObject::Cast (const ClangASTType &clang_ast_type)
3790 {
3791     return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
3792 }
3793 
3794 ValueObjectSP
3795 ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3796 {
3797     ValueObjectSP valobj_sp;
3798     AddressType address_type;
3799     addr_t ptr_value = GetPointerValue (&address_type);
3800 
3801     if (ptr_value != LLDB_INVALID_ADDRESS)
3802     {
3803         Address ptr_addr (ptr_value);
3804         ExecutionContext exe_ctx (GetExecutionContextRef());
3805         valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3806                                                name,
3807                                                ptr_addr,
3808                                                clang_ast_type);
3809     }
3810     return valobj_sp;
3811 }
3812 
3813 ValueObjectSP
3814 ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3815 {
3816     ValueObjectSP valobj_sp;
3817     AddressType address_type;
3818     addr_t ptr_value = GetPointerValue (&address_type);
3819 
3820     if (ptr_value != LLDB_INVALID_ADDRESS)
3821     {
3822         Address ptr_addr (ptr_value);
3823         ExecutionContext exe_ctx (GetExecutionContextRef());
3824         valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3825                                                name,
3826                                                ptr_addr,
3827                                                type_sp);
3828     }
3829     return valobj_sp;
3830 }
3831 
3832 ValueObject::EvaluationPoint::EvaluationPoint () :
3833     m_mod_id(),
3834     m_exe_ctx_ref(),
3835     m_needs_update (true),
3836     m_first_update (true)
3837 {
3838 }
3839 
3840 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
3841     m_mod_id(),
3842     m_exe_ctx_ref(),
3843     m_needs_update (true),
3844     m_first_update (true)
3845 {
3846     ExecutionContext exe_ctx(exe_scope);
3847     TargetSP target_sp (exe_ctx.GetTargetSP());
3848     if (target_sp)
3849     {
3850         m_exe_ctx_ref.SetTargetSP (target_sp);
3851         ProcessSP process_sp (exe_ctx.GetProcessSP());
3852         if (!process_sp)
3853             process_sp = target_sp->GetProcessSP();
3854 
3855         if (process_sp)
3856         {
3857             m_mod_id = process_sp->GetModID();
3858             m_exe_ctx_ref.SetProcessSP (process_sp);
3859 
3860             ThreadSP thread_sp (exe_ctx.GetThreadSP());
3861 
3862             if (!thread_sp)
3863             {
3864                 if (use_selected)
3865                     thread_sp = process_sp->GetThreadList().GetSelectedThread();
3866             }
3867 
3868             if (thread_sp)
3869             {
3870                 m_exe_ctx_ref.SetThreadSP(thread_sp);
3871 
3872                 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3873                 if (!frame_sp)
3874                 {
3875                     if (use_selected)
3876                         frame_sp = thread_sp->GetSelectedFrame();
3877                 }
3878                 if (frame_sp)
3879                     m_exe_ctx_ref.SetFrameSP(frame_sp);
3880             }
3881         }
3882     }
3883 }
3884 
3885 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3886     m_mod_id(),
3887     m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3888     m_needs_update (true),
3889     m_first_update (true)
3890 {
3891 }
3892 
3893 ValueObject::EvaluationPoint::~EvaluationPoint ()
3894 {
3895 }
3896 
3897 // This function checks the EvaluationPoint against the current process state.  If the current
3898 // state matches the evaluation point, or the evaluation point is already invalid, then we return
3899 // false, meaning "no change".  If the current state is different, we update our state, and return
3900 // true meaning "yes, change".  If we did see a change, we also set m_needs_update to true, so
3901 // future calls to NeedsUpdate will return true.
3902 // exe_scope will be set to the current execution context scope.
3903 
3904 bool
3905 ValueObject::EvaluationPoint::SyncWithProcessState()
3906 {
3907 
3908     // Start with the target, if it is NULL, then we're obviously not going to get any further:
3909     const bool thread_and_frame_only_if_stopped = true;
3910     ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3911 
3912     if (exe_ctx.GetTargetPtr() == NULL)
3913         return false;
3914 
3915     // If we don't have a process nothing can change.
3916     Process *process = exe_ctx.GetProcessPtr();
3917     if (process == NULL)
3918         return false;
3919 
3920     // If our stop id is the current stop ID, nothing has changed:
3921     ProcessModID current_mod_id = process->GetModID();
3922 
3923     // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3924     // In either case, we aren't going to be able to sync with the process state.
3925     if (current_mod_id.GetStopID() == 0)
3926         return false;
3927 
3928     bool changed = false;
3929     const bool was_valid = m_mod_id.IsValid();
3930     if (was_valid)
3931     {
3932         if (m_mod_id == current_mod_id)
3933         {
3934             // Everything is already up to date in this object, no need to
3935             // update the execution context scope.
3936             changed = false;
3937         }
3938         else
3939         {
3940             m_mod_id = current_mod_id;
3941             m_needs_update = true;
3942             changed = true;
3943         }
3944     }
3945 
3946     // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3947     // That way we'll be sure to return a valid exe_scope.
3948     // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
3949 
3950     if (m_exe_ctx_ref.HasThreadRef())
3951     {
3952         ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3953         if (thread_sp)
3954         {
3955             if (m_exe_ctx_ref.HasFrameRef())
3956             {
3957                 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3958                 if (!frame_sp)
3959                 {
3960                     // We used to have a frame, but now it is gone
3961                     SetInvalid();
3962                     changed = was_valid;
3963                 }
3964             }
3965         }
3966         else
3967         {
3968             // We used to have a thread, but now it is gone
3969             SetInvalid();
3970             changed = was_valid;
3971         }
3972 
3973     }
3974     return changed;
3975 }
3976 
3977 void
3978 ValueObject::EvaluationPoint::SetUpdated ()
3979 {
3980     ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3981     if (process_sp)
3982         m_mod_id = process_sp->GetModID();
3983     m_first_update = false;
3984     m_needs_update = false;
3985 }
3986 
3987 
3988 
3989 void
3990 ValueObject::ClearUserVisibleData(uint32_t clear_mask)
3991 {
3992     if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3993         m_value_str.clear();
3994 
3995     if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3996         m_location_str.clear();
3997 
3998     if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3999         m_summary_str.clear();
4000 
4001     if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4002         m_object_desc_str.clear();
4003 
4004     if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4005     {
4006             if (m_synthetic_value)
4007                 m_synthetic_value = NULL;
4008     }
4009 
4010     if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4011         m_validation_result.reset();
4012 }
4013 
4014 SymbolContextScope *
4015 ValueObject::GetSymbolContextScope()
4016 {
4017     if (m_parent)
4018     {
4019         if (!m_parent->IsPointerOrReferenceType())
4020             return m_parent->GetSymbolContextScope();
4021     }
4022     return NULL;
4023 }
4024 
4025 lldb::ValueObjectSP
4026 ValueObject::CreateValueObjectFromExpression (const char* name,
4027                                               const char* expression,
4028                                               const ExecutionContext& exe_ctx)
4029 {
4030     lldb::ValueObjectSP retval_sp;
4031     lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4032     if (!target_sp)
4033         return retval_sp;
4034     if (!expression || !*expression)
4035         return retval_sp;
4036     target_sp->EvaluateExpression (expression,
4037                                    exe_ctx.GetFrameSP().get(),
4038                                    retval_sp);
4039     if (retval_sp && name && *name)
4040         retval_sp->SetName(ConstString(name));
4041     return retval_sp;
4042 }
4043 
4044 lldb::ValueObjectSP
4045 ValueObject::CreateValueObjectFromAddress (const char* name,
4046                                            uint64_t address,
4047                                            const ExecutionContext& exe_ctx,
4048                                            ClangASTType type)
4049 {
4050     if (type)
4051     {
4052         ClangASTType pointer_type(type.GetPointerType());
4053         if (pointer_type)
4054         {
4055             lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4056             lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4057                                                                                      pointer_type,
4058                                                                                      ConstString(name),
4059                                                                                      buffer,
4060                                                                                      lldb::endian::InlHostByteOrder(),
4061                                                                                      exe_ctx.GetAddressByteSize()));
4062             if (ptr_result_valobj_sp)
4063             {
4064                 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4065                 Error err;
4066                 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4067                 if (ptr_result_valobj_sp && name && *name)
4068                     ptr_result_valobj_sp->SetName(ConstString(name));
4069             }
4070             return ptr_result_valobj_sp;
4071         }
4072     }
4073     return lldb::ValueObjectSP();
4074 }
4075 
4076 lldb::ValueObjectSP
4077 ValueObject::CreateValueObjectFromData (const char* name,
4078                                         const DataExtractor& data,
4079                                         const ExecutionContext& exe_ctx,
4080                                         ClangASTType type)
4081 {
4082     lldb::ValueObjectSP new_value_sp;
4083     new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4084                                                    type,
4085                                                    ConstString(name),
4086                                                    data,
4087                                                    LLDB_INVALID_ADDRESS);
4088     new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4089     if (new_value_sp && name && *name)
4090         new_value_sp->SetName(ConstString(name));
4091     return new_value_sp;
4092 }
4093 
4094 ModuleSP
4095 ValueObject::GetModule ()
4096 {
4097     ValueObject* root(GetRoot());
4098     if (root != this)
4099         return root->GetModule();
4100     return lldb::ModuleSP();
4101 }
4102 
4103 ValueObject*
4104 ValueObject::GetRoot ()
4105 {
4106     if (m_root)
4107         return m_root;
4108     ValueObject* parent = m_parent;
4109     if (!parent)
4110         return (m_root = this);
4111     while (parent->m_parent)
4112     {
4113         if (parent->m_root)
4114             return (m_root = parent->m_root);
4115         parent = parent->m_parent;
4116     }
4117     return (m_root = parent);
4118 }
4119 
4120 AddressType
4121 ValueObject::GetAddressTypeOfChildren()
4122 {
4123     if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4124     {
4125         ValueObject* root(GetRoot());
4126         if (root != this)
4127             return root->GetAddressTypeOfChildren();
4128     }
4129     return m_address_type_of_ptr_or_ref_children;
4130 }
4131 
4132 lldb::DynamicValueType
4133 ValueObject::GetDynamicValueType ()
4134 {
4135     ValueObject* with_dv_info = this;
4136     while (with_dv_info)
4137     {
4138         if (with_dv_info->HasDynamicValueTypeInfo())
4139             return with_dv_info->GetDynamicValueTypeImpl();
4140         with_dv_info = with_dv_info->m_parent;
4141     }
4142     return lldb::eNoDynamicValues;
4143 }
4144 
4145 lldb::Format
4146 ValueObject::GetFormat () const
4147 {
4148     const ValueObject* with_fmt_info = this;
4149     while (with_fmt_info)
4150     {
4151         if (with_fmt_info->m_format != lldb::eFormatDefault)
4152             return with_fmt_info->m_format;
4153         with_fmt_info = with_fmt_info->m_parent;
4154     }
4155     return m_format;
4156 }
4157 
4158 lldb::LanguageType
4159 ValueObject::GetPreferredDisplayLanguage ()
4160 {
4161     lldb::LanguageType type = lldb::eLanguageTypeUnknown;
4162     if (GetRoot())
4163     {
4164         if (GetRoot() == this)
4165         {
4166             if (StackFrameSP frame_sp = GetFrameSP())
4167             {
4168                 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4169                 if (CompileUnit* cu = sc.comp_unit)
4170                     type = cu->GetLanguage();
4171             }
4172         }
4173         else
4174         {
4175             type = GetRoot()->GetPreferredDisplayLanguage();
4176         }
4177     }
4178     return type;
4179 }
4180 
4181 bool
4182 ValueObject::CanProvideValue ()
4183 {
4184     return (false == GetClangType().IsAggregateType());
4185 }
4186 
4187 ValueObjectSP
4188 ValueObject::Persist ()
4189 {
4190     if (!UpdateValueIfNeeded())
4191         return nullptr;
4192 
4193     TargetSP target_sp(GetTargetSP());
4194     if (!target_sp)
4195         return nullptr;
4196 
4197     ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4198 
4199     ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4200     if (clang_var_sp)
4201     {
4202         clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4203         clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4204         target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4205     }
4206 
4207     return clang_var_sp->GetValueObject();
4208 }
4209