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