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