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