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