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/Core/ValueObject.h"
16 // Other libraries and framework includes
17 #include "llvm/Support/raw_ostream.h"
18 #include "clang/AST/Type.h"
21 #include "lldb/Core/DataBufferHeap.h"
22 #include "lldb/Core/Debugger.h"
23 #include "lldb/Core/Log.h"
24 #include "lldb/Core/Module.h"
25 #include "lldb/Core/StreamString.h"
26 #include "lldb/Core/ValueObjectCast.h"
27 #include "lldb/Core/ValueObjectChild.h"
28 #include "lldb/Core/ValueObjectConstResult.h"
29 #include "lldb/Core/ValueObjectDynamicValue.h"
30 #include "lldb/Core/ValueObjectList.h"
31 #include "lldb/Core/ValueObjectMemory.h"
32 #include "lldb/Core/ValueObjectSyntheticFilter.h"
34 #include "lldb/DataFormatters/DataVisualization.h"
35 #include "lldb/DataFormatters/StringPrinter.h"
36 #include "lldb/DataFormatters/ValueObjectPrinter.h"
38 #include "lldb/Expression/ClangExpressionVariable.h"
39 #include "lldb/Expression/ClangPersistentVariables.h"
41 #include "lldb/Host/Endian.h"
43 #include "lldb/Interpreter/CommandInterpreter.h"
45 #include "lldb/Symbol/ClangASTType.h"
46 #include "lldb/Symbol/ClangASTContext.h"
47 #include "lldb/Symbol/CompileUnit.h"
48 #include "lldb/Symbol/Type.h"
50 #include "lldb/Target/ExecutionContext.h"
51 #include "lldb/Target/LanguageRuntime.h"
52 #include "lldb/Target/ObjCLanguageRuntime.h"
53 #include "lldb/Target/Process.h"
54 #include "lldb/Target/RegisterContext.h"
55 #include "lldb/Target/SectionLoadList.h"
56 #include "lldb/Target/Target.h"
57 #include "lldb/Target/Thread.h"
60 using namespace lldb_private;
61 using namespace lldb_utility;
63 static user_id_t g_value_obj_uid = 0;
65 //----------------------------------------------------------------------
66 // ValueObject constructor
67 //----------------------------------------------------------------------
68 ValueObject::ValueObject (ValueObject &parent) :
69 UserID (++g_value_obj_uid), // Unique identifier for every value object
72 m_update_point (parent.GetUpdatePoint ()),
82 m_validation_result(),
83 m_manager(parent.GetManager()),
85 m_synthetic_children (),
86 m_dynamic_value (NULL),
87 m_synthetic_value(NULL),
89 m_format (eFormatDefault),
90 m_last_format (eFormatDefault),
91 m_last_format_mgr_revision(0),
94 m_synthetic_children_sp(),
95 m_type_validator_sp(),
96 m_user_id_of_forced_summary(),
97 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
99 m_preferred_display_language(lldb::eLanguageTypeUnknown),
100 m_value_is_valid (false),
101 m_value_did_change (false),
102 m_children_count_valid (false),
103 m_old_value_valid (false),
104 m_is_deref_of_parent (false),
105 m_is_array_item_for_pointer(false),
106 m_is_bitfield_for_scalar(false),
107 m_is_child_at_offset(false),
108 m_is_getting_summary(false),
109 m_did_calculate_complete_objc_class_type(false),
110 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
112 m_manager->ManageObject(this);
115 //----------------------------------------------------------------------
116 // ValueObject constructor
117 //----------------------------------------------------------------------
118 ValueObject::ValueObject (ExecutionContextScope *exe_scope,
119 AddressType child_ptr_or_ref_addr_type) :
120 UserID (++g_value_obj_uid), // Unique identifier for every value object
123 m_update_point (exe_scope),
132 m_object_desc_str (),
133 m_validation_result(),
136 m_synthetic_children (),
137 m_dynamic_value (NULL),
138 m_synthetic_value(NULL),
139 m_deref_valobj(NULL),
140 m_format (eFormatDefault),
141 m_last_format (eFormatDefault),
142 m_last_format_mgr_revision(0),
145 m_synthetic_children_sp(),
146 m_type_validator_sp(),
147 m_user_id_of_forced_summary(),
148 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
150 m_preferred_display_language(lldb::eLanguageTypeUnknown),
151 m_value_is_valid (false),
152 m_value_did_change (false),
153 m_children_count_valid (false),
154 m_old_value_valid (false),
155 m_is_deref_of_parent (false),
156 m_is_array_item_for_pointer(false),
157 m_is_bitfield_for_scalar(false),
158 m_is_child_at_offset(false),
159 m_is_getting_summary(false),
160 m_did_calculate_complete_objc_class_type(false),
161 m_is_synthetic_children_generated(false)
163 m_manager = new ValueObjectManager();
164 m_manager->ManageObject (this);
167 //----------------------------------------------------------------------
169 //----------------------------------------------------------------------
170 ValueObject::~ValueObject ()
175 ValueObject::UpdateValueIfNeeded (bool update_format)
178 bool did_change_formats = false;
181 did_change_formats = UpdateFormatsIfNeeded();
183 // If this is a constant value, then our success is predicated on whether
184 // we have an error or not
187 // if you are constant, things might still have changed behind your back
188 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
189 // in this case, your value has not changed, but "computed" entries might have, so you might now have
190 // a different summary, or a different object description. clear these so we will recompute them
191 if (update_format && !did_change_formats)
192 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
193 return m_error.Success();
196 bool first_update = IsChecksumEmpty();
200 m_update_point.SetUpdated();
202 // Save the old value using swap to avoid a string copy which
203 // also will clear our m_value_str
204 if (m_value_str.empty())
206 m_old_value_valid = false;
210 m_old_value_valid = true;
211 m_old_value_str.swap (m_value_str);
212 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
215 ClearUserVisibleData();
219 const bool value_was_valid = GetValueIsValid();
220 SetValueDidChange (false);
224 // Call the pure virtual function to update the value
226 bool need_compare_checksums = false;
227 llvm::SmallVector<uint8_t, 16> old_checksum;
229 if (!first_update && CanProvideValue())
231 need_compare_checksums = true;
232 old_checksum.resize(m_value_checksum.size());
233 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
236 bool success = UpdateValue ();
238 SetValueIsValid (success);
242 const uint64_t max_checksum_size = 128;
243 m_data.Checksum(m_value_checksum,
248 need_compare_checksums = false;
249 m_value_checksum.clear();
252 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
255 SetValueDidChange (false);
256 else if (!m_value_did_change && success == false)
258 // The value wasn't gotten successfully, so we mark this
259 // as changed if the value used to be valid and now isn't
260 SetValueDidChange (value_was_valid);
262 else if (need_compare_checksums)
264 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
270 m_error.SetErrorString("out of scope");
273 return m_error.Success();
277 ValueObject::UpdateFormatsIfNeeded()
279 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
281 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
282 GetName().GetCString(), static_cast<void*>(this),
283 m_last_format_mgr_revision,
284 DataVisualization::GetCurrentRevision());
286 bool any_change = false;
288 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
290 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
293 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
294 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
295 #ifndef LLDB_DISABLE_PYTHON
296 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
298 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
305 ValueObject::SetNeedsUpdate ()
307 m_update_point.SetNeedsUpdate();
308 // We have to clear the value string here so ConstResult children will notice if their values are
309 // changed by hand (i.e. with SetValueAsCString).
310 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
314 ValueObject::ClearDynamicTypeInformation ()
316 m_children_count_valid = false;
317 m_did_calculate_complete_objc_class_type = false;
318 m_last_format_mgr_revision = 0;
319 m_override_type = ClangASTType();
320 SetValueFormat(lldb::TypeFormatImplSP());
321 SetSummaryFormat(lldb::TypeSummaryImplSP());
322 SetSyntheticChildren(lldb::SyntheticChildrenSP());
326 ValueObject::MaybeCalculateCompleteType ()
328 ClangASTType clang_type(GetClangTypeImpl());
330 if (m_did_calculate_complete_objc_class_type)
332 if (m_override_type.IsValid())
333 return m_override_type;
338 ClangASTType class_type;
339 bool is_pointer_type = false;
341 if (clang_type.IsObjCObjectPointerType(&class_type))
343 is_pointer_type = true;
345 else if (clang_type.IsObjCObjectOrInterfaceType())
347 class_type = clang_type;
354 m_did_calculate_complete_objc_class_type = true;
358 ConstString class_name (class_type.GetConstTypeName());
362 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
366 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
368 if (objc_language_runtime)
370 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
372 if (complete_objc_class_type_sp)
374 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
376 if (complete_class.GetCompleteType())
380 m_override_type = complete_class.GetPointerType();
384 m_override_type = complete_class;
387 if (m_override_type.IsValid())
388 return m_override_type;
399 ValueObject::GetClangType ()
401 return MaybeCalculateCompleteType();
405 ValueObject::GetTypeImpl ()
407 return TypeImpl(GetClangType());
411 ValueObject::GetDataExtractor ()
413 UpdateValueIfNeeded(false);
418 ValueObject::GetError()
420 UpdateValueIfNeeded(false);
425 ValueObject::GetName() const
431 ValueObject::GetLocationAsCString ()
433 return GetLocationAsCStringImpl(m_value,
438 ValueObject::GetLocationAsCStringImpl (const Value& value,
439 const DataExtractor& data)
441 if (UpdateValueIfNeeded(false))
443 if (m_location_str.empty())
447 Value::ValueType value_type = value.GetValueType();
451 case Value::eValueTypeScalar:
452 case Value::eValueTypeVector:
453 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
455 RegisterInfo *reg_info = value.GetRegisterInfo();
459 m_location_str = reg_info->name;
460 else if (reg_info->alt_name)
461 m_location_str = reg_info->alt_name;
462 if (m_location_str.empty())
463 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
466 if (m_location_str.empty())
467 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
470 case Value::eValueTypeLoadAddress:
471 case Value::eValueTypeFileAddress:
472 case Value::eValueTypeHostAddress:
474 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
475 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
476 m_location_str.swap(sstr.GetString());
482 return m_location_str.c_str();
486 ValueObject::GetValue()
492 ValueObject::GetValue() const
498 ValueObject::ResolveValue (Scalar &scalar)
500 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
502 ExecutionContext exe_ctx (GetExecutionContextRef());
503 Value tmp_value(m_value);
504 scalar = tmp_value.ResolveValue(&exe_ctx);
505 if (scalar.IsValid())
507 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
508 if (bitfield_bit_size)
509 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
517 ValueObject::GetValueIsValid () const
519 return m_value_is_valid;
524 ValueObject::SetValueIsValid (bool b)
526 m_value_is_valid = b;
530 ValueObject::GetValueDidChange ()
532 return m_value_did_change;
536 ValueObject::SetValueDidChange (bool value_changed)
538 m_value_did_change = value_changed;
542 ValueObject::GetChildAtIndex (size_t idx, bool can_create)
544 ValueObjectSP child_sp;
545 // We may need to update our value if we are dynamic
546 if (IsPossibleDynamicType ())
547 UpdateValueIfNeeded(false);
548 if (idx < GetNumChildren())
550 // Check if we have already made the child value object?
551 if (can_create && !m_children.HasChildAtIndex(idx))
553 // No we haven't created the child at this index, so lets have our
554 // subclass do it and cache the result for quick future access.
555 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
558 ValueObject* child = m_children.GetChildAtIndex(idx);
560 return child->GetSP();
566 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
567 size_t* index_of_error)
569 if (idxs.size() == 0)
571 ValueObjectSP root(GetSP());
572 for (size_t idx : idxs)
574 root = root->GetChildAtIndex(idx, true);
578 *index_of_error = idx;
586 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
587 size_t* index_of_error)
589 if (idxs.size() == 0)
591 ValueObjectSP root(GetSP());
592 for (std::pair<size_t, bool> idx : idxs)
594 root = root->GetChildAtIndex(idx.first, idx.second);
598 *index_of_error = idx.first;
606 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
607 size_t* index_of_error)
609 if (idxs.size() == 0)
611 ValueObjectSP root(GetSP());
612 for (size_t idx : idxs)
614 root = root->GetChildAtIndex(idx, true);
618 *index_of_error = idx;
626 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
627 size_t* index_of_error)
629 if (idxs.size() == 0)
631 ValueObjectSP root(GetSP());
632 for (std::pair<size_t, bool> idx : idxs)
634 root = root->GetChildAtIndex(idx.first, idx.second);
638 *index_of_error = idx.first;
646 ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
647 ConstString* name_of_error)
649 if (names.size() == 0)
651 ValueObjectSP root(GetSP());
652 for (ConstString name : names)
654 root = root->GetChildMemberWithName(name, true);
658 *name_of_error = name;
666 ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
667 ConstString* name_of_error)
669 if (names.size() == 0)
671 ValueObjectSP root(GetSP());
672 for (ConstString name : names)
674 root = root->GetChildMemberWithName(name, true);
678 *name_of_error = name;
686 ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
687 ConstString* name_of_error)
689 if (names.size() == 0)
691 ValueObjectSP root(GetSP());
692 for (std::pair<ConstString, bool> name : names)
694 root = root->GetChildMemberWithName(name.first, name.second);
698 *name_of_error = name.first;
706 ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
707 ConstString* name_of_error)
709 if (names.size() == 0)
711 ValueObjectSP root(GetSP());
712 for (std::pair<ConstString, bool> name : names)
714 root = root->GetChildMemberWithName(name.first, name.second);
718 *name_of_error = name.first;
726 ValueObject::GetIndexOfChildWithName (const ConstString &name)
728 bool omit_empty_base_classes = true;
729 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
733 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
735 // when getting a child by name, it could be buried inside some base
736 // classes (which really aren't part of the expression path), so we
737 // need a vector of indexes that can get us down to the correct child
738 ValueObjectSP child_sp;
740 // We may need to update our value if we are dynamic
741 if (IsPossibleDynamicType ())
742 UpdateValueIfNeeded(false);
744 std::vector<uint32_t> child_indexes;
745 bool omit_empty_base_classes = true;
746 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
747 omit_empty_base_classes,
749 if (num_child_indexes > 0)
751 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
752 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
754 child_sp = GetChildAtIndex(*pos, can_create);
755 for (++pos; pos != end; ++pos)
759 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
760 child_sp = new_child_sp;
774 ValueObject::GetNumChildren ()
776 UpdateValueIfNeeded();
777 if (!m_children_count_valid)
779 SetNumChildren (CalculateNumChildren());
781 return m_children.GetChildrenCount();
785 ValueObject::MightHaveChildren()
787 bool has_children = false;
788 const uint32_t type_info = GetTypeInfo();
791 if (type_info & (eTypeHasChildren |
798 has_children = GetNumChildren () > 0;
803 // Should only be called by ValueObject::GetNumChildren()
805 ValueObject::SetNumChildren (size_t num_children)
807 m_children_count_valid = true;
808 m_children.SetChildrenCount(num_children);
812 ValueObject::SetName (const ConstString &name)
818 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
820 ValueObject *valobj = NULL;
822 bool omit_empty_base_classes = true;
823 bool ignore_array_bounds = synthetic_array_member;
824 std::string child_name_str;
825 uint32_t child_byte_size = 0;
826 int32_t child_byte_offset = 0;
827 uint32_t child_bitfield_bit_size = 0;
828 uint32_t child_bitfield_bit_offset = 0;
829 bool child_is_base_class = false;
830 bool child_is_deref_of_parent = false;
832 const bool transparent_pointers = synthetic_array_member == false;
833 ClangASTType child_clang_type;
835 ExecutionContext exe_ctx (GetExecutionContextRef());
837 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
839 transparent_pointers,
840 omit_empty_base_classes,
845 child_bitfield_bit_size,
846 child_bitfield_bit_offset,
848 child_is_deref_of_parent,
850 if (child_clang_type)
853 child_byte_offset += child_byte_size * synthetic_index;
855 ConstString child_name;
856 if (!child_name_str.empty())
857 child_name.SetCString (child_name_str.c_str());
859 valobj = new ValueObjectChild (*this,
864 child_bitfield_bit_size,
865 child_bitfield_bit_offset,
867 child_is_deref_of_parent,
868 eAddressTypeInvalid);
870 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
877 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
878 std::string& destination)
880 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
884 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
885 std::string& destination,
886 const TypeSummaryOptions& options)
890 // ideally we would like to bail out if passing NULL, but if we do so
891 // we end up not providing the summary for function pointers anymore
892 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
895 m_is_getting_summary = true;
897 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
898 // information that we might care to see in a crash log. might be useful in very specific situations though.
899 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
900 GetTypeName().GetCString(),
901 GetName().GetCString(),
902 summary_ptr->GetDescription().c_str());*/
904 if (UpdateValueIfNeeded (false) && summary_ptr)
906 if (HasSyntheticValue())
907 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
908 summary_ptr->FormatObject(this, destination, options);
910 m_is_getting_summary = false;
911 return !destination.empty();
915 ValueObject::GetSummaryAsCString ()
917 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
919 GetSummaryAsCString(GetSummaryFormat().get(),
921 TypeSummaryOptions());
923 if (m_summary_str.empty())
925 return m_summary_str.c_str();
929 ValueObject::GetSummaryAsCString (std::string& destination,
930 const TypeSummaryOptions& options)
932 return GetSummaryAsCString(GetSummaryFormat().get(),
938 ValueObject::IsCStringContainer(bool check_pointer)
940 ClangASTType pointee_or_element_clang_type;
941 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
942 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
943 pointee_or_element_clang_type.IsCharType ());
944 if (!is_char_arr_ptr)
948 if (type_flags.Test(eTypeIsArray))
950 addr_t cstr_address = LLDB_INVALID_ADDRESS;
951 AddressType cstr_address_type = eAddressTypeInvalid;
952 cstr_address = GetAddressOf (true, &cstr_address_type);
953 return (cstr_address != LLDB_INVALID_ADDRESS);
957 ValueObject::GetPointeeData (DataExtractor& data,
961 ClangASTType pointee_or_element_clang_type;
962 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
963 const bool is_pointer_type = type_info & eTypeIsPointer;
964 const bool is_array_type = type_info & eTypeIsArray;
965 if (!(is_pointer_type || is_array_type))
971 ExecutionContext exe_ctx (GetExecutionContextRef());
973 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
974 const uint64_t bytes = item_count * item_type_size;
975 const uint64_t offset = item_idx * item_type_size;
977 if (item_idx == 0 && item_count == 1) // simply a deref
982 ValueObjectSP pointee_sp = Dereference(error);
983 if (error.Fail() || pointee_sp.get() == NULL)
985 return pointee_sp->GetData(data, error);
989 ValueObjectSP child_sp = GetChildAtIndex(0, true);
990 if (child_sp.get() == NULL)
993 return child_sp->GetData(data, error);
997 else /* (items > 1) */
1000 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1001 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1003 AddressType addr_type;
1004 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
1008 case eAddressTypeFile:
1010 ModuleSP module_sp (GetModule());
1013 addr = addr + offset;
1015 module_sp->ResolveFileAddress(addr, so_addr);
1016 ExecutionContext exe_ctx (GetExecutionContextRef());
1017 Target* target = exe_ctx.GetTargetPtr();
1020 heap_buf_ptr->SetByteSize(bytes);
1021 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1022 if (error.Success())
1024 data.SetData(data_sp);
1031 case eAddressTypeLoad:
1033 ExecutionContext exe_ctx (GetExecutionContextRef());
1034 Process *process = exe_ctx.GetProcessPtr();
1037 heap_buf_ptr->SetByteSize(bytes);
1038 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
1039 if (error.Success() || bytes_read > 0)
1041 data.SetData(data_sp);
1047 case eAddressTypeHost:
1049 const uint64_t max_bytes = GetClangType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
1050 if (max_bytes > offset)
1052 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1053 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1054 if (addr == LLDB_INVALID_ADDRESS)
1056 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1057 data.SetData(data_sp);
1062 case eAddressTypeInvalid:
1070 ValueObject::GetData (DataExtractor& data, Error &error)
1072 UpdateValueIfNeeded(false);
1073 ExecutionContext exe_ctx (GetExecutionContextRef());
1074 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
1077 if (m_data.GetByteSize())
1080 return data.GetByteSize();
1087 data.SetAddressByteSize(m_data.GetAddressByteSize());
1088 data.SetByteOrder(m_data.GetByteOrder());
1089 return data.GetByteSize();
1093 ValueObject::SetData (DataExtractor &data, Error &error)
1096 // Make sure our value is up to date first so that our location and location
1098 if (!UpdateValueIfNeeded(false))
1100 error.SetErrorString("unable to read value");
1105 const Encoding encoding = GetClangType().GetEncoding(count);
1107 const size_t byte_size = GetByteSize();
1109 Value::ValueType value_type = m_value.GetValueType();
1113 case Value::eValueTypeScalar:
1115 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1117 if (!set_error.Success())
1119 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1124 case Value::eValueTypeLoadAddress:
1126 // If it is a load address, then the scalar value is the storage location
1127 // of the data, and we have to shove this value down to that load location.
1128 ExecutionContext exe_ctx (GetExecutionContextRef());
1129 Process *process = exe_ctx.GetProcessPtr();
1132 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1133 size_t bytes_written = process->WriteMemory(target_addr,
1134 data.GetDataStart(),
1137 if (!error.Success())
1139 if (bytes_written != byte_size)
1141 error.SetErrorString("unable to write value to memory");
1147 case Value::eValueTypeHostAddress:
1149 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1150 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1151 m_data.SetData(buffer_sp, 0);
1152 data.CopyByteOrderedData (0,
1154 const_cast<uint8_t *>(m_data.GetDataStart()),
1156 m_data.GetByteOrder());
1157 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1160 case Value::eValueTypeFileAddress:
1161 case Value::eValueTypeVector:
1165 // If we have reached this point, then we have successfully changed the value.
1170 // will compute strlen(str), but without consuming more than
1171 // maxlen bytes out of str (this serves the purpose of reading
1172 // chunks of a string without having to worry about
1173 // missing NULL terminators in the chunk)
1174 // of course, if strlen(str) > maxlen, the function will return
1175 // maxlen_value (which should be != maxlen, because that allows you
1176 // to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1178 strlen_or_inf (const char* str,
1180 uint32_t maxlen_value)
1189 return maxlen_value;
1196 CopyStringDataToBufferSP(const StreamString& source,
1197 lldb::DataBufferSP& destination)
1199 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1200 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1205 ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
1207 uint32_t max_length,
1212 ExecutionContext exe_ctx (GetExecutionContextRef());
1213 Target* target = exe_ctx.GetTargetPtr();
1217 s << "<no target to read from>";
1218 error.SetErrorString("no target to read from");
1219 CopyStringDataToBufferSP(s, buffer_sp);
1223 if (max_length == 0)
1224 max_length = target->GetMaximumSizeOfStringSummary();
1226 size_t bytes_read = 0;
1227 size_t total_bytes_read = 0;
1229 ClangASTType clang_type = GetClangType();
1230 ClangASTType elem_or_pointee_clang_type;
1231 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
1232 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
1233 elem_or_pointee_clang_type.IsCharType ())
1235 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1236 AddressType cstr_address_type = eAddressTypeInvalid;
1238 size_t cstr_len = 0;
1239 bool capped_data = false;
1240 if (type_flags.Test (eTypeIsArray))
1243 uint64_t array_size = 0;
1244 if (clang_type.IsArrayType(NULL, &array_size, NULL))
1246 cstr_len = array_size;
1247 if (cstr_len > max_length)
1250 cstr_len = max_length;
1253 cstr_address = GetAddressOf (true, &cstr_address_type);
1257 // We have a pointer
1258 cstr_address = GetPointerValue (&cstr_address_type);
1261 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1263 s << "<invalid address>";
1264 error.SetErrorString("invalid address");
1265 CopyStringDataToBufferSP(s, buffer_sp);
1269 Address cstr_so_addr (cstr_address);
1271 if (cstr_len > 0 && honor_array)
1273 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1274 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1275 GetPointeeData(data, 0, cstr_len);
1277 if ((bytes_read = data.GetByteSize()) > 0)
1279 total_bytes_read = bytes_read;
1280 for (size_t offset = 0; offset < bytes_read; offset++)
1281 s.Printf("%c", *data.PeekData(offset, 1));
1288 cstr_len = max_length;
1289 const size_t k_max_buf_size = 64;
1293 int cstr_len_displayed = -1;
1294 bool capped_cstr = false;
1295 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1296 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1297 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
1299 total_bytes_read += bytes_read;
1300 const char *cstr = data.PeekCStr(0);
1301 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1302 if (len > k_max_buf_size)
1303 len = k_max_buf_size;
1305 if (cstr_len_displayed < 0)
1306 cstr_len_displayed = len;
1310 cstr_len_displayed += len;
1311 if (len > bytes_read)
1316 for (size_t offset = 0; offset < bytes_read; offset++)
1317 s.Printf("%c", *data.PeekData(offset, 1));
1319 if (len < k_max_buf_size)
1322 if (len >= cstr_len)
1332 if (cstr_len_displayed >= 0)
1341 error.SetErrorString("not a string object");
1342 s << "<not a string object>";
1344 CopyStringDataToBufferSP(s, buffer_sp);
1345 return total_bytes_read;
1348 std::pair<TypeValidatorResult, std::string>
1349 ValueObject::GetValidationStatus ()
1351 if (!UpdateValueIfNeeded(true))
1352 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1354 if (m_validation_result.hasValue())
1355 return m_validation_result.getValue();
1357 if (!m_type_validator_sp)
1358 return {TypeValidatorResult::Success,""}; // no validator no failure
1360 auto outcome = m_type_validator_sp->FormatObject(this);
1362 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1366 ValueObject::GetObjectDescription ()
1369 if (!UpdateValueIfNeeded (true))
1372 if (!m_object_desc_str.empty())
1373 return m_object_desc_str.c_str();
1375 ExecutionContext exe_ctx (GetExecutionContextRef());
1376 Process *process = exe_ctx.GetProcessPtr();
1377 if (process == NULL)
1382 LanguageType language = GetObjectRuntimeLanguage();
1383 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1385 if (runtime == NULL)
1387 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
1388 ClangASTType clang_type = GetClangType();
1392 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
1394 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
1399 if (runtime && runtime->GetObjectDescription(s, *this))
1401 m_object_desc_str.append (s.GetData());
1404 if (m_object_desc_str.empty())
1407 return m_object_desc_str.c_str();
1411 ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1412 std::string& destination)
1414 if (UpdateValueIfNeeded(false))
1415 return format.FormatObject(this,destination);
1421 ValueObject::GetValueAsCString (lldb::Format format,
1422 std::string& destination)
1424 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
1428 ValueObject::GetValueAsCString ()
1430 if (UpdateValueIfNeeded(true))
1432 lldb::TypeFormatImplSP format_sp;
1433 lldb::Format my_format = GetFormat();
1434 if (my_format == lldb::eFormatDefault)
1436 if (m_type_format_sp)
1437 format_sp = m_type_format_sp;
1440 if (m_is_bitfield_for_scalar)
1441 my_format = eFormatUnsigned;
1444 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
1446 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1448 my_format = reg_info->format;
1452 my_format = GetValue().GetClangType().GetFormat();
1457 if (my_format != m_last_format || m_value_str.empty())
1459 m_last_format = my_format;
1461 format_sp.reset(new TypeFormatImpl_Format(my_format));
1462 if (GetValueAsCString(*format_sp.get(), m_value_str))
1464 if (!m_value_did_change && m_old_value_valid)
1466 // The value was gotten successfully, so we consider the
1467 // value as changed if the value string differs
1468 SetValueDidChange (m_old_value_str != m_value_str);
1473 if (m_value_str.empty())
1475 return m_value_str.c_str();
1478 // if > 8bytes, 0 is returned. this method should mostly be used
1479 // to read address values out of pointers
1481 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
1483 // If our byte size is zero this is an aggregate type that has children
1484 if (CanProvideValue())
1487 if (ResolveValue (scalar))
1491 return scalar.ULongLong(fail_value);
1493 // fallthrough, otherwise...
1502 ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1504 // If our byte size is zero this is an aggregate type that has children
1505 if (CanProvideValue())
1508 if (ResolveValue (scalar))
1512 return scalar.SLongLong(fail_value);
1514 // fallthrough, otherwise...
1522 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1523 // this call up to date by returning true for your new special cases. We will eventually move
1524 // to checking this call result before trying to display special cases
1526 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1527 Format custom_format)
1529 Flags flags(GetTypeInfo());
1530 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
1531 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1533 if (IsCStringContainer(true) &&
1534 (custom_format == eFormatCString ||
1535 custom_format == eFormatCharArray ||
1536 custom_format == eFormatChar ||
1537 custom_format == eFormatVectorOfChar))
1540 if (flags.Test(eTypeIsArray))
1542 if ((custom_format == eFormatBytes) ||
1543 (custom_format == eFormatBytesWithASCII))
1546 if ((custom_format == eFormatVectorOfChar) ||
1547 (custom_format == eFormatVectorOfFloat32) ||
1548 (custom_format == eFormatVectorOfFloat64) ||
1549 (custom_format == eFormatVectorOfSInt16) ||
1550 (custom_format == eFormatVectorOfSInt32) ||
1551 (custom_format == eFormatVectorOfSInt64) ||
1552 (custom_format == eFormatVectorOfSInt8) ||
1553 (custom_format == eFormatVectorOfUInt128) ||
1554 (custom_format == eFormatVectorOfUInt16) ||
1555 (custom_format == eFormatVectorOfUInt32) ||
1556 (custom_format == eFormatVectorOfUInt64) ||
1557 (custom_format == eFormatVectorOfUInt8))
1565 ValueObject::DumpPrintableRepresentation(Stream& s,
1566 ValueObjectRepresentationStyle val_obj_display,
1567 Format custom_format,
1568 PrintableRepresentationSpecialCases special,
1572 Flags flags(GetTypeInfo());
1574 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1575 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1579 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
1580 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1582 // when being asked to get a printable display an array or pointer type directly,
1583 // try to "do the right thing"
1585 if (IsCStringContainer(true) &&
1586 (custom_format == eFormatCString ||
1587 custom_format == eFormatCharArray ||
1588 custom_format == eFormatChar ||
1589 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
1592 lldb::DataBufferSP buffer_sp;
1593 ReadPointedString(buffer_sp,
1596 (custom_format == eFormatVectorOfChar) ||
1597 (custom_format == eFormatCharArray));
1598 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
1599 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1600 options.SetStream(&s);
1601 options.SetPrefixToken(0);
1602 options.SetQuote('"');
1603 options.SetSourceSize(buffer_sp->GetByteSize());
1604 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
1605 return !error.Fail();
1608 if (custom_format == eFormatEnum)
1611 // this only works for arrays, because I have no way to know when
1612 // the pointed memory ends, and no special \0 end of data marker
1613 if (flags.Test(eTypeIsArray))
1615 if ((custom_format == eFormatBytes) ||
1616 (custom_format == eFormatBytesWithASCII))
1618 const size_t count = GetNumChildren();
1621 for (size_t low = 0; low < count; low++)
1627 ValueObjectSP child = GetChildAtIndex(low,true);
1630 s << "<invalid child>";
1633 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1641 if ((custom_format == eFormatVectorOfChar) ||
1642 (custom_format == eFormatVectorOfFloat32) ||
1643 (custom_format == eFormatVectorOfFloat64) ||
1644 (custom_format == eFormatVectorOfSInt16) ||
1645 (custom_format == eFormatVectorOfSInt32) ||
1646 (custom_format == eFormatVectorOfSInt64) ||
1647 (custom_format == eFormatVectorOfSInt8) ||
1648 (custom_format == eFormatVectorOfUInt128) ||
1649 (custom_format == eFormatVectorOfUInt16) ||
1650 (custom_format == eFormatVectorOfUInt32) ||
1651 (custom_format == eFormatVectorOfUInt64) ||
1652 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1654 const size_t count = GetNumChildren();
1656 Format format = FormatManager::GetSingleItemFormat(custom_format);
1659 for (size_t low = 0; low < count; low++)
1665 ValueObjectSP child = GetChildAtIndex(low,true);
1668 s << "<invalid child>";
1671 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1680 if ((custom_format == eFormatBoolean) ||
1681 (custom_format == eFormatBinary) ||
1682 (custom_format == eFormatChar) ||
1683 (custom_format == eFormatCharPrintable) ||
1684 (custom_format == eFormatComplexFloat) ||
1685 (custom_format == eFormatDecimal) ||
1686 (custom_format == eFormatHex) ||
1687 (custom_format == eFormatHexUppercase) ||
1688 (custom_format == eFormatFloat) ||
1689 (custom_format == eFormatOctal) ||
1690 (custom_format == eFormatOSType) ||
1691 (custom_format == eFormatUnicode16) ||
1692 (custom_format == eFormatUnicode32) ||
1693 (custom_format == eFormatUnsigned) ||
1694 (custom_format == eFormatPointer) ||
1695 (custom_format == eFormatComplexInteger) ||
1696 (custom_format == eFormatComplex) ||
1697 (custom_format == eFormatDefault)) // use the [] operator
1705 bool var_success = false;
1708 const char *cstr = NULL;
1710 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1711 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1712 // area for cases where our desired output is not backed by some other longer-term storage
1715 if (custom_format != eFormatInvalid)
1716 SetFormat(custom_format);
1718 switch(val_obj_display)
1720 case eValueObjectRepresentationStyleValue:
1721 cstr = GetValueAsCString();
1724 case eValueObjectRepresentationStyleSummary:
1725 cstr = GetSummaryAsCString();
1728 case eValueObjectRepresentationStyleLanguageSpecific:
1729 cstr = GetObjectDescription();
1732 case eValueObjectRepresentationStyleLocation:
1733 cstr = GetLocationAsCString();
1736 case eValueObjectRepresentationStyleChildrenCount:
1737 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
1738 cstr = strm.GetString().c_str();
1741 case eValueObjectRepresentationStyleType:
1742 cstr = GetTypeName().AsCString();
1745 case eValueObjectRepresentationStyleName:
1746 cstr = GetName().AsCString();
1749 case eValueObjectRepresentationStyleExpressionPath:
1750 GetExpressionPath(strm, false);
1751 cstr = strm.GetString().c_str();
1757 if (val_obj_display == eValueObjectRepresentationStyleValue)
1758 cstr = GetSummaryAsCString();
1759 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1761 if (!CanProvideValue())
1763 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1764 cstr = strm.GetString().c_str();
1767 cstr = GetValueAsCString();
1778 s.Printf("<%s>", m_error.AsCString());
1782 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1783 s.PutCString("<no summary available>");
1784 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1785 s.PutCString("<no value available>");
1786 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1787 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1789 s.PutCString("<no printable representation>");
1792 // we should only return false here if we could not do *anything*
1793 // even if we have an error message as output, that's a success
1794 // from our callers' perspective, so return true
1797 if (custom_format != eFormatInvalid)
1798 SetFormat(eFormatDefault);
1805 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
1807 if (!UpdateValueIfNeeded(false))
1808 return LLDB_INVALID_ADDRESS;
1810 switch (m_value.GetValueType())
1812 case Value::eValueTypeScalar:
1813 case Value::eValueTypeVector:
1814 if (scalar_is_load_address)
1817 *address_type = eAddressTypeLoad;
1818 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1822 case Value::eValueTypeLoadAddress:
1823 case Value::eValueTypeFileAddress:
1826 *address_type = m_value.GetValueAddressType ();
1827 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1830 case Value::eValueTypeHostAddress:
1833 *address_type = m_value.GetValueAddressType ();
1834 return LLDB_INVALID_ADDRESS;
1839 *address_type = eAddressTypeInvalid;
1840 return LLDB_INVALID_ADDRESS;
1844 ValueObject::GetPointerValue (AddressType *address_type)
1846 addr_t address = LLDB_INVALID_ADDRESS;
1848 *address_type = eAddressTypeInvalid;
1850 if (!UpdateValueIfNeeded(false))
1853 switch (m_value.GetValueType())
1855 case Value::eValueTypeScalar:
1856 case Value::eValueTypeVector:
1857 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1860 case Value::eValueTypeHostAddress:
1861 case Value::eValueTypeLoadAddress:
1862 case Value::eValueTypeFileAddress:
1864 lldb::offset_t data_offset = 0;
1865 address = m_data.GetPointer(&data_offset);
1871 *address_type = GetAddressTypeOfChildren();
1877 ValueObject::SetValueFromCString (const char *value_str, Error& error)
1880 // Make sure our value is up to date first so that our location and location
1882 if (!UpdateValueIfNeeded(false))
1884 error.SetErrorString("unable to read value");
1889 const Encoding encoding = GetClangType().GetEncoding (count);
1891 const size_t byte_size = GetByteSize();
1893 Value::ValueType value_type = m_value.GetValueType();
1895 if (value_type == Value::eValueTypeScalar)
1897 // If the value is already a scalar, then let the scalar change itself:
1898 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1900 else if (byte_size <= Scalar::GetMaxByteSize())
1902 // If the value fits in a scalar, then make a new scalar and again let the
1903 // scalar code do the conversion, then figure out where to put the new value.
1905 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1906 if (error.Success())
1910 case Value::eValueTypeLoadAddress:
1912 // If it is a load address, then the scalar value is the storage location
1913 // of the data, and we have to shove this value down to that load location.
1914 ExecutionContext exe_ctx (GetExecutionContextRef());
1915 Process *process = exe_ctx.GetProcessPtr();
1918 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1919 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1923 if (!error.Success())
1925 if (bytes_written != byte_size)
1927 error.SetErrorString("unable to write value to memory");
1933 case Value::eValueTypeHostAddress:
1935 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1936 DataExtractor new_data;
1937 new_data.SetByteOrder (m_data.GetByteOrder());
1939 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1940 m_data.SetData(buffer_sp, 0);
1941 bool success = new_scalar.GetData(new_data);
1944 new_data.CopyByteOrderedData (0,
1946 const_cast<uint8_t *>(m_data.GetDataStart()),
1948 m_data.GetByteOrder());
1950 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1954 case Value::eValueTypeFileAddress:
1955 case Value::eValueTypeScalar:
1956 case Value::eValueTypeVector:
1967 // We don't support setting things bigger than a scalar at present.
1968 error.SetErrorString("unable to write aggregate data type");
1972 // If we have reached this point, then we have successfully changed the value.
1978 ValueObject::GetDeclaration (Declaration &decl)
1985 ValueObject::GetTypeName()
1987 return GetClangType().GetConstTypeName();
1991 ValueObject::GetDisplayTypeName()
1993 return GetTypeName();
1997 ValueObject::GetQualifiedTypeName()
1999 return GetClangType().GetConstQualifiedTypeName();
2004 ValueObject::GetObjectRuntimeLanguage ()
2006 return GetClangType().GetMinimumLanguage ();
2010 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
2012 m_synthetic_children[key] = valobj;
2016 ValueObject::GetSyntheticChild (const ConstString &key) const
2018 ValueObjectSP synthetic_child_sp;
2019 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
2020 if (pos != m_synthetic_children.end())
2021 synthetic_child_sp = pos->second->GetSP();
2022 return synthetic_child_sp;
2026 ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
2028 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
2032 ValueObject::IsPointerType ()
2034 return GetClangType().IsPointerType();
2038 ValueObject::IsArrayType ()
2040 return GetClangType().IsArrayType (NULL, NULL, NULL);
2044 ValueObject::IsScalarType ()
2046 return GetClangType().IsScalarType ();
2050 ValueObject::IsIntegerType (bool &is_signed)
2052 return GetClangType().IsIntegerType (is_signed);
2056 ValueObject::IsPointerOrReferenceType ()
2058 return GetClangType().IsPointerOrReferenceType ();
2062 ValueObject::IsPossibleDynamicType ()
2064 ExecutionContext exe_ctx (GetExecutionContextRef());
2065 Process *process = exe_ctx.GetProcessPtr();
2067 return process->IsPossibleDynamicValue(*this);
2069 return GetClangType().IsPossibleDynamicType (NULL, true, true);
2073 ValueObject::IsRuntimeSupportValue ()
2075 Process *process(GetProcessSP().get());
2078 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2080 runtime = process->GetObjCLanguageRuntime();
2082 return runtime->IsRuntimeSupportValue(*this);
2088 ValueObject::IsObjCNil ()
2090 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
2091 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
2094 bool canReadValue = true;
2095 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
2096 return canReadValue && isZero;
2099 // This allows you to create an array member using and index
2100 // that doesn't not fall in the normal bounds of the array.
2101 // Many times structure can be defined as:
2102 // struct Collection
2104 // uint32_t item_count;
2105 // Item item_array[0];
2107 // The size of the "item_array" is 1, but many times in practice
2108 // there are more items in "item_array".
2111 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
2113 ValueObjectSP synthetic_child_sp;
2114 if (IsPointerType () || IsArrayType())
2117 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
2118 ConstString index_const_str(index_str);
2119 // Check if we have already created a synthetic array member in this
2120 // valid object. If we have we will re-use it.
2121 synthetic_child_sp = GetSyntheticChild (index_const_str);
2122 if (!synthetic_child_sp)
2124 ValueObject *synthetic_child;
2125 // We haven't made a synthetic array member for INDEX yet, so
2126 // lets make one and cache it for any future reference.
2127 synthetic_child = CreateChildAtIndex(0, true, index);
2129 // Cache the value if we got one back...
2130 if (synthetic_child)
2132 AddSyntheticChild(index_const_str, synthetic_child);
2133 synthetic_child_sp = synthetic_child->GetSP();
2134 synthetic_child_sp->SetName(ConstString(index_str));
2135 synthetic_child_sp->m_is_array_item_for_pointer = true;
2139 return synthetic_child_sp;
2143 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2145 ValueObjectSP synthetic_child_sp;
2146 if (IsScalarType ())
2149 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2150 ConstString index_const_str(index_str);
2151 // Check if we have already created a synthetic array member in this
2152 // valid object. If we have we will re-use it.
2153 synthetic_child_sp = GetSyntheticChild (index_const_str);
2154 if (!synthetic_child_sp)
2156 // We haven't made a synthetic array member for INDEX yet, so
2157 // lets make one and cache it for any future reference.
2158 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2167 eAddressTypeInvalid);
2169 // Cache the value if we got one back...
2170 if (synthetic_child)
2172 AddSyntheticChild(index_const_str, synthetic_child);
2173 synthetic_child_sp = synthetic_child->GetSP();
2174 synthetic_child_sp->SetName(ConstString(index_str));
2175 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2179 return synthetic_child_sp;
2183 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2186 ValueObjectSP synthetic_child_sp;
2189 snprintf(name_str, sizeof(name_str), "@%i", offset);
2190 ConstString name_const_str(name_str);
2192 // Check if we have already created a synthetic array member in this
2193 // valid object. If we have we will re-use it.
2194 synthetic_child_sp = GetSyntheticChild (name_const_str);
2196 if (synthetic_child_sp.get())
2197 return synthetic_child_sp;
2200 return ValueObjectSP();
2202 ExecutionContext exe_ctx (GetExecutionContextRef());
2204 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2207 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
2213 eAddressTypeInvalid);
2214 if (synthetic_child)
2216 AddSyntheticChild(name_const_str, synthetic_child);
2217 synthetic_child_sp = synthetic_child->GetSP();
2218 synthetic_child_sp->SetName(name_const_str);
2219 synthetic_child_sp->m_is_child_at_offset = true;
2221 return synthetic_child_sp;
2225 ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
2227 ValueObjectSP synthetic_child_sp;
2230 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2231 ConstString name_const_str(name_str);
2233 // Check if we have already created a synthetic array member in this
2234 // valid object. If we have we will re-use it.
2235 synthetic_child_sp = GetSyntheticChild (name_const_str);
2237 if (synthetic_child_sp.get())
2238 return synthetic_child_sp;
2241 return ValueObjectSP();
2243 const bool is_base_class = true;
2245 ExecutionContext exe_ctx (GetExecutionContextRef());
2247 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2250 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
2256 eAddressTypeInvalid);
2257 if (synthetic_child)
2259 AddSyntheticChild(name_const_str, synthetic_child);
2260 synthetic_child_sp = synthetic_child->GetSP();
2261 synthetic_child_sp->SetName(name_const_str);
2263 return synthetic_child_sp;
2267 // your expression path needs to have a leading . or ->
2268 // (unless it somehow "looks like" an array, in which case it has
2269 // a leading [ symbol). while the [ is meaningful and should be shown
2270 // to the user, . and -> are just parser design, but by no means
2271 // added information for the user.. strip them off
2273 SkipLeadingExpressionPathSeparators(const char* expression)
2275 if (!expression || !expression[0])
2277 if (expression[0] == '.')
2278 return expression+1;
2279 if (expression[0] == '-' && expression[1] == '>')
2280 return expression+2;
2285 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2287 ValueObjectSP synthetic_child_sp;
2288 ConstString name_const_string(expression);
2289 // Check if we have already created a synthetic array member in this
2290 // valid object. If we have we will re-use it.
2291 synthetic_child_sp = GetSyntheticChild (name_const_string);
2292 if (!synthetic_child_sp)
2294 // We haven't made a synthetic array member for expression yet, so
2295 // lets make one and cache it for any future reference.
2296 synthetic_child_sp = GetValueForExpressionPath(expression,
2298 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
2300 // Cache the value if we got one back...
2301 if (synthetic_child_sp.get())
2303 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
2304 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2305 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
2308 return synthetic_child_sp;
2312 ValueObject::CalculateSyntheticValue (bool use_synthetic)
2314 if (use_synthetic == false)
2317 TargetSP target_sp(GetTargetSP());
2318 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
2320 m_synthetic_value = NULL;
2324 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2326 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
2329 if (m_synthetic_children_sp.get() == NULL)
2332 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2335 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
2339 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
2341 if (use_dynamic == eNoDynamicValues)
2344 if (!m_dynamic_value && !IsDynamic())
2346 ExecutionContext exe_ctx (GetExecutionContextRef());
2347 Process *process = exe_ctx.GetProcessPtr();
2348 if (process && process->IsPossibleDynamicValue(*this))
2350 ClearDynamicTypeInformation ();
2351 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2357 ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
2359 if (use_dynamic == eNoDynamicValues)
2360 return ValueObjectSP();
2362 if (!IsDynamic() && m_dynamic_value == NULL)
2364 CalculateDynamicValue(use_dynamic);
2366 if (m_dynamic_value)
2367 return m_dynamic_value->GetSP();
2369 return ValueObjectSP();
2373 ValueObject::GetStaticValue()
2379 ValueObject::GetNonSyntheticValue ()
2385 ValueObject::GetSyntheticValue (bool use_synthetic)
2387 if (use_synthetic == false)
2388 return ValueObjectSP();
2390 CalculateSyntheticValue(use_synthetic);
2392 if (m_synthetic_value)
2393 return m_synthetic_value->GetSP();
2395 return ValueObjectSP();
2399 ValueObject::HasSyntheticValue()
2401 UpdateFormatsIfNeeded();
2403 if (m_synthetic_children_sp.get() == NULL)
2406 CalculateSyntheticValue(true);
2408 if (m_synthetic_value)
2415 ValueObject::GetBaseClassPath (Stream &s)
2419 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
2420 ClangASTType clang_type = GetClangType();
2421 std::string cxx_class_name;
2422 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
2423 if (this_had_base_class)
2425 if (parent_had_base_class)
2427 s.PutCString(cxx_class_name.c_str());
2429 return parent_had_base_class || this_had_base_class;
2436 ValueObject::GetNonBaseClassParent()
2440 if (GetParent()->IsBaseClass())
2441 return GetParent()->GetNonBaseClassParent();
2450 ValueObject::IsBaseClass (uint32_t& depth)
2459 GetParent()->IsBaseClass(depth);
2463 // TODO: a base of no parent? weird..
2469 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
2471 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2472 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2473 // something that can hopefully be used in expression
2474 if (m_is_synthetic_children_generated)
2476 UpdateValueIfNeeded();
2478 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2480 if (IsPointerOrReferenceType())
2482 s.Printf("((%s)0x%" PRIx64 ")",
2483 GetTypeName().AsCString("void"),
2484 GetValueAsUnsigned(0));
2489 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2490 if (load_addr != LLDB_INVALID_ADDRESS)
2492 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2493 GetTypeName().AsCString("void"),
2500 if (CanProvideValue())
2502 s.Printf("((%s)%s)",
2503 GetTypeName().AsCString("void"),
2504 GetValueAsCString());
2511 const bool is_deref_of_parent = IsDereferenceOfParent ();
2513 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2515 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2516 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2517 // the eHonorPointers mode is meant to produce strings in this latter format
2521 ValueObject* parent = GetParent();
2524 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
2526 // if we are a deref_of_parent just because we are synthetic array
2527 // members made up to allow ptr[%d] syntax to work in variable
2528 // printing, then add our name ([%d]) to the expression path
2529 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
2530 s.PutCString(m_name.AsCString());
2534 if (!is_deref_of_parent)
2536 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2537 if (non_base_class_parent)
2539 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2540 if (non_base_class_parent_clang_type)
2542 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
2548 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2550 if (non_base_class_parent_type_info & eTypeIsPointer)
2554 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2555 !(non_base_class_parent_type_info & eTypeIsArray))
2563 const char *name = GetName().GetCString();
2566 if (qualify_cxx_base_classes)
2568 if (GetBaseClassPath (s))
2576 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2583 ValueObject::GetValueForExpressionPath(const char* expression,
2584 const char** first_unparsed,
2585 ExpressionPathScanEndReason* reason_to_stop,
2586 ExpressionPathEndResultType* final_value_type,
2587 const GetValueForExpressionPathOptions& options,
2588 ExpressionPathAftermath* final_task_on_target)
2591 const char* dummy_first_unparsed;
2592 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2593 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2594 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2596 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2597 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2598 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2599 final_value_type ? final_value_type : &dummy_final_value_type,
2601 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2603 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2606 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
2608 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
2611 ValueObjectSP final_value = ret_val->Dereference(error);
2612 if (error.Fail() || !final_value.get())
2615 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2616 if (final_value_type)
2617 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2618 return ValueObjectSP();
2622 if (final_task_on_target)
2623 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2627 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2630 ValueObjectSP final_value = ret_val->AddressOf(error);
2631 if (error.Fail() || !final_value.get())
2634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2635 if (final_value_type)
2636 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2637 return ValueObjectSP();
2641 if (final_task_on_target)
2642 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2647 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2651 ValueObject::GetValuesForExpressionPath(const char* expression,
2652 ValueObjectListSP& list,
2653 const char** first_unparsed,
2654 ExpressionPathScanEndReason* reason_to_stop,
2655 ExpressionPathEndResultType* final_value_type,
2656 const GetValueForExpressionPathOptions& options,
2657 ExpressionPathAftermath* final_task_on_target)
2659 const char* dummy_first_unparsed;
2660 ExpressionPathScanEndReason dummy_reason_to_stop;
2661 ExpressionPathEndResultType dummy_final_value_type;
2662 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2664 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2665 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2666 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2667 final_value_type ? final_value_type : &dummy_final_value_type,
2669 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2671 if (!ret_val.get()) // if there are errors, I add nothing to the list
2674 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
2676 // I need not expand a range, just post-process the final value and return
2677 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2679 list->Append(ret_val);
2682 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
2684 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
2687 ValueObjectSP final_value = ret_val->Dereference(error);
2688 if (error.Fail() || !final_value.get())
2691 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2692 if (final_value_type)
2693 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2698 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2699 list->Append(final_value);
2703 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2706 ValueObjectSP final_value = ret_val->AddressOf(error);
2707 if (error.Fail() || !final_value.get())
2710 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2711 if (final_value_type)
2712 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2717 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2718 list->Append(final_value);
2726 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2727 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2730 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2731 final_value_type ? final_value_type : &dummy_final_value_type,
2733 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2735 // in any non-covered case, just do the obviously right thing
2736 list->Append(ret_val);
2741 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2742 const char** first_unparsed,
2743 ExpressionPathScanEndReason* reason_to_stop,
2744 ExpressionPathEndResultType* final_result,
2745 const GetValueForExpressionPathOptions& options,
2746 ExpressionPathAftermath* what_next)
2748 ValueObjectSP root = GetSP();
2751 return ValueObjectSP();
2753 *first_unparsed = expression_cstr;
2758 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2760 ClangASTType root_clang_type = root->GetClangType();
2761 ClangASTType pointee_clang_type;
2762 Flags pointee_clang_type_info;
2764 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
2765 if (pointee_clang_type)
2766 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
2768 if (!expression_cstr || *expression_cstr == '\0')
2770 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2774 switch (*expression_cstr)
2778 if (options.m_check_dot_vs_arrow_syntax &&
2779 root_clang_type_info.Test(eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
2781 *first_unparsed = expression_cstr;
2782 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2783 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2784 return ValueObjectSP();
2786 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2787 root_clang_type_info.Test(eTypeIsPointer) &&
2788 options.m_no_fragile_ivar)
2790 *first_unparsed = expression_cstr;
2791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2793 return ValueObjectSP();
2795 if (expression_cstr[1] != '>')
2797 *first_unparsed = expression_cstr;
2798 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2799 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2800 return ValueObjectSP();
2802 expression_cstr++; // skip the -
2804 case '.': // or fallthrough from ->
2806 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
2807 root_clang_type_info.Test(eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
2809 *first_unparsed = expression_cstr;
2810 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2811 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2812 return ValueObjectSP();
2814 expression_cstr++; // skip .
2815 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2816 ConstString child_name;
2817 if (!next_separator) // if no other separator just expand this last layer
2819 child_name.SetCString (expression_cstr);
2820 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2822 if (child_valobj_sp.get()) // we know we are done, so just return
2824 *first_unparsed = "";
2825 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2826 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2827 return child_valobj_sp;
2831 switch (options.m_synthetic_children_traversal)
2833 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2835 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2836 if (root->IsSynthetic())
2838 child_valobj_sp = root->GetNonSyntheticValue();
2839 if (child_valobj_sp.get())
2840 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2843 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2844 if (!root->IsSynthetic())
2846 child_valobj_sp = root->GetSyntheticValue();
2847 if (child_valobj_sp.get())
2848 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2851 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2852 if (root->IsSynthetic())
2854 child_valobj_sp = root->GetNonSyntheticValue();
2855 if (child_valobj_sp.get())
2856 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2860 child_valobj_sp = root->GetSyntheticValue();
2861 if (child_valobj_sp.get())
2862 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2868 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2869 // so we hit the "else" branch, and return an error
2870 if(child_valobj_sp.get()) // if it worked, just return
2872 *first_unparsed = "";
2873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2874 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2875 return child_valobj_sp;
2879 *first_unparsed = expression_cstr;
2880 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2881 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2882 return ValueObjectSP();
2885 else // other layers do expand
2887 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2888 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2889 if (child_valobj_sp.get()) // store the new root and move on
2891 root = child_valobj_sp;
2892 *first_unparsed = next_separator;
2893 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2898 switch (options.m_synthetic_children_traversal)
2900 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2902 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2903 if (root->IsSynthetic())
2905 child_valobj_sp = root->GetNonSyntheticValue();
2906 if (child_valobj_sp.get())
2907 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2910 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2911 if (!root->IsSynthetic())
2913 child_valobj_sp = root->GetSyntheticValue();
2914 if (child_valobj_sp.get())
2915 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2918 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2919 if (root->IsSynthetic())
2921 child_valobj_sp = root->GetNonSyntheticValue();
2922 if (child_valobj_sp.get())
2923 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2927 child_valobj_sp = root->GetSyntheticValue();
2928 if (child_valobj_sp.get())
2929 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2935 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2936 // so we hit the "else" branch, and return an error
2937 if(child_valobj_sp.get()) // if it worked, move on
2939 root = child_valobj_sp;
2940 *first_unparsed = next_separator;
2941 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2946 *first_unparsed = expression_cstr;
2947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2949 return ValueObjectSP();
2956 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer) && !root_clang_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
2958 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
2960 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
2962 *first_unparsed = expression_cstr;
2963 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2964 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2965 return ValueObjectSP();
2968 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2970 *first_unparsed = expression_cstr;
2971 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2972 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2973 return ValueObjectSP();
2976 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2978 if (!root_clang_type_info.Test(eTypeIsArray))
2980 *first_unparsed = expression_cstr;
2981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2983 return ValueObjectSP();
2985 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2987 *first_unparsed = expression_cstr+2;
2988 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2989 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2993 const char *separator_position = ::strchr(expression_cstr+1,'-');
2994 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2995 if (!close_bracket_position) // if there is no ], this is a syntax error
2997 *first_unparsed = expression_cstr;
2998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3000 return ValueObjectSP();
3002 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3005 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3006 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3008 *first_unparsed = expression_cstr;
3009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3010 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3011 return ValueObjectSP();
3013 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3015 if (root_clang_type_info.Test(eTypeIsArray))
3017 *first_unparsed = expression_cstr+2;
3018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
3024 *first_unparsed = expression_cstr;
3025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3027 return ValueObjectSP();
3030 // from here on we do have a valid index
3031 if (root_clang_type_info.Test(eTypeIsArray))
3033 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3034 if (!child_valobj_sp)
3035 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
3036 if (!child_valobj_sp)
3037 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3038 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
3039 if (child_valobj_sp)
3041 root = child_valobj_sp;
3042 *first_unparsed = end+1; // skip ]
3043 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3048 *first_unparsed = expression_cstr;
3049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3051 return ValueObjectSP();
3054 else if (root_clang_type_info.Test(eTypeIsPointer))
3056 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
3057 pointee_clang_type_info.Test(eTypeIsScalar))
3060 root = root->Dereference(error);
3061 if (error.Fail() || !root.get())
3063 *first_unparsed = expression_cstr;
3064 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3065 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3066 return ValueObjectSP();
3070 *what_next = eExpressionPathAftermathNothing;
3076 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
3077 && pointee_clang_type_info.AllClear(eTypeIsPointer)
3078 && root->HasSyntheticValue()
3079 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3080 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
3082 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
3085 root = root->GetSyntheticArrayMember(index, true);
3088 *first_unparsed = expression_cstr;
3089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3091 return ValueObjectSP();
3095 *first_unparsed = end+1; // skip ]
3096 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3101 else if (root_clang_type_info.Test(eTypeIsScalar))
3103 root = root->GetSyntheticBitFieldChild(index, index, true);
3106 *first_unparsed = expression_cstr;
3107 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3108 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3109 return ValueObjectSP();
3111 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3113 *first_unparsed = end+1; // skip ]
3114 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3115 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3119 else if (root_clang_type_info.Test(eTypeIsVector))
3121 root = root->GetChildAtIndex(index, true);
3124 *first_unparsed = expression_cstr;
3125 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3126 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3127 return ValueObjectSP();
3131 *first_unparsed = end+1; // skip ]
3132 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3136 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3137 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
3139 if (root->HasSyntheticValue())
3140 root = root->GetSyntheticValue();
3141 else if (!root->IsSynthetic())
3143 *first_unparsed = expression_cstr;
3144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3146 return ValueObjectSP();
3148 // if we are here, then root itself is a synthetic VO.. should be good to go
3152 *first_unparsed = expression_cstr;
3153 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3154 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3155 return ValueObjectSP();
3157 root = root->GetChildAtIndex(index, true);
3160 *first_unparsed = expression_cstr;
3161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3163 return ValueObjectSP();
3167 *first_unparsed = end+1; // skip ]
3168 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3174 *first_unparsed = expression_cstr;
3175 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3176 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3177 return ValueObjectSP();
3180 else // we have a low and a high index
3183 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3184 if (!end || end != separator_position) // if something weird is in our way return an error
3186 *first_unparsed = expression_cstr;
3187 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3188 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3189 return ValueObjectSP();
3191 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3192 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3194 *first_unparsed = expression_cstr;
3195 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3196 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3197 return ValueObjectSP();
3199 if (index_lower > index_higher) // swap indices if required
3201 unsigned long temp = index_lower;
3202 index_lower = index_higher;
3203 index_higher = temp;
3205 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
3207 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3210 *first_unparsed = expression_cstr;
3211 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3212 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3213 return ValueObjectSP();
3217 *first_unparsed = end+1; // skip ]
3218 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3219 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3223 else if (root_clang_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3224 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3225 pointee_clang_type_info.Test(eTypeIsScalar))
3228 root = root->Dereference(error);
3229 if (error.Fail() || !root.get())
3231 *first_unparsed = expression_cstr;
3232 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3233 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3234 return ValueObjectSP();
3238 *what_next = ValueObject::eExpressionPathAftermathNothing;
3244 *first_unparsed = expression_cstr;
3245 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3246 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
3252 default: // some non-separator is in the way
3254 *first_unparsed = expression_cstr;
3255 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3256 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3257 return ValueObjectSP();
3265 ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3266 const char** first_unparsed,
3268 ValueObjectListSP& list,
3269 ExpressionPathScanEndReason* reason_to_stop,
3270 ExpressionPathEndResultType* final_result,
3271 const GetValueForExpressionPathOptions& options,
3272 ExpressionPathAftermath* what_next)
3277 *first_unparsed = expression_cstr;
3282 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3284 ClangASTType root_clang_type = root->GetClangType();
3285 ClangASTType pointee_clang_type;
3286 Flags pointee_clang_type_info;
3287 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
3288 if (pointee_clang_type)
3289 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
3291 if (!expression_cstr || *expression_cstr == '\0')
3293 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
3298 switch (*expression_cstr)
3302 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
3304 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3306 *first_unparsed = expression_cstr;
3307 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3308 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3311 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3313 *first_unparsed = expression_cstr;
3314 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3315 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3319 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3321 if (!root_clang_type_info.Test(eTypeIsArray))
3323 *first_unparsed = expression_cstr;
3324 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3325 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3328 else // expand this into list
3330 const size_t max_index = root->GetNumChildren() - 1;
3331 for (size_t index = 0; index < max_index; index++)
3333 ValueObjectSP child =
3334 root->GetChildAtIndex(index, true);
3335 list->Append(child);
3337 *first_unparsed = expression_cstr+2;
3338 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3339 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3340 return max_index; // tell me number of items I added to the VOList
3343 const char *separator_position = ::strchr(expression_cstr+1,'-');
3344 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3345 if (!close_bracket_position) // if there is no ], this is a syntax error
3347 *first_unparsed = expression_cstr;
3348 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3349 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3352 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3355 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3356 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3358 *first_unparsed = expression_cstr;
3359 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3360 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3363 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3365 if (root_clang_type_info.Test(eTypeIsArray))
3367 const size_t max_index = root->GetNumChildren() - 1;
3368 for (size_t index = 0; index < max_index; index++)
3370 ValueObjectSP child =
3371 root->GetChildAtIndex(index, true);
3372 list->Append(child);
3374 *first_unparsed = expression_cstr+2;
3375 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3376 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3377 return max_index; // tell me number of items I added to the VOList
3381 *first_unparsed = expression_cstr;
3382 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3383 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3387 // from here on we do have a valid index
3388 if (root_clang_type_info.Test(eTypeIsArray))
3390 root = root->GetChildAtIndex(index, true);
3393 *first_unparsed = expression_cstr;
3394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3395 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3401 *first_unparsed = end+1; // skip ]
3402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3403 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3407 else if (root_clang_type_info.Test(eTypeIsPointer))
3409 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
3410 pointee_clang_type_info.Test(eTypeIsScalar))
3413 root = root->Dereference(error);
3414 if (error.Fail() || !root.get())
3416 *first_unparsed = expression_cstr;
3417 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3418 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3423 *what_next = eExpressionPathAftermathNothing;
3429 root = root->GetSyntheticArrayMember(index, true);
3432 *first_unparsed = expression_cstr;
3433 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3434 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3440 *first_unparsed = end+1; // skip ]
3441 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3442 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3447 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3449 root = root->GetSyntheticBitFieldChild(index, index, true);
3452 *first_unparsed = expression_cstr;
3453 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3454 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3457 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3460 *first_unparsed = end+1; // skip ]
3461 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3462 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3467 else // we have a low and a high index
3470 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3471 if (!end || end != separator_position) // if something weird is in our way return an error
3473 *first_unparsed = expression_cstr;
3474 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3475 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3478 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3479 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3481 *first_unparsed = expression_cstr;
3482 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3483 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3486 if (index_lower > index_higher) // swap indices if required
3488 unsigned long temp = index_lower;
3489 index_lower = index_higher;
3490 index_higher = temp;
3492 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
3494 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3497 *first_unparsed = expression_cstr;
3498 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3499 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3505 *first_unparsed = end+1; // skip ]
3506 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3507 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3511 else if (root_clang_type_info.Test(eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3512 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3513 pointee_clang_type_info.Test(eTypeIsScalar))
3516 root = root->Dereference(error);
3517 if (error.Fail() || !root.get())
3519 *first_unparsed = expression_cstr;
3520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3521 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3526 *what_next = ValueObject::eExpressionPathAftermathNothing;
3532 for (unsigned long index = index_lower;
3533 index <= index_higher; index++)
3535 ValueObjectSP child =
3536 root->GetChildAtIndex(index, true);
3537 list->Append(child);
3539 *first_unparsed = end+1;
3540 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3541 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3542 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3547 default: // some non-[ separator, or something entirely wrong, is in the way
3549 *first_unparsed = expression_cstr;
3550 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3551 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3560 ValueObject::LogValueObject (Log *log)
3563 return LogValueObject (log, DumpValueObjectOptions(*this));
3567 ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
3574 log->PutCString(s.GetData());
3579 ValueObject::Dump (Stream &s)
3581 Dump (s, DumpValueObjectOptions(*this));
3585 ValueObject::Dump (Stream &s,
3586 const DumpValueObjectOptions& options)
3588 ValueObjectPrinter printer(this,&s,options);
3589 printer.PrintValueObject();
3593 ValueObject::CreateConstantValue (const ConstString &name)
3595 ValueObjectSP valobj_sp;
3597 if (UpdateValueIfNeeded(false) && m_error.Success())
3599 ExecutionContext exe_ctx (GetExecutionContextRef());
3602 data.SetByteOrder (m_data.GetByteOrder());
3603 data.SetAddressByteSize(m_data.GetAddressByteSize());
3607 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3608 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3611 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3613 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3622 ExecutionContext exe_ctx (GetExecutionContextRef());
3623 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
3629 ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3632 ValueObjectSP result_sp(GetSP());
3636 case lldb::eDynamicCanRunTarget:
3637 case lldb::eDynamicDontRunTarget:
3639 if (!result_sp->IsDynamic())
3641 if (result_sp->GetDynamicValue(dynValue))
3642 result_sp = result_sp->GetDynamicValue(dynValue);
3646 case lldb::eNoDynamicValues:
3648 if (result_sp->IsDynamic())
3650 if (result_sp->GetStaticValue())
3651 result_sp = result_sp->GetStaticValue();
3659 if (!result_sp->IsSynthetic())
3661 if (result_sp->GetSyntheticValue())
3662 result_sp = result_sp->GetSyntheticValue();
3667 if (result_sp->IsSynthetic())
3669 if (result_sp->GetNonSyntheticValue())
3670 result_sp = result_sp->GetNonSyntheticValue();
3678 ValueObject::GetCPPVTableAddress (AddressType &address_type)
3680 ClangASTType pointee_type;
3681 ClangASTType this_type(GetClangType());
3682 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3685 bool ptr_or_ref = false;
3686 if (type_info & (eTypeIsPointer | eTypeIsReference))
3689 type_info = pointee_type.GetTypeInfo();
3692 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
3693 if ((type_info & cpp_class) == cpp_class)
3697 address_type = GetAddressTypeOfChildren();
3698 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3701 return GetAddressOf (false, &address_type);
3705 address_type = eAddressTypeInvalid;
3706 return LLDB_INVALID_ADDRESS;
3710 ValueObject::Dereference (Error &error)
3713 return m_deref_valobj->GetSP();
3715 const bool is_pointer_type = IsPointerType();
3716 if (is_pointer_type)
3718 bool omit_empty_base_classes = true;
3719 bool ignore_array_bounds = false;
3721 std::string child_name_str;
3722 uint32_t child_byte_size = 0;
3723 int32_t child_byte_offset = 0;
3724 uint32_t child_bitfield_bit_size = 0;
3725 uint32_t child_bitfield_bit_offset = 0;
3726 bool child_is_base_class = false;
3727 bool child_is_deref_of_parent = false;
3728 const bool transparent_pointers = false;
3729 ClangASTType clang_type = GetClangType();
3730 ClangASTType child_clang_type;
3732 ExecutionContext exe_ctx (GetExecutionContextRef());
3734 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3736 transparent_pointers,
3737 omit_empty_base_classes,
3738 ignore_array_bounds,
3742 child_bitfield_bit_size,
3743 child_bitfield_bit_offset,
3744 child_is_base_class,
3745 child_is_deref_of_parent,
3747 if (child_clang_type && child_byte_size)
3749 ConstString child_name;
3750 if (!child_name_str.empty())
3751 child_name.SetCString (child_name_str.c_str());
3753 m_deref_valobj = new ValueObjectChild (*this,
3758 child_bitfield_bit_size,
3759 child_bitfield_bit_offset,
3760 child_is_base_class,
3761 child_is_deref_of_parent,
3762 eAddressTypeInvalid);
3769 return m_deref_valobj->GetSP();
3774 GetExpressionPath(strm, true);
3776 if (is_pointer_type)
3777 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3779 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3780 return ValueObjectSP();
3785 ValueObject::AddressOf (Error &error)
3787 if (m_addr_of_valobj_sp)
3788 return m_addr_of_valobj_sp;
3790 AddressType address_type = eAddressTypeInvalid;
3791 const bool scalar_is_load_address = false;
3792 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
3794 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
3796 switch (address_type)
3798 case eAddressTypeInvalid:
3800 StreamString expr_path_strm;
3801 GetExpressionPath(expr_path_strm, true);
3802 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3806 case eAddressTypeFile:
3807 case eAddressTypeLoad:
3809 ClangASTType clang_type = GetClangType();
3812 std::string name (1, '&');
3813 name.append (m_name.AsCString(""));
3814 ExecutionContext exe_ctx (GetExecutionContextRef());
3815 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3816 clang_type.GetPointerType(),
3817 ConstString (name.c_str()),
3819 eAddressTypeInvalid,
3820 m_data.GetAddressByteSize());
3830 StreamString expr_path_strm;
3831 GetExpressionPath(expr_path_strm, true);
3832 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3835 return m_addr_of_valobj_sp;
3839 ValueObject::Cast (const ClangASTType &clang_ast_type)
3841 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
3845 ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3847 ValueObjectSP valobj_sp;
3848 AddressType address_type;
3849 addr_t ptr_value = GetPointerValue (&address_type);
3851 if (ptr_value != LLDB_INVALID_ADDRESS)
3853 Address ptr_addr (ptr_value);
3854 ExecutionContext exe_ctx (GetExecutionContextRef());
3855 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3864 ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3866 ValueObjectSP valobj_sp;
3867 AddressType address_type;
3868 addr_t ptr_value = GetPointerValue (&address_type);
3870 if (ptr_value != LLDB_INVALID_ADDRESS)
3872 Address ptr_addr (ptr_value);
3873 ExecutionContext exe_ctx (GetExecutionContextRef());
3874 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3882 ValueObject::EvaluationPoint::EvaluationPoint () :
3885 m_needs_update (true)
3889 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
3892 m_needs_update (true)
3894 ExecutionContext exe_ctx(exe_scope);
3895 TargetSP target_sp (exe_ctx.GetTargetSP());
3898 m_exe_ctx_ref.SetTargetSP (target_sp);
3899 ProcessSP process_sp (exe_ctx.GetProcessSP());
3901 process_sp = target_sp->GetProcessSP();
3905 m_mod_id = process_sp->GetModID();
3906 m_exe_ctx_ref.SetProcessSP (process_sp);
3908 ThreadSP thread_sp (exe_ctx.GetThreadSP());
3913 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3918 m_exe_ctx_ref.SetThreadSP(thread_sp);
3920 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3924 frame_sp = thread_sp->GetSelectedFrame();
3927 m_exe_ctx_ref.SetFrameSP(frame_sp);
3933 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3935 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3936 m_needs_update (true)
3940 ValueObject::EvaluationPoint::~EvaluationPoint ()
3944 // This function checks the EvaluationPoint against the current process state. If the current
3945 // state matches the evaluation point, or the evaluation point is already invalid, then we return
3946 // false, meaning "no change". If the current state is different, we update our state, and return
3947 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3948 // future calls to NeedsUpdate will return true.
3949 // exe_scope will be set to the current execution context scope.
3952 ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
3954 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3955 const bool thread_and_frame_only_if_stopped = true;
3956 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3958 if (exe_ctx.GetTargetPtr() == NULL)
3961 // If we don't have a process nothing can change.
3962 Process *process = exe_ctx.GetProcessPtr();
3963 if (process == NULL)
3966 // If our stop id is the current stop ID, nothing has changed:
3967 ProcessModID current_mod_id = process->GetModID();
3969 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3970 // In either case, we aren't going to be able to sync with the process state.
3971 if (current_mod_id.GetStopID() == 0)
3974 bool changed = false;
3975 const bool was_valid = m_mod_id.IsValid();
3978 if (m_mod_id == current_mod_id)
3980 // Everything is already up to date in this object, no need to
3981 // update the execution context scope.
3986 m_mod_id = current_mod_id;
3987 m_needs_update = true;
3992 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3993 // That way we'll be sure to return a valid exe_scope.
3994 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
3996 if (!accept_invalid_exe_ctx)
3998 if (m_exe_ctx_ref.HasThreadRef())
4000 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4003 if (m_exe_ctx_ref.HasFrameRef())
4005 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4008 // We used to have a frame, but now it is gone
4010 changed = was_valid;
4016 // We used to have a thread, but now it is gone
4018 changed = was_valid;
4027 ValueObject::EvaluationPoint::SetUpdated ()
4029 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4031 m_mod_id = process_sp->GetModID();
4032 m_needs_update = false;
4038 ValueObject::ClearUserVisibleData(uint32_t clear_mask)
4040 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4041 m_value_str.clear();
4043 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4044 m_location_str.clear();
4046 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4047 m_summary_str.clear();
4049 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4050 m_object_desc_str.clear();
4052 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4054 if (m_synthetic_value)
4055 m_synthetic_value = NULL;
4058 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4059 m_validation_result.reset();
4062 SymbolContextScope *
4063 ValueObject::GetSymbolContextScope()
4067 if (!m_parent->IsPointerOrReferenceType())
4068 return m_parent->GetSymbolContextScope();
4074 ValueObject::CreateValueObjectFromExpression (const char* name,
4075 const char* expression,
4076 const ExecutionContext& exe_ctx)
4078 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4083 ValueObject::CreateValueObjectFromExpression (const char* name,
4084 const char* expression,
4085 const ExecutionContext& exe_ctx,
4086 const EvaluateExpressionOptions& options)
4088 lldb::ValueObjectSP retval_sp;
4089 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4092 if (!expression || !*expression)
4094 target_sp->EvaluateExpression (expression,
4095 exe_ctx.GetFrameSP().get(),
4098 if (retval_sp && name && *name)
4099 retval_sp->SetName(ConstString(name));
4104 ValueObject::CreateValueObjectFromAddress (const char* name,
4106 const ExecutionContext& exe_ctx,
4111 ClangASTType pointer_type(type.GetPointerType());
4114 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4115 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4119 exe_ctx.GetByteOrder(),
4120 exe_ctx.GetAddressByteSize()));
4121 if (ptr_result_valobj_sp)
4123 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4125 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4126 if (ptr_result_valobj_sp && name && *name)
4127 ptr_result_valobj_sp->SetName(ConstString(name));
4129 return ptr_result_valobj_sp;
4132 return lldb::ValueObjectSP();
4136 ValueObject::CreateValueObjectFromData (const char* name,
4137 const DataExtractor& data,
4138 const ExecutionContext& exe_ctx,
4141 lldb::ValueObjectSP new_value_sp;
4142 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4146 LLDB_INVALID_ADDRESS);
4147 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4148 if (new_value_sp && name && *name)
4149 new_value_sp->SetName(ConstString(name));
4150 return new_value_sp;
4154 ValueObject::GetModule ()
4156 ValueObject* root(GetRoot());
4158 return root->GetModule();
4159 return lldb::ModuleSP();
4163 ValueObject::GetRoot ()
4167 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4168 return (vo->m_parent != nullptr);
4173 ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4175 ValueObject* vo = this;
4186 ValueObject::GetAddressTypeOfChildren()
4188 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4190 ValueObject* root(GetRoot());
4192 return root->GetAddressTypeOfChildren();
4194 return m_address_type_of_ptr_or_ref_children;
4197 lldb::DynamicValueType
4198 ValueObject::GetDynamicValueType ()
4200 ValueObject* with_dv_info = this;
4201 while (with_dv_info)
4203 if (with_dv_info->HasDynamicValueTypeInfo())
4204 return with_dv_info->GetDynamicValueTypeImpl();
4205 with_dv_info = with_dv_info->m_parent;
4207 return lldb::eNoDynamicValues;
4211 ValueObject::GetFormat () const
4213 const ValueObject* with_fmt_info = this;
4214 while (with_fmt_info)
4216 if (with_fmt_info->m_format != lldb::eFormatDefault)
4217 return with_fmt_info->m_format;
4218 with_fmt_info = with_fmt_info->m_parent;
4224 ValueObject::GetPreferredDisplayLanguage ()
4226 lldb::LanguageType type = m_preferred_display_language;
4227 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4231 if (GetRoot() == this)
4233 if (StackFrameSP frame_sp = GetFrameSP())
4235 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4236 if (CompileUnit* cu = sc.comp_unit)
4237 type = cu->GetLanguage();
4242 type = GetRoot()->GetPreferredDisplayLanguage();
4246 return (m_preferred_display_language = type); // only compute it once
4250 ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4252 m_preferred_display_language = lt;
4256 ValueObject::CanProvideValue ()
4258 // we need to support invalid types as providers of values because some bare-board
4259 // debugging scenarios have no notion of types, but still manage to have raw numeric
4260 // values for things like registers. sigh.
4261 const ClangASTType &type(GetClangType());
4262 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4266 ValueObject::IsChecksumEmpty ()
4268 return m_value_checksum.empty();
4272 ValueObject::Persist ()
4274 if (!UpdateValueIfNeeded())
4277 TargetSP target_sp(GetTargetSP());
4281 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4283 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4286 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4287 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4288 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4291 return clang_var_sp->GetValueObject();
4295 ValueObject::IsSyntheticChildrenGenerated ()
4297 return m_is_synthetic_children_generated;
4301 ValueObject::SetSyntheticChildrenGenerated (bool b)
4303 m_is_synthetic_children_generated = b;