1 //===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/Core/ValueObject.h"
18 // Other libraries and framework includes
19 #include "llvm/Support/raw_ostream.h"
20 #include "clang/AST/Type.h"
23 #include "lldb/Core/DataBufferHeap.h"
24 #include "lldb/Core/Debugger.h"
25 #include "lldb/Core/Log.h"
26 #include "lldb/Core/Module.h"
27 #include "lldb/Core/StreamString.h"
28 #include "lldb/Core/ValueObjectCast.h"
29 #include "lldb/Core/ValueObjectChild.h"
30 #include "lldb/Core/ValueObjectConstResult.h"
31 #include "lldb/Core/ValueObjectDynamicValue.h"
32 #include "lldb/Core/ValueObjectList.h"
33 #include "lldb/Core/ValueObjectMemory.h"
34 #include "lldb/Core/ValueObjectSyntheticFilter.h"
36 #include "lldb/DataFormatters/DataVisualization.h"
37 #include "lldb/DataFormatters/ValueObjectPrinter.h"
39 #include "lldb/Host/Endian.h"
41 #include "lldb/Interpreter/CommandInterpreter.h"
42 #include "lldb/Interpreter/ScriptInterpreterPython.h"
44 #include "lldb/Symbol/ClangASTType.h"
45 #include "lldb/Symbol/ClangASTContext.h"
46 #include "lldb/Symbol/Type.h"
48 #include "lldb/Target/ExecutionContext.h"
49 #include "lldb/Target/LanguageRuntime.h"
50 #include "lldb/Target/ObjCLanguageRuntime.h"
51 #include "lldb/Target/Process.h"
52 #include "lldb/Target/RegisterContext.h"
53 #include "lldb/Target/SectionLoadList.h"
54 #include "lldb/Target/Target.h"
55 #include "lldb/Target/Thread.h"
58 using namespace lldb_private;
59 using namespace lldb_utility;
61 static user_id_t g_value_obj_uid = 0;
63 //----------------------------------------------------------------------
64 // ValueObject constructor
65 //----------------------------------------------------------------------
66 ValueObject::ValueObject (ValueObject &parent) :
67 UserID (++g_value_obj_uid), // Unique identifier for every value object
70 m_update_point (parent.GetUpdatePoint ()),
80 m_manager(parent.GetManager()),
82 m_synthetic_children (),
83 m_dynamic_value (NULL),
84 m_synthetic_value(NULL),
86 m_format (eFormatDefault),
87 m_last_format (eFormatDefault),
88 m_last_format_mgr_revision(0),
91 m_synthetic_children_sp(),
92 m_user_id_of_forced_summary(),
93 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
94 m_value_is_valid (false),
95 m_value_did_change (false),
96 m_children_count_valid (false),
97 m_old_value_valid (false),
98 m_is_deref_of_parent (false),
99 m_is_array_item_for_pointer(false),
100 m_is_bitfield_for_scalar(false),
101 m_is_child_at_offset(false),
102 m_is_getting_summary(false),
103 m_did_calculate_complete_objc_class_type(false)
105 m_manager->ManageObject(this);
108 //----------------------------------------------------------------------
109 // ValueObject constructor
110 //----------------------------------------------------------------------
111 ValueObject::ValueObject (ExecutionContextScope *exe_scope,
112 AddressType child_ptr_or_ref_addr_type) :
113 UserID (++g_value_obj_uid), // Unique identifier for every value object
116 m_update_point (exe_scope),
125 m_object_desc_str (),
128 m_synthetic_children (),
129 m_dynamic_value (NULL),
130 m_synthetic_value(NULL),
131 m_deref_valobj(NULL),
132 m_format (eFormatDefault),
133 m_last_format (eFormatDefault),
134 m_last_format_mgr_revision(0),
137 m_synthetic_children_sp(),
138 m_user_id_of_forced_summary(),
139 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
140 m_value_is_valid (false),
141 m_value_did_change (false),
142 m_children_count_valid (false),
143 m_old_value_valid (false),
144 m_is_deref_of_parent (false),
145 m_is_array_item_for_pointer(false),
146 m_is_bitfield_for_scalar(false),
147 m_is_child_at_offset(false),
148 m_is_getting_summary(false),
149 m_did_calculate_complete_objc_class_type(false)
151 m_manager = new ValueObjectManager();
152 m_manager->ManageObject (this);
155 //----------------------------------------------------------------------
157 //----------------------------------------------------------------------
158 ValueObject::~ValueObject ()
163 ValueObject::UpdateValueIfNeeded (bool update_format)
166 bool did_change_formats = false;
169 did_change_formats = UpdateFormatsIfNeeded();
171 // If this is a constant value, then our success is predicated on whether
172 // we have an error or not
175 // if you are constant, things might still have changed behind your back
176 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
177 // in this case, your value has not changed, but "computed" entries might have, so you might now have
178 // a different summary, or a different object description. clear these so we will recompute them
179 if (update_format && !did_change_formats)
180 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
181 return m_error.Success();
184 bool first_update = m_update_point.IsFirstEvaluation();
186 if (m_update_point.NeedsUpdating())
188 m_update_point.SetUpdated();
190 // Save the old value using swap to avoid a string copy which
191 // also will clear our m_value_str
192 if (m_value_str.empty())
194 m_old_value_valid = false;
198 m_old_value_valid = true;
199 m_old_value_str.swap (m_value_str);
200 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
203 ClearUserVisibleData();
207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
215 SetValueIsValid (success);
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
228 m_error.SetErrorString("out of scope");
231 return m_error.Success();
235 ValueObject::UpdateFormatsIfNeeded()
237 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
239 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
240 GetName().GetCString(),
242 m_last_format_mgr_revision,
243 DataVisualization::GetCurrentRevision());
245 bool any_change = false;
247 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
249 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
250 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
251 #ifndef LLDB_DISABLE_PYTHON
252 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
265 ValueObject::SetNeedsUpdate ()
267 m_update_point.SetNeedsUpdate();
268 // We have to clear the value string here so ConstResult children will notice if their values are
269 // changed by hand (i.e. with SetValueAsCString).
270 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
274 ValueObject::ClearDynamicTypeInformation ()
276 m_children_count_valid = false;
277 m_did_calculate_complete_objc_class_type = false;
278 m_last_format_mgr_revision = 0;
279 m_override_type = ClangASTType();
280 SetValueFormat(lldb::TypeFormatImplSP());
281 SetSummaryFormat(lldb::TypeSummaryImplSP());
282 SetSyntheticChildren(lldb::SyntheticChildrenSP());
286 ValueObject::MaybeCalculateCompleteType ()
288 ClangASTType clang_type(GetClangTypeImpl());
290 if (m_did_calculate_complete_objc_class_type)
292 if (m_override_type.IsValid())
293 return m_override_type;
298 ClangASTType class_type;
299 bool is_pointer_type = false;
301 if (clang_type.IsObjCObjectPointerType(&class_type))
303 is_pointer_type = true;
305 else if (clang_type.IsObjCObjectOrInterfaceType())
307 class_type = clang_type;
314 m_did_calculate_complete_objc_class_type = true;
318 ConstString class_name (class_type.GetConstTypeName());
322 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
326 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
328 if (objc_language_runtime)
330 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
332 if (complete_objc_class_type_sp)
334 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
336 if (complete_class.GetCompleteType())
340 m_override_type = complete_class.GetPointerType();
344 m_override_type = complete_class;
347 if (m_override_type.IsValid())
348 return m_override_type;
359 ValueObject::GetClangType ()
361 return MaybeCalculateCompleteType();
365 ValueObject::GetTypeImpl ()
367 return TypeImpl(GetClangType());
371 ValueObject::GetDataExtractor ()
373 UpdateValueIfNeeded(false);
378 ValueObject::GetError()
380 UpdateValueIfNeeded(false);
385 ValueObject::GetName() const
391 ValueObject::GetLocationAsCString ()
393 return GetLocationAsCStringImpl(m_value,
398 ValueObject::GetLocationAsCStringImpl (const Value& value,
399 const DataExtractor& data)
401 if (UpdateValueIfNeeded(false))
403 if (m_location_str.empty())
407 Value::ValueType value_type = value.GetValueType();
411 case Value::eValueTypeScalar:
412 case Value::eValueTypeVector:
413 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
415 RegisterInfo *reg_info = value.GetRegisterInfo();
419 m_location_str = reg_info->name;
420 else if (reg_info->alt_name)
421 m_location_str = reg_info->alt_name;
422 if (m_location_str.empty())
423 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
426 if (m_location_str.empty())
427 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
430 case Value::eValueTypeLoadAddress:
431 case Value::eValueTypeFileAddress:
432 case Value::eValueTypeHostAddress:
434 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
435 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
436 m_location_str.swap(sstr.GetString());
442 return m_location_str.c_str();
446 ValueObject::GetValue()
452 ValueObject::GetValue() const
458 ValueObject::ResolveValue (Scalar &scalar)
460 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
462 ExecutionContext exe_ctx (GetExecutionContextRef());
463 Value tmp_value(m_value);
464 scalar = tmp_value.ResolveValue(&exe_ctx);
465 if (scalar.IsValid())
467 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
468 if (bitfield_bit_size)
469 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
477 ValueObject::GetValueIsValid () const
479 return m_value_is_valid;
484 ValueObject::SetValueIsValid (bool b)
486 m_value_is_valid = b;
490 ValueObject::GetValueDidChange ()
492 GetValueAsCString ();
493 return m_value_did_change;
497 ValueObject::SetValueDidChange (bool value_changed)
499 m_value_did_change = value_changed;
503 ValueObject::GetChildAtIndex (size_t idx, bool can_create)
505 ValueObjectSP child_sp;
506 // We may need to update our value if we are dynamic
507 if (IsPossibleDynamicType ())
508 UpdateValueIfNeeded(false);
509 if (idx < GetNumChildren())
511 // Check if we have already made the child value object?
512 if (can_create && !m_children.HasChildAtIndex(idx))
514 // No we haven't created the child at this index, so lets have our
515 // subclass do it and cache the result for quick future access.
516 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
519 ValueObject* child = m_children.GetChildAtIndex(idx);
521 return child->GetSP();
527 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
528 size_t* index_of_error)
530 if (idxs.size() == 0)
532 ValueObjectSP root(GetSP());
533 for (size_t idx : idxs)
535 root = root->GetChildAtIndex(idx, true);
539 *index_of_error = idx;
547 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
548 size_t* index_of_error)
550 if (idxs.size() == 0)
552 ValueObjectSP root(GetSP());
553 for (std::pair<size_t, bool> idx : idxs)
555 root = root->GetChildAtIndex(idx.first, idx.second);
559 *index_of_error = idx.first;
567 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
568 size_t* index_of_error)
570 if (idxs.size() == 0)
572 ValueObjectSP root(GetSP());
573 for (size_t idx : idxs)
575 root = root->GetChildAtIndex(idx, true);
579 *index_of_error = idx;
587 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
588 size_t* index_of_error)
590 if (idxs.size() == 0)
592 ValueObjectSP root(GetSP());
593 for (std::pair<size_t, bool> idx : idxs)
595 root = root->GetChildAtIndex(idx.first, idx.second);
599 *index_of_error = idx.first;
607 ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
608 ConstString* name_of_error)
610 if (names.size() == 0)
612 ValueObjectSP root(GetSP());
613 for (ConstString name : names)
615 root = root->GetChildMemberWithName(name, true);
619 *name_of_error = name;
627 ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
628 ConstString* name_of_error)
630 if (names.size() == 0)
632 ValueObjectSP root(GetSP());
633 for (ConstString name : names)
635 root = root->GetChildMemberWithName(name, true);
639 *name_of_error = name;
647 ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
648 ConstString* name_of_error)
650 if (names.size() == 0)
652 ValueObjectSP root(GetSP());
653 for (std::pair<ConstString, bool> name : names)
655 root = root->GetChildMemberWithName(name.first, name.second);
659 *name_of_error = name.first;
667 ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
668 ConstString* name_of_error)
670 if (names.size() == 0)
672 ValueObjectSP root(GetSP());
673 for (std::pair<ConstString, bool> name : names)
675 root = root->GetChildMemberWithName(name.first, name.second);
679 *name_of_error = name.first;
687 ValueObject::GetIndexOfChildWithName (const ConstString &name)
689 bool omit_empty_base_classes = true;
690 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
694 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
696 // when getting a child by name, it could be buried inside some base
697 // classes (which really aren't part of the expression path), so we
698 // need a vector of indexes that can get us down to the correct child
699 ValueObjectSP child_sp;
701 // We may need to update our value if we are dynamic
702 if (IsPossibleDynamicType ())
703 UpdateValueIfNeeded(false);
705 std::vector<uint32_t> child_indexes;
706 bool omit_empty_base_classes = true;
707 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
708 omit_empty_base_classes,
710 if (num_child_indexes > 0)
712 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
713 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
715 child_sp = GetChildAtIndex(*pos, can_create);
716 for (++pos; pos != end; ++pos)
720 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
721 child_sp = new_child_sp;
735 ValueObject::GetNumChildren ()
737 UpdateValueIfNeeded();
738 if (!m_children_count_valid)
740 SetNumChildren (CalculateNumChildren());
742 return m_children.GetChildrenCount();
746 ValueObject::MightHaveChildren()
748 bool has_children = false;
749 const uint32_t type_info = GetTypeInfo();
752 if (type_info & (ClangASTType::eTypeHasChildren |
753 ClangASTType::eTypeIsPointer |
754 ClangASTType::eTypeIsReference))
759 has_children = GetNumChildren () > 0;
764 // Should only be called by ValueObject::GetNumChildren()
766 ValueObject::SetNumChildren (size_t num_children)
768 m_children_count_valid = true;
769 m_children.SetChildrenCount(num_children);
773 ValueObject::SetName (const ConstString &name)
779 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
781 ValueObject *valobj = NULL;
783 bool omit_empty_base_classes = true;
784 bool ignore_array_bounds = synthetic_array_member;
785 std::string child_name_str;
786 uint32_t child_byte_size = 0;
787 int32_t child_byte_offset = 0;
788 uint32_t child_bitfield_bit_size = 0;
789 uint32_t child_bitfield_bit_offset = 0;
790 bool child_is_base_class = false;
791 bool child_is_deref_of_parent = false;
793 const bool transparent_pointers = synthetic_array_member == false;
794 ClangASTType child_clang_type;
796 ExecutionContext exe_ctx (GetExecutionContextRef());
798 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
799 GetName().GetCString(),
801 transparent_pointers,
802 omit_empty_base_classes,
807 child_bitfield_bit_size,
808 child_bitfield_bit_offset,
810 child_is_deref_of_parent);
811 if (child_clang_type)
814 child_byte_offset += child_byte_size * synthetic_index;
816 ConstString child_name;
817 if (!child_name_str.empty())
818 child_name.SetCString (child_name_str.c_str());
820 valobj = new ValueObjectChild (*this,
825 child_bitfield_bit_size,
826 child_bitfield_bit_offset,
828 child_is_deref_of_parent,
829 eAddressTypeInvalid);
831 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
838 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
839 std::string& destination)
843 // ideally we would like to bail out if passing NULL, but if we do so
844 // we end up not providing the summary for function pointers anymore
845 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
848 m_is_getting_summary = true;
850 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
851 // information that we might care to see in a crash log. might be useful in very specific situations though.
852 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
853 GetTypeName().GetCString(),
854 GetName().GetCString(),
855 summary_ptr->GetDescription().c_str());*/
857 if (UpdateValueIfNeeded (false))
861 if (HasSyntheticValue())
862 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
863 summary_ptr->FormatObject(this, destination);
867 ClangASTType clang_type = GetClangType();
869 // Do some default printout for function pointers
872 if (clang_type.IsFunctionPointerType ())
875 AddressType func_ptr_address_type = eAddressTypeInvalid;
876 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
877 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
879 switch (func_ptr_address_type)
881 case eAddressTypeInvalid:
882 case eAddressTypeFile:
885 case eAddressTypeLoad:
887 ExecutionContext exe_ctx (GetExecutionContextRef());
890 Target *target = exe_ctx.GetTargetPtr();
891 if (target && target->GetSectionLoadList().IsEmpty() == false)
893 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
896 exe_ctx.GetBestExecutionContextScope(),
897 Address::DumpStyleResolvedDescription,
898 Address::DumpStyleSectionNameOffset);
904 case eAddressTypeHost:
908 if (sstr.GetSize() > 0)
910 destination.assign (1, '(');
911 destination.append (sstr.GetData(), sstr.GetSize());
912 destination.append (1, ')');
918 m_is_getting_summary = false;
919 return !destination.empty();
923 ValueObject::GetSummaryAsCString ()
925 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
927 GetSummaryAsCString(GetSummaryFormat().get(),
930 if (m_summary_str.empty())
932 return m_summary_str.c_str();
936 ValueObject::IsCStringContainer(bool check_pointer)
938 ClangASTType pointee_or_element_clang_type;
939 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
940 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
941 pointee_or_element_clang_type.IsCharType ());
942 if (!is_char_arr_ptr)
946 if (type_flags.Test(ClangASTType::eTypeIsArray))
948 addr_t cstr_address = LLDB_INVALID_ADDRESS;
949 AddressType cstr_address_type = eAddressTypeInvalid;
950 cstr_address = GetAddressOf (true, &cstr_address_type);
951 return (cstr_address != LLDB_INVALID_ADDRESS);
955 ValueObject::GetPointeeData (DataExtractor& data,
959 ClangASTType pointee_or_element_clang_type;
960 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
961 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
962 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
963 if (!(is_pointer_type || is_array_type))
969 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
970 const uint64_t bytes = item_count * item_type_size;
971 const uint64_t offset = item_idx * item_type_size;
973 if (item_idx == 0 && item_count == 1) // simply a deref
978 ValueObjectSP pointee_sp = Dereference(error);
979 if (error.Fail() || pointee_sp.get() == NULL)
981 return pointee_sp->GetData(data);
985 ValueObjectSP child_sp = GetChildAtIndex(0, true);
986 if (child_sp.get() == NULL)
988 return child_sp->GetData(data);
992 else /* (items > 1) */
995 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
996 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
998 AddressType addr_type;
999 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
1003 case eAddressTypeFile:
1005 ModuleSP module_sp (GetModule());
1008 addr = addr + offset;
1010 module_sp->ResolveFileAddress(addr, so_addr);
1011 ExecutionContext exe_ctx (GetExecutionContextRef());
1012 Target* target = exe_ctx.GetTargetPtr();
1015 heap_buf_ptr->SetByteSize(bytes);
1016 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1017 if (error.Success())
1019 data.SetData(data_sp);
1026 case eAddressTypeLoad:
1028 ExecutionContext exe_ctx (GetExecutionContextRef());
1029 Process *process = exe_ctx.GetProcessPtr();
1032 heap_buf_ptr->SetByteSize(bytes);
1033 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
1034 if (error.Success() || bytes_read > 0)
1036 data.SetData(data_sp);
1042 case eAddressTypeHost:
1044 const uint64_t max_bytes = GetClangType().GetByteSize();
1045 if (max_bytes > offset)
1047 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1048 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1049 data.SetData(data_sp);
1054 case eAddressTypeInvalid:
1062 ValueObject::GetData (DataExtractor& data)
1064 UpdateValueIfNeeded(false);
1065 ExecutionContext exe_ctx (GetExecutionContextRef());
1066 Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
1069 if (m_data.GetByteSize())
1072 return data.GetByteSize();
1079 data.SetAddressByteSize(m_data.GetAddressByteSize());
1080 data.SetByteOrder(m_data.GetByteOrder());
1081 return data.GetByteSize();
1085 ValueObject::SetData (DataExtractor &data, Error &error)
1088 // Make sure our value is up to date first so that our location and location
1090 if (!UpdateValueIfNeeded(false))
1092 error.SetErrorString("unable to read value");
1097 const Encoding encoding = GetClangType().GetEncoding(count);
1099 const size_t byte_size = GetByteSize();
1101 Value::ValueType value_type = m_value.GetValueType();
1105 case Value::eValueTypeScalar:
1107 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1109 if (!set_error.Success())
1111 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1116 case Value::eValueTypeLoadAddress:
1118 // If it is a load address, then the scalar value is the storage location
1119 // of the data, and we have to shove this value down to that load location.
1120 ExecutionContext exe_ctx (GetExecutionContextRef());
1121 Process *process = exe_ctx.GetProcessPtr();
1124 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1125 size_t bytes_written = process->WriteMemory(target_addr,
1126 data.GetDataStart(),
1129 if (!error.Success())
1131 if (bytes_written != byte_size)
1133 error.SetErrorString("unable to write value to memory");
1139 case Value::eValueTypeHostAddress:
1141 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1142 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1143 m_data.SetData(buffer_sp, 0);
1144 data.CopyByteOrderedData (0,
1146 const_cast<uint8_t *>(m_data.GetDataStart()),
1148 m_data.GetByteOrder());
1149 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1152 case Value::eValueTypeFileAddress:
1153 case Value::eValueTypeVector:
1157 // If we have reached this point, then we have successfully changed the value.
1162 // will compute strlen(str), but without consuming more than
1163 // maxlen bytes out of str (this serves the purpose of reading
1164 // chunks of a string without having to worry about
1165 // missing NULL terminators in the chunk)
1166 // of course, if strlen(str) > maxlen, the function will return
1167 // maxlen_value (which should be != maxlen, because that allows you
1168 // to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1170 strlen_or_inf (const char* str,
1172 uint32_t maxlen_value)
1181 return maxlen_value;
1188 ValueObject::ReadPointedString (Stream& s,
1190 uint32_t max_length,
1194 ExecutionContext exe_ctx (GetExecutionContextRef());
1195 Target* target = exe_ctx.GetTargetPtr();
1199 s << "<no target to read from>";
1200 error.SetErrorString("no target to read from");
1204 if (max_length == 0)
1205 max_length = target->GetMaximumSizeOfStringSummary();
1207 size_t bytes_read = 0;
1208 size_t total_bytes_read = 0;
1210 ClangASTType clang_type = GetClangType();
1211 ClangASTType elem_or_pointee_clang_type;
1212 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
1213 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1214 elem_or_pointee_clang_type.IsCharType ())
1216 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1217 AddressType cstr_address_type = eAddressTypeInvalid;
1219 size_t cstr_len = 0;
1220 bool capped_data = false;
1221 if (type_flags.Test (ClangASTType::eTypeIsArray))
1224 uint64_t array_size = 0;
1225 if (clang_type.IsArrayType(NULL, &array_size, NULL))
1227 cstr_len = array_size;
1228 if (cstr_len > max_length)
1231 cstr_len = max_length;
1234 cstr_address = GetAddressOf (true, &cstr_address_type);
1238 // We have a pointer
1239 cstr_address = GetPointerValue (&cstr_address_type);
1242 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1244 s << "<invalid address>";
1245 error.SetErrorString("invalid address");
1249 Address cstr_so_addr (cstr_address);
1251 if (cstr_len > 0 && honor_array)
1253 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1254 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1255 GetPointeeData(data, 0, cstr_len);
1257 if ((bytes_read = data.GetByteSize()) > 0)
1259 total_bytes_read = bytes_read;
1262 0, // Start offset in "data"
1264 1, // Size of item (1 byte for a char!)
1265 bytes_read, // How many bytes to print?
1266 UINT32_MAX, // num per line
1267 LLDB_INVALID_ADDRESS,// base address
1268 0, // bitfield bit size
1269 0); // bitfield bit offset
1277 cstr_len = max_length;
1278 const size_t k_max_buf_size = 64;
1282 int cstr_len_displayed = -1;
1283 bool capped_cstr = false;
1284 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1285 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1286 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
1288 total_bytes_read += bytes_read;
1289 const char *cstr = data.PeekCStr(0);
1290 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1291 if (len > k_max_buf_size)
1292 len = k_max_buf_size;
1293 if (cstr && cstr_len_displayed < 0)
1296 if (cstr_len_displayed < 0)
1297 cstr_len_displayed = len;
1301 cstr_len_displayed += len;
1302 if (len > bytes_read)
1308 0, // Start offset in "data"
1310 1, // Size of item (1 byte for a char!)
1311 len, // How many bytes to print?
1312 UINT32_MAX, // num per line
1313 LLDB_INVALID_ADDRESS,// base address
1314 0, // bitfield bit size
1315 0); // bitfield bit offset
1317 if (len < k_max_buf_size)
1320 if (len >= cstr_len)
1330 if (cstr_len_displayed >= 0)
1340 error.SetErrorString("not a string object");
1341 s << "<not a string object>";
1343 return total_bytes_read;
1347 ValueObject::GetObjectDescription ()
1350 if (!UpdateValueIfNeeded (true))
1353 if (!m_object_desc_str.empty())
1354 return m_object_desc_str.c_str();
1356 ExecutionContext exe_ctx (GetExecutionContextRef());
1357 Process *process = exe_ctx.GetProcessPtr();
1358 if (process == NULL)
1363 LanguageType language = GetObjectRuntimeLanguage();
1364 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1366 if (runtime == NULL)
1368 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
1369 ClangASTType clang_type = GetClangType();
1373 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
1375 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
1380 if (runtime && runtime->GetObjectDescription(s, *this))
1382 m_object_desc_str.append (s.GetData());
1385 if (m_object_desc_str.empty())
1388 return m_object_desc_str.c_str();
1392 ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1393 std::string& destination)
1395 if (UpdateValueIfNeeded(false))
1396 return format.FormatObject(this,destination);
1402 ValueObject::GetValueAsCString (lldb::Format format,
1403 std::string& destination)
1405 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
1409 ValueObject::GetValueAsCString ()
1411 if (UpdateValueIfNeeded(true))
1413 lldb::TypeFormatImplSP format_sp;
1414 lldb::Format my_format = GetFormat();
1415 if (my_format == lldb::eFormatDefault)
1417 if (m_type_format_sp)
1418 format_sp = m_type_format_sp;
1421 if (m_is_bitfield_for_scalar)
1422 my_format = eFormatUnsigned;
1425 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
1427 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1429 my_format = reg_info->format;
1433 my_format = GetClangType().GetFormat();
1438 if (my_format != m_last_format || m_value_str.empty())
1440 m_last_format = my_format;
1442 format_sp.reset(new TypeFormatImpl_Format(my_format));
1443 if (GetValueAsCString(*format_sp.get(), m_value_str))
1445 if (!m_value_did_change && m_old_value_valid)
1447 // The value was gotten successfully, so we consider the
1448 // value as changed if the value string differs
1449 SetValueDidChange (m_old_value_str != m_value_str);
1454 if (m_value_str.empty())
1456 return m_value_str.c_str();
1459 // if > 8bytes, 0 is returned. this method should mostly be used
1460 // to read address values out of pointers
1462 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
1464 // If our byte size is zero this is an aggregate type that has children
1465 if (!GetClangType().IsAggregateType())
1468 if (ResolveValue (scalar))
1472 return scalar.ULongLong(fail_value);
1474 // fallthrough, otherwise...
1483 ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1485 // If our byte size is zero this is an aggregate type that has children
1486 if (!GetClangType().IsAggregateType())
1489 if (ResolveValue (scalar))
1493 return scalar.SLongLong(fail_value);
1495 // fallthrough, otherwise...
1503 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1504 // this call up to date by returning true for your new special cases. We will eventually move
1505 // to checking this call result before trying to display special cases
1507 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1508 Format custom_format)
1510 Flags flags(GetTypeInfo());
1511 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1512 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1514 if (IsCStringContainer(true) &&
1515 (custom_format == eFormatCString ||
1516 custom_format == eFormatCharArray ||
1517 custom_format == eFormatChar ||
1518 custom_format == eFormatVectorOfChar))
1521 if (flags.Test(ClangASTType::eTypeIsArray))
1523 if ((custom_format == eFormatBytes) ||
1524 (custom_format == eFormatBytesWithASCII))
1527 if ((custom_format == eFormatVectorOfChar) ||
1528 (custom_format == eFormatVectorOfFloat32) ||
1529 (custom_format == eFormatVectorOfFloat64) ||
1530 (custom_format == eFormatVectorOfSInt16) ||
1531 (custom_format == eFormatVectorOfSInt32) ||
1532 (custom_format == eFormatVectorOfSInt64) ||
1533 (custom_format == eFormatVectorOfSInt8) ||
1534 (custom_format == eFormatVectorOfUInt128) ||
1535 (custom_format == eFormatVectorOfUInt16) ||
1536 (custom_format == eFormatVectorOfUInt32) ||
1537 (custom_format == eFormatVectorOfUInt64) ||
1538 (custom_format == eFormatVectorOfUInt8))
1546 ValueObject::DumpPrintableRepresentation(Stream& s,
1547 ValueObjectRepresentationStyle val_obj_display,
1548 Format custom_format,
1549 PrintableRepresentationSpecialCases special,
1553 Flags flags(GetTypeInfo());
1555 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1556 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1560 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1561 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1563 // when being asked to get a printable display an array or pointer type directly,
1564 // try to "do the right thing"
1566 if (IsCStringContainer(true) &&
1567 (custom_format == eFormatCString ||
1568 custom_format == eFormatCharArray ||
1569 custom_format == eFormatChar ||
1570 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
1573 ReadPointedString(s,
1576 (custom_format == eFormatVectorOfChar) ||
1577 (custom_format == eFormatCharArray));
1578 return !error.Fail();
1581 if (custom_format == eFormatEnum)
1584 // this only works for arrays, because I have no way to know when
1585 // the pointed memory ends, and no special \0 end of data marker
1586 if (flags.Test(ClangASTType::eTypeIsArray))
1588 if ((custom_format == eFormatBytes) ||
1589 (custom_format == eFormatBytesWithASCII))
1591 const size_t count = GetNumChildren();
1594 for (size_t low = 0; low < count; low++)
1600 ValueObjectSP child = GetChildAtIndex(low,true);
1603 s << "<invalid child>";
1606 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1614 if ((custom_format == eFormatVectorOfChar) ||
1615 (custom_format == eFormatVectorOfFloat32) ||
1616 (custom_format == eFormatVectorOfFloat64) ||
1617 (custom_format == eFormatVectorOfSInt16) ||
1618 (custom_format == eFormatVectorOfSInt32) ||
1619 (custom_format == eFormatVectorOfSInt64) ||
1620 (custom_format == eFormatVectorOfSInt8) ||
1621 (custom_format == eFormatVectorOfUInt128) ||
1622 (custom_format == eFormatVectorOfUInt16) ||
1623 (custom_format == eFormatVectorOfUInt32) ||
1624 (custom_format == eFormatVectorOfUInt64) ||
1625 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1627 const size_t count = GetNumChildren();
1629 Format format = FormatManager::GetSingleItemFormat(custom_format);
1632 for (size_t low = 0; low < count; low++)
1638 ValueObjectSP child = GetChildAtIndex(low,true);
1641 s << "<invalid child>";
1644 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1653 if ((custom_format == eFormatBoolean) ||
1654 (custom_format == eFormatBinary) ||
1655 (custom_format == eFormatChar) ||
1656 (custom_format == eFormatCharPrintable) ||
1657 (custom_format == eFormatComplexFloat) ||
1658 (custom_format == eFormatDecimal) ||
1659 (custom_format == eFormatHex) ||
1660 (custom_format == eFormatHexUppercase) ||
1661 (custom_format == eFormatFloat) ||
1662 (custom_format == eFormatOctal) ||
1663 (custom_format == eFormatOSType) ||
1664 (custom_format == eFormatUnicode16) ||
1665 (custom_format == eFormatUnicode32) ||
1666 (custom_format == eFormatUnsigned) ||
1667 (custom_format == eFormatPointer) ||
1668 (custom_format == eFormatComplexInteger) ||
1669 (custom_format == eFormatComplex) ||
1670 (custom_format == eFormatDefault)) // use the [] operator
1678 bool var_success = false;
1681 const char *cstr = NULL;
1683 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1684 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1685 // area for cases where our desired output is not backed by some other longer-term storage
1688 if (custom_format != eFormatInvalid)
1689 SetFormat(custom_format);
1691 switch(val_obj_display)
1693 case eValueObjectRepresentationStyleValue:
1694 cstr = GetValueAsCString();
1697 case eValueObjectRepresentationStyleSummary:
1698 cstr = GetSummaryAsCString();
1701 case eValueObjectRepresentationStyleLanguageSpecific:
1702 cstr = GetObjectDescription();
1705 case eValueObjectRepresentationStyleLocation:
1706 cstr = GetLocationAsCString();
1709 case eValueObjectRepresentationStyleChildrenCount:
1710 strm.Printf("%zu", GetNumChildren());
1711 cstr = strm.GetString().c_str();
1714 case eValueObjectRepresentationStyleType:
1715 cstr = GetTypeName().AsCString();
1718 case eValueObjectRepresentationStyleName:
1719 cstr = GetName().AsCString();
1722 case eValueObjectRepresentationStyleExpressionPath:
1723 GetExpressionPath(strm, false);
1724 cstr = strm.GetString().c_str();
1730 if (val_obj_display == eValueObjectRepresentationStyleValue)
1731 cstr = GetSummaryAsCString();
1732 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1734 if (GetClangType().IsAggregateType())
1736 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1737 cstr = strm.GetString().c_str();
1740 cstr = GetValueAsCString();
1751 s.Printf("<%s>", m_error.AsCString());
1755 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1756 s.PutCString("<no summary available>");
1757 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1758 s.PutCString("<no value available>");
1759 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1760 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1762 s.PutCString("<no printable representation>");
1765 // we should only return false here if we could not do *anything*
1766 // even if we have an error message as output, that's a success
1767 // from our callers' perspective, so return true
1770 if (custom_format != eFormatInvalid)
1771 SetFormat(eFormatDefault);
1778 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
1780 if (!UpdateValueIfNeeded(false))
1781 return LLDB_INVALID_ADDRESS;
1783 switch (m_value.GetValueType())
1785 case Value::eValueTypeScalar:
1786 case Value::eValueTypeVector:
1787 if (scalar_is_load_address)
1790 *address_type = eAddressTypeLoad;
1791 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1795 case Value::eValueTypeLoadAddress:
1796 case Value::eValueTypeFileAddress:
1797 case Value::eValueTypeHostAddress:
1800 *address_type = m_value.GetValueAddressType ();
1801 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1806 *address_type = eAddressTypeInvalid;
1807 return LLDB_INVALID_ADDRESS;
1811 ValueObject::GetPointerValue (AddressType *address_type)
1813 addr_t address = LLDB_INVALID_ADDRESS;
1815 *address_type = eAddressTypeInvalid;
1817 if (!UpdateValueIfNeeded(false))
1820 switch (m_value.GetValueType())
1822 case Value::eValueTypeScalar:
1823 case Value::eValueTypeVector:
1824 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1827 case Value::eValueTypeHostAddress:
1828 case Value::eValueTypeLoadAddress:
1829 case Value::eValueTypeFileAddress:
1831 lldb::offset_t data_offset = 0;
1832 address = m_data.GetPointer(&data_offset);
1838 *address_type = GetAddressTypeOfChildren();
1844 ValueObject::SetValueFromCString (const char *value_str, Error& error)
1847 // Make sure our value is up to date first so that our location and location
1849 if (!UpdateValueIfNeeded(false))
1851 error.SetErrorString("unable to read value");
1856 const Encoding encoding = GetClangType().GetEncoding (count);
1858 const size_t byte_size = GetByteSize();
1860 Value::ValueType value_type = m_value.GetValueType();
1862 if (value_type == Value::eValueTypeScalar)
1864 // If the value is already a scalar, then let the scalar change itself:
1865 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1867 else if (byte_size <= Scalar::GetMaxByteSize())
1869 // If the value fits in a scalar, then make a new scalar and again let the
1870 // scalar code do the conversion, then figure out where to put the new value.
1872 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1873 if (error.Success())
1877 case Value::eValueTypeLoadAddress:
1879 // If it is a load address, then the scalar value is the storage location
1880 // of the data, and we have to shove this value down to that load location.
1881 ExecutionContext exe_ctx (GetExecutionContextRef());
1882 Process *process = exe_ctx.GetProcessPtr();
1885 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1886 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1890 if (!error.Success())
1892 if (bytes_written != byte_size)
1894 error.SetErrorString("unable to write value to memory");
1900 case Value::eValueTypeHostAddress:
1902 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1903 DataExtractor new_data;
1904 new_data.SetByteOrder (m_data.GetByteOrder());
1906 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1907 m_data.SetData(buffer_sp, 0);
1908 bool success = new_scalar.GetData(new_data);
1911 new_data.CopyByteOrderedData (0,
1913 const_cast<uint8_t *>(m_data.GetDataStart()),
1915 m_data.GetByteOrder());
1917 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1921 case Value::eValueTypeFileAddress:
1922 case Value::eValueTypeScalar:
1923 case Value::eValueTypeVector:
1934 // We don't support setting things bigger than a scalar at present.
1935 error.SetErrorString("unable to write aggregate data type");
1939 // If we have reached this point, then we have successfully changed the value.
1945 ValueObject::GetDeclaration (Declaration &decl)
1952 ValueObject::GetTypeName()
1954 return GetClangType().GetConstTypeName();
1958 ValueObject::GetQualifiedTypeName()
1960 return GetClangType().GetConstQualifiedTypeName();
1965 ValueObject::GetObjectRuntimeLanguage ()
1967 return GetClangType().GetMinimumLanguage ();
1971 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
1973 m_synthetic_children[key] = valobj;
1977 ValueObject::GetSyntheticChild (const ConstString &key) const
1979 ValueObjectSP synthetic_child_sp;
1980 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
1981 if (pos != m_synthetic_children.end())
1982 synthetic_child_sp = pos->second->GetSP();
1983 return synthetic_child_sp;
1987 ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
1989 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
1993 ValueObject::IsPointerType ()
1995 return GetClangType().IsPointerType();
1999 ValueObject::IsArrayType ()
2001 return GetClangType().IsArrayType (NULL, NULL, NULL);
2005 ValueObject::IsScalarType ()
2007 return GetClangType().IsScalarType ();
2011 ValueObject::IsIntegerType (bool &is_signed)
2013 return GetClangType().IsIntegerType (is_signed);
2017 ValueObject::IsPointerOrReferenceType ()
2019 return GetClangType().IsPointerOrReferenceType ();
2023 ValueObject::IsPossibleDynamicType ()
2025 ExecutionContext exe_ctx (GetExecutionContextRef());
2026 Process *process = exe_ctx.GetProcessPtr();
2028 return process->IsPossibleDynamicValue(*this);
2030 return GetClangType().IsPossibleDynamicType (NULL, true, true);
2034 ValueObject::IsObjCNil ()
2036 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2037 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
2040 bool canReadValue = true;
2041 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
2042 return canReadValue && isZero;
2046 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
2048 const uint32_t type_info = GetTypeInfo ();
2049 if (type_info & ClangASTType::eTypeIsArray)
2050 return GetSyntheticArrayMemberFromArray(index, can_create);
2052 if (type_info & ClangASTType::eTypeIsPointer)
2053 return GetSyntheticArrayMemberFromPointer(index, can_create);
2055 return ValueObjectSP();
2060 ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
2062 ValueObjectSP synthetic_child_sp;
2063 if (IsPointerType ())
2066 snprintf(index_str, sizeof(index_str), "[%zu]", index);
2067 ConstString index_const_str(index_str);
2068 // Check if we have already created a synthetic array member in this
2069 // valid object. If we have we will re-use it.
2070 synthetic_child_sp = GetSyntheticChild (index_const_str);
2071 if (!synthetic_child_sp)
2073 ValueObject *synthetic_child;
2074 // We haven't made a synthetic array member for INDEX yet, so
2075 // lets make one and cache it for any future reference.
2076 synthetic_child = CreateChildAtIndex(0, true, index);
2078 // Cache the value if we got one back...
2079 if (synthetic_child)
2081 AddSyntheticChild(index_const_str, synthetic_child);
2082 synthetic_child_sp = synthetic_child->GetSP();
2083 synthetic_child_sp->SetName(ConstString(index_str));
2084 synthetic_child_sp->m_is_array_item_for_pointer = true;
2088 return synthetic_child_sp;
2091 // This allows you to create an array member using and index
2092 // that doesn't not fall in the normal bounds of the array.
2093 // Many times structure can be defined as:
2094 // struct Collection
2096 // uint32_t item_count;
2097 // Item item_array[0];
2099 // The size of the "item_array" is 1, but many times in practice
2100 // there are more items in "item_array".
2103 ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
2105 ValueObjectSP synthetic_child_sp;
2109 snprintf(index_str, sizeof(index_str), "[%zu]", index);
2110 ConstString index_const_str(index_str);
2111 // Check if we have already created a synthetic array member in this
2112 // valid object. If we have we will re-use it.
2113 synthetic_child_sp = GetSyntheticChild (index_const_str);
2114 if (!synthetic_child_sp)
2116 ValueObject *synthetic_child;
2117 // We haven't made a synthetic array member for INDEX yet, so
2118 // lets make one and cache it for any future reference.
2119 synthetic_child = CreateChildAtIndex(0, true, index);
2121 // Cache the value if we got one back...
2122 if (synthetic_child)
2124 AddSyntheticChild(index_const_str, synthetic_child);
2125 synthetic_child_sp = synthetic_child->GetSP();
2126 synthetic_child_sp->SetName(ConstString(index_str));
2127 synthetic_child_sp->m_is_array_item_for_pointer = true;
2131 return synthetic_child_sp;
2135 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2137 ValueObjectSP synthetic_child_sp;
2138 if (IsScalarType ())
2141 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2142 ConstString index_const_str(index_str);
2143 // Check if we have already created a synthetic array member in this
2144 // valid object. If we have we will re-use it.
2145 synthetic_child_sp = GetSyntheticChild (index_const_str);
2146 if (!synthetic_child_sp)
2148 // We haven't made a synthetic array member for INDEX yet, so
2149 // lets make one and cache it for any future reference.
2150 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2159 eAddressTypeInvalid);
2161 // Cache the value if we got one back...
2162 if (synthetic_child)
2164 AddSyntheticChild(index_const_str, synthetic_child);
2165 synthetic_child_sp = synthetic_child->GetSP();
2166 synthetic_child_sp->SetName(ConstString(index_str));
2167 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2171 return synthetic_child_sp;
2175 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2178 ValueObjectSP synthetic_child_sp;
2181 snprintf(name_str, sizeof(name_str), "@%i", offset);
2182 ConstString name_const_str(name_str);
2184 // Check if we have already created a synthetic array member in this
2185 // valid object. If we have we will re-use it.
2186 synthetic_child_sp = GetSyntheticChild (name_const_str);
2188 if (synthetic_child_sp.get())
2189 return synthetic_child_sp;
2192 return ValueObjectSP();
2194 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2203 eAddressTypeInvalid);
2204 if (synthetic_child)
2206 AddSyntheticChild(name_const_str, synthetic_child);
2207 synthetic_child_sp = synthetic_child->GetSP();
2208 synthetic_child_sp->SetName(name_const_str);
2209 synthetic_child_sp->m_is_child_at_offset = true;
2211 return synthetic_child_sp;
2214 // your expression path needs to have a leading . or ->
2215 // (unless it somehow "looks like" an array, in which case it has
2216 // a leading [ symbol). while the [ is meaningful and should be shown
2217 // to the user, . and -> are just parser design, but by no means
2218 // added information for the user.. strip them off
2220 SkipLeadingExpressionPathSeparators(const char* expression)
2222 if (!expression || !expression[0])
2224 if (expression[0] == '.')
2225 return expression+1;
2226 if (expression[0] == '-' && expression[1] == '>')
2227 return expression+2;
2232 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2234 ValueObjectSP synthetic_child_sp;
2235 ConstString name_const_string(expression);
2236 // Check if we have already created a synthetic array member in this
2237 // valid object. If we have we will re-use it.
2238 synthetic_child_sp = GetSyntheticChild (name_const_string);
2239 if (!synthetic_child_sp)
2241 // We haven't made a synthetic array member for expression yet, so
2242 // lets make one and cache it for any future reference.
2243 synthetic_child_sp = GetValueForExpressionPath(expression,
2245 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
2247 // Cache the value if we got one back...
2248 if (synthetic_child_sp.get())
2250 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
2251 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2252 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
2255 return synthetic_child_sp;
2259 ValueObject::CalculateSyntheticValue (bool use_synthetic)
2261 if (use_synthetic == false)
2264 TargetSP target_sp(GetTargetSP());
2265 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
2267 m_synthetic_value = NULL;
2271 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2273 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
2276 if (m_synthetic_children_sp.get() == NULL)
2279 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2282 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
2286 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
2288 if (use_dynamic == eNoDynamicValues)
2291 if (!m_dynamic_value && !IsDynamic())
2293 ExecutionContext exe_ctx (GetExecutionContextRef());
2294 Process *process = exe_ctx.GetProcessPtr();
2295 if (process && process->IsPossibleDynamicValue(*this))
2297 ClearDynamicTypeInformation ();
2298 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2304 ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
2306 if (use_dynamic == eNoDynamicValues)
2307 return ValueObjectSP();
2309 if (!IsDynamic() && m_dynamic_value == NULL)
2311 CalculateDynamicValue(use_dynamic);
2313 if (m_dynamic_value)
2314 return m_dynamic_value->GetSP();
2316 return ValueObjectSP();
2320 ValueObject::GetStaticValue()
2326 ValueObject::GetNonSyntheticValue ()
2332 ValueObject::GetSyntheticValue (bool use_synthetic)
2334 if (use_synthetic == false)
2335 return ValueObjectSP();
2337 CalculateSyntheticValue(use_synthetic);
2339 if (m_synthetic_value)
2340 return m_synthetic_value->GetSP();
2342 return ValueObjectSP();
2346 ValueObject::HasSyntheticValue()
2348 UpdateFormatsIfNeeded();
2350 if (m_synthetic_children_sp.get() == NULL)
2353 CalculateSyntheticValue(true);
2355 if (m_synthetic_value)
2362 ValueObject::GetBaseClassPath (Stream &s)
2366 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
2367 ClangASTType clang_type = GetClangType();
2368 std::string cxx_class_name;
2369 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
2370 if (this_had_base_class)
2372 if (parent_had_base_class)
2374 s.PutCString(cxx_class_name.c_str());
2376 return parent_had_base_class || this_had_base_class;
2383 ValueObject::GetNonBaseClassParent()
2387 if (GetParent()->IsBaseClass())
2388 return GetParent()->GetNonBaseClassParent();
2396 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
2398 const bool is_deref_of_parent = IsDereferenceOfParent ();
2400 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2402 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2403 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2404 // the eHonorPointers mode is meant to produce strings in this latter format
2408 ValueObject* parent = GetParent();
2411 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
2413 // if we are a deref_of_parent just because we are synthetic array
2414 // members made up to allow ptr[%d] syntax to work in variable
2415 // printing, then add our name ([%d]) to the expression path
2416 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
2417 s.PutCString(m_name.AsCString());
2421 if (!is_deref_of_parent)
2423 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2424 if (non_base_class_parent)
2426 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2427 if (non_base_class_parent_clang_type)
2429 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
2435 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2437 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
2441 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2442 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
2450 const char *name = GetName().GetCString();
2453 if (qualify_cxx_base_classes)
2455 if (GetBaseClassPath (s))
2463 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2470 ValueObject::GetValueForExpressionPath(const char* expression,
2471 const char** first_unparsed,
2472 ExpressionPathScanEndReason* reason_to_stop,
2473 ExpressionPathEndResultType* final_value_type,
2474 const GetValueForExpressionPathOptions& options,
2475 ExpressionPathAftermath* final_task_on_target)
2478 const char* dummy_first_unparsed;
2479 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2480 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2481 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2483 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2484 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2485 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2486 final_value_type ? final_value_type : &dummy_final_value_type,
2488 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2490 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2493 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
2495 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
2498 ValueObjectSP final_value = ret_val->Dereference(error);
2499 if (error.Fail() || !final_value.get())
2502 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2503 if (final_value_type)
2504 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2505 return ValueObjectSP();
2509 if (final_task_on_target)
2510 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2514 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2517 ValueObjectSP final_value = ret_val->AddressOf(error);
2518 if (error.Fail() || !final_value.get())
2521 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2522 if (final_value_type)
2523 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2524 return ValueObjectSP();
2528 if (final_task_on_target)
2529 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2534 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2538 ValueObject::GetValuesForExpressionPath(const char* expression,
2539 ValueObjectListSP& list,
2540 const char** first_unparsed,
2541 ExpressionPathScanEndReason* reason_to_stop,
2542 ExpressionPathEndResultType* final_value_type,
2543 const GetValueForExpressionPathOptions& options,
2544 ExpressionPathAftermath* final_task_on_target)
2546 const char* dummy_first_unparsed;
2547 ExpressionPathScanEndReason dummy_reason_to_stop;
2548 ExpressionPathEndResultType dummy_final_value_type;
2549 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2551 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2552 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2553 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2554 final_value_type ? final_value_type : &dummy_final_value_type,
2556 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2558 if (!ret_val.get()) // if there are errors, I add nothing to the list
2561 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
2563 // I need not expand a range, just post-process the final value and return
2564 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2566 list->Append(ret_val);
2569 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
2571 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
2574 ValueObjectSP final_value = ret_val->Dereference(error);
2575 if (error.Fail() || !final_value.get())
2578 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2579 if (final_value_type)
2580 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2585 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2586 list->Append(final_value);
2590 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2593 ValueObjectSP final_value = ret_val->AddressOf(error);
2594 if (error.Fail() || !final_value.get())
2597 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2598 if (final_value_type)
2599 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2604 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2605 list->Append(final_value);
2613 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2614 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2617 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2618 final_value_type ? final_value_type : &dummy_final_value_type,
2620 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2622 // in any non-covered case, just do the obviously right thing
2623 list->Append(ret_val);
2628 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2629 const char** first_unparsed,
2630 ExpressionPathScanEndReason* reason_to_stop,
2631 ExpressionPathEndResultType* final_result,
2632 const GetValueForExpressionPathOptions& options,
2633 ExpressionPathAftermath* what_next)
2635 ValueObjectSP root = GetSP();
2638 return ValueObjectSP();
2640 *first_unparsed = expression_cstr;
2645 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2647 ClangASTType root_clang_type = root->GetClangType();
2648 ClangASTType pointee_clang_type;
2649 Flags pointee_clang_type_info;
2651 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
2652 if (pointee_clang_type)
2653 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
2655 if (!expression_cstr || *expression_cstr == '\0')
2657 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2661 switch (*expression_cstr)
2665 if (options.m_check_dot_vs_arrow_syntax &&
2666 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
2668 *first_unparsed = expression_cstr;
2669 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2670 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2671 return ValueObjectSP();
2673 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2674 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
2675 options.m_no_fragile_ivar)
2677 *first_unparsed = expression_cstr;
2678 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2679 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2680 return ValueObjectSP();
2682 if (expression_cstr[1] != '>')
2684 *first_unparsed = expression_cstr;
2685 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2686 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2687 return ValueObjectSP();
2689 expression_cstr++; // skip the -
2691 case '.': // or fallthrough from ->
2693 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
2694 root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
2696 *first_unparsed = expression_cstr;
2697 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2698 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2699 return ValueObjectSP();
2701 expression_cstr++; // skip .
2702 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2703 ConstString child_name;
2704 if (!next_separator) // if no other separator just expand this last layer
2706 child_name.SetCString (expression_cstr);
2707 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2709 if (child_valobj_sp.get()) // we know we are done, so just return
2711 *first_unparsed = "";
2712 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2713 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2714 return child_valobj_sp;
2716 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2718 if (root->IsSynthetic())
2720 *first_unparsed = expression_cstr;
2721 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2722 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2723 return ValueObjectSP();
2726 child_valobj_sp = root->GetSyntheticValue();
2727 if (child_valobj_sp.get())
2728 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2731 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2732 // so we hit the "else" branch, and return an error
2733 if(child_valobj_sp.get()) // if it worked, just return
2735 *first_unparsed = "";
2736 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2737 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2738 return child_valobj_sp;
2742 *first_unparsed = expression_cstr;
2743 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2744 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2745 return ValueObjectSP();
2748 else // other layers do expand
2750 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2751 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2752 if (child_valobj_sp.get()) // store the new root and move on
2754 root = child_valobj_sp;
2755 *first_unparsed = next_separator;
2756 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2759 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2761 if (root->IsSynthetic())
2763 *first_unparsed = expression_cstr;
2764 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2765 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2766 return ValueObjectSP();
2769 child_valobj_sp = root->GetSyntheticValue(true);
2770 if (child_valobj_sp)
2771 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2774 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2775 // so we hit the "else" branch, and return an error
2776 if(child_valobj_sp.get()) // if it worked, move on
2778 root = child_valobj_sp;
2779 *first_unparsed = next_separator;
2780 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2785 *first_unparsed = expression_cstr;
2786 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2787 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2788 return ValueObjectSP();
2795 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && !root_clang_type_info.Test(ClangASTType::eTypeIsVector)) // if this is not a T[] nor a T*
2797 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
2799 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2801 *first_unparsed = expression_cstr;
2802 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2803 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2804 return ValueObjectSP();
2807 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2809 *first_unparsed = expression_cstr;
2810 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2811 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2812 return ValueObjectSP();
2815 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2817 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2819 *first_unparsed = expression_cstr;
2820 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2821 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2822 return ValueObjectSP();
2824 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2826 *first_unparsed = expression_cstr+2;
2827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2828 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2832 const char *separator_position = ::strchr(expression_cstr+1,'-');
2833 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2834 if (!close_bracket_position) // if there is no ], this is a syntax error
2836 *first_unparsed = expression_cstr;
2837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2839 return ValueObjectSP();
2841 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2844 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2845 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2847 *first_unparsed = expression_cstr;
2848 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2849 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2850 return ValueObjectSP();
2852 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2854 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2856 *first_unparsed = expression_cstr+2;
2857 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2858 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2863 *first_unparsed = expression_cstr;
2864 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2865 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2866 return ValueObjectSP();
2869 // from here on we do have a valid index
2870 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2872 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2873 if (!child_valobj_sp)
2874 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2875 if (!child_valobj_sp)
2876 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2877 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2878 if (child_valobj_sp)
2880 root = child_valobj_sp;
2881 *first_unparsed = end+1; // skip ]
2882 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2887 *first_unparsed = expression_cstr;
2888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2889 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2890 return ValueObjectSP();
2893 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
2895 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
2896 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
2899 root = root->Dereference(error);
2900 if (error.Fail() || !root.get())
2902 *first_unparsed = expression_cstr;
2903 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2904 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2905 return ValueObjectSP();
2909 *what_next = eExpressionPathAftermathNothing;
2915 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2916 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
2917 && root->HasSyntheticValue()
2918 && options.m_no_synthetic_children == false)
2920 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2923 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2926 *first_unparsed = expression_cstr;
2927 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2928 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2929 return ValueObjectSP();
2933 *first_unparsed = end+1; // skip ]
2934 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2939 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
2941 root = root->GetSyntheticBitFieldChild(index, index, true);
2944 *first_unparsed = expression_cstr;
2945 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2946 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2947 return ValueObjectSP();
2949 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2951 *first_unparsed = end+1; // skip ]
2952 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2953 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
2957 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
2959 root = root->GetChildAtIndex(index, true);
2962 *first_unparsed = expression_cstr;
2963 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2964 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2965 return ValueObjectSP();
2969 *first_unparsed = end+1; // skip ]
2970 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2974 else if (options.m_no_synthetic_children == false)
2976 if (root->HasSyntheticValue())
2977 root = root->GetSyntheticValue();
2978 else if (!root->IsSynthetic())
2980 *first_unparsed = expression_cstr;
2981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2983 return ValueObjectSP();
2985 // if we are here, then root itself is a synthetic VO.. should be good to go
2989 *first_unparsed = expression_cstr;
2990 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2991 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2992 return ValueObjectSP();
2994 root = root->GetChildAtIndex(index, true);
2997 *first_unparsed = expression_cstr;
2998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3000 return ValueObjectSP();
3004 *first_unparsed = end+1; // skip ]
3005 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3011 *first_unparsed = expression_cstr;
3012 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3013 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3014 return ValueObjectSP();
3017 else // we have a low and a high index
3020 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3021 if (!end || end != separator_position) // if something weird is in our way return an error
3023 *first_unparsed = expression_cstr;
3024 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3025 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3026 return ValueObjectSP();
3028 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3029 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3031 *first_unparsed = expression_cstr;
3032 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3033 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3034 return ValueObjectSP();
3036 if (index_lower > index_higher) // swap indices if required
3038 unsigned long temp = index_lower;
3039 index_lower = index_higher;
3040 index_higher = temp;
3042 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
3044 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3047 *first_unparsed = expression_cstr;
3048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3050 return ValueObjectSP();
3054 *first_unparsed = end+1; // skip ]
3055 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3056 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3060 else if (root_clang_type_info.Test(ClangASTType::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
3061 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3062 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3065 root = root->Dereference(error);
3066 if (error.Fail() || !root.get())
3068 *first_unparsed = expression_cstr;
3069 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3070 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3071 return ValueObjectSP();
3075 *what_next = ValueObject::eExpressionPathAftermathNothing;
3081 *first_unparsed = expression_cstr;
3082 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3083 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
3089 default: // some non-separator is in the way
3091 *first_unparsed = expression_cstr;
3092 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3093 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3094 return ValueObjectSP();
3102 ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3103 const char** first_unparsed,
3105 ValueObjectListSP& list,
3106 ExpressionPathScanEndReason* reason_to_stop,
3107 ExpressionPathEndResultType* final_result,
3108 const GetValueForExpressionPathOptions& options,
3109 ExpressionPathAftermath* what_next)
3114 *first_unparsed = expression_cstr;
3119 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3121 ClangASTType root_clang_type = root->GetClangType();
3122 ClangASTType pointee_clang_type;
3123 Flags pointee_clang_type_info;
3124 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
3125 if (pointee_clang_type)
3126 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
3128 if (!expression_cstr || *expression_cstr == '\0')
3130 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
3135 switch (*expression_cstr)
3139 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
3141 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3143 *first_unparsed = expression_cstr;
3144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3148 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3150 *first_unparsed = expression_cstr;
3151 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3152 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3156 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3158 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3160 *first_unparsed = expression_cstr;
3161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3165 else // expand this into list
3167 const size_t max_index = root->GetNumChildren() - 1;
3168 for (size_t index = 0; index < max_index; index++)
3170 ValueObjectSP child =
3171 root->GetChildAtIndex(index, true);
3172 list->Append(child);
3174 *first_unparsed = expression_cstr+2;
3175 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3176 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3177 return max_index; // tell me number of items I added to the VOList
3180 const char *separator_position = ::strchr(expression_cstr+1,'-');
3181 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3182 if (!close_bracket_position) // if there is no ], this is a syntax error
3184 *first_unparsed = expression_cstr;
3185 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3186 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3189 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3192 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3193 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3195 *first_unparsed = expression_cstr;
3196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3200 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3202 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3204 const size_t max_index = root->GetNumChildren() - 1;
3205 for (size_t index = 0; index < max_index; index++)
3207 ValueObjectSP child =
3208 root->GetChildAtIndex(index, true);
3209 list->Append(child);
3211 *first_unparsed = expression_cstr+2;
3212 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3213 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3214 return max_index; // tell me number of items I added to the VOList
3218 *first_unparsed = expression_cstr;
3219 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3220 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3224 // from here on we do have a valid index
3225 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3227 root = root->GetChildAtIndex(index, true);
3230 *first_unparsed = expression_cstr;
3231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3232 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3238 *first_unparsed = end+1; // skip ]
3239 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3240 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3244 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
3246 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
3247 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3250 root = root->Dereference(error);
3251 if (error.Fail() || !root.get())
3253 *first_unparsed = expression_cstr;
3254 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3255 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3260 *what_next = eExpressionPathAftermathNothing;
3266 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3269 *first_unparsed = expression_cstr;
3270 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3271 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3277 *first_unparsed = end+1; // skip ]
3278 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3279 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3284 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3286 root = root->GetSyntheticBitFieldChild(index, index, true);
3289 *first_unparsed = expression_cstr;
3290 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3291 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3294 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3297 *first_unparsed = end+1; // skip ]
3298 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3299 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3304 else // we have a low and a high index
3307 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3308 if (!end || end != separator_position) // if something weird is in our way return an error
3310 *first_unparsed = expression_cstr;
3311 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3312 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3315 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3316 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3318 *first_unparsed = expression_cstr;
3319 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3320 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3323 if (index_lower > index_higher) // swap indices if required
3325 unsigned long temp = index_lower;
3326 index_lower = index_higher;
3327 index_higher = temp;
3329 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
3331 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3334 *first_unparsed = expression_cstr;
3335 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3336 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3342 *first_unparsed = end+1; // skip ]
3343 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3344 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3348 else if (root_clang_type_info.Test(ClangASTType::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
3349 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3350 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3353 root = root->Dereference(error);
3354 if (error.Fail() || !root.get())
3356 *first_unparsed = expression_cstr;
3357 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3358 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3363 *what_next = ValueObject::eExpressionPathAftermathNothing;
3369 for (unsigned long index = index_lower;
3370 index <= index_higher; index++)
3372 ValueObjectSP child =
3373 root->GetChildAtIndex(index, true);
3374 list->Append(child);
3376 *first_unparsed = end+1;
3377 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3378 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3379 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3384 default: // some non-[ separator, or something entirely wrong, is in the way
3386 *first_unparsed = expression_cstr;
3387 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3388 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3397 ValueObject::LogValueObject (Log *log)
3400 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
3404 ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
3411 log->PutCString(s.GetData());
3416 ValueObject::Dump (Stream &s)
3419 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3420 printer.PrintValueObject();
3424 ValueObject::Dump (Stream &s,
3425 const DumpValueObjectOptions& options)
3427 ValueObjectPrinter printer(this,&s,options);
3428 printer.PrintValueObject();
3432 ValueObject::CreateConstantValue (const ConstString &name)
3434 ValueObjectSP valobj_sp;
3436 if (UpdateValueIfNeeded(false) && m_error.Success())
3438 ExecutionContext exe_ctx (GetExecutionContextRef());
3441 data.SetByteOrder (m_data.GetByteOrder());
3442 data.SetAddressByteSize(m_data.GetAddressByteSize());
3446 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3447 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3450 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3452 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3461 ExecutionContext exe_ctx (GetExecutionContextRef());
3462 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
3468 ValueObject::Dereference (Error &error)
3471 return m_deref_valobj->GetSP();
3473 const bool is_pointer_type = IsPointerType();
3474 if (is_pointer_type)
3476 bool omit_empty_base_classes = true;
3477 bool ignore_array_bounds = false;
3479 std::string child_name_str;
3480 uint32_t child_byte_size = 0;
3481 int32_t child_byte_offset = 0;
3482 uint32_t child_bitfield_bit_size = 0;
3483 uint32_t child_bitfield_bit_offset = 0;
3484 bool child_is_base_class = false;
3485 bool child_is_deref_of_parent = false;
3486 const bool transparent_pointers = false;
3487 ClangASTType clang_type = GetClangType();
3488 ClangASTType child_clang_type;
3490 ExecutionContext exe_ctx (GetExecutionContextRef());
3492 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3493 GetName().GetCString(),
3495 transparent_pointers,
3496 omit_empty_base_classes,
3497 ignore_array_bounds,
3501 child_bitfield_bit_size,
3502 child_bitfield_bit_offset,
3503 child_is_base_class,
3504 child_is_deref_of_parent);
3505 if (child_clang_type && child_byte_size)
3507 ConstString child_name;
3508 if (!child_name_str.empty())
3509 child_name.SetCString (child_name_str.c_str());
3511 m_deref_valobj = new ValueObjectChild (*this,
3516 child_bitfield_bit_size,
3517 child_bitfield_bit_offset,
3518 child_is_base_class,
3519 child_is_deref_of_parent,
3520 eAddressTypeInvalid);
3527 return m_deref_valobj->GetSP();
3532 GetExpressionPath(strm, true);
3534 if (is_pointer_type)
3535 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3537 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3538 return ValueObjectSP();
3543 ValueObject::AddressOf (Error &error)
3545 if (m_addr_of_valobj_sp)
3546 return m_addr_of_valobj_sp;
3548 AddressType address_type = eAddressTypeInvalid;
3549 const bool scalar_is_load_address = false;
3550 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
3552 if (addr != LLDB_INVALID_ADDRESS)
3554 switch (address_type)
3556 case eAddressTypeInvalid:
3558 StreamString expr_path_strm;
3559 GetExpressionPath(expr_path_strm, true);
3560 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3564 case eAddressTypeFile:
3565 case eAddressTypeLoad:
3566 case eAddressTypeHost:
3568 ClangASTType clang_type = GetClangType();
3571 std::string name (1, '&');
3572 name.append (m_name.AsCString(""));
3573 ExecutionContext exe_ctx (GetExecutionContextRef());
3574 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3575 clang_type.GetPointerType(),
3576 ConstString (name.c_str()),
3578 eAddressTypeInvalid,
3579 m_data.GetAddressByteSize());
3587 StreamString expr_path_strm;
3588 GetExpressionPath(expr_path_strm, true);
3589 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3592 return m_addr_of_valobj_sp;
3596 ValueObject::Cast (const ClangASTType &clang_ast_type)
3598 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
3602 ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3604 ValueObjectSP valobj_sp;
3605 AddressType address_type;
3606 addr_t ptr_value = GetPointerValue (&address_type);
3608 if (ptr_value != LLDB_INVALID_ADDRESS)
3610 Address ptr_addr (ptr_value);
3611 ExecutionContext exe_ctx (GetExecutionContextRef());
3612 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3621 ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3623 ValueObjectSP valobj_sp;
3624 AddressType address_type;
3625 addr_t ptr_value = GetPointerValue (&address_type);
3627 if (ptr_value != LLDB_INVALID_ADDRESS)
3629 Address ptr_addr (ptr_value);
3630 ExecutionContext exe_ctx (GetExecutionContextRef());
3631 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3639 ValueObject::EvaluationPoint::EvaluationPoint () :
3642 m_needs_update (true),
3643 m_first_update (true)
3647 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
3650 m_needs_update (true),
3651 m_first_update (true)
3653 ExecutionContext exe_ctx(exe_scope);
3654 TargetSP target_sp (exe_ctx.GetTargetSP());
3657 m_exe_ctx_ref.SetTargetSP (target_sp);
3658 ProcessSP process_sp (exe_ctx.GetProcessSP());
3660 process_sp = target_sp->GetProcessSP();
3664 m_mod_id = process_sp->GetModID();
3665 m_exe_ctx_ref.SetProcessSP (process_sp);
3667 ThreadSP thread_sp (exe_ctx.GetThreadSP());
3672 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3677 m_exe_ctx_ref.SetThreadSP(thread_sp);
3679 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3683 frame_sp = thread_sp->GetSelectedFrame();
3686 m_exe_ctx_ref.SetFrameSP(frame_sp);
3692 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3694 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3695 m_needs_update (true),
3696 m_first_update (true)
3700 ValueObject::EvaluationPoint::~EvaluationPoint ()
3704 // This function checks the EvaluationPoint against the current process state. If the current
3705 // state matches the evaluation point, or the evaluation point is already invalid, then we return
3706 // false, meaning "no change". If the current state is different, we update our state, and return
3707 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3708 // future calls to NeedsUpdate will return true.
3709 // exe_scope will be set to the current execution context scope.
3712 ValueObject::EvaluationPoint::SyncWithProcessState()
3715 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3716 const bool thread_and_frame_only_if_stopped = true;
3717 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3719 if (exe_ctx.GetTargetPtr() == NULL)
3722 // If we don't have a process nothing can change.
3723 Process *process = exe_ctx.GetProcessPtr();
3724 if (process == NULL)
3727 // If our stop id is the current stop ID, nothing has changed:
3728 ProcessModID current_mod_id = process->GetModID();
3730 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3731 // In either case, we aren't going to be able to sync with the process state.
3732 if (current_mod_id.GetStopID() == 0)
3735 bool changed = false;
3736 const bool was_valid = m_mod_id.IsValid();
3739 if (m_mod_id == current_mod_id)
3741 // Everything is already up to date in this object, no need to
3742 // update the execution context scope.
3747 m_mod_id = current_mod_id;
3748 m_needs_update = true;
3753 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3754 // That way we'll be sure to return a valid exe_scope.
3755 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
3757 if (m_exe_ctx_ref.HasThreadRef())
3759 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3762 if (m_exe_ctx_ref.HasFrameRef())
3764 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3767 // We used to have a frame, but now it is gone
3769 changed = was_valid;
3775 // We used to have a thread, but now it is gone
3777 changed = was_valid;
3785 ValueObject::EvaluationPoint::SetUpdated ()
3787 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3789 m_mod_id = process_sp->GetModID();
3790 m_first_update = false;
3791 m_needs_update = false;
3797 ValueObject::ClearUserVisibleData(uint32_t clear_mask)
3799 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3800 m_value_str.clear();
3802 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3803 m_location_str.clear();
3805 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3807 m_summary_str.clear();
3810 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3811 m_object_desc_str.clear();
3813 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3815 if (m_synthetic_value)
3816 m_synthetic_value = NULL;
3820 SymbolContextScope *
3821 ValueObject::GetSymbolContextScope()
3825 if (!m_parent->IsPointerOrReferenceType())
3826 return m_parent->GetSymbolContextScope();
3832 ValueObject::CreateValueObjectFromExpression (const char* name,
3833 const char* expression,
3834 const ExecutionContext& exe_ctx)
3836 lldb::ValueObjectSP retval_sp;
3837 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3840 if (!expression || !*expression)
3842 target_sp->EvaluateExpression (expression,
3843 exe_ctx.GetFrameSP().get(),
3845 if (retval_sp && name && *name)
3846 retval_sp->SetName(ConstString(name));
3851 ValueObject::CreateValueObjectFromAddress (const char* name,
3853 const ExecutionContext& exe_ctx,
3858 ClangASTType pointer_type(type.GetPointerType());
3861 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3862 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3866 lldb::endian::InlHostByteOrder(),
3867 exe_ctx.GetAddressByteSize()));
3868 if (ptr_result_valobj_sp)
3870 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3872 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3873 if (ptr_result_valobj_sp && name && *name)
3874 ptr_result_valobj_sp->SetName(ConstString(name));
3876 return ptr_result_valobj_sp;
3879 return lldb::ValueObjectSP();
3883 ValueObject::CreateValueObjectFromData (const char* name,
3884 DataExtractor& data,
3885 const ExecutionContext& exe_ctx,
3888 lldb::ValueObjectSP new_value_sp;
3889 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3893 LLDB_INVALID_ADDRESS);
3894 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3895 if (new_value_sp && name && *name)
3896 new_value_sp->SetName(ConstString(name));
3897 return new_value_sp;
3901 ValueObject::GetModule ()
3903 ValueObject* root(GetRoot());
3905 return root->GetModule();
3906 return lldb::ModuleSP();
3910 ValueObject::GetRoot ()
3914 ValueObject* parent = m_parent;
3916 return (m_root = this);
3917 while (parent->m_parent)
3920 return (m_root = parent->m_root);
3921 parent = parent->m_parent;
3923 return (m_root = parent);
3927 ValueObject::GetAddressTypeOfChildren()
3929 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3931 ValueObject* root(GetRoot());
3933 return root->GetAddressTypeOfChildren();
3935 return m_address_type_of_ptr_or_ref_children;
3938 lldb::DynamicValueType
3939 ValueObject::GetDynamicValueType ()
3941 ValueObject* with_dv_info = this;
3942 while (with_dv_info)
3944 if (with_dv_info->HasDynamicValueTypeInfo())
3945 return with_dv_info->GetDynamicValueTypeImpl();
3946 with_dv_info = with_dv_info->m_parent;
3948 return lldb::eNoDynamicValues;
3952 ValueObject::GetFormat () const
3954 const ValueObject* with_fmt_info = this;
3955 while (with_fmt_info)
3957 if (with_fmt_info->m_format != lldb::eFormatDefault)
3958 return with_fmt_info->m_format;
3959 with_fmt_info = with_fmt_info->m_parent;