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