1 //===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/Core/ValueObject.h"
18 // Other libraries and framework includes
19 #include "llvm/Support/raw_ostream.h"
20 #include "clang/AST/Type.h"
23 #include "lldb/Core/DataBufferHeap.h"
24 #include "lldb/Core/Debugger.h"
25 #include "lldb/Core/Log.h"
26 #include "lldb/Core/Module.h"
27 #include "lldb/Core/StreamString.h"
28 #include "lldb/Core/ValueObjectCast.h"
29 #include "lldb/Core/ValueObjectChild.h"
30 #include "lldb/Core/ValueObjectConstResult.h"
31 #include "lldb/Core/ValueObjectDynamicValue.h"
32 #include "lldb/Core/ValueObjectList.h"
33 #include "lldb/Core/ValueObjectMemory.h"
34 #include "lldb/Core/ValueObjectSyntheticFilter.h"
36 #include "lldb/DataFormatters/DataVisualization.h"
37 #include "lldb/DataFormatters/ValueObjectPrinter.h"
39 #include "lldb/Host/Endian.h"
41 #include "lldb/Interpreter/CommandInterpreter.h"
42 #include "lldb/Interpreter/ScriptInterpreterPython.h"
44 #include "lldb/Symbol/ClangASTType.h"
45 #include "lldb/Symbol/ClangASTContext.h"
46 #include "lldb/Symbol/Type.h"
48 #include "lldb/Target/ExecutionContext.h"
49 #include "lldb/Target/LanguageRuntime.h"
50 #include "lldb/Target/ObjCLanguageRuntime.h"
51 #include "lldb/Target/Process.h"
52 #include "lldb/Target/RegisterContext.h"
53 #include "lldb/Target/SectionLoadList.h"
54 #include "lldb/Target/Target.h"
55 #include "lldb/Target/Thread.h"
58 using namespace lldb_private;
59 using namespace lldb_utility;
61 static user_id_t g_value_obj_uid = 0;
63 //----------------------------------------------------------------------
64 // ValueObject constructor
65 //----------------------------------------------------------------------
66 ValueObject::ValueObject (ValueObject &parent) :
67 UserID (++g_value_obj_uid), // Unique identifier for every value object
70 m_update_point (parent.GetUpdatePoint ()),
80 m_manager(parent.GetManager()),
82 m_synthetic_children (),
83 m_dynamic_value (NULL),
84 m_synthetic_value(NULL),
86 m_format (eFormatDefault),
87 m_last_format (eFormatDefault),
88 m_last_format_mgr_revision(0),
91 m_synthetic_children_sp(),
92 m_user_id_of_forced_summary(),
93 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
94 m_value_is_valid (false),
95 m_value_did_change (false),
96 m_children_count_valid (false),
97 m_old_value_valid (false),
98 m_is_deref_of_parent (false),
99 m_is_array_item_for_pointer(false),
100 m_is_bitfield_for_scalar(false),
101 m_is_child_at_offset(false),
102 m_is_getting_summary(false),
103 m_did_calculate_complete_objc_class_type(false)
105 m_manager->ManageObject(this);
108 //----------------------------------------------------------------------
109 // ValueObject constructor
110 //----------------------------------------------------------------------
111 ValueObject::ValueObject (ExecutionContextScope *exe_scope,
112 AddressType child_ptr_or_ref_addr_type) :
113 UserID (++g_value_obj_uid), // Unique identifier for every value object
116 m_update_point (exe_scope),
125 m_object_desc_str (),
128 m_synthetic_children (),
129 m_dynamic_value (NULL),
130 m_synthetic_value(NULL),
131 m_deref_valobj(NULL),
132 m_format (eFormatDefault),
133 m_last_format (eFormatDefault),
134 m_last_format_mgr_revision(0),
137 m_synthetic_children_sp(),
138 m_user_id_of_forced_summary(),
139 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
140 m_value_is_valid (false),
141 m_value_did_change (false),
142 m_children_count_valid (false),
143 m_old_value_valid (false),
144 m_is_deref_of_parent (false),
145 m_is_array_item_for_pointer(false),
146 m_is_bitfield_for_scalar(false),
147 m_is_child_at_offset(false),
148 m_is_getting_summary(false),
149 m_did_calculate_complete_objc_class_type(false)
151 m_manager = new ValueObjectManager();
152 m_manager->ManageObject (this);
155 //----------------------------------------------------------------------
157 //----------------------------------------------------------------------
158 ValueObject::~ValueObject ()
163 ValueObject::UpdateValueIfNeeded (bool update_format)
166 bool did_change_formats = false;
169 did_change_formats = UpdateFormatsIfNeeded();
171 // If this is a constant value, then our success is predicated on whether
172 // we have an error or not
175 // if you are constant, things might still have changed behind your back
176 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
177 // in this case, your value has not changed, but "computed" entries might have, so you might now have
178 // a different summary, or a different object description. clear these so we will recompute them
179 if (update_format && !did_change_formats)
180 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
181 return m_error.Success();
184 bool first_update = m_update_point.IsFirstEvaluation();
186 if (m_update_point.NeedsUpdating())
188 m_update_point.SetUpdated();
190 // Save the old value using swap to avoid a string copy which
191 // also will clear our m_value_str
192 if (m_value_str.empty())
194 m_old_value_valid = false;
198 m_old_value_valid = true;
199 m_old_value_str.swap (m_value_str);
200 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
203 ClearUserVisibleData();
207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
215 SetValueIsValid (success);
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
228 m_error.SetErrorString("out of scope");
231 return m_error.Success();
235 ValueObject::UpdateFormatsIfNeeded()
237 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
239 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
240 GetName().GetCString(), static_cast<void*>(this),
241 m_last_format_mgr_revision,
242 DataVisualization::GetCurrentRevision());
244 bool any_change = false;
246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
248 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
251 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
253 #ifndef LLDB_DISABLE_PYTHON
254 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
262 ValueObject::SetNeedsUpdate ()
264 m_update_point.SetNeedsUpdate();
265 // We have to clear the value string here so ConstResult children will notice if their values are
266 // changed by hand (i.e. with SetValueAsCString).
267 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
271 ValueObject::ClearDynamicTypeInformation ()
273 m_children_count_valid = false;
274 m_did_calculate_complete_objc_class_type = false;
275 m_last_format_mgr_revision = 0;
276 m_override_type = ClangASTType();
277 SetValueFormat(lldb::TypeFormatImplSP());
278 SetSummaryFormat(lldb::TypeSummaryImplSP());
279 SetSyntheticChildren(lldb::SyntheticChildrenSP());
283 ValueObject::MaybeCalculateCompleteType ()
285 ClangASTType clang_type(GetClangTypeImpl());
287 if (m_did_calculate_complete_objc_class_type)
289 if (m_override_type.IsValid())
290 return m_override_type;
295 ClangASTType class_type;
296 bool is_pointer_type = false;
298 if (clang_type.IsObjCObjectPointerType(&class_type))
300 is_pointer_type = true;
302 else if (clang_type.IsObjCObjectOrInterfaceType())
304 class_type = clang_type;
311 m_did_calculate_complete_objc_class_type = true;
315 ConstString class_name (class_type.GetConstTypeName());
319 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
323 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
325 if (objc_language_runtime)
327 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
329 if (complete_objc_class_type_sp)
331 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
333 if (complete_class.GetCompleteType())
337 m_override_type = complete_class.GetPointerType();
341 m_override_type = complete_class;
344 if (m_override_type.IsValid())
345 return m_override_type;
356 ValueObject::GetClangType ()
358 return MaybeCalculateCompleteType();
362 ValueObject::GetTypeImpl ()
364 return TypeImpl(GetClangType());
368 ValueObject::GetDataExtractor ()
370 UpdateValueIfNeeded(false);
375 ValueObject::GetError()
377 UpdateValueIfNeeded(false);
382 ValueObject::GetName() const
388 ValueObject::GetLocationAsCString ()
390 return GetLocationAsCStringImpl(m_value,
395 ValueObject::GetLocationAsCStringImpl (const Value& value,
396 const DataExtractor& data)
398 if (UpdateValueIfNeeded(false))
400 if (m_location_str.empty())
404 Value::ValueType value_type = value.GetValueType();
408 case Value::eValueTypeScalar:
409 case Value::eValueTypeVector:
410 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
412 RegisterInfo *reg_info = value.GetRegisterInfo();
416 m_location_str = reg_info->name;
417 else if (reg_info->alt_name)
418 m_location_str = reg_info->alt_name;
419 if (m_location_str.empty())
420 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
423 if (m_location_str.empty())
424 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
427 case Value::eValueTypeLoadAddress:
428 case Value::eValueTypeFileAddress:
429 case Value::eValueTypeHostAddress:
431 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
432 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
433 m_location_str.swap(sstr.GetString());
439 return m_location_str.c_str();
443 ValueObject::GetValue()
449 ValueObject::GetValue() const
455 ValueObject::ResolveValue (Scalar &scalar)
457 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
459 ExecutionContext exe_ctx (GetExecutionContextRef());
460 Value tmp_value(m_value);
461 scalar = tmp_value.ResolveValue(&exe_ctx);
462 if (scalar.IsValid())
464 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
465 if (bitfield_bit_size)
466 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
474 ValueObject::GetValueIsValid () const
476 return m_value_is_valid;
481 ValueObject::SetValueIsValid (bool b)
483 m_value_is_valid = b;
487 ValueObject::GetValueDidChange ()
489 GetValueAsCString ();
490 return m_value_did_change;
494 ValueObject::SetValueDidChange (bool value_changed)
496 m_value_did_change = value_changed;
500 ValueObject::GetChildAtIndex (size_t idx, bool can_create)
502 ValueObjectSP child_sp;
503 // We may need to update our value if we are dynamic
504 if (IsPossibleDynamicType ())
505 UpdateValueIfNeeded(false);
506 if (idx < GetNumChildren())
508 // Check if we have already made the child value object?
509 if (can_create && !m_children.HasChildAtIndex(idx))
511 // No we haven't created the child at this index, so lets have our
512 // subclass do it and cache the result for quick future access.
513 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
516 ValueObject* child = m_children.GetChildAtIndex(idx);
518 return child->GetSP();
524 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
525 size_t* index_of_error)
527 if (idxs.size() == 0)
529 ValueObjectSP root(GetSP());
530 for (size_t idx : idxs)
532 root = root->GetChildAtIndex(idx, true);
536 *index_of_error = idx;
544 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
545 size_t* index_of_error)
547 if (idxs.size() == 0)
549 ValueObjectSP root(GetSP());
550 for (std::pair<size_t, bool> idx : idxs)
552 root = root->GetChildAtIndex(idx.first, idx.second);
556 *index_of_error = idx.first;
564 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
565 size_t* index_of_error)
567 if (idxs.size() == 0)
569 ValueObjectSP root(GetSP());
570 for (size_t idx : idxs)
572 root = root->GetChildAtIndex(idx, true);
576 *index_of_error = idx;
584 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
585 size_t* index_of_error)
587 if (idxs.size() == 0)
589 ValueObjectSP root(GetSP());
590 for (std::pair<size_t, bool> idx : idxs)
592 root = root->GetChildAtIndex(idx.first, idx.second);
596 *index_of_error = idx.first;
604 ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
605 ConstString* name_of_error)
607 if (names.size() == 0)
609 ValueObjectSP root(GetSP());
610 for (ConstString name : names)
612 root = root->GetChildMemberWithName(name, true);
616 *name_of_error = name;
624 ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
625 ConstString* name_of_error)
627 if (names.size() == 0)
629 ValueObjectSP root(GetSP());
630 for (ConstString name : names)
632 root = root->GetChildMemberWithName(name, true);
636 *name_of_error = name;
644 ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
645 ConstString* name_of_error)
647 if (names.size() == 0)
649 ValueObjectSP root(GetSP());
650 for (std::pair<ConstString, bool> name : names)
652 root = root->GetChildMemberWithName(name.first, name.second);
656 *name_of_error = name.first;
664 ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
665 ConstString* name_of_error)
667 if (names.size() == 0)
669 ValueObjectSP root(GetSP());
670 for (std::pair<ConstString, bool> name : names)
672 root = root->GetChildMemberWithName(name.first, name.second);
676 *name_of_error = name.first;
684 ValueObject::GetIndexOfChildWithName (const ConstString &name)
686 bool omit_empty_base_classes = true;
687 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
691 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
693 // when getting a child by name, it could be buried inside some base
694 // classes (which really aren't part of the expression path), so we
695 // need a vector of indexes that can get us down to the correct child
696 ValueObjectSP child_sp;
698 // We may need to update our value if we are dynamic
699 if (IsPossibleDynamicType ())
700 UpdateValueIfNeeded(false);
702 std::vector<uint32_t> child_indexes;
703 bool omit_empty_base_classes = true;
704 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
705 omit_empty_base_classes,
707 if (num_child_indexes > 0)
709 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
710 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
712 child_sp = GetChildAtIndex(*pos, can_create);
713 for (++pos; pos != end; ++pos)
717 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
718 child_sp = new_child_sp;
732 ValueObject::GetNumChildren ()
734 UpdateValueIfNeeded();
735 if (!m_children_count_valid)
737 SetNumChildren (CalculateNumChildren());
739 return m_children.GetChildrenCount();
743 ValueObject::MightHaveChildren()
745 bool has_children = false;
746 const uint32_t type_info = GetTypeInfo();
749 if (type_info & (ClangASTType::eTypeHasChildren |
750 ClangASTType::eTypeIsPointer |
751 ClangASTType::eTypeIsReference))
756 has_children = GetNumChildren () > 0;
761 // Should only be called by ValueObject::GetNumChildren()
763 ValueObject::SetNumChildren (size_t num_children)
765 m_children_count_valid = true;
766 m_children.SetChildrenCount(num_children);
770 ValueObject::SetName (const ConstString &name)
776 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
778 ValueObject *valobj = NULL;
780 bool omit_empty_base_classes = true;
781 bool ignore_array_bounds = synthetic_array_member;
782 std::string child_name_str;
783 uint32_t child_byte_size = 0;
784 int32_t child_byte_offset = 0;
785 uint32_t child_bitfield_bit_size = 0;
786 uint32_t child_bitfield_bit_offset = 0;
787 bool child_is_base_class = false;
788 bool child_is_deref_of_parent = false;
790 const bool transparent_pointers = synthetic_array_member == false;
791 ClangASTType child_clang_type;
793 ExecutionContext exe_ctx (GetExecutionContextRef());
795 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
797 transparent_pointers,
798 omit_empty_base_classes,
803 child_bitfield_bit_size,
804 child_bitfield_bit_offset,
806 child_is_deref_of_parent,
808 if (child_clang_type)
811 child_byte_offset += child_byte_size * synthetic_index;
813 ConstString child_name;
814 if (!child_name_str.empty())
815 child_name.SetCString (child_name_str.c_str());
817 valobj = new ValueObjectChild (*this,
822 child_bitfield_bit_size,
823 child_bitfield_bit_offset,
825 child_is_deref_of_parent,
826 eAddressTypeInvalid);
828 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
835 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
836 std::string& destination)
840 // ideally we would like to bail out if passing NULL, but if we do so
841 // we end up not providing the summary for function pointers anymore
842 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
845 m_is_getting_summary = true;
847 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
848 // information that we might care to see in a crash log. might be useful in very specific situations though.
849 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
850 GetTypeName().GetCString(),
851 GetName().GetCString(),
852 summary_ptr->GetDescription().c_str());*/
854 if (UpdateValueIfNeeded (false))
858 if (HasSyntheticValue())
859 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
860 summary_ptr->FormatObject(this, destination);
864 ClangASTType clang_type = GetClangType();
866 // Do some default printout for function pointers
869 if (clang_type.IsFunctionPointerType ())
872 AddressType func_ptr_address_type = eAddressTypeInvalid;
873 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
874 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
876 switch (func_ptr_address_type)
878 case eAddressTypeInvalid:
879 case eAddressTypeFile:
882 case eAddressTypeLoad:
884 ExecutionContext exe_ctx (GetExecutionContextRef());
887 Target *target = exe_ctx.GetTargetPtr();
888 if (target && target->GetSectionLoadList().IsEmpty() == false)
890 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
893 exe_ctx.GetBestExecutionContextScope(),
894 Address::DumpStyleResolvedDescription,
895 Address::DumpStyleSectionNameOffset);
901 case eAddressTypeHost:
905 if (sstr.GetSize() > 0)
907 destination.assign (1, '(');
908 destination.append (sstr.GetData(), sstr.GetSize());
909 destination.append (1, ')');
915 m_is_getting_summary = false;
916 return !destination.empty();
920 ValueObject::GetSummaryAsCString ()
922 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
924 GetSummaryAsCString(GetSummaryFormat().get(),
927 if (m_summary_str.empty())
929 return m_summary_str.c_str();
933 ValueObject::IsCStringContainer(bool check_pointer)
935 ClangASTType pointee_or_element_clang_type;
936 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
937 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
938 pointee_or_element_clang_type.IsCharType ());
939 if (!is_char_arr_ptr)
943 if (type_flags.Test(ClangASTType::eTypeIsArray))
945 addr_t cstr_address = LLDB_INVALID_ADDRESS;
946 AddressType cstr_address_type = eAddressTypeInvalid;
947 cstr_address = GetAddressOf (true, &cstr_address_type);
948 return (cstr_address != LLDB_INVALID_ADDRESS);
952 ValueObject::GetPointeeData (DataExtractor& data,
956 ClangASTType pointee_or_element_clang_type;
957 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
958 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
959 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
960 if (!(is_pointer_type || is_array_type))
966 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
967 const uint64_t bytes = item_count * item_type_size;
968 const uint64_t offset = item_idx * item_type_size;
970 if (item_idx == 0 && item_count == 1) // simply a deref
975 ValueObjectSP pointee_sp = Dereference(error);
976 if (error.Fail() || pointee_sp.get() == NULL)
978 return pointee_sp->GetData(data, error);
982 ValueObjectSP child_sp = GetChildAtIndex(0, true);
983 if (child_sp.get() == NULL)
986 return child_sp->GetData(data, error);
990 else /* (items > 1) */
993 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
994 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
996 AddressType addr_type;
997 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
1001 case eAddressTypeFile:
1003 ModuleSP module_sp (GetModule());
1006 addr = addr + offset;
1008 module_sp->ResolveFileAddress(addr, so_addr);
1009 ExecutionContext exe_ctx (GetExecutionContextRef());
1010 Target* target = exe_ctx.GetTargetPtr();
1013 heap_buf_ptr->SetByteSize(bytes);
1014 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1015 if (error.Success())
1017 data.SetData(data_sp);
1024 case eAddressTypeLoad:
1026 ExecutionContext exe_ctx (GetExecutionContextRef());
1027 Process *process = exe_ctx.GetProcessPtr();
1030 heap_buf_ptr->SetByteSize(bytes);
1031 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
1032 if (error.Success() || bytes_read > 0)
1034 data.SetData(data_sp);
1040 case eAddressTypeHost:
1042 const uint64_t max_bytes = GetClangType().GetByteSize();
1043 if (max_bytes > offset)
1045 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1046 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1047 data.SetData(data_sp);
1052 case eAddressTypeInvalid:
1060 ValueObject::GetData (DataExtractor& data, Error &error)
1062 UpdateValueIfNeeded(false);
1063 ExecutionContext exe_ctx (GetExecutionContextRef());
1064 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
1067 if (m_data.GetByteSize())
1070 return data.GetByteSize();
1077 data.SetAddressByteSize(m_data.GetAddressByteSize());
1078 data.SetByteOrder(m_data.GetByteOrder());
1079 return data.GetByteSize();
1083 ValueObject::SetData (DataExtractor &data, Error &error)
1086 // Make sure our value is up to date first so that our location and location
1088 if (!UpdateValueIfNeeded(false))
1090 error.SetErrorString("unable to read value");
1095 const Encoding encoding = GetClangType().GetEncoding(count);
1097 const size_t byte_size = GetByteSize();
1099 Value::ValueType value_type = m_value.GetValueType();
1103 case Value::eValueTypeScalar:
1105 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1107 if (!set_error.Success())
1109 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1114 case Value::eValueTypeLoadAddress:
1116 // If it is a load address, then the scalar value is the storage location
1117 // of the data, and we have to shove this value down to that load location.
1118 ExecutionContext exe_ctx (GetExecutionContextRef());
1119 Process *process = exe_ctx.GetProcessPtr();
1122 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1123 size_t bytes_written = process->WriteMemory(target_addr,
1124 data.GetDataStart(),
1127 if (!error.Success())
1129 if (bytes_written != byte_size)
1131 error.SetErrorString("unable to write value to memory");
1137 case Value::eValueTypeHostAddress:
1139 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1140 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1141 m_data.SetData(buffer_sp, 0);
1142 data.CopyByteOrderedData (0,
1144 const_cast<uint8_t *>(m_data.GetDataStart()),
1146 m_data.GetByteOrder());
1147 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1150 case Value::eValueTypeFileAddress:
1151 case Value::eValueTypeVector:
1155 // If we have reached this point, then we have successfully changed the value.
1160 // will compute strlen(str), but without consuming more than
1161 // maxlen bytes out of str (this serves the purpose of reading
1162 // chunks of a string without having to worry about
1163 // missing NULL terminators in the chunk)
1164 // of course, if strlen(str) > maxlen, the function will return
1165 // maxlen_value (which should be != maxlen, because that allows you
1166 // to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1168 strlen_or_inf (const char* str,
1170 uint32_t maxlen_value)
1179 return maxlen_value;
1186 ValueObject::ReadPointedString (Stream& s,
1188 uint32_t max_length,
1192 ExecutionContext exe_ctx (GetExecutionContextRef());
1193 Target* target = exe_ctx.GetTargetPtr();
1197 s << "<no target to read from>";
1198 error.SetErrorString("no target to read from");
1202 if (max_length == 0)
1203 max_length = target->GetMaximumSizeOfStringSummary();
1205 size_t bytes_read = 0;
1206 size_t total_bytes_read = 0;
1208 ClangASTType clang_type = GetClangType();
1209 ClangASTType elem_or_pointee_clang_type;
1210 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
1211 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1212 elem_or_pointee_clang_type.IsCharType ())
1214 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1215 AddressType cstr_address_type = eAddressTypeInvalid;
1217 size_t cstr_len = 0;
1218 bool capped_data = false;
1219 if (type_flags.Test (ClangASTType::eTypeIsArray))
1222 uint64_t array_size = 0;
1223 if (clang_type.IsArrayType(NULL, &array_size, NULL))
1225 cstr_len = array_size;
1226 if (cstr_len > max_length)
1229 cstr_len = max_length;
1232 cstr_address = GetAddressOf (true, &cstr_address_type);
1236 // We have a pointer
1237 cstr_address = GetPointerValue (&cstr_address_type);
1240 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1242 s << "<invalid address>";
1243 error.SetErrorString("invalid address");
1247 Address cstr_so_addr (cstr_address);
1249 if (cstr_len > 0 && honor_array)
1251 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1252 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1253 GetPointeeData(data, 0, cstr_len);
1255 if ((bytes_read = data.GetByteSize()) > 0)
1257 total_bytes_read = bytes_read;
1260 0, // Start offset in "data"
1262 1, // Size of item (1 byte for a char!)
1263 bytes_read, // How many bytes to print?
1264 UINT32_MAX, // num per line
1265 LLDB_INVALID_ADDRESS,// base address
1266 0, // bitfield bit size
1267 0); // bitfield bit offset
1275 cstr_len = max_length;
1276 const size_t k_max_buf_size = 64;
1280 int cstr_len_displayed = -1;
1281 bool capped_cstr = false;
1282 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1283 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1284 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
1286 total_bytes_read += bytes_read;
1287 const char *cstr = data.PeekCStr(0);
1288 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1289 if (len > k_max_buf_size)
1290 len = k_max_buf_size;
1291 if (cstr && cstr_len_displayed < 0)
1294 if (cstr_len_displayed < 0)
1295 cstr_len_displayed = len;
1299 cstr_len_displayed += len;
1300 if (len > bytes_read)
1306 0, // Start offset in "data"
1308 1, // Size of item (1 byte for a char!)
1309 len, // How many bytes to print?
1310 UINT32_MAX, // num per line
1311 LLDB_INVALID_ADDRESS,// base address
1312 0, // bitfield bit size
1313 0); // bitfield bit offset
1315 if (len < k_max_buf_size)
1318 if (len >= cstr_len)
1328 if (cstr_len_displayed >= 0)
1338 error.SetErrorString("not a string object");
1339 s << "<not a string object>";
1341 return total_bytes_read;
1345 ValueObject::GetObjectDescription ()
1348 if (!UpdateValueIfNeeded (true))
1351 if (!m_object_desc_str.empty())
1352 return m_object_desc_str.c_str();
1354 ExecutionContext exe_ctx (GetExecutionContextRef());
1355 Process *process = exe_ctx.GetProcessPtr();
1356 if (process == NULL)
1361 LanguageType language = GetObjectRuntimeLanguage();
1362 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1364 if (runtime == NULL)
1366 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
1367 ClangASTType clang_type = GetClangType();
1371 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
1373 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
1378 if (runtime && runtime->GetObjectDescription(s, *this))
1380 m_object_desc_str.append (s.GetData());
1383 if (m_object_desc_str.empty())
1386 return m_object_desc_str.c_str();
1390 ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1391 std::string& destination)
1393 if (UpdateValueIfNeeded(false))
1394 return format.FormatObject(this,destination);
1400 ValueObject::GetValueAsCString (lldb::Format format,
1401 std::string& destination)
1403 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
1407 ValueObject::GetValueAsCString ()
1409 if (UpdateValueIfNeeded(true))
1411 lldb::TypeFormatImplSP format_sp;
1412 lldb::Format my_format = GetFormat();
1413 if (my_format == lldb::eFormatDefault)
1415 if (m_type_format_sp)
1416 format_sp = m_type_format_sp;
1419 if (m_is_bitfield_for_scalar)
1420 my_format = eFormatUnsigned;
1423 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
1425 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1427 my_format = reg_info->format;
1431 my_format = GetClangType().GetFormat();
1436 if (my_format != m_last_format || m_value_str.empty())
1438 m_last_format = my_format;
1440 format_sp.reset(new TypeFormatImpl_Format(my_format));
1441 if (GetValueAsCString(*format_sp.get(), m_value_str))
1443 if (!m_value_did_change && m_old_value_valid)
1445 // The value was gotten successfully, so we consider the
1446 // value as changed if the value string differs
1447 SetValueDidChange (m_old_value_str != m_value_str);
1452 if (m_value_str.empty())
1454 return m_value_str.c_str();
1457 // if > 8bytes, 0 is returned. this method should mostly be used
1458 // to read address values out of pointers
1460 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
1462 // If our byte size is zero this is an aggregate type that has children
1463 if (!GetClangType().IsAggregateType())
1466 if (ResolveValue (scalar))
1470 return scalar.ULongLong(fail_value);
1472 // fallthrough, otherwise...
1481 ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1483 // If our byte size is zero this is an aggregate type that has children
1484 if (!GetClangType().IsAggregateType())
1487 if (ResolveValue (scalar))
1491 return scalar.SLongLong(fail_value);
1493 // fallthrough, otherwise...
1501 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1502 // this call up to date by returning true for your new special cases. We will eventually move
1503 // to checking this call result before trying to display special cases
1505 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1506 Format custom_format)
1508 Flags flags(GetTypeInfo());
1509 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1510 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1512 if (IsCStringContainer(true) &&
1513 (custom_format == eFormatCString ||
1514 custom_format == eFormatCharArray ||
1515 custom_format == eFormatChar ||
1516 custom_format == eFormatVectorOfChar))
1519 if (flags.Test(ClangASTType::eTypeIsArray))
1521 if ((custom_format == eFormatBytes) ||
1522 (custom_format == eFormatBytesWithASCII))
1525 if ((custom_format == eFormatVectorOfChar) ||
1526 (custom_format == eFormatVectorOfFloat32) ||
1527 (custom_format == eFormatVectorOfFloat64) ||
1528 (custom_format == eFormatVectorOfSInt16) ||
1529 (custom_format == eFormatVectorOfSInt32) ||
1530 (custom_format == eFormatVectorOfSInt64) ||
1531 (custom_format == eFormatVectorOfSInt8) ||
1532 (custom_format == eFormatVectorOfUInt128) ||
1533 (custom_format == eFormatVectorOfUInt16) ||
1534 (custom_format == eFormatVectorOfUInt32) ||
1535 (custom_format == eFormatVectorOfUInt64) ||
1536 (custom_format == eFormatVectorOfUInt8))
1544 ValueObject::DumpPrintableRepresentation(Stream& s,
1545 ValueObjectRepresentationStyle val_obj_display,
1546 Format custom_format,
1547 PrintableRepresentationSpecialCases special,
1551 Flags flags(GetTypeInfo());
1553 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1554 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1558 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1559 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1561 // when being asked to get a printable display an array or pointer type directly,
1562 // try to "do the right thing"
1564 if (IsCStringContainer(true) &&
1565 (custom_format == eFormatCString ||
1566 custom_format == eFormatCharArray ||
1567 custom_format == eFormatChar ||
1568 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
1571 ReadPointedString(s,
1574 (custom_format == eFormatVectorOfChar) ||
1575 (custom_format == eFormatCharArray));
1576 return !error.Fail();
1579 if (custom_format == eFormatEnum)
1582 // this only works for arrays, because I have no way to know when
1583 // the pointed memory ends, and no special \0 end of data marker
1584 if (flags.Test(ClangASTType::eTypeIsArray))
1586 if ((custom_format == eFormatBytes) ||
1587 (custom_format == eFormatBytesWithASCII))
1589 const size_t count = GetNumChildren();
1592 for (size_t low = 0; low < count; low++)
1598 ValueObjectSP child = GetChildAtIndex(low,true);
1601 s << "<invalid child>";
1604 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1612 if ((custom_format == eFormatVectorOfChar) ||
1613 (custom_format == eFormatVectorOfFloat32) ||
1614 (custom_format == eFormatVectorOfFloat64) ||
1615 (custom_format == eFormatVectorOfSInt16) ||
1616 (custom_format == eFormatVectorOfSInt32) ||
1617 (custom_format == eFormatVectorOfSInt64) ||
1618 (custom_format == eFormatVectorOfSInt8) ||
1619 (custom_format == eFormatVectorOfUInt128) ||
1620 (custom_format == eFormatVectorOfUInt16) ||
1621 (custom_format == eFormatVectorOfUInt32) ||
1622 (custom_format == eFormatVectorOfUInt64) ||
1623 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1625 const size_t count = GetNumChildren();
1627 Format format = FormatManager::GetSingleItemFormat(custom_format);
1630 for (size_t low = 0; low < count; low++)
1636 ValueObjectSP child = GetChildAtIndex(low,true);
1639 s << "<invalid child>";
1642 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1651 if ((custom_format == eFormatBoolean) ||
1652 (custom_format == eFormatBinary) ||
1653 (custom_format == eFormatChar) ||
1654 (custom_format == eFormatCharPrintable) ||
1655 (custom_format == eFormatComplexFloat) ||
1656 (custom_format == eFormatDecimal) ||
1657 (custom_format == eFormatHex) ||
1658 (custom_format == eFormatHexUppercase) ||
1659 (custom_format == eFormatFloat) ||
1660 (custom_format == eFormatOctal) ||
1661 (custom_format == eFormatOSType) ||
1662 (custom_format == eFormatUnicode16) ||
1663 (custom_format == eFormatUnicode32) ||
1664 (custom_format == eFormatUnsigned) ||
1665 (custom_format == eFormatPointer) ||
1666 (custom_format == eFormatComplexInteger) ||
1667 (custom_format == eFormatComplex) ||
1668 (custom_format == eFormatDefault)) // use the [] operator
1676 bool var_success = false;
1679 const char *cstr = NULL;
1681 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1682 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1683 // area for cases where our desired output is not backed by some other longer-term storage
1686 if (custom_format != eFormatInvalid)
1687 SetFormat(custom_format);
1689 switch(val_obj_display)
1691 case eValueObjectRepresentationStyleValue:
1692 cstr = GetValueAsCString();
1695 case eValueObjectRepresentationStyleSummary:
1696 cstr = GetSummaryAsCString();
1699 case eValueObjectRepresentationStyleLanguageSpecific:
1700 cstr = GetObjectDescription();
1703 case eValueObjectRepresentationStyleLocation:
1704 cstr = GetLocationAsCString();
1707 case eValueObjectRepresentationStyleChildrenCount:
1708 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
1709 cstr = strm.GetString().c_str();
1712 case eValueObjectRepresentationStyleType:
1713 cstr = GetTypeName().AsCString();
1716 case eValueObjectRepresentationStyleName:
1717 cstr = GetName().AsCString();
1720 case eValueObjectRepresentationStyleExpressionPath:
1721 GetExpressionPath(strm, false);
1722 cstr = strm.GetString().c_str();
1728 if (val_obj_display == eValueObjectRepresentationStyleValue)
1729 cstr = GetSummaryAsCString();
1730 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1732 if (GetClangType().IsAggregateType())
1734 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1735 cstr = strm.GetString().c_str();
1738 cstr = GetValueAsCString();
1749 s.Printf("<%s>", m_error.AsCString());
1753 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1754 s.PutCString("<no summary available>");
1755 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1756 s.PutCString("<no value available>");
1757 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1758 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1760 s.PutCString("<no printable representation>");
1763 // we should only return false here if we could not do *anything*
1764 // even if we have an error message as output, that's a success
1765 // from our callers' perspective, so return true
1768 if (custom_format != eFormatInvalid)
1769 SetFormat(eFormatDefault);
1776 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
1778 if (!UpdateValueIfNeeded(false))
1779 return LLDB_INVALID_ADDRESS;
1781 switch (m_value.GetValueType())
1783 case Value::eValueTypeScalar:
1784 case Value::eValueTypeVector:
1785 if (scalar_is_load_address)
1788 *address_type = eAddressTypeLoad;
1789 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1793 case Value::eValueTypeLoadAddress:
1794 case Value::eValueTypeFileAddress:
1795 case Value::eValueTypeHostAddress:
1798 *address_type = m_value.GetValueAddressType ();
1799 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1804 *address_type = eAddressTypeInvalid;
1805 return LLDB_INVALID_ADDRESS;
1809 ValueObject::GetPointerValue (AddressType *address_type)
1811 addr_t address = LLDB_INVALID_ADDRESS;
1813 *address_type = eAddressTypeInvalid;
1815 if (!UpdateValueIfNeeded(false))
1818 switch (m_value.GetValueType())
1820 case Value::eValueTypeScalar:
1821 case Value::eValueTypeVector:
1822 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1825 case Value::eValueTypeHostAddress:
1826 case Value::eValueTypeLoadAddress:
1827 case Value::eValueTypeFileAddress:
1829 lldb::offset_t data_offset = 0;
1830 address = m_data.GetPointer(&data_offset);
1836 *address_type = GetAddressTypeOfChildren();
1842 ValueObject::SetValueFromCString (const char *value_str, Error& error)
1845 // Make sure our value is up to date first so that our location and location
1847 if (!UpdateValueIfNeeded(false))
1849 error.SetErrorString("unable to read value");
1854 const Encoding encoding = GetClangType().GetEncoding (count);
1856 const size_t byte_size = GetByteSize();
1858 Value::ValueType value_type = m_value.GetValueType();
1860 if (value_type == Value::eValueTypeScalar)
1862 // If the value is already a scalar, then let the scalar change itself:
1863 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1865 else if (byte_size <= Scalar::GetMaxByteSize())
1867 // If the value fits in a scalar, then make a new scalar and again let the
1868 // scalar code do the conversion, then figure out where to put the new value.
1870 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1871 if (error.Success())
1875 case Value::eValueTypeLoadAddress:
1877 // If it is a load address, then the scalar value is the storage location
1878 // of the data, and we have to shove this value down to that load location.
1879 ExecutionContext exe_ctx (GetExecutionContextRef());
1880 Process *process = exe_ctx.GetProcessPtr();
1883 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1884 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1888 if (!error.Success())
1890 if (bytes_written != byte_size)
1892 error.SetErrorString("unable to write value to memory");
1898 case Value::eValueTypeHostAddress:
1900 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1901 DataExtractor new_data;
1902 new_data.SetByteOrder (m_data.GetByteOrder());
1904 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1905 m_data.SetData(buffer_sp, 0);
1906 bool success = new_scalar.GetData(new_data);
1909 new_data.CopyByteOrderedData (0,
1911 const_cast<uint8_t *>(m_data.GetDataStart()),
1913 m_data.GetByteOrder());
1915 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1919 case Value::eValueTypeFileAddress:
1920 case Value::eValueTypeScalar:
1921 case Value::eValueTypeVector:
1932 // We don't support setting things bigger than a scalar at present.
1933 error.SetErrorString("unable to write aggregate data type");
1937 // If we have reached this point, then we have successfully changed the value.
1943 ValueObject::GetDeclaration (Declaration &decl)
1950 ValueObject::GetTypeName()
1952 return GetClangType().GetConstTypeName();
1956 ValueObject::GetDisplayTypeName()
1958 return GetTypeName();
1962 ValueObject::GetQualifiedTypeName()
1964 return GetClangType().GetConstQualifiedTypeName();
1969 ValueObject::GetObjectRuntimeLanguage ()
1971 return GetClangType().GetMinimumLanguage ();
1975 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
1977 m_synthetic_children[key] = valobj;
1981 ValueObject::GetSyntheticChild (const ConstString &key) const
1983 ValueObjectSP synthetic_child_sp;
1984 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
1985 if (pos != m_synthetic_children.end())
1986 synthetic_child_sp = pos->second->GetSP();
1987 return synthetic_child_sp;
1991 ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
1993 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
1997 ValueObject::IsPointerType ()
1999 return GetClangType().IsPointerType();
2003 ValueObject::IsArrayType ()
2005 return GetClangType().IsArrayType (NULL, NULL, NULL);
2009 ValueObject::IsScalarType ()
2011 return GetClangType().IsScalarType ();
2015 ValueObject::IsIntegerType (bool &is_signed)
2017 return GetClangType().IsIntegerType (is_signed);
2021 ValueObject::IsPointerOrReferenceType ()
2023 return GetClangType().IsPointerOrReferenceType ();
2027 ValueObject::IsPossibleDynamicType ()
2029 ExecutionContext exe_ctx (GetExecutionContextRef());
2030 Process *process = exe_ctx.GetProcessPtr();
2032 return process->IsPossibleDynamicValue(*this);
2034 return GetClangType().IsPossibleDynamicType (NULL, true, true);
2038 ValueObject::IsObjCNil ()
2040 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2041 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
2044 bool canReadValue = true;
2045 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
2046 return canReadValue && isZero;
2050 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
2052 const uint32_t type_info = GetTypeInfo ();
2053 if (type_info & ClangASTType::eTypeIsArray)
2054 return GetSyntheticArrayMemberFromArray(index, can_create);
2056 if (type_info & ClangASTType::eTypeIsPointer)
2057 return GetSyntheticArrayMemberFromPointer(index, can_create);
2059 return ValueObjectSP();
2064 ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
2066 ValueObjectSP synthetic_child_sp;
2067 if (IsPointerType ())
2070 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
2071 ConstString index_const_str(index_str);
2072 // Check if we have already created a synthetic array member in this
2073 // valid object. If we have we will re-use it.
2074 synthetic_child_sp = GetSyntheticChild (index_const_str);
2075 if (!synthetic_child_sp)
2077 ValueObject *synthetic_child;
2078 // We haven't made a synthetic array member for INDEX yet, so
2079 // lets make one and cache it for any future reference.
2080 synthetic_child = CreateChildAtIndex(0, true, index);
2082 // Cache the value if we got one back...
2083 if (synthetic_child)
2085 AddSyntheticChild(index_const_str, synthetic_child);
2086 synthetic_child_sp = synthetic_child->GetSP();
2087 synthetic_child_sp->SetName(ConstString(index_str));
2088 synthetic_child_sp->m_is_array_item_for_pointer = true;
2092 return synthetic_child_sp;
2095 // This allows you to create an array member using and index
2096 // that doesn't not fall in the normal bounds of the array.
2097 // Many times structure can be defined as:
2098 // struct Collection
2100 // uint32_t item_count;
2101 // Item item_array[0];
2103 // The size of the "item_array" is 1, but many times in practice
2104 // there are more items in "item_array".
2107 ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
2109 ValueObjectSP synthetic_child_sp;
2113 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
2114 ConstString index_const_str(index_str);
2115 // Check if we have already created a synthetic array member in this
2116 // valid object. If we have we will re-use it.
2117 synthetic_child_sp = GetSyntheticChild (index_const_str);
2118 if (!synthetic_child_sp)
2120 ValueObject *synthetic_child;
2121 // We haven't made a synthetic array member for INDEX yet, so
2122 // lets make one and cache it for any future reference.
2123 synthetic_child = CreateChildAtIndex(0, true, index);
2125 // Cache the value if we got one back...
2126 if (synthetic_child)
2128 AddSyntheticChild(index_const_str, synthetic_child);
2129 synthetic_child_sp = synthetic_child->GetSP();
2130 synthetic_child_sp->SetName(ConstString(index_str));
2131 synthetic_child_sp->m_is_array_item_for_pointer = true;
2135 return synthetic_child_sp;
2139 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2141 ValueObjectSP synthetic_child_sp;
2142 if (IsScalarType ())
2145 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2146 ConstString index_const_str(index_str);
2147 // Check if we have already created a synthetic array member in this
2148 // valid object. If we have we will re-use it.
2149 synthetic_child_sp = GetSyntheticChild (index_const_str);
2150 if (!synthetic_child_sp)
2152 // We haven't made a synthetic array member for INDEX yet, so
2153 // lets make one and cache it for any future reference.
2154 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2163 eAddressTypeInvalid);
2165 // Cache the value if we got one back...
2166 if (synthetic_child)
2168 AddSyntheticChild(index_const_str, synthetic_child);
2169 synthetic_child_sp = synthetic_child->GetSP();
2170 synthetic_child_sp->SetName(ConstString(index_str));
2171 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2175 return synthetic_child_sp;
2179 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2182 ValueObjectSP synthetic_child_sp;
2185 snprintf(name_str, sizeof(name_str), "@%i", offset);
2186 ConstString name_const_str(name_str);
2188 // Check if we have already created a synthetic array member in this
2189 // valid object. If we have we will re-use it.
2190 synthetic_child_sp = GetSyntheticChild (name_const_str);
2192 if (synthetic_child_sp.get())
2193 return synthetic_child_sp;
2196 return ValueObjectSP();
2198 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2207 eAddressTypeInvalid);
2208 if (synthetic_child)
2210 AddSyntheticChild(name_const_str, synthetic_child);
2211 synthetic_child_sp = synthetic_child->GetSP();
2212 synthetic_child_sp->SetName(name_const_str);
2213 synthetic_child_sp->m_is_child_at_offset = true;
2215 return synthetic_child_sp;
2219 ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
2221 ValueObjectSP synthetic_child_sp;
2224 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2225 ConstString name_const_str(name_str);
2227 // Check if we have already created a synthetic array member in this
2228 // valid object. If we have we will re-use it.
2229 synthetic_child_sp = GetSyntheticChild (name_const_str);
2231 if (synthetic_child_sp.get())
2232 return synthetic_child_sp;
2235 return ValueObjectSP();
2237 const bool is_base_class = true;
2239 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2248 eAddressTypeInvalid);
2249 if (synthetic_child)
2251 AddSyntheticChild(name_const_str, synthetic_child);
2252 synthetic_child_sp = synthetic_child->GetSP();
2253 synthetic_child_sp->SetName(name_const_str);
2255 return synthetic_child_sp;
2259 // your expression path needs to have a leading . or ->
2260 // (unless it somehow "looks like" an array, in which case it has
2261 // a leading [ symbol). while the [ is meaningful and should be shown
2262 // to the user, . and -> are just parser design, but by no means
2263 // added information for the user.. strip them off
2265 SkipLeadingExpressionPathSeparators(const char* expression)
2267 if (!expression || !expression[0])
2269 if (expression[0] == '.')
2270 return expression+1;
2271 if (expression[0] == '-' && expression[1] == '>')
2272 return expression+2;
2277 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2279 ValueObjectSP synthetic_child_sp;
2280 ConstString name_const_string(expression);
2281 // Check if we have already created a synthetic array member in this
2282 // valid object. If we have we will re-use it.
2283 synthetic_child_sp = GetSyntheticChild (name_const_string);
2284 if (!synthetic_child_sp)
2286 // We haven't made a synthetic array member for expression yet, so
2287 // lets make one and cache it for any future reference.
2288 synthetic_child_sp = GetValueForExpressionPath(expression,
2290 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
2292 // Cache the value if we got one back...
2293 if (synthetic_child_sp.get())
2295 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
2296 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2297 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
2300 return synthetic_child_sp;
2304 ValueObject::CalculateSyntheticValue (bool use_synthetic)
2306 if (use_synthetic == false)
2309 TargetSP target_sp(GetTargetSP());
2310 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
2312 m_synthetic_value = NULL;
2316 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2318 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
2321 if (m_synthetic_children_sp.get() == NULL)
2324 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2327 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
2331 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
2333 if (use_dynamic == eNoDynamicValues)
2336 if (!m_dynamic_value && !IsDynamic())
2338 ExecutionContext exe_ctx (GetExecutionContextRef());
2339 Process *process = exe_ctx.GetProcessPtr();
2340 if (process && process->IsPossibleDynamicValue(*this))
2342 ClearDynamicTypeInformation ();
2343 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2349 ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
2351 if (use_dynamic == eNoDynamicValues)
2352 return ValueObjectSP();
2354 if (!IsDynamic() && m_dynamic_value == NULL)
2356 CalculateDynamicValue(use_dynamic);
2358 if (m_dynamic_value)
2359 return m_dynamic_value->GetSP();
2361 return ValueObjectSP();
2365 ValueObject::GetStaticValue()
2371 ValueObject::GetNonSyntheticValue ()
2377 ValueObject::GetSyntheticValue (bool use_synthetic)
2379 if (use_synthetic == false)
2380 return ValueObjectSP();
2382 CalculateSyntheticValue(use_synthetic);
2384 if (m_synthetic_value)
2385 return m_synthetic_value->GetSP();
2387 return ValueObjectSP();
2391 ValueObject::HasSyntheticValue()
2393 UpdateFormatsIfNeeded();
2395 if (m_synthetic_children_sp.get() == NULL)
2398 CalculateSyntheticValue(true);
2400 if (m_synthetic_value)
2407 ValueObject::GetBaseClassPath (Stream &s)
2411 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
2412 ClangASTType clang_type = GetClangType();
2413 std::string cxx_class_name;
2414 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
2415 if (this_had_base_class)
2417 if (parent_had_base_class)
2419 s.PutCString(cxx_class_name.c_str());
2421 return parent_had_base_class || this_had_base_class;
2428 ValueObject::GetNonBaseClassParent()
2432 if (GetParent()->IsBaseClass())
2433 return GetParent()->GetNonBaseClassParent();
2442 ValueObject::IsBaseClass (uint32_t& depth)
2451 GetParent()->IsBaseClass(depth);
2455 // TODO: a base of no parent? weird..
2461 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
2463 const bool is_deref_of_parent = IsDereferenceOfParent ();
2465 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2467 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2468 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2469 // the eHonorPointers mode is meant to produce strings in this latter format
2473 ValueObject* parent = GetParent();
2476 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
2478 // if we are a deref_of_parent just because we are synthetic array
2479 // members made up to allow ptr[%d] syntax to work in variable
2480 // printing, then add our name ([%d]) to the expression path
2481 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
2482 s.PutCString(m_name.AsCString());
2486 if (!is_deref_of_parent)
2488 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2489 if (non_base_class_parent)
2491 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2492 if (non_base_class_parent_clang_type)
2494 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
2500 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2502 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
2506 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2507 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
2515 const char *name = GetName().GetCString();
2518 if (qualify_cxx_base_classes)
2520 if (GetBaseClassPath (s))
2528 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2535 ValueObject::GetValueForExpressionPath(const char* expression,
2536 const char** first_unparsed,
2537 ExpressionPathScanEndReason* reason_to_stop,
2538 ExpressionPathEndResultType* final_value_type,
2539 const GetValueForExpressionPathOptions& options,
2540 ExpressionPathAftermath* final_task_on_target)
2543 const char* dummy_first_unparsed;
2544 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2545 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2546 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2548 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2549 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2550 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2551 final_value_type ? final_value_type : &dummy_final_value_type,
2553 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2555 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2558 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
2560 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
2563 ValueObjectSP final_value = ret_val->Dereference(error);
2564 if (error.Fail() || !final_value.get())
2567 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2568 if (final_value_type)
2569 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2570 return ValueObjectSP();
2574 if (final_task_on_target)
2575 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2579 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2582 ValueObjectSP final_value = ret_val->AddressOf(error);
2583 if (error.Fail() || !final_value.get())
2586 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2587 if (final_value_type)
2588 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2589 return ValueObjectSP();
2593 if (final_task_on_target)
2594 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2599 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2603 ValueObject::GetValuesForExpressionPath(const char* expression,
2604 ValueObjectListSP& list,
2605 const char** first_unparsed,
2606 ExpressionPathScanEndReason* reason_to_stop,
2607 ExpressionPathEndResultType* final_value_type,
2608 const GetValueForExpressionPathOptions& options,
2609 ExpressionPathAftermath* final_task_on_target)
2611 const char* dummy_first_unparsed;
2612 ExpressionPathScanEndReason dummy_reason_to_stop;
2613 ExpressionPathEndResultType dummy_final_value_type;
2614 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2616 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2617 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2618 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2619 final_value_type ? final_value_type : &dummy_final_value_type,
2621 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2623 if (!ret_val.get()) // if there are errors, I add nothing to the list
2626 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
2628 // I need not expand a range, just post-process the final value and return
2629 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2631 list->Append(ret_val);
2634 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
2636 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
2639 ValueObjectSP final_value = ret_val->Dereference(error);
2640 if (error.Fail() || !final_value.get())
2643 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2644 if (final_value_type)
2645 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2650 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2651 list->Append(final_value);
2655 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2658 ValueObjectSP final_value = ret_val->AddressOf(error);
2659 if (error.Fail() || !final_value.get())
2662 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2663 if (final_value_type)
2664 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2669 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2670 list->Append(final_value);
2678 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2679 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2682 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2683 final_value_type ? final_value_type : &dummy_final_value_type,
2685 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2687 // in any non-covered case, just do the obviously right thing
2688 list->Append(ret_val);
2693 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2694 const char** first_unparsed,
2695 ExpressionPathScanEndReason* reason_to_stop,
2696 ExpressionPathEndResultType* final_result,
2697 const GetValueForExpressionPathOptions& options,
2698 ExpressionPathAftermath* what_next)
2700 ValueObjectSP root = GetSP();
2703 return ValueObjectSP();
2705 *first_unparsed = expression_cstr;
2710 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2712 ClangASTType root_clang_type = root->GetClangType();
2713 ClangASTType pointee_clang_type;
2714 Flags pointee_clang_type_info;
2716 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
2717 if (pointee_clang_type)
2718 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
2720 if (!expression_cstr || *expression_cstr == '\0')
2722 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2726 switch (*expression_cstr)
2730 if (options.m_check_dot_vs_arrow_syntax &&
2731 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
2733 *first_unparsed = expression_cstr;
2734 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2735 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2736 return ValueObjectSP();
2738 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2739 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
2740 options.m_no_fragile_ivar)
2742 *first_unparsed = expression_cstr;
2743 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2744 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2745 return ValueObjectSP();
2747 if (expression_cstr[1] != '>')
2749 *first_unparsed = expression_cstr;
2750 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2751 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2752 return ValueObjectSP();
2754 expression_cstr++; // skip the -
2756 case '.': // or fallthrough from ->
2758 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
2759 root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
2761 *first_unparsed = expression_cstr;
2762 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2763 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2764 return ValueObjectSP();
2766 expression_cstr++; // skip .
2767 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2768 ConstString child_name;
2769 if (!next_separator) // if no other separator just expand this last layer
2771 child_name.SetCString (expression_cstr);
2772 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2774 if (child_valobj_sp.get()) // we know we are done, so just return
2776 *first_unparsed = "";
2777 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2778 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2779 return child_valobj_sp;
2781 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2783 if (root->IsSynthetic())
2785 *first_unparsed = expression_cstr;
2786 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2787 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2788 return ValueObjectSP();
2791 child_valobj_sp = root->GetSyntheticValue();
2792 if (child_valobj_sp.get())
2793 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2796 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2797 // so we hit the "else" branch, and return an error
2798 if(child_valobj_sp.get()) // if it worked, just return
2800 *first_unparsed = "";
2801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2802 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2803 return child_valobj_sp;
2807 *first_unparsed = expression_cstr;
2808 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2809 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2810 return ValueObjectSP();
2813 else // other layers do expand
2815 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2816 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2817 if (child_valobj_sp.get()) // store the new root and move on
2819 root = child_valobj_sp;
2820 *first_unparsed = next_separator;
2821 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2824 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2826 if (root->IsSynthetic())
2828 *first_unparsed = expression_cstr;
2829 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2830 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2831 return ValueObjectSP();
2834 child_valobj_sp = root->GetSyntheticValue(true);
2835 if (child_valobj_sp)
2836 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2839 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2840 // so we hit the "else" branch, and return an error
2841 if(child_valobj_sp.get()) // if it worked, move on
2843 root = child_valobj_sp;
2844 *first_unparsed = next_separator;
2845 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2850 *first_unparsed = expression_cstr;
2851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2852 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2853 return ValueObjectSP();
2860 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && !root_clang_type_info.Test(ClangASTType::eTypeIsVector)) // if this is not a T[] nor a T*
2862 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
2864 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2866 *first_unparsed = expression_cstr;
2867 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2868 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2869 return ValueObjectSP();
2872 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2874 *first_unparsed = expression_cstr;
2875 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2876 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2877 return ValueObjectSP();
2880 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2882 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2884 *first_unparsed = expression_cstr;
2885 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2886 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2887 return ValueObjectSP();
2889 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2891 *first_unparsed = expression_cstr+2;
2892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2893 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2897 const char *separator_position = ::strchr(expression_cstr+1,'-');
2898 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2899 if (!close_bracket_position) // if there is no ], this is a syntax error
2901 *first_unparsed = expression_cstr;
2902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2904 return ValueObjectSP();
2906 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2909 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2910 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2912 *first_unparsed = expression_cstr;
2913 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2914 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2915 return ValueObjectSP();
2917 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2919 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2921 *first_unparsed = expression_cstr+2;
2922 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2923 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2928 *first_unparsed = expression_cstr;
2929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2930 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2931 return ValueObjectSP();
2934 // from here on we do have a valid index
2935 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2937 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2938 if (!child_valobj_sp)
2939 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2940 if (!child_valobj_sp)
2941 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2942 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2943 if (child_valobj_sp)
2945 root = child_valobj_sp;
2946 *first_unparsed = end+1; // skip ]
2947 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2952 *first_unparsed = expression_cstr;
2953 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2954 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2955 return ValueObjectSP();
2958 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
2960 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
2961 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
2964 root = root->Dereference(error);
2965 if (error.Fail() || !root.get())
2967 *first_unparsed = expression_cstr;
2968 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2969 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2970 return ValueObjectSP();
2974 *what_next = eExpressionPathAftermathNothing;
2980 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2981 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
2982 && root->HasSyntheticValue()
2983 && options.m_no_synthetic_children == false)
2985 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2988 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2991 *first_unparsed = expression_cstr;
2992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2994 return ValueObjectSP();
2998 *first_unparsed = end+1; // skip ]
2999 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3004 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3006 root = root->GetSyntheticBitFieldChild(index, index, true);
3009 *first_unparsed = expression_cstr;
3010 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3011 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3012 return ValueObjectSP();
3014 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3016 *first_unparsed = end+1; // skip ]
3017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3022 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
3024 root = root->GetChildAtIndex(index, true);
3027 *first_unparsed = expression_cstr;
3028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3030 return ValueObjectSP();
3034 *first_unparsed = end+1; // skip ]
3035 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3039 else if (options.m_no_synthetic_children == false)
3041 if (root->HasSyntheticValue())
3042 root = root->GetSyntheticValue();
3043 else if (!root->IsSynthetic())
3045 *first_unparsed = expression_cstr;
3046 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3047 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3048 return ValueObjectSP();
3050 // if we are here, then root itself is a synthetic VO.. should be good to go
3054 *first_unparsed = expression_cstr;
3055 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3056 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3057 return ValueObjectSP();
3059 root = root->GetChildAtIndex(index, true);
3062 *first_unparsed = expression_cstr;
3063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3065 return ValueObjectSP();
3069 *first_unparsed = end+1; // skip ]
3070 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3076 *first_unparsed = expression_cstr;
3077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3079 return ValueObjectSP();
3082 else // we have a low and a high index
3085 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3086 if (!end || end != separator_position) // if something weird is in our way return an error
3088 *first_unparsed = expression_cstr;
3089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3091 return ValueObjectSP();
3093 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3094 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3096 *first_unparsed = expression_cstr;
3097 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3098 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3099 return ValueObjectSP();
3101 if (index_lower > index_higher) // swap indices if required
3103 unsigned long temp = index_lower;
3104 index_lower = index_higher;
3105 index_higher = temp;
3107 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
3109 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3112 *first_unparsed = expression_cstr;
3113 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3114 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3115 return ValueObjectSP();
3119 *first_unparsed = end+1; // skip ]
3120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3121 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3125 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3126 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3127 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3130 root = root->Dereference(error);
3131 if (error.Fail() || !root.get())
3133 *first_unparsed = expression_cstr;
3134 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3135 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3136 return ValueObjectSP();
3140 *what_next = ValueObject::eExpressionPathAftermathNothing;
3146 *first_unparsed = expression_cstr;
3147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
3154 default: // some non-separator is in the way
3156 *first_unparsed = expression_cstr;
3157 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3158 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3159 return ValueObjectSP();
3167 ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3168 const char** first_unparsed,
3170 ValueObjectListSP& list,
3171 ExpressionPathScanEndReason* reason_to_stop,
3172 ExpressionPathEndResultType* final_result,
3173 const GetValueForExpressionPathOptions& options,
3174 ExpressionPathAftermath* what_next)
3179 *first_unparsed = expression_cstr;
3184 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3186 ClangASTType root_clang_type = root->GetClangType();
3187 ClangASTType pointee_clang_type;
3188 Flags pointee_clang_type_info;
3189 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
3190 if (pointee_clang_type)
3191 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
3193 if (!expression_cstr || *expression_cstr == '\0')
3195 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
3200 switch (*expression_cstr)
3204 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
3206 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3208 *first_unparsed = expression_cstr;
3209 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3210 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3213 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3215 *first_unparsed = expression_cstr;
3216 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3217 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3221 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3223 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3225 *first_unparsed = expression_cstr;
3226 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3227 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3230 else // expand this into list
3232 const size_t max_index = root->GetNumChildren() - 1;
3233 for (size_t index = 0; index < max_index; index++)
3235 ValueObjectSP child =
3236 root->GetChildAtIndex(index, true);
3237 list->Append(child);
3239 *first_unparsed = expression_cstr+2;
3240 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3241 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3242 return max_index; // tell me number of items I added to the VOList
3245 const char *separator_position = ::strchr(expression_cstr+1,'-');
3246 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3247 if (!close_bracket_position) // if there is no ], this is a syntax error
3249 *first_unparsed = expression_cstr;
3250 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3251 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3254 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3257 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3258 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3260 *first_unparsed = expression_cstr;
3261 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3262 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3265 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3267 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3269 const size_t max_index = root->GetNumChildren() - 1;
3270 for (size_t index = 0; index < max_index; index++)
3272 ValueObjectSP child =
3273 root->GetChildAtIndex(index, true);
3274 list->Append(child);
3276 *first_unparsed = expression_cstr+2;
3277 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3278 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3279 return max_index; // tell me number of items I added to the VOList
3283 *first_unparsed = expression_cstr;
3284 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3285 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3289 // from here on we do have a valid index
3290 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3292 root = root->GetChildAtIndex(index, true);
3295 *first_unparsed = expression_cstr;
3296 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3297 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3303 *first_unparsed = end+1; // skip ]
3304 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3305 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3309 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
3311 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
3312 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3315 root = root->Dereference(error);
3316 if (error.Fail() || !root.get())
3318 *first_unparsed = expression_cstr;
3319 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3320 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3325 *what_next = eExpressionPathAftermathNothing;
3331 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3334 *first_unparsed = expression_cstr;
3335 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3336 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3342 *first_unparsed = end+1; // skip ]
3343 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3344 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3349 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3351 root = root->GetSyntheticBitFieldChild(index, index, true);
3354 *first_unparsed = expression_cstr;
3355 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3356 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3359 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3362 *first_unparsed = end+1; // skip ]
3363 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3364 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3369 else // we have a low and a high index
3372 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3373 if (!end || end != separator_position) // if something weird is in our way return an error
3375 *first_unparsed = expression_cstr;
3376 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3377 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3380 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3381 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3383 *first_unparsed = expression_cstr;
3384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3385 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3388 if (index_lower > index_higher) // swap indices if required
3390 unsigned long temp = index_lower;
3391 index_lower = index_higher;
3392 index_higher = temp;
3394 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
3396 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3399 *first_unparsed = expression_cstr;
3400 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3401 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3407 *first_unparsed = end+1; // skip ]
3408 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3409 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3413 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
3414 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3415 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3418 root = root->Dereference(error);
3419 if (error.Fail() || !root.get())
3421 *first_unparsed = expression_cstr;
3422 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3423 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3428 *what_next = ValueObject::eExpressionPathAftermathNothing;
3434 for (unsigned long index = index_lower;
3435 index <= index_higher; index++)
3437 ValueObjectSP child =
3438 root->GetChildAtIndex(index, true);
3439 list->Append(child);
3441 *first_unparsed = end+1;
3442 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3443 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3444 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3449 default: // some non-[ separator, or something entirely wrong, is in the way
3451 *first_unparsed = expression_cstr;
3452 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3453 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3462 ValueObject::LogValueObject (Log *log)
3465 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
3469 ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
3476 log->PutCString(s.GetData());
3481 ValueObject::Dump (Stream &s)
3484 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3485 printer.PrintValueObject();
3489 ValueObject::Dump (Stream &s,
3490 const DumpValueObjectOptions& options)
3492 ValueObjectPrinter printer(this,&s,options);
3493 printer.PrintValueObject();
3497 ValueObject::CreateConstantValue (const ConstString &name)
3499 ValueObjectSP valobj_sp;
3501 if (UpdateValueIfNeeded(false) && m_error.Success())
3503 ExecutionContext exe_ctx (GetExecutionContextRef());
3506 data.SetByteOrder (m_data.GetByteOrder());
3507 data.SetAddressByteSize(m_data.GetAddressByteSize());
3511 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3512 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3515 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3517 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3526 ExecutionContext exe_ctx (GetExecutionContextRef());
3527 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
3533 ValueObject::GetCPPVTableAddress (AddressType &address_type)
3535 ClangASTType pointee_type;
3536 ClangASTType this_type(GetClangType());
3537 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3540 bool ptr_or_ref = false;
3541 if (type_info & (ClangASTType::eTypeIsPointer | ClangASTType::eTypeIsReference))
3544 type_info = pointee_type.GetTypeInfo();
3547 const uint32_t cpp_class = ClangASTType::eTypeIsClass | ClangASTType::eTypeIsCPlusPlus;
3548 if ((type_info & cpp_class) == cpp_class)
3552 address_type = GetAddressTypeOfChildren();
3553 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3556 return GetAddressOf (false, &address_type);
3560 address_type = eAddressTypeInvalid;
3561 return LLDB_INVALID_ADDRESS;
3565 ValueObject::Dereference (Error &error)
3568 return m_deref_valobj->GetSP();
3570 const bool is_pointer_type = IsPointerType();
3571 if (is_pointer_type)
3573 bool omit_empty_base_classes = true;
3574 bool ignore_array_bounds = false;
3576 std::string child_name_str;
3577 uint32_t child_byte_size = 0;
3578 int32_t child_byte_offset = 0;
3579 uint32_t child_bitfield_bit_size = 0;
3580 uint32_t child_bitfield_bit_offset = 0;
3581 bool child_is_base_class = false;
3582 bool child_is_deref_of_parent = false;
3583 const bool transparent_pointers = false;
3584 ClangASTType clang_type = GetClangType();
3585 ClangASTType child_clang_type;
3587 ExecutionContext exe_ctx (GetExecutionContextRef());
3589 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3591 transparent_pointers,
3592 omit_empty_base_classes,
3593 ignore_array_bounds,
3597 child_bitfield_bit_size,
3598 child_bitfield_bit_offset,
3599 child_is_base_class,
3600 child_is_deref_of_parent,
3602 if (child_clang_type && child_byte_size)
3604 ConstString child_name;
3605 if (!child_name_str.empty())
3606 child_name.SetCString (child_name_str.c_str());
3608 m_deref_valobj = new ValueObjectChild (*this,
3613 child_bitfield_bit_size,
3614 child_bitfield_bit_offset,
3615 child_is_base_class,
3616 child_is_deref_of_parent,
3617 eAddressTypeInvalid);
3624 return m_deref_valobj->GetSP();
3629 GetExpressionPath(strm, true);
3631 if (is_pointer_type)
3632 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3634 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3635 return ValueObjectSP();
3640 ValueObject::AddressOf (Error &error)
3642 if (m_addr_of_valobj_sp)
3643 return m_addr_of_valobj_sp;
3645 AddressType address_type = eAddressTypeInvalid;
3646 const bool scalar_is_load_address = false;
3647 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
3649 if (addr != LLDB_INVALID_ADDRESS)
3651 switch (address_type)
3653 case eAddressTypeInvalid:
3655 StreamString expr_path_strm;
3656 GetExpressionPath(expr_path_strm, true);
3657 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3661 case eAddressTypeFile:
3662 case eAddressTypeLoad:
3663 case eAddressTypeHost:
3665 ClangASTType clang_type = GetClangType();
3668 std::string name (1, '&');
3669 name.append (m_name.AsCString(""));
3670 ExecutionContext exe_ctx (GetExecutionContextRef());
3671 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3672 clang_type.GetPointerType(),
3673 ConstString (name.c_str()),
3675 eAddressTypeInvalid,
3676 m_data.GetAddressByteSize());
3684 StreamString expr_path_strm;
3685 GetExpressionPath(expr_path_strm, true);
3686 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3689 return m_addr_of_valobj_sp;
3693 ValueObject::Cast (const ClangASTType &clang_ast_type)
3695 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
3699 ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3701 ValueObjectSP valobj_sp;
3702 AddressType address_type;
3703 addr_t ptr_value = GetPointerValue (&address_type);
3705 if (ptr_value != LLDB_INVALID_ADDRESS)
3707 Address ptr_addr (ptr_value);
3708 ExecutionContext exe_ctx (GetExecutionContextRef());
3709 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3718 ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3720 ValueObjectSP valobj_sp;
3721 AddressType address_type;
3722 addr_t ptr_value = GetPointerValue (&address_type);
3724 if (ptr_value != LLDB_INVALID_ADDRESS)
3726 Address ptr_addr (ptr_value);
3727 ExecutionContext exe_ctx (GetExecutionContextRef());
3728 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3736 ValueObject::EvaluationPoint::EvaluationPoint () :
3739 m_needs_update (true),
3740 m_first_update (true)
3744 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
3747 m_needs_update (true),
3748 m_first_update (true)
3750 ExecutionContext exe_ctx(exe_scope);
3751 TargetSP target_sp (exe_ctx.GetTargetSP());
3754 m_exe_ctx_ref.SetTargetSP (target_sp);
3755 ProcessSP process_sp (exe_ctx.GetProcessSP());
3757 process_sp = target_sp->GetProcessSP();
3761 m_mod_id = process_sp->GetModID();
3762 m_exe_ctx_ref.SetProcessSP (process_sp);
3764 ThreadSP thread_sp (exe_ctx.GetThreadSP());
3769 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3774 m_exe_ctx_ref.SetThreadSP(thread_sp);
3776 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3780 frame_sp = thread_sp->GetSelectedFrame();
3783 m_exe_ctx_ref.SetFrameSP(frame_sp);
3789 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3791 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3792 m_needs_update (true),
3793 m_first_update (true)
3797 ValueObject::EvaluationPoint::~EvaluationPoint ()
3801 // This function checks the EvaluationPoint against the current process state. If the current
3802 // state matches the evaluation point, or the evaluation point is already invalid, then we return
3803 // false, meaning "no change". If the current state is different, we update our state, and return
3804 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3805 // future calls to NeedsUpdate will return true.
3806 // exe_scope will be set to the current execution context scope.
3809 ValueObject::EvaluationPoint::SyncWithProcessState()
3812 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3813 const bool thread_and_frame_only_if_stopped = true;
3814 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
3816 if (exe_ctx.GetTargetPtr() == NULL)
3819 // If we don't have a process nothing can change.
3820 Process *process = exe_ctx.GetProcessPtr();
3821 if (process == NULL)
3824 // If our stop id is the current stop ID, nothing has changed:
3825 ProcessModID current_mod_id = process->GetModID();
3827 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3828 // In either case, we aren't going to be able to sync with the process state.
3829 if (current_mod_id.GetStopID() == 0)
3832 bool changed = false;
3833 const bool was_valid = m_mod_id.IsValid();
3836 if (m_mod_id == current_mod_id)
3838 // Everything is already up to date in this object, no need to
3839 // update the execution context scope.
3844 m_mod_id = current_mod_id;
3845 m_needs_update = true;
3850 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3851 // That way we'll be sure to return a valid exe_scope.
3852 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
3854 if (m_exe_ctx_ref.HasThreadRef())
3856 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3859 if (m_exe_ctx_ref.HasFrameRef())
3861 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3864 // We used to have a frame, but now it is gone
3866 changed = was_valid;
3872 // We used to have a thread, but now it is gone
3874 changed = was_valid;
3882 ValueObject::EvaluationPoint::SetUpdated ()
3884 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3886 m_mod_id = process_sp->GetModID();
3887 m_first_update = false;
3888 m_needs_update = false;
3894 ValueObject::ClearUserVisibleData(uint32_t clear_mask)
3896 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3897 m_value_str.clear();
3899 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3900 m_location_str.clear();
3902 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3904 m_summary_str.clear();
3907 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3908 m_object_desc_str.clear();
3910 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3912 if (m_synthetic_value)
3913 m_synthetic_value = NULL;
3917 SymbolContextScope *
3918 ValueObject::GetSymbolContextScope()
3922 if (!m_parent->IsPointerOrReferenceType())
3923 return m_parent->GetSymbolContextScope();
3929 ValueObject::CreateValueObjectFromExpression (const char* name,
3930 const char* expression,
3931 const ExecutionContext& exe_ctx)
3933 lldb::ValueObjectSP retval_sp;
3934 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3937 if (!expression || !*expression)
3939 target_sp->EvaluateExpression (expression,
3940 exe_ctx.GetFrameSP().get(),
3942 if (retval_sp && name && *name)
3943 retval_sp->SetName(ConstString(name));
3948 ValueObject::CreateValueObjectFromAddress (const char* name,
3950 const ExecutionContext& exe_ctx,
3955 ClangASTType pointer_type(type.GetPointerType());
3958 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3959 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3963 lldb::endian::InlHostByteOrder(),
3964 exe_ctx.GetAddressByteSize()));
3965 if (ptr_result_valobj_sp)
3967 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3969 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3970 if (ptr_result_valobj_sp && name && *name)
3971 ptr_result_valobj_sp->SetName(ConstString(name));
3973 return ptr_result_valobj_sp;
3976 return lldb::ValueObjectSP();
3980 ValueObject::CreateValueObjectFromData (const char* name,
3981 const DataExtractor& data,
3982 const ExecutionContext& exe_ctx,
3985 lldb::ValueObjectSP new_value_sp;
3986 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3990 LLDB_INVALID_ADDRESS);
3991 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3992 if (new_value_sp && name && *name)
3993 new_value_sp->SetName(ConstString(name));
3994 return new_value_sp;
3998 ValueObject::GetModule ()
4000 ValueObject* root(GetRoot());
4002 return root->GetModule();
4003 return lldb::ModuleSP();
4007 ValueObject::GetRoot ()
4011 ValueObject* parent = m_parent;
4013 return (m_root = this);
4014 while (parent->m_parent)
4017 return (m_root = parent->m_root);
4018 parent = parent->m_parent;
4020 return (m_root = parent);
4024 ValueObject::GetAddressTypeOfChildren()
4026 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4028 ValueObject* root(GetRoot());
4030 return root->GetAddressTypeOfChildren();
4032 return m_address_type_of_ptr_or_ref_children;
4035 lldb::DynamicValueType
4036 ValueObject::GetDynamicValueType ()
4038 ValueObject* with_dv_info = this;
4039 while (with_dv_info)
4041 if (with_dv_info->HasDynamicValueTypeInfo())
4042 return with_dv_info->GetDynamicValueTypeImpl();
4043 with_dv_info = with_dv_info->m_parent;
4045 return lldb::eNoDynamicValues;
4049 ValueObject::GetFormat () const
4051 const ValueObject* with_fmt_info = this;
4052 while (with_fmt_info)
4054 if (with_fmt_info->m_format != lldb::eFormatDefault)
4055 return with_fmt_info->m_format;
4056 with_fmt_info = with_fmt_info->m_parent;