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