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"
38 #include "lldb/Host/Endian.h"
40 #include "lldb/Interpreter/CommandInterpreter.h"
41 #include "lldb/Interpreter/ScriptInterpreterPython.h"
43 #include "lldb/Symbol/ClangASTType.h"
44 #include "lldb/Symbol/ClangASTContext.h"
45 #include "lldb/Symbol/Type.h"
47 #include "lldb/Target/ExecutionContext.h"
48 #include "lldb/Target/LanguageRuntime.h"
49 #include "lldb/Target/ObjCLanguageRuntime.h"
50 #include "lldb/Target/Process.h"
51 #include "lldb/Target/RegisterContext.h"
52 #include "lldb/Target/Target.h"
53 #include "lldb/Target/Thread.h"
56 using namespace lldb_private;
57 using namespace lldb_utility;
59 static user_id_t g_value_obj_uid = 0;
61 //----------------------------------------------------------------------
62 // ValueObject constructor
63 //----------------------------------------------------------------------
64 ValueObject::ValueObject (ValueObject &parent) :
65 UserID (++g_value_obj_uid), // Unique identifier for every value object
68 m_update_point (parent.GetUpdatePoint ()),
78 m_manager(parent.GetManager()),
80 m_synthetic_children (),
81 m_dynamic_value (NULL),
82 m_synthetic_value(NULL),
84 m_format (eFormatDefault),
85 m_last_format (eFormatDefault),
86 m_last_format_mgr_revision(0),
89 m_synthetic_children_sp(),
90 m_user_id_of_forced_summary(),
91 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
92 m_value_is_valid (false),
93 m_value_did_change (false),
94 m_children_count_valid (false),
95 m_old_value_valid (false),
96 m_is_deref_of_parent (false),
97 m_is_array_item_for_pointer(false),
98 m_is_bitfield_for_scalar(false),
99 m_is_child_at_offset(false),
100 m_is_getting_summary(false),
101 m_did_calculate_complete_objc_class_type(false)
103 m_manager->ManageObject(this);
106 //----------------------------------------------------------------------
107 // ValueObject constructor
108 //----------------------------------------------------------------------
109 ValueObject::ValueObject (ExecutionContextScope *exe_scope,
110 AddressType child_ptr_or_ref_addr_type) :
111 UserID (++g_value_obj_uid), // Unique identifier for every value object
114 m_update_point (exe_scope),
123 m_object_desc_str (),
126 m_synthetic_children (),
127 m_dynamic_value (NULL),
128 m_synthetic_value(NULL),
129 m_deref_valobj(NULL),
130 m_format (eFormatDefault),
131 m_last_format (eFormatDefault),
132 m_last_format_mgr_revision(0),
135 m_synthetic_children_sp(),
136 m_user_id_of_forced_summary(),
137 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
138 m_value_is_valid (false),
139 m_value_did_change (false),
140 m_children_count_valid (false),
141 m_old_value_valid (false),
142 m_is_deref_of_parent (false),
143 m_is_array_item_for_pointer(false),
144 m_is_bitfield_for_scalar(false),
145 m_is_child_at_offset(false),
146 m_is_getting_summary(false),
147 m_did_calculate_complete_objc_class_type(false)
149 m_manager = new ValueObjectManager();
150 m_manager->ManageObject (this);
153 //----------------------------------------------------------------------
155 //----------------------------------------------------------------------
156 ValueObject::~ValueObject ()
161 ValueObject::UpdateValueIfNeeded (bool update_format)
164 bool did_change_formats = false;
167 did_change_formats = UpdateFormatsIfNeeded();
169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
173 // if you were asked to update your formatters, but did not get a chance to do it
174 // clear your own values (this serves the purpose of faking a stop-id for frozen
175 // objects (which are regarded as constant, but could have changes behind their backs
176 // because of the frozen-pointer depth limit)
177 // TODO: decouple summary from value and then remove this code and only force-clear the summary
178 if (update_format && !did_change_formats)
179 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
180 return m_error.Success();
183 bool first_update = m_update_point.IsFirstEvaluation();
185 if (m_update_point.NeedsUpdating())
187 m_update_point.SetUpdated();
189 // Save the old value using swap to avoid a string copy which
190 // also will clear our m_value_str
191 if (m_value_str.empty())
193 m_old_value_valid = false;
197 m_old_value_valid = true;
198 m_old_value_str.swap (m_value_str);
199 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
202 ClearUserVisibleData();
206 const bool value_was_valid = GetValueIsValid();
207 SetValueDidChange (false);
211 // Call the pure virtual function to update the value
212 bool success = UpdateValue ();
214 SetValueIsValid (success);
217 SetValueDidChange (false);
218 else if (!m_value_did_change && success == false)
220 // The value wasn't gotten successfully, so we mark this
221 // as changed if the value used to be valid and now isn't
222 SetValueDidChange (value_was_valid);
227 m_error.SetErrorString("out of scope");
230 return m_error.Success();
234 ValueObject::UpdateFormatsIfNeeded()
236 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
238 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
239 GetName().GetCString(),
241 m_last_format_mgr_revision,
242 DataVisualization::GetCurrentRevision());
244 bool any_change = false;
246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
248 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
250 #ifndef LLDB_DISABLE_PYTHON
251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
264 ValueObject::SetNeedsUpdate ()
266 m_update_point.SetNeedsUpdate();
267 // We have to clear the value string here so ConstResult children will notice if their values are
268 // changed by hand (i.e. with SetValueAsCString).
269 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
273 ValueObject::ClearDynamicTypeInformation ()
275 m_did_calculate_complete_objc_class_type = false;
276 m_last_format_mgr_revision = 0;
277 m_override_type = ClangASTType();
278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
284 ValueObject::MaybeCalculateCompleteType ()
286 ClangASTType clang_type(GetClangTypeImpl());
288 if (m_did_calculate_complete_objc_class_type)
290 if (m_override_type.IsValid())
291 return m_override_type;
296 ClangASTType class_type;
297 bool is_pointer_type = false;
299 if (clang_type.IsObjCObjectPointerType(&class_type))
301 is_pointer_type = true;
303 else if (clang_type.IsObjCObjectOrInterfaceType())
305 class_type = clang_type;
312 m_did_calculate_complete_objc_class_type = true;
316 ConstString class_name (class_type.GetConstTypeName());
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
324 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
326 if (objc_language_runtime)
328 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
330 if (complete_objc_class_type_sp)
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
334 if (complete_class.GetCompleteType())
338 m_override_type = complete_class.GetPointerType();
342 m_override_type = complete_class;
345 if (m_override_type.IsValid())
346 return m_override_type;
357 ValueObject::GetClangType ()
359 return MaybeCalculateCompleteType();
363 ValueObject::GetDataExtractor ()
365 UpdateValueIfNeeded(false);
370 ValueObject::GetError()
372 UpdateValueIfNeeded(false);
377 ValueObject::GetName() const
383 ValueObject::GetLocationAsCString ()
385 return GetLocationAsCStringImpl(m_value,
390 ValueObject::GetLocationAsCStringImpl (const Value& value,
391 const DataExtractor& data)
393 if (UpdateValueIfNeeded(false))
395 if (m_location_str.empty())
399 Value::ValueType value_type = value.GetValueType();
403 case Value::eValueTypeScalar:
404 case Value::eValueTypeVector:
405 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
407 RegisterInfo *reg_info = value.GetRegisterInfo();
411 m_location_str = reg_info->name;
412 else if (reg_info->alt_name)
413 m_location_str = reg_info->alt_name;
414 if (m_location_str.empty())
415 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
418 if (m_location_str.empty())
419 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
422 case Value::eValueTypeLoadAddress:
423 case Value::eValueTypeFileAddress:
424 case Value::eValueTypeHostAddress:
426 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
427 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
428 m_location_str.swap(sstr.GetString());
434 return m_location_str.c_str();
438 ValueObject::GetValue()
444 ValueObject::GetValue() const
450 ValueObject::ResolveValue (Scalar &scalar)
452 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
454 ExecutionContext exe_ctx (GetExecutionContextRef());
455 Value tmp_value(m_value);
456 scalar = tmp_value.ResolveValue(&exe_ctx);
457 if (scalar.IsValid())
459 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
460 if (bitfield_bit_size)
461 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
469 ValueObject::GetValueIsValid () const
471 return m_value_is_valid;
476 ValueObject::SetValueIsValid (bool b)
478 m_value_is_valid = b;
482 ValueObject::GetValueDidChange ()
484 GetValueAsCString ();
485 return m_value_did_change;
489 ValueObject::SetValueDidChange (bool value_changed)
491 m_value_did_change = value_changed;
495 ValueObject::GetChildAtIndex (size_t idx, bool can_create)
497 ValueObjectSP child_sp;
498 // We may need to update our value if we are dynamic
499 if (IsPossibleDynamicType ())
500 UpdateValueIfNeeded(false);
501 if (idx < GetNumChildren())
503 // Check if we have already made the child value object?
504 if (can_create && !m_children.HasChildAtIndex(idx))
506 // No we haven't created the child at this index, so lets have our
507 // subclass do it and cache the result for quick future access.
508 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
511 ValueObject* child = m_children.GetChildAtIndex(idx);
513 return child->GetSP();
519 ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
520 size_t* index_of_error)
522 if (idxs.size() == 0)
524 ValueObjectSP root(GetSP());
525 for (size_t idx : idxs)
527 root = root->GetChildAtIndex(idx, true);
531 *index_of_error = idx;
539 ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
540 size_t* index_of_error)
542 if (idxs.size() == 0)
544 ValueObjectSP root(GetSP());
545 for (std::pair<size_t, bool> idx : idxs)
547 root = root->GetChildAtIndex(idx.first, idx.second);
551 *index_of_error = idx.first;
559 ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
560 size_t* index_of_error)
562 if (idxs.size() == 0)
564 ValueObjectSP root(GetSP());
565 for (size_t idx : idxs)
567 root = root->GetChildAtIndex(idx, true);
571 *index_of_error = idx;
579 ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
580 size_t* index_of_error)
582 if (idxs.size() == 0)
584 ValueObjectSP root(GetSP());
585 for (std::pair<size_t, bool> idx : idxs)
587 root = root->GetChildAtIndex(idx.first, idx.second);
591 *index_of_error = idx.first;
599 ValueObject::GetIndexOfChildWithName (const ConstString &name)
601 bool omit_empty_base_classes = true;
602 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
606 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
608 // when getting a child by name, it could be buried inside some base
609 // classes (which really aren't part of the expression path), so we
610 // need a vector of indexes that can get us down to the correct child
611 ValueObjectSP child_sp;
613 // We may need to update our value if we are dynamic
614 if (IsPossibleDynamicType ())
615 UpdateValueIfNeeded(false);
617 std::vector<uint32_t> child_indexes;
618 bool omit_empty_base_classes = true;
619 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
620 omit_empty_base_classes,
622 if (num_child_indexes > 0)
624 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
625 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
627 child_sp = GetChildAtIndex(*pos, can_create);
628 for (++pos; pos != end; ++pos)
632 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
633 child_sp = new_child_sp;
647 ValueObject::GetNumChildren ()
649 UpdateValueIfNeeded();
650 if (!m_children_count_valid)
652 SetNumChildren (CalculateNumChildren());
654 return m_children.GetChildrenCount();
658 ValueObject::MightHaveChildren()
660 bool has_children = false;
661 const uint32_t type_info = GetTypeInfo();
664 if (type_info & (ClangASTType::eTypeHasChildren |
665 ClangASTType::eTypeIsPointer |
666 ClangASTType::eTypeIsReference))
671 has_children = GetNumChildren () > 0;
676 // Should only be called by ValueObject::GetNumChildren()
678 ValueObject::SetNumChildren (size_t num_children)
680 m_children_count_valid = true;
681 m_children.SetChildrenCount(num_children);
685 ValueObject::SetName (const ConstString &name)
691 ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
693 ValueObject *valobj = NULL;
695 bool omit_empty_base_classes = true;
696 bool ignore_array_bounds = synthetic_array_member;
697 std::string child_name_str;
698 uint32_t child_byte_size = 0;
699 int32_t child_byte_offset = 0;
700 uint32_t child_bitfield_bit_size = 0;
701 uint32_t child_bitfield_bit_offset = 0;
702 bool child_is_base_class = false;
703 bool child_is_deref_of_parent = false;
705 const bool transparent_pointers = synthetic_array_member == false;
706 ClangASTType child_clang_type;
708 ExecutionContext exe_ctx (GetExecutionContextRef());
710 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
711 GetName().GetCString(),
713 transparent_pointers,
714 omit_empty_base_classes,
719 child_bitfield_bit_size,
720 child_bitfield_bit_offset,
722 child_is_deref_of_parent);
723 if (child_clang_type)
726 child_byte_offset += child_byte_size * synthetic_index;
728 ConstString child_name;
729 if (!child_name_str.empty())
730 child_name.SetCString (child_name_str.c_str());
732 valobj = new ValueObjectChild (*this,
737 child_bitfield_bit_size,
738 child_bitfield_bit_offset,
740 child_is_deref_of_parent,
741 eAddressTypeInvalid);
743 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
750 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
751 std::string& destination)
755 // ideally we would like to bail out if passing NULL, but if we do so
756 // we end up not providing the summary for function pointers anymore
757 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
760 m_is_getting_summary = true;
762 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
763 // information that we might care to see in a crash log. might be useful in very specific situations though.
764 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
765 GetTypeName().GetCString(),
766 GetName().GetCString(),
767 summary_ptr->GetDescription().c_str());*/
769 if (UpdateValueIfNeeded (false))
773 if (HasSyntheticValue())
774 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
775 summary_ptr->FormatObject(this, destination);
779 ClangASTType clang_type = GetClangType();
781 // Do some default printout for function pointers
784 if (clang_type.IsFunctionPointerType ())
787 AddressType func_ptr_address_type = eAddressTypeInvalid;
788 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
789 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
791 switch (func_ptr_address_type)
793 case eAddressTypeInvalid:
794 case eAddressTypeFile:
797 case eAddressTypeLoad:
799 ExecutionContext exe_ctx (GetExecutionContextRef());
802 Target *target = exe_ctx.GetTargetPtr();
803 if (target && target->GetSectionLoadList().IsEmpty() == false)
805 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
808 exe_ctx.GetBestExecutionContextScope(),
809 Address::DumpStyleResolvedDescription,
810 Address::DumpStyleSectionNameOffset);
816 case eAddressTypeHost:
820 if (sstr.GetSize() > 0)
822 destination.assign (1, '(');
823 destination.append (sstr.GetData(), sstr.GetSize());
824 destination.append (1, ')');
830 m_is_getting_summary = false;
831 return !destination.empty();
835 ValueObject::GetSummaryAsCString ()
837 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
839 GetSummaryAsCString(GetSummaryFormat().get(),
842 if (m_summary_str.empty())
844 return m_summary_str.c_str();
848 ValueObject::IsCStringContainer(bool check_pointer)
850 ClangASTType pointee_or_element_clang_type;
851 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
852 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
853 pointee_or_element_clang_type.IsCharType ());
854 if (!is_char_arr_ptr)
858 if (type_flags.Test(ClangASTType::eTypeIsArray))
860 addr_t cstr_address = LLDB_INVALID_ADDRESS;
861 AddressType cstr_address_type = eAddressTypeInvalid;
862 cstr_address = GetAddressOf (true, &cstr_address_type);
863 return (cstr_address != LLDB_INVALID_ADDRESS);
867 ValueObject::GetPointeeData (DataExtractor& data,
871 ClangASTType pointee_or_element_clang_type;
872 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
873 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
874 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
875 if (!(is_pointer_type || is_array_type))
881 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
882 const uint64_t bytes = item_count * item_type_size;
883 const uint64_t offset = item_idx * item_type_size;
885 if (item_idx == 0 && item_count == 1) // simply a deref
890 ValueObjectSP pointee_sp = Dereference(error);
891 if (error.Fail() || pointee_sp.get() == NULL)
893 return pointee_sp->GetDataExtractor().Copy(data);
897 ValueObjectSP child_sp = GetChildAtIndex(0, true);
898 if (child_sp.get() == NULL)
900 return child_sp->GetDataExtractor().Copy(data);
904 else /* (items > 1) */
907 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
908 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
910 AddressType addr_type;
911 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
915 case eAddressTypeFile:
917 ModuleSP module_sp (GetModule());
920 addr = addr + offset;
922 module_sp->ResolveFileAddress(addr, so_addr);
923 ExecutionContext exe_ctx (GetExecutionContextRef());
924 Target* target = exe_ctx.GetTargetPtr();
927 heap_buf_ptr->SetByteSize(bytes);
928 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
931 data.SetData(data_sp);
938 case eAddressTypeLoad:
940 ExecutionContext exe_ctx (GetExecutionContextRef());
941 Process *process = exe_ctx.GetProcessPtr();
944 heap_buf_ptr->SetByteSize(bytes);
945 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
948 data.SetData(data_sp);
954 case eAddressTypeHost:
956 const uint64_t max_bytes = GetClangType().GetByteSize();
957 if (max_bytes > offset)
959 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
960 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
961 data.SetData(data_sp);
966 case eAddressTypeInvalid:
974 ValueObject::GetData (DataExtractor& data)
976 UpdateValueIfNeeded(false);
977 ExecutionContext exe_ctx (GetExecutionContextRef());
978 Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
981 if (m_data.GetByteSize())
984 return data.GetByteSize();
991 data.SetAddressByteSize(m_data.GetAddressByteSize());
992 data.SetByteOrder(m_data.GetByteOrder());
993 return data.GetByteSize();
997 ValueObject::SetData (DataExtractor &data, Error &error)
1000 // Make sure our value is up to date first so that our location and location
1002 if (!UpdateValueIfNeeded(false))
1004 error.SetErrorString("unable to read value");
1009 const Encoding encoding = GetClangType().GetEncoding(count);
1011 const size_t byte_size = GetByteSize();
1013 Value::ValueType value_type = m_value.GetValueType();
1017 case Value::eValueTypeScalar:
1019 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1021 if (!set_error.Success())
1023 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1028 case Value::eValueTypeLoadAddress:
1030 // If it is a load address, then the scalar value is the storage location
1031 // of the data, and we have to shove this value down to that load location.
1032 ExecutionContext exe_ctx (GetExecutionContextRef());
1033 Process *process = exe_ctx.GetProcessPtr();
1036 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1037 size_t bytes_written = process->WriteMemory(target_addr,
1038 data.GetDataStart(),
1041 if (!error.Success())
1043 if (bytes_written != byte_size)
1045 error.SetErrorString("unable to write value to memory");
1051 case Value::eValueTypeHostAddress:
1053 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1054 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1055 m_data.SetData(buffer_sp, 0);
1056 data.CopyByteOrderedData (0,
1058 const_cast<uint8_t *>(m_data.GetDataStart()),
1060 m_data.GetByteOrder());
1061 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1064 case Value::eValueTypeFileAddress:
1065 case Value::eValueTypeVector:
1069 // If we have reached this point, then we have successfully changed the value.
1074 // will compute strlen(str), but without consuming more than
1075 // maxlen bytes out of str (this serves the purpose of reading
1076 // chunks of a string without having to worry about
1077 // missing NULL terminators in the chunk)
1078 // of course, if strlen(str) > maxlen, the function will return
1079 // maxlen_value (which should be != maxlen, because that allows you
1080 // to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1082 strlen_or_inf (const char* str,
1084 uint32_t maxlen_value)
1093 return maxlen_value;
1100 ValueObject::ReadPointedString (Stream& s,
1102 uint32_t max_length,
1106 ExecutionContext exe_ctx (GetExecutionContextRef());
1107 Target* target = exe_ctx.GetTargetPtr();
1111 s << "<no target to read from>";
1112 error.SetErrorString("no target to read from");
1116 if (max_length == 0)
1117 max_length = target->GetMaximumSizeOfStringSummary();
1119 size_t bytes_read = 0;
1120 size_t total_bytes_read = 0;
1122 ClangASTType clang_type = GetClangType();
1123 ClangASTType elem_or_pointee_clang_type;
1124 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
1125 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1126 elem_or_pointee_clang_type.IsCharType ())
1128 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1129 AddressType cstr_address_type = eAddressTypeInvalid;
1131 size_t cstr_len = 0;
1132 bool capped_data = false;
1133 if (type_flags.Test (ClangASTType::eTypeIsArray))
1136 uint64_t array_size = 0;
1137 if (clang_type.IsArrayType(NULL, &array_size, NULL))
1139 cstr_len = array_size;
1140 if (cstr_len > max_length)
1143 cstr_len = max_length;
1146 cstr_address = GetAddressOf (true, &cstr_address_type);
1150 // We have a pointer
1151 cstr_address = GetPointerValue (&cstr_address_type);
1154 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1156 s << "<invalid address>";
1157 error.SetErrorString("invalid address");
1161 Address cstr_so_addr (cstr_address);
1163 if (cstr_len > 0 && honor_array)
1165 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1166 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1167 GetPointeeData(data, 0, cstr_len);
1169 if ((bytes_read = data.GetByteSize()) > 0)
1171 total_bytes_read = bytes_read;
1174 0, // Start offset in "data"
1176 1, // Size of item (1 byte for a char!)
1177 bytes_read, // How many bytes to print?
1178 UINT32_MAX, // num per line
1179 LLDB_INVALID_ADDRESS,// base address
1180 0, // bitfield bit size
1181 0); // bitfield bit offset
1189 cstr_len = max_length;
1190 const size_t k_max_buf_size = 64;
1194 int cstr_len_displayed = -1;
1195 bool capped_cstr = false;
1196 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1197 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1198 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
1200 total_bytes_read += bytes_read;
1201 const char *cstr = data.PeekCStr(0);
1202 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1203 if (len > k_max_buf_size)
1204 len = k_max_buf_size;
1205 if (cstr && cstr_len_displayed < 0)
1208 if (cstr_len_displayed < 0)
1209 cstr_len_displayed = len;
1213 cstr_len_displayed += len;
1214 if (len > bytes_read)
1220 0, // Start offset in "data"
1222 1, // Size of item (1 byte for a char!)
1223 len, // How many bytes to print?
1224 UINT32_MAX, // num per line
1225 LLDB_INVALID_ADDRESS,// base address
1226 0, // bitfield bit size
1227 0); // bitfield bit offset
1229 if (len < k_max_buf_size)
1232 if (len >= cstr_len)
1242 if (cstr_len_displayed >= 0)
1252 error.SetErrorString("not a string object");
1253 s << "<not a string object>";
1255 return total_bytes_read;
1259 ValueObject::GetObjectDescription ()
1262 if (!UpdateValueIfNeeded (true))
1265 if (!m_object_desc_str.empty())
1266 return m_object_desc_str.c_str();
1268 ExecutionContext exe_ctx (GetExecutionContextRef());
1269 Process *process = exe_ctx.GetProcessPtr();
1270 if (process == NULL)
1275 LanguageType language = GetObjectRuntimeLanguage();
1276 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1278 if (runtime == NULL)
1280 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
1281 ClangASTType clang_type = GetClangType();
1285 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
1287 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
1292 if (runtime && runtime->GetObjectDescription(s, *this))
1294 m_object_desc_str.append (s.GetData());
1297 if (m_object_desc_str.empty())
1300 return m_object_desc_str.c_str();
1304 ValueObject::GetValueAsCString (lldb::Format format,
1305 std::string& destination)
1307 if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
1309 const Value::ContextType context_type = m_value.GetContextType();
1311 if (context_type == Value::eContextTypeRegisterInfo)
1313 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1316 ExecutionContext exe_ctx (GetExecutionContextRef());
1318 StreamString reg_sstr;
1319 m_data.Dump (®_sstr,
1322 reg_info->byte_size,
1325 LLDB_INVALID_ADDRESS,
1328 exe_ctx.GetBestExecutionContextScope());
1329 destination.swap(reg_sstr.GetString());
1334 ClangASTType clang_type = GetClangType ();
1337 // put custom bytes to display in this DataExtractor to override the default value logic
1338 lldb_private::DataExtractor special_format_data;
1339 if (format == eFormatCString)
1341 Flags type_flags(clang_type.GetTypeInfo(NULL));
1342 if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
1344 // if we are dumping a pointer as a c-string, get the pointee data as a string
1345 TargetSP target_sp(GetTargetSP());
1348 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1350 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1351 Address address(GetPointerValue());
1352 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1353 special_format_data.SetData(buffer_sp);
1359 ExecutionContext exe_ctx (GetExecutionContextRef());
1360 clang_type.DumpTypeValue (&sstr, // The stream to use for display
1361 format, // Format to display this type with
1362 special_format_data.GetByteSize() ?
1363 special_format_data: m_data, // Data to extract from
1364 0, // Byte offset into "m_data"
1365 GetByteSize(), // Byte size of item in "m_data"
1366 GetBitfieldBitSize(), // Bitfield bit size
1367 GetBitfieldBitOffset(), // Bitfield bit offset
1368 exe_ctx.GetBestExecutionContextScope());
1369 // Don't set the m_error to anything here otherwise
1370 // we won't be able to re-format as anything else. The
1371 // code for ClangASTType::DumpTypeValue() should always
1372 // return something, even if that something contains
1373 // an error messsage. "m_error" is used to detect errors
1374 // when reading the valid object, not for formatting errors.
1375 if (sstr.GetString().empty())
1376 destination.clear();
1378 destination.swap(sstr.GetString());
1381 return !destination.empty();
1388 ValueObject::GetValueAsCString ()
1390 if (UpdateValueIfNeeded(true))
1392 lldb::Format my_format = GetFormat();
1393 if (my_format == lldb::eFormatDefault)
1395 if (m_type_format_sp)
1396 my_format = m_type_format_sp->GetFormat();
1399 if (m_is_bitfield_for_scalar)
1400 my_format = eFormatUnsigned;
1403 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
1405 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1407 my_format = reg_info->format;
1411 my_format = GetClangType().GetFormat();
1416 if (my_format != m_last_format || m_value_str.empty())
1418 m_last_format = my_format;
1419 if (GetValueAsCString(my_format, m_value_str))
1421 if (!m_value_did_change && m_old_value_valid)
1423 // The value was gotten successfully, so we consider the
1424 // value as changed if the value string differs
1425 SetValueDidChange (m_old_value_str != m_value_str);
1430 if (m_value_str.empty())
1432 return m_value_str.c_str();
1435 // if > 8bytes, 0 is returned. this method should mostly be used
1436 // to read address values out of pointers
1438 ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
1440 // If our byte size is zero this is an aggregate type that has children
1441 if (!GetClangType().IsAggregateType())
1444 if (ResolveValue (scalar))
1448 return scalar.ULongLong(fail_value);
1450 // fallthrough, otherwise...
1458 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1459 // this call up to date by returning true for your new special cases. We will eventually move
1460 // to checking this call result before trying to display special cases
1462 ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1463 Format custom_format)
1465 Flags flags(GetTypeInfo());
1466 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1467 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1469 if (IsCStringContainer(true) &&
1470 (custom_format == eFormatCString ||
1471 custom_format == eFormatCharArray ||
1472 custom_format == eFormatChar ||
1473 custom_format == eFormatVectorOfChar))
1476 if (flags.Test(ClangASTType::eTypeIsArray))
1478 if ((custom_format == eFormatBytes) ||
1479 (custom_format == eFormatBytesWithASCII))
1482 if ((custom_format == eFormatVectorOfChar) ||
1483 (custom_format == eFormatVectorOfFloat32) ||
1484 (custom_format == eFormatVectorOfFloat64) ||
1485 (custom_format == eFormatVectorOfSInt16) ||
1486 (custom_format == eFormatVectorOfSInt32) ||
1487 (custom_format == eFormatVectorOfSInt64) ||
1488 (custom_format == eFormatVectorOfSInt8) ||
1489 (custom_format == eFormatVectorOfUInt128) ||
1490 (custom_format == eFormatVectorOfUInt16) ||
1491 (custom_format == eFormatVectorOfUInt32) ||
1492 (custom_format == eFormatVectorOfUInt64) ||
1493 (custom_format == eFormatVectorOfUInt8))
1501 ValueObject::DumpPrintableRepresentation(Stream& s,
1502 ValueObjectRepresentationStyle val_obj_display,
1503 Format custom_format,
1504 PrintableRepresentationSpecialCases special)
1507 Flags flags(GetTypeInfo());
1509 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1510 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1514 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
1515 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
1517 // when being asked to get a printable display an array or pointer type directly,
1518 // try to "do the right thing"
1520 if (IsCStringContainer(true) &&
1521 (custom_format == eFormatCString ||
1522 custom_format == eFormatCharArray ||
1523 custom_format == eFormatChar ||
1524 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
1527 ReadPointedString(s,
1530 (custom_format == eFormatVectorOfChar) ||
1531 (custom_format == eFormatCharArray));
1532 return !error.Fail();
1535 if (custom_format == eFormatEnum)
1538 // this only works for arrays, because I have no way to know when
1539 // the pointed memory ends, and no special \0 end of data marker
1540 if (flags.Test(ClangASTType::eTypeIsArray))
1542 if ((custom_format == eFormatBytes) ||
1543 (custom_format == eFormatBytesWithASCII))
1545 const size_t count = GetNumChildren();
1548 for (size_t low = 0; low < count; low++)
1554 ValueObjectSP child = GetChildAtIndex(low,true);
1557 s << "<invalid child>";
1560 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1568 if ((custom_format == eFormatVectorOfChar) ||
1569 (custom_format == eFormatVectorOfFloat32) ||
1570 (custom_format == eFormatVectorOfFloat64) ||
1571 (custom_format == eFormatVectorOfSInt16) ||
1572 (custom_format == eFormatVectorOfSInt32) ||
1573 (custom_format == eFormatVectorOfSInt64) ||
1574 (custom_format == eFormatVectorOfSInt8) ||
1575 (custom_format == eFormatVectorOfUInt128) ||
1576 (custom_format == eFormatVectorOfUInt16) ||
1577 (custom_format == eFormatVectorOfUInt32) ||
1578 (custom_format == eFormatVectorOfUInt64) ||
1579 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1581 const size_t count = GetNumChildren();
1583 Format format = FormatManager::GetSingleItemFormat(custom_format);
1586 for (size_t low = 0; low < count; low++)
1592 ValueObjectSP child = GetChildAtIndex(low,true);
1595 s << "<invalid child>";
1598 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1607 if ((custom_format == eFormatBoolean) ||
1608 (custom_format == eFormatBinary) ||
1609 (custom_format == eFormatChar) ||
1610 (custom_format == eFormatCharPrintable) ||
1611 (custom_format == eFormatComplexFloat) ||
1612 (custom_format == eFormatDecimal) ||
1613 (custom_format == eFormatHex) ||
1614 (custom_format == eFormatHexUppercase) ||
1615 (custom_format == eFormatFloat) ||
1616 (custom_format == eFormatOctal) ||
1617 (custom_format == eFormatOSType) ||
1618 (custom_format == eFormatUnicode16) ||
1619 (custom_format == eFormatUnicode32) ||
1620 (custom_format == eFormatUnsigned) ||
1621 (custom_format == eFormatPointer) ||
1622 (custom_format == eFormatComplexInteger) ||
1623 (custom_format == eFormatComplex) ||
1624 (custom_format == eFormatDefault)) // use the [] operator
1632 bool var_success = false;
1635 const char *cstr = NULL;
1637 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1638 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1639 // area for cases where our desired output is not backed by some other longer-term storage
1642 if (custom_format != eFormatInvalid)
1643 SetFormat(custom_format);
1645 switch(val_obj_display)
1647 case eValueObjectRepresentationStyleValue:
1648 cstr = GetValueAsCString();
1651 case eValueObjectRepresentationStyleSummary:
1652 cstr = GetSummaryAsCString();
1655 case eValueObjectRepresentationStyleLanguageSpecific:
1656 cstr = GetObjectDescription();
1659 case eValueObjectRepresentationStyleLocation:
1660 cstr = GetLocationAsCString();
1663 case eValueObjectRepresentationStyleChildrenCount:
1664 strm.Printf("%zu", GetNumChildren());
1665 cstr = strm.GetString().c_str();
1668 case eValueObjectRepresentationStyleType:
1669 cstr = GetTypeName().AsCString();
1672 case eValueObjectRepresentationStyleName:
1673 cstr = GetName().AsCString();
1676 case eValueObjectRepresentationStyleExpressionPath:
1677 GetExpressionPath(strm, false);
1678 cstr = strm.GetString().c_str();
1684 if (val_obj_display == eValueObjectRepresentationStyleValue)
1685 cstr = GetSummaryAsCString();
1686 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1688 if (GetClangType().IsAggregateType())
1690 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1691 cstr = strm.GetString().c_str();
1694 cstr = GetValueAsCString();
1703 s.Printf("<%s>", m_error.AsCString());
1704 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1705 s.PutCString("<no summary available>");
1706 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1707 s.PutCString("<no value available>");
1708 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1709 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1711 s.PutCString("<no printable representation>");
1714 // we should only return false here if we could not do *anything*
1715 // even if we have an error message as output, that's a success
1716 // from our callers' perspective, so return true
1719 if (custom_format != eFormatInvalid)
1720 SetFormat(eFormatDefault);
1727 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
1729 if (!UpdateValueIfNeeded(false))
1730 return LLDB_INVALID_ADDRESS;
1732 switch (m_value.GetValueType())
1734 case Value::eValueTypeScalar:
1735 case Value::eValueTypeVector:
1736 if (scalar_is_load_address)
1739 *address_type = eAddressTypeLoad;
1740 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1744 case Value::eValueTypeLoadAddress:
1745 case Value::eValueTypeFileAddress:
1746 case Value::eValueTypeHostAddress:
1749 *address_type = m_value.GetValueAddressType ();
1750 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1755 *address_type = eAddressTypeInvalid;
1756 return LLDB_INVALID_ADDRESS;
1760 ValueObject::GetPointerValue (AddressType *address_type)
1762 addr_t address = LLDB_INVALID_ADDRESS;
1764 *address_type = eAddressTypeInvalid;
1766 if (!UpdateValueIfNeeded(false))
1769 switch (m_value.GetValueType())
1771 case Value::eValueTypeScalar:
1772 case Value::eValueTypeVector:
1773 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1776 case Value::eValueTypeHostAddress:
1777 case Value::eValueTypeLoadAddress:
1778 case Value::eValueTypeFileAddress:
1780 lldb::offset_t data_offset = 0;
1781 address = m_data.GetPointer(&data_offset);
1787 *address_type = GetAddressTypeOfChildren();
1793 ValueObject::SetValueFromCString (const char *value_str, Error& error)
1796 // Make sure our value is up to date first so that our location and location
1798 if (!UpdateValueIfNeeded(false))
1800 error.SetErrorString("unable to read value");
1805 const Encoding encoding = GetClangType().GetEncoding (count);
1807 const size_t byte_size = GetByteSize();
1809 Value::ValueType value_type = m_value.GetValueType();
1811 if (value_type == Value::eValueTypeScalar)
1813 // If the value is already a scalar, then let the scalar change itself:
1814 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1816 else if (byte_size <= Scalar::GetMaxByteSize())
1818 // If the value fits in a scalar, then make a new scalar and again let the
1819 // scalar code do the conversion, then figure out where to put the new value.
1821 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1822 if (error.Success())
1826 case Value::eValueTypeLoadAddress:
1828 // If it is a load address, then the scalar value is the storage location
1829 // of the data, and we have to shove this value down to that load location.
1830 ExecutionContext exe_ctx (GetExecutionContextRef());
1831 Process *process = exe_ctx.GetProcessPtr();
1834 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1835 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1839 if (!error.Success())
1841 if (bytes_written != byte_size)
1843 error.SetErrorString("unable to write value to memory");
1849 case Value::eValueTypeHostAddress:
1851 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1852 DataExtractor new_data;
1853 new_data.SetByteOrder (m_data.GetByteOrder());
1855 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1856 m_data.SetData(buffer_sp, 0);
1857 bool success = new_scalar.GetData(new_data);
1860 new_data.CopyByteOrderedData (0,
1862 const_cast<uint8_t *>(m_data.GetDataStart()),
1864 m_data.GetByteOrder());
1866 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1870 case Value::eValueTypeFileAddress:
1871 case Value::eValueTypeScalar:
1872 case Value::eValueTypeVector:
1883 // We don't support setting things bigger than a scalar at present.
1884 error.SetErrorString("unable to write aggregate data type");
1888 // If we have reached this point, then we have successfully changed the value.
1894 ValueObject::GetDeclaration (Declaration &decl)
1901 ValueObject::GetTypeName()
1903 return GetClangType().GetConstTypeName();
1907 ValueObject::GetQualifiedTypeName()
1909 return GetClangType().GetConstQualifiedTypeName();
1914 ValueObject::GetObjectRuntimeLanguage ()
1916 return GetClangType().GetMinimumLanguage ();
1920 ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
1922 m_synthetic_children[key] = valobj;
1926 ValueObject::GetSyntheticChild (const ConstString &key) const
1928 ValueObjectSP synthetic_child_sp;
1929 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
1930 if (pos != m_synthetic_children.end())
1931 synthetic_child_sp = pos->second->GetSP();
1932 return synthetic_child_sp;
1936 ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
1938 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
1942 ValueObject::IsPointerType ()
1944 return GetClangType().IsPointerType();
1948 ValueObject::IsArrayType ()
1950 return GetClangType().IsArrayType (NULL, NULL, NULL);
1954 ValueObject::IsScalarType ()
1956 return GetClangType().IsScalarType ();
1960 ValueObject::IsIntegerType (bool &is_signed)
1962 return GetClangType().IsIntegerType (is_signed);
1966 ValueObject::IsPointerOrReferenceType ()
1968 return GetClangType().IsPointerOrReferenceType ();
1972 ValueObject::IsPossibleDynamicType ()
1974 ExecutionContext exe_ctx (GetExecutionContextRef());
1975 Process *process = exe_ctx.GetProcessPtr();
1977 return process->IsPossibleDynamicValue(*this);
1979 return GetClangType().IsPossibleDynamicType (NULL, true, true);
1983 ValueObject::IsObjCNil ()
1985 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
1986 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
1989 bool canReadValue = true;
1990 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
1991 return canReadValue && isZero;
1995 ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
1997 const uint32_t type_info = GetTypeInfo ();
1998 if (type_info & ClangASTType::eTypeIsArray)
1999 return GetSyntheticArrayMemberFromArray(index, can_create);
2001 if (type_info & ClangASTType::eTypeIsPointer)
2002 return GetSyntheticArrayMemberFromPointer(index, can_create);
2004 return ValueObjectSP();
2009 ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
2011 ValueObjectSP synthetic_child_sp;
2012 if (IsPointerType ())
2015 snprintf(index_str, sizeof(index_str), "[%zu]", index);
2016 ConstString index_const_str(index_str);
2017 // Check if we have already created a synthetic array member in this
2018 // valid object. If we have we will re-use it.
2019 synthetic_child_sp = GetSyntheticChild (index_const_str);
2020 if (!synthetic_child_sp)
2022 ValueObject *synthetic_child;
2023 // We haven't made a synthetic array member for INDEX yet, so
2024 // lets make one and cache it for any future reference.
2025 synthetic_child = CreateChildAtIndex(0, true, index);
2027 // Cache the value if we got one back...
2028 if (synthetic_child)
2030 AddSyntheticChild(index_const_str, synthetic_child);
2031 synthetic_child_sp = synthetic_child->GetSP();
2032 synthetic_child_sp->SetName(ConstString(index_str));
2033 synthetic_child_sp->m_is_array_item_for_pointer = true;
2037 return synthetic_child_sp;
2040 // This allows you to create an array member using and index
2041 // that doesn't not fall in the normal bounds of the array.
2042 // Many times structure can be defined as:
2043 // struct Collection
2045 // uint32_t item_count;
2046 // Item item_array[0];
2048 // The size of the "item_array" is 1, but many times in practice
2049 // there are more items in "item_array".
2052 ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
2054 ValueObjectSP synthetic_child_sp;
2058 snprintf(index_str, sizeof(index_str), "[%zu]", index);
2059 ConstString index_const_str(index_str);
2060 // Check if we have already created a synthetic array member in this
2061 // valid object. If we have we will re-use it.
2062 synthetic_child_sp = GetSyntheticChild (index_const_str);
2063 if (!synthetic_child_sp)
2065 ValueObject *synthetic_child;
2066 // We haven't made a synthetic array member for INDEX yet, so
2067 // lets make one and cache it for any future reference.
2068 synthetic_child = CreateChildAtIndex(0, true, index);
2070 // Cache the value if we got one back...
2071 if (synthetic_child)
2073 AddSyntheticChild(index_const_str, synthetic_child);
2074 synthetic_child_sp = synthetic_child->GetSP();
2075 synthetic_child_sp->SetName(ConstString(index_str));
2076 synthetic_child_sp->m_is_array_item_for_pointer = true;
2080 return synthetic_child_sp;
2084 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2086 ValueObjectSP synthetic_child_sp;
2087 if (IsScalarType ())
2090 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2091 ConstString index_const_str(index_str);
2092 // Check if we have already created a synthetic array member in this
2093 // valid object. If we have we will re-use it.
2094 synthetic_child_sp = GetSyntheticChild (index_const_str);
2095 if (!synthetic_child_sp)
2097 // We haven't made a synthetic array member for INDEX yet, so
2098 // lets make one and cache it for any future reference.
2099 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2108 eAddressTypeInvalid);
2110 // Cache the value if we got one back...
2111 if (synthetic_child)
2113 AddSyntheticChild(index_const_str, synthetic_child);
2114 synthetic_child_sp = synthetic_child->GetSP();
2115 synthetic_child_sp->SetName(ConstString(index_str));
2116 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2120 return synthetic_child_sp;
2124 ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2127 ValueObjectSP synthetic_child_sp;
2130 snprintf(name_str, sizeof(name_str), "@%i", offset);
2131 ConstString name_const_str(name_str);
2133 // Check if we have already created a synthetic array member in this
2134 // valid object. If we have we will re-use it.
2135 synthetic_child_sp = GetSyntheticChild (name_const_str);
2137 if (synthetic_child_sp.get())
2138 return synthetic_child_sp;
2141 return ValueObjectSP();
2143 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2152 eAddressTypeInvalid);
2153 if (synthetic_child)
2155 AddSyntheticChild(name_const_str, synthetic_child);
2156 synthetic_child_sp = synthetic_child->GetSP();
2157 synthetic_child_sp->SetName(name_const_str);
2158 synthetic_child_sp->m_is_child_at_offset = true;
2160 return synthetic_child_sp;
2163 // your expression path needs to have a leading . or ->
2164 // (unless it somehow "looks like" an array, in which case it has
2165 // a leading [ symbol). while the [ is meaningful and should be shown
2166 // to the user, . and -> are just parser design, but by no means
2167 // added information for the user.. strip them off
2169 SkipLeadingExpressionPathSeparators(const char* expression)
2171 if (!expression || !expression[0])
2173 if (expression[0] == '.')
2174 return expression+1;
2175 if (expression[0] == '-' && expression[1] == '>')
2176 return expression+2;
2181 ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2183 ValueObjectSP synthetic_child_sp;
2184 ConstString name_const_string(expression);
2185 // Check if we have already created a synthetic array member in this
2186 // valid object. If we have we will re-use it.
2187 synthetic_child_sp = GetSyntheticChild (name_const_string);
2188 if (!synthetic_child_sp)
2190 // We haven't made a synthetic array member for expression yet, so
2191 // lets make one and cache it for any future reference.
2192 synthetic_child_sp = GetValueForExpressionPath(expression,
2194 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
2196 // Cache the value if we got one back...
2197 if (synthetic_child_sp.get())
2199 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
2200 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
2201 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
2204 return synthetic_child_sp;
2208 ValueObject::CalculateSyntheticValue (bool use_synthetic)
2210 if (use_synthetic == false)
2213 TargetSP target_sp(GetTargetSP());
2214 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2216 m_synthetic_value = NULL;
2220 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2222 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
2225 if (m_synthetic_children_sp.get() == NULL)
2228 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2231 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
2235 ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
2237 if (use_dynamic == eNoDynamicValues)
2240 if (!m_dynamic_value && !IsDynamic())
2242 ExecutionContext exe_ctx (GetExecutionContextRef());
2243 Process *process = exe_ctx.GetProcessPtr();
2244 if (process && process->IsPossibleDynamicValue(*this))
2246 ClearDynamicTypeInformation ();
2247 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2253 ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
2255 if (use_dynamic == eNoDynamicValues)
2256 return ValueObjectSP();
2258 if (!IsDynamic() && m_dynamic_value == NULL)
2260 CalculateDynamicValue(use_dynamic);
2262 if (m_dynamic_value)
2263 return m_dynamic_value->GetSP();
2265 return ValueObjectSP();
2269 ValueObject::GetStaticValue()
2275 ValueObject::GetNonSyntheticValue ()
2281 ValueObject::GetSyntheticValue (bool use_synthetic)
2283 if (use_synthetic == false)
2284 return ValueObjectSP();
2286 CalculateSyntheticValue(use_synthetic);
2288 if (m_synthetic_value)
2289 return m_synthetic_value->GetSP();
2291 return ValueObjectSP();
2295 ValueObject::HasSyntheticValue()
2297 UpdateFormatsIfNeeded();
2299 if (m_synthetic_children_sp.get() == NULL)
2302 CalculateSyntheticValue(true);
2304 if (m_synthetic_value)
2311 ValueObject::GetBaseClassPath (Stream &s)
2315 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
2316 ClangASTType clang_type = GetClangType();
2317 std::string cxx_class_name;
2318 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
2319 if (this_had_base_class)
2321 if (parent_had_base_class)
2323 s.PutCString(cxx_class_name.c_str());
2325 return parent_had_base_class || this_had_base_class;
2332 ValueObject::GetNonBaseClassParent()
2336 if (GetParent()->IsBaseClass())
2337 return GetParent()->GetNonBaseClassParent();
2345 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
2347 const bool is_deref_of_parent = IsDereferenceOfParent ();
2349 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2351 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2352 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2353 // the eHonorPointers mode is meant to produce strings in this latter format
2357 ValueObject* parent = GetParent();
2360 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
2362 // if we are a deref_of_parent just because we are synthetic array
2363 // members made up to allow ptr[%d] syntax to work in variable
2364 // printing, then add our name ([%d]) to the expression path
2365 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
2366 s.PutCString(m_name.AsCString());
2370 if (!is_deref_of_parent)
2372 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2373 if (non_base_class_parent)
2375 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2376 if (non_base_class_parent_clang_type)
2378 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
2384 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2386 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
2390 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2391 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
2399 const char *name = GetName().GetCString();
2402 if (qualify_cxx_base_classes)
2404 if (GetBaseClassPath (s))
2412 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
2419 ValueObject::GetValueForExpressionPath(const char* expression,
2420 const char** first_unparsed,
2421 ExpressionPathScanEndReason* reason_to_stop,
2422 ExpressionPathEndResultType* final_value_type,
2423 const GetValueForExpressionPathOptions& options,
2424 ExpressionPathAftermath* final_task_on_target)
2427 const char* dummy_first_unparsed;
2428 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2429 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2430 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2432 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2433 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2434 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2435 final_value_type ? final_value_type : &dummy_final_value_type,
2437 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2439 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2442 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
2444 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
2447 ValueObjectSP final_value = ret_val->Dereference(error);
2448 if (error.Fail() || !final_value.get())
2451 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2452 if (final_value_type)
2453 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2454 return ValueObjectSP();
2458 if (final_task_on_target)
2459 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2463 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2466 ValueObjectSP final_value = ret_val->AddressOf(error);
2467 if (error.Fail() || !final_value.get())
2470 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2471 if (final_value_type)
2472 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2473 return ValueObjectSP();
2477 if (final_task_on_target)
2478 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2483 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2487 ValueObject::GetValuesForExpressionPath(const char* expression,
2488 ValueObjectListSP& list,
2489 const char** first_unparsed,
2490 ExpressionPathScanEndReason* reason_to_stop,
2491 ExpressionPathEndResultType* final_value_type,
2492 const GetValueForExpressionPathOptions& options,
2493 ExpressionPathAftermath* final_task_on_target)
2495 const char* dummy_first_unparsed;
2496 ExpressionPathScanEndReason dummy_reason_to_stop;
2497 ExpressionPathEndResultType dummy_final_value_type;
2498 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2500 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2501 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2502 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2503 final_value_type ? final_value_type : &dummy_final_value_type,
2505 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2507 if (!ret_val.get()) // if there are errors, I add nothing to the list
2510 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
2512 // I need not expand a range, just post-process the final value and return
2513 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
2515 list->Append(ret_val);
2518 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
2520 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
2523 ValueObjectSP final_value = ret_val->Dereference(error);
2524 if (error.Fail() || !final_value.get())
2527 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2528 if (final_value_type)
2529 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2534 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2535 list->Append(final_value);
2539 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
2542 ValueObjectSP final_value = ret_val->AddressOf(error);
2543 if (error.Fail() || !final_value.get())
2546 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2547 if (final_value_type)
2548 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
2553 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
2554 list->Append(final_value);
2562 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2563 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2566 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2567 final_value_type ? final_value_type : &dummy_final_value_type,
2569 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2571 // in any non-covered case, just do the obviously right thing
2572 list->Append(ret_val);
2577 ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2578 const char** first_unparsed,
2579 ExpressionPathScanEndReason* reason_to_stop,
2580 ExpressionPathEndResultType* final_result,
2581 const GetValueForExpressionPathOptions& options,
2582 ExpressionPathAftermath* what_next)
2584 ValueObjectSP root = GetSP();
2587 return ValueObjectSP();
2589 *first_unparsed = expression_cstr;
2594 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2596 ClangASTType root_clang_type = root->GetClangType();
2597 ClangASTType pointee_clang_type;
2598 Flags pointee_clang_type_info;
2600 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
2601 if (pointee_clang_type)
2602 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
2604 if (!expression_cstr || *expression_cstr == '\0')
2606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2610 switch (*expression_cstr)
2614 if (options.m_check_dot_vs_arrow_syntax &&
2615 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
2617 *first_unparsed = expression_cstr;
2618 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2619 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2620 return ValueObjectSP();
2622 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2623 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
2624 options.m_no_fragile_ivar)
2626 *first_unparsed = expression_cstr;
2627 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2628 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2629 return ValueObjectSP();
2631 if (expression_cstr[1] != '>')
2633 *first_unparsed = expression_cstr;
2634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2635 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2636 return ValueObjectSP();
2638 expression_cstr++; // skip the -
2640 case '.': // or fallthrough from ->
2642 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
2643 root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
2645 *first_unparsed = expression_cstr;
2646 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2647 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2648 return ValueObjectSP();
2650 expression_cstr++; // skip .
2651 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2652 ConstString child_name;
2653 if (!next_separator) // if no other separator just expand this last layer
2655 child_name.SetCString (expression_cstr);
2656 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2658 if (child_valobj_sp.get()) // we know we are done, so just return
2660 *first_unparsed = "";
2661 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2662 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2663 return child_valobj_sp;
2665 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2667 if (root->IsSynthetic())
2669 *first_unparsed = expression_cstr;
2670 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2671 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2672 return ValueObjectSP();
2675 child_valobj_sp = root->GetSyntheticValue();
2676 if (child_valobj_sp.get())
2677 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2680 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2681 // so we hit the "else" branch, and return an error
2682 if(child_valobj_sp.get()) // if it worked, just return
2684 *first_unparsed = "";
2685 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2686 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2687 return child_valobj_sp;
2691 *first_unparsed = expression_cstr;
2692 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2693 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2694 return ValueObjectSP();
2697 else // other layers do expand
2699 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2700 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2701 if (child_valobj_sp.get()) // store the new root and move on
2703 root = child_valobj_sp;
2704 *first_unparsed = next_separator;
2705 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2708 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2710 if (root->IsSynthetic())
2712 *first_unparsed = expression_cstr;
2713 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2714 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2715 return ValueObjectSP();
2718 child_valobj_sp = root->GetSyntheticValue(true);
2719 if (child_valobj_sp)
2720 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2723 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2724 // so we hit the "else" branch, and return an error
2725 if(child_valobj_sp.get()) // if it worked, move on
2727 root = child_valobj_sp;
2728 *first_unparsed = next_separator;
2729 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2734 *first_unparsed = expression_cstr;
2735 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2736 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2737 return ValueObjectSP();
2744 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*
2746 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
2748 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2750 *first_unparsed = expression_cstr;
2751 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2752 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2753 return ValueObjectSP();
2756 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2758 *first_unparsed = expression_cstr;
2759 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2760 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2761 return ValueObjectSP();
2764 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2766 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2768 *first_unparsed = expression_cstr;
2769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2771 return ValueObjectSP();
2773 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2775 *first_unparsed = expression_cstr+2;
2776 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2777 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2781 const char *separator_position = ::strchr(expression_cstr+1,'-');
2782 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2783 if (!close_bracket_position) // if there is no ], this is a syntax error
2785 *first_unparsed = expression_cstr;
2786 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2787 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2788 return ValueObjectSP();
2790 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2793 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2794 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2796 *first_unparsed = expression_cstr;
2797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2799 return ValueObjectSP();
2801 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2803 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2805 *first_unparsed = expression_cstr+2;
2806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
2812 *first_unparsed = expression_cstr;
2813 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2814 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2815 return ValueObjectSP();
2818 // from here on we do have a valid index
2819 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
2821 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2822 if (!child_valobj_sp)
2823 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2824 if (!child_valobj_sp)
2825 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2826 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2827 if (child_valobj_sp)
2829 root = child_valobj_sp;
2830 *first_unparsed = end+1; // skip ]
2831 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2836 *first_unparsed = expression_cstr;
2837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2839 return ValueObjectSP();
2842 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
2844 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
2845 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
2848 root = root->Dereference(error);
2849 if (error.Fail() || !root.get())
2851 *first_unparsed = expression_cstr;
2852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2854 return ValueObjectSP();
2858 *what_next = eExpressionPathAftermathNothing;
2864 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2865 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
2866 && root->HasSyntheticValue()
2867 && options.m_no_synthetic_children == false)
2869 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
2872 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2875 *first_unparsed = expression_cstr;
2876 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2877 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2878 return ValueObjectSP();
2882 *first_unparsed = end+1; // skip ]
2883 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2888 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
2890 root = root->GetSyntheticBitFieldChild(index, index, true);
2893 *first_unparsed = expression_cstr;
2894 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2895 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2896 return ValueObjectSP();
2898 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2900 *first_unparsed = end+1; // skip ]
2901 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2902 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
2906 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
2908 root = root->GetChildAtIndex(index, true);
2911 *first_unparsed = expression_cstr;
2912 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2913 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2914 return ValueObjectSP();
2918 *first_unparsed = end+1; // skip ]
2919 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2923 else if (options.m_no_synthetic_children == false)
2925 if (root->HasSyntheticValue())
2926 root = root->GetSyntheticValue();
2927 else if (!root->IsSynthetic())
2929 *first_unparsed = expression_cstr;
2930 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2931 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2932 return ValueObjectSP();
2934 // if we are here, then root itself is a synthetic VO.. should be good to go
2938 *first_unparsed = expression_cstr;
2939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2940 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2941 return ValueObjectSP();
2943 root = root->GetChildAtIndex(index, true);
2946 *first_unparsed = expression_cstr;
2947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2949 return ValueObjectSP();
2953 *first_unparsed = end+1; // skip ]
2954 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2960 *first_unparsed = expression_cstr;
2961 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2962 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2963 return ValueObjectSP();
2966 else // we have a low and a high index
2969 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2970 if (!end || end != separator_position) // if something weird is in our way return an error
2972 *first_unparsed = expression_cstr;
2973 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2974 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2975 return ValueObjectSP();
2977 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2978 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2980 *first_unparsed = expression_cstr;
2981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2983 return ValueObjectSP();
2985 if (index_lower > index_higher) // swap indices if required
2987 unsigned long temp = index_lower;
2988 index_lower = index_higher;
2989 index_higher = temp;
2991 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
2993 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2996 *first_unparsed = expression_cstr;
2997 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2998 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2999 return ValueObjectSP();
3003 *first_unparsed = end+1; // skip ]
3004 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3005 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
3009 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
3010 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3011 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3014 root = root->Dereference(error);
3015 if (error.Fail() || !root.get())
3017 *first_unparsed = expression_cstr;
3018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3020 return ValueObjectSP();
3024 *what_next = ValueObject::eExpressionPathAftermathNothing;
3030 *first_unparsed = expression_cstr;
3031 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3032 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
3038 default: // some non-separator is in the way
3040 *first_unparsed = expression_cstr;
3041 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3042 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3043 return ValueObjectSP();
3051 ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3052 const char** first_unparsed,
3054 ValueObjectListSP& list,
3055 ExpressionPathScanEndReason* reason_to_stop,
3056 ExpressionPathEndResultType* final_result,
3057 const GetValueForExpressionPathOptions& options,
3058 ExpressionPathAftermath* what_next)
3063 *first_unparsed = expression_cstr;
3068 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3070 ClangASTType root_clang_type = root->GetClangType();
3071 ClangASTType pointee_clang_type;
3072 Flags pointee_clang_type_info;
3073 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
3074 if (pointee_clang_type)
3075 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
3077 if (!expression_cstr || *expression_cstr == '\0')
3079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
3084 switch (*expression_cstr)
3088 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
3090 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3092 *first_unparsed = expression_cstr;
3093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3097 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3099 *first_unparsed = expression_cstr;
3100 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3101 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3105 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3107 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3109 *first_unparsed = expression_cstr;
3110 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3111 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3114 else // expand this into list
3116 const size_t max_index = root->GetNumChildren() - 1;
3117 for (size_t index = 0; index < max_index; index++)
3119 ValueObjectSP child =
3120 root->GetChildAtIndex(index, true);
3121 list->Append(child);
3123 *first_unparsed = expression_cstr+2;
3124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3126 return max_index; // tell me number of items I added to the VOList
3129 const char *separator_position = ::strchr(expression_cstr+1,'-');
3130 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3131 if (!close_bracket_position) // if there is no ], this is a syntax error
3133 *first_unparsed = expression_cstr;
3134 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3135 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3138 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3141 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3142 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3144 *first_unparsed = expression_cstr;
3145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3149 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3151 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3153 const size_t max_index = root->GetNumChildren() - 1;
3154 for (size_t index = 0; index < max_index; index++)
3156 ValueObjectSP child =
3157 root->GetChildAtIndex(index, true);
3158 list->Append(child);
3160 *first_unparsed = expression_cstr+2;
3161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3163 return max_index; // tell me number of items I added to the VOList
3167 *first_unparsed = expression_cstr;
3168 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3169 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3173 // from here on we do have a valid index
3174 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
3176 root = root->GetChildAtIndex(index, true);
3179 *first_unparsed = expression_cstr;
3180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3187 *first_unparsed = end+1; // skip ]
3188 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3189 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3193 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
3195 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
3196 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3199 root = root->Dereference(error);
3200 if (error.Fail() || !root.get())
3202 *first_unparsed = expression_cstr;
3203 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3204 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3209 *what_next = eExpressionPathAftermathNothing;
3215 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3218 *first_unparsed = expression_cstr;
3219 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3220 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3226 *first_unparsed = end+1; // skip ]
3227 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3228 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3233 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3235 root = root->GetSyntheticBitFieldChild(index, index, true);
3238 *first_unparsed = expression_cstr;
3239 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3240 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3243 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3246 *first_unparsed = end+1; // skip ]
3247 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3248 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3253 else // we have a low and a high index
3256 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3257 if (!end || end != separator_position) // if something weird is in our way return an error
3259 *first_unparsed = expression_cstr;
3260 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3261 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3264 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3265 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3267 *first_unparsed = expression_cstr;
3268 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3269 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3272 if (index_lower > index_higher) // swap indices if required
3274 unsigned long temp = index_lower;
3275 index_lower = index_higher;
3276 index_higher = temp;
3278 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
3280 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3283 *first_unparsed = expression_cstr;
3284 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3285 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3291 *first_unparsed = end+1; // skip ]
3292 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3293 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3297 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
3298 *what_next == ValueObject::eExpressionPathAftermathDereference &&
3299 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
3302 root = root->Dereference(error);
3303 if (error.Fail() || !root.get())
3305 *first_unparsed = expression_cstr;
3306 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3307 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3312 *what_next = ValueObject::eExpressionPathAftermathNothing;
3318 for (unsigned long index = index_lower;
3319 index <= index_higher; index++)
3321 ValueObjectSP child =
3322 root->GetChildAtIndex(index, true);
3323 list->Append(child);
3325 *first_unparsed = end+1;
3326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3327 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
3328 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3333 default: // some non-[ separator, or something entirely wrong, is in the way
3335 *first_unparsed = expression_cstr;
3336 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3337 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3346 DumpValueObject_Impl (Stream &s,
3347 ValueObject *valobj,
3348 const ValueObject::DumpValueObjectOptions& options,
3350 uint32_t curr_depth)
3354 bool update_success = valobj->UpdateValueIfNeeded (true);
3356 const char *root_valobj_name =
3357 options.m_root_valobj_name.empty() ?
3358 valobj->GetName().AsCString() :
3359 options.m_root_valobj_name.c_str();
3361 if (update_success && options.m_use_dynamic != eNoDynamicValues)
3363 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
3365 valobj = dynamic_value;
3368 ClangASTType clang_type = valobj->GetClangType();
3369 const Flags type_flags (clang_type.GetTypeInfo ());
3370 const char *err_cstr = NULL;
3371 const bool has_children = type_flags.Test (ClangASTType::eTypeHasChildren);
3372 const bool has_value = type_flags.Test (ClangASTType::eTypeHasValue);
3374 const bool print_valobj = options.m_flat_output == false || has_value;
3378 if (options.m_show_location)
3380 s.Printf("%s: ", valobj->GetLocationAsCString());
3385 bool show_type = true;
3386 // if we are at the root-level and been asked to hide the root's type, then hide it
3387 if (curr_depth == 0 && options.m_hide_root_type)
3390 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3391 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3395 // Some ValueObjects don't have types (like registers sets). Only print
3396 // the type if there is one to print
3397 ConstString qualified_type_name(valobj->GetQualifiedTypeName());
3398 if (qualified_type_name)
3399 s.Printf("(%s) ", qualified_type_name.GetCString());
3402 if (options.m_flat_output)
3404 // If we are showing types, also qualify the C++ base classes
3405 const bool qualify_cxx_base_classes = options.m_show_types;
3406 if (!options.m_hide_name)
3408 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3412 else if (!options.m_hide_name)
3414 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3415 s.Printf ("%s =", name_cstr);
3418 if (!options.m_scope_already_checked && !valobj->IsInScope())
3420 err_cstr = "out of scope";
3424 std::string summary_str;
3425 std::string value_str;
3426 const char *val_cstr = NULL;
3427 const char *sum_cstr = NULL;
3428 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
3430 if (options.m_omit_summary_depth > 0)
3433 bool is_nil = valobj->IsObjCNil();
3435 if (err_cstr == NULL)
3437 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
3439 valobj->GetValueAsCString(options.m_format,
3444 val_cstr = valobj->GetValueAsCString();
3446 value_str = val_cstr;
3448 err_cstr = valobj->GetError().AsCString();
3453 s.Printf (" <%s>\n", err_cstr);
3457 const bool is_ref = type_flags.Test (ClangASTType::eTypeIsReference);
3462 else if (options.m_omit_summary_depth == 0)
3464 if (options.m_summary_sp)
3466 valobj->GetSummaryAsCString(entry, summary_str);
3467 sum_cstr = summary_str.c_str();
3470 sum_cstr = valobj->GetSummaryAsCString();
3473 // Make sure we have a value and make sure the summary didn't
3474 // specify that the value should not be printed - and do not print
3475 // the value if this thing is nil
3476 // (but show the value if the user passes a format explicitly)
3477 if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
3478 s.Printf(" %s", value_str.c_str());
3481 s.Printf(" %s", sum_cstr);
3483 // let's avoid the overly verbose no description error for a nil thing
3484 if (options.m_use_objc && !is_nil)
3486 if (!options.m_hide_value || !options.m_hide_name)
3488 const char *object_desc = valobj->GetObjectDescription();
3490 s.Printf("%s\n", object_desc);
3492 s.Printf ("[no Objective-C description available]\n");
3497 if (curr_depth < options.m_max_depth)
3499 // We will show children for all concrete types. We won't show
3500 // pointer contents unless a pointer depth has been specified.
3501 // We won't reference contents unless the reference is the
3502 // root object (depth of zero).
3503 bool print_children = true;
3505 // Use a new temporary pointer depth in case we override the
3506 // current pointer depth below...
3507 uint32_t curr_ptr_depth = ptr_depth;
3509 const bool is_ptr = type_flags.Test (ClangASTType::eTypeIsPointer);
3510 if (is_ptr || is_ref)
3512 // We have a pointer or reference whose value is an address.
3513 // Make sure that address is not NULL
3514 AddressType ptr_address_type;
3515 if (valobj->GetPointerValue (&ptr_address_type) == 0)
3516 print_children = false;
3518 else if (is_ref && curr_depth == 0)
3520 // If this is the root object (depth is zero) that we are showing
3521 // and it is a reference, and no pointer depth has been supplied
3522 // print out what it references. Don't do this at deeper depths
3523 // otherwise we can end up with infinite recursion...
3527 if (curr_ptr_depth == 0)
3528 print_children = false;
3531 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
3533 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3534 ValueObject* synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
3536 size_t num_children = synth_valobj->GetNumChildren();
3537 bool print_dotdotdot = false;
3540 if (options.m_flat_output)
3548 s.PutCString(is_ref ? ": {\n" : " {\n");
3552 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3554 if (num_children > max_num_children && !options.m_ignore_cap)
3556 num_children = max_num_children;
3557 print_dotdotdot = true;
3560 ValueObject::DumpValueObjectOptions child_options(options);
3561 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
3562 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
3563 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
3564 for (size_t idx=0; idx<num_children; ++idx)
3566 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
3569 DumpValueObject_Impl (s,
3572 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3577 if (!options.m_flat_output)
3579 if (print_dotdotdot)
3581 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3582 Target *target = exe_ctx.GetTargetPtr();
3584 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
3591 else if (has_children)
3593 // Aggregate, no children...
3595 s.PutCString(" {}\n");
3611 if (has_children && print_valobj)
3613 s.PutCString("{...}\n");
3621 ValueObject::LogValueObject (Log *log,
3622 ValueObject *valobj)
3625 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3629 ValueObject::LogValueObject (Log *log,
3630 ValueObject *valobj,
3631 const DumpValueObjectOptions& options)
3636 ValueObject::DumpValueObject (s, valobj, options);
3638 log->PutCString(s.GetData());
3643 ValueObject::DumpValueObject (Stream &s,
3644 ValueObject *valobj)
3650 DumpValueObject_Impl(s,
3652 DumpValueObjectOptions::DefaultOptions(),
3658 ValueObject::DumpValueObject (Stream &s,
3659 ValueObject *valobj,
3660 const DumpValueObjectOptions& options)
3662 DumpValueObject_Impl(s,
3665 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3666 0 // current object depth is 0 since we are just starting
3671 ValueObject::CreateConstantValue (const ConstString &name)
3673 ValueObjectSP valobj_sp;
3675 if (UpdateValueIfNeeded(false) && m_error.Success())
3677 ExecutionContext exe_ctx (GetExecutionContextRef());
3680 data.SetByteOrder (m_data.GetByteOrder());
3681 data.SetAddressByteSize(m_data.GetAddressByteSize());
3685 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3686 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3689 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
3691 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3700 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
3706 ValueObject::Dereference (Error &error)
3709 return m_deref_valobj->GetSP();
3711 const bool is_pointer_type = IsPointerType();
3712 if (is_pointer_type)
3714 bool omit_empty_base_classes = true;
3715 bool ignore_array_bounds = false;
3717 std::string child_name_str;
3718 uint32_t child_byte_size = 0;
3719 int32_t child_byte_offset = 0;
3720 uint32_t child_bitfield_bit_size = 0;
3721 uint32_t child_bitfield_bit_offset = 0;
3722 bool child_is_base_class = false;
3723 bool child_is_deref_of_parent = false;
3724 const bool transparent_pointers = false;
3725 ClangASTType clang_type = GetClangType();
3726 ClangASTType child_clang_type;
3728 ExecutionContext exe_ctx (GetExecutionContextRef());
3730 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3731 GetName().GetCString(),
3733 transparent_pointers,
3734 omit_empty_base_classes,
3735 ignore_array_bounds,
3739 child_bitfield_bit_size,
3740 child_bitfield_bit_offset,
3741 child_is_base_class,
3742 child_is_deref_of_parent);
3743 if (child_clang_type && child_byte_size)
3745 ConstString child_name;
3746 if (!child_name_str.empty())
3747 child_name.SetCString (child_name_str.c_str());
3749 m_deref_valobj = new ValueObjectChild (*this,
3754 child_bitfield_bit_size,
3755 child_bitfield_bit_offset,
3756 child_is_base_class,
3757 child_is_deref_of_parent,
3758 eAddressTypeInvalid);
3765 return m_deref_valobj->GetSP();
3770 GetExpressionPath(strm, true);
3772 if (is_pointer_type)
3773 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3775 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3776 return ValueObjectSP();
3781 ValueObject::AddressOf (Error &error)
3783 if (m_addr_of_valobj_sp)
3784 return m_addr_of_valobj_sp;
3786 AddressType address_type = eAddressTypeInvalid;
3787 const bool scalar_is_load_address = false;
3788 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
3790 if (addr != LLDB_INVALID_ADDRESS)
3792 switch (address_type)
3794 case eAddressTypeInvalid:
3796 StreamString expr_path_strm;
3797 GetExpressionPath(expr_path_strm, true);
3798 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3802 case eAddressTypeFile:
3803 case eAddressTypeLoad:
3804 case eAddressTypeHost:
3806 ClangASTType clang_type = GetClangType();
3809 std::string name (1, '&');
3810 name.append (m_name.AsCString(""));
3811 ExecutionContext exe_ctx (GetExecutionContextRef());
3812 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3813 clang_type.GetPointerType(),
3814 ConstString (name.c_str()),
3816 eAddressTypeInvalid,
3817 m_data.GetAddressByteSize());
3825 StreamString expr_path_strm;
3826 GetExpressionPath(expr_path_strm, true);
3827 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3830 return m_addr_of_valobj_sp;
3834 ValueObject::Cast (const ClangASTType &clang_ast_type)
3836 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
3840 ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3842 ValueObjectSP valobj_sp;
3843 AddressType address_type;
3844 addr_t ptr_value = GetPointerValue (&address_type);
3846 if (ptr_value != LLDB_INVALID_ADDRESS)
3848 Address ptr_addr (ptr_value);
3849 ExecutionContext exe_ctx (GetExecutionContextRef());
3850 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3859 ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3861 ValueObjectSP valobj_sp;
3862 AddressType address_type;
3863 addr_t ptr_value = GetPointerValue (&address_type);
3865 if (ptr_value != LLDB_INVALID_ADDRESS)
3867 Address ptr_addr (ptr_value);
3868 ExecutionContext exe_ctx (GetExecutionContextRef());
3869 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
3877 ValueObject::EvaluationPoint::EvaluationPoint () :
3880 m_needs_update (true),
3881 m_first_update (true)
3885 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
3888 m_needs_update (true),
3889 m_first_update (true)
3891 ExecutionContext exe_ctx(exe_scope);
3892 TargetSP target_sp (exe_ctx.GetTargetSP());
3895 m_exe_ctx_ref.SetTargetSP (target_sp);
3896 ProcessSP process_sp (exe_ctx.GetProcessSP());
3898 process_sp = target_sp->GetProcessSP();
3902 m_mod_id = process_sp->GetModID();
3903 m_exe_ctx_ref.SetProcessSP (process_sp);
3905 ThreadSP thread_sp (exe_ctx.GetThreadSP());
3910 thread_sp = process_sp->GetThreadList().GetSelectedThread();
3915 m_exe_ctx_ref.SetThreadSP(thread_sp);
3917 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3921 frame_sp = thread_sp->GetSelectedFrame();
3924 m_exe_ctx_ref.SetFrameSP(frame_sp);
3930 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3932 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3933 m_needs_update (true),
3934 m_first_update (true)
3938 ValueObject::EvaluationPoint::~EvaluationPoint ()
3942 // This function checks the EvaluationPoint against the current process state. If the current
3943 // state matches the evaluation point, or the evaluation point is already invalid, then we return
3944 // false, meaning "no change". If the current state is different, we update our state, and return
3945 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3946 // future calls to NeedsUpdate will return true.
3947 // exe_scope will be set to the current execution context scope.
3950 ValueObject::EvaluationPoint::SyncWithProcessState()
3953 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3954 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
3956 if (exe_ctx.GetTargetPtr() == NULL)
3959 // If we don't have a process nothing can change.
3960 Process *process = exe_ctx.GetProcessPtr();
3961 if (process == NULL)
3964 // If our stop id is the current stop ID, nothing has changed:
3965 ProcessModID current_mod_id = process->GetModID();
3967 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3968 // In either case, we aren't going to be able to sync with the process state.
3969 if (current_mod_id.GetStopID() == 0)
3972 bool changed = false;
3973 const bool was_valid = m_mod_id.IsValid();
3976 if (m_mod_id == current_mod_id)
3978 // Everything is already up to date in this object, no need to
3979 // update the execution context scope.
3984 m_mod_id = current_mod_id;
3985 m_needs_update = true;
3990 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3991 // That way we'll be sure to return a valid exe_scope.
3992 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
3994 if (m_exe_ctx_ref.HasThreadRef())
3996 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3999 if (m_exe_ctx_ref.HasFrameRef())
4001 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4004 // We used to have a frame, but now it is gone
4006 changed = was_valid;
4012 // We used to have a thread, but now it is gone
4014 changed = was_valid;
4022 ValueObject::EvaluationPoint::SetUpdated ()
4024 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4026 m_mod_id = process_sp->GetModID();
4027 m_first_update = false;
4028 m_needs_update = false;
4034 ValueObject::ClearUserVisibleData(uint32_t clear_mask)
4036 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4037 m_value_str.clear();
4039 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4040 m_location_str.clear();
4042 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4044 m_summary_str.clear();
4047 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4048 m_object_desc_str.clear();
4050 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4052 if (m_synthetic_value)
4053 m_synthetic_value = NULL;
4057 SymbolContextScope *
4058 ValueObject::GetSymbolContextScope()
4062 if (!m_parent->IsPointerOrReferenceType())
4063 return m_parent->GetSymbolContextScope();
4069 ValueObject::CreateValueObjectFromExpression (const char* name,
4070 const char* expression,
4071 const ExecutionContext& exe_ctx)
4073 lldb::ValueObjectSP retval_sp;
4074 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4077 if (!expression || !*expression)
4079 target_sp->EvaluateExpression (expression,
4080 exe_ctx.GetFrameSP().get(),
4082 if (retval_sp && name && *name)
4083 retval_sp->SetName(ConstString(name));
4088 ValueObject::CreateValueObjectFromAddress (const char* name,
4090 const ExecutionContext& exe_ctx,
4095 ClangASTType pointer_type(type.GetPointerType());
4098 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4099 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4103 lldb::endian::InlHostByteOrder(),
4104 exe_ctx.GetAddressByteSize()));
4105 if (ptr_result_valobj_sp)
4107 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4109 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4110 if (ptr_result_valobj_sp && name && *name)
4111 ptr_result_valobj_sp->SetName(ConstString(name));
4113 return ptr_result_valobj_sp;
4116 return lldb::ValueObjectSP();
4120 ValueObject::CreateValueObjectFromData (const char* name,
4121 DataExtractor& data,
4122 const ExecutionContext& exe_ctx,
4125 lldb::ValueObjectSP new_value_sp;
4126 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4130 LLDB_INVALID_ADDRESS);
4131 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4132 if (new_value_sp && name && *name)
4133 new_value_sp->SetName(ConstString(name));
4134 return new_value_sp;
4138 ValueObject::GetModule ()
4140 ValueObject* root(GetRoot());
4142 return root->GetModule();
4143 return lldb::ModuleSP();
4147 ValueObject::GetRoot ()
4151 ValueObject* parent = m_parent;
4153 return (m_root = this);
4154 while (parent->m_parent)
4157 return (m_root = parent->m_root);
4158 parent = parent->m_parent;
4160 return (m_root = parent);
4164 ValueObject::GetAddressTypeOfChildren()
4166 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4168 ValueObject* root(GetRoot());
4170 return root->GetAddressTypeOfChildren();
4172 return m_address_type_of_ptr_or_ref_children;
4175 lldb::DynamicValueType
4176 ValueObject::GetDynamicValueType ()
4178 ValueObject* with_dv_info = this;
4179 while (with_dv_info)
4181 if (with_dv_info->HasDynamicValueTypeInfo())
4182 return with_dv_info->GetDynamicValueTypeImpl();
4183 with_dv_info = with_dv_info->m_parent;
4185 return lldb::eNoDynamicValues;
4189 ValueObject::GetFormat () const
4191 const ValueObject* with_fmt_info = this;
4192 while (with_fmt_info)
4194 if (with_fmt_info->m_format != lldb::eFormatDefault)
4195 return with_fmt_info->m_format;
4196 with_fmt_info = with_fmt_info->m_parent;