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