Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ValueObject.cpp -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Core/ValueObject.h" |
| 11 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Address.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ValueObjectCast.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ValueObjectChild.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ValueObjectConstResult.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ValueObjectDynamicValue.h" |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ValueObjectMemory.h" |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObjectSyntheticFilter.h" |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 20 | #include "lldb/DataFormatters/DataVisualization.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 21 | #include "lldb/DataFormatters/DumpValueObjectOptions.h" |
| 22 | #include "lldb/DataFormatters/FormatManager.h" |
Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 23 | #include "lldb/DataFormatters/StringPrinter.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 24 | #include "lldb/DataFormatters/TypeFormat.h" |
| 25 | #include "lldb/DataFormatters/TypeSummary.h" |
| 26 | #include "lldb/DataFormatters/TypeValidator.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 27 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 28 | #include "lldb/Expression/ExpressionVariable.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/ClangASTContext.h" |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 30 | #include "lldb/Symbol/CompileUnit.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/CompilerType.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/Declaration.h" |
| 33 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Symbol/Type.h" |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 35 | #include "lldb/Target/ExecutionContext.h" |
Enrico Granata | 407b5c6 | 2015-11-02 21:52:05 +0000 | [diff] [blame] | 36 | #include "lldb/Target/Language.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 37 | #include "lldb/Target/LanguageRuntime.h" |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 38 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Target/Process.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 40 | #include "lldb/Target/StackFrame.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 41 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | #include "lldb/Target/Thread.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 43 | #include "lldb/Target/ThreadList.h" |
| 44 | #include "lldb/Utility/DataBuffer.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 45 | #include "lldb/Utility/DataBufferHeap.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 46 | #include "lldb/Utility/Flags.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 47 | #include "lldb/Utility/Log.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 48 | #include "lldb/Utility/Logging.h" |
| 49 | #include "lldb/Utility/Scalar.h" |
| 50 | #include "lldb/Utility/SharingPtr.h" |
| 51 | #include "lldb/Utility/Stream.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 52 | #include "lldb/Utility/StreamString.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 53 | #include "lldb/lldb-private-types.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 54 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 55 | #include "llvm/Support/Compiler.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 56 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 57 | #include <algorithm> |
| 58 | #include <cstdint> |
| 59 | #include <cstdlib> |
| 60 | #include <memory> |
| 61 | #include <tuple> |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 62 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 63 | #include <assert.h> |
| 64 | #include <inttypes.h> |
| 65 | #include <stdio.h> |
| 66 | #include <string.h> |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 67 | |
| 68 | namespace lldb_private { |
| 69 | class ExecutionContextScope; |
| 70 | } |
| 71 | namespace lldb_private { |
| 72 | class SymbolContextScope; |
| 73 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | |
| 75 | using namespace lldb; |
| 76 | using namespace lldb_private; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 77 | using namespace lldb_utility; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 79 | static user_id_t g_value_obj_uid = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
| 81 | //---------------------------------------------------------------------- |
| 82 | // ValueObject constructor |
| 83 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | ValueObject::ValueObject(ValueObject &parent) |
| 85 | : UserID(++g_value_obj_uid), // Unique identifier for every value object |
| 86 | m_parent(&parent), m_root(NULL), m_update_point(parent.GetUpdatePoint()), |
| 87 | m_name(), m_data(), m_value(), m_error(), m_value_str(), |
| 88 | m_old_value_str(), m_location_str(), m_summary_str(), m_object_desc_str(), |
| 89 | m_validation_result(), m_manager(parent.GetManager()), m_children(), |
| 90 | m_synthetic_children(), m_dynamic_value(NULL), m_synthetic_value(NULL), |
| 91 | m_deref_valobj(NULL), m_format(eFormatDefault), |
| 92 | m_last_format(eFormatDefault), m_last_format_mgr_revision(0), |
| 93 | m_type_summary_sp(), m_type_format_sp(), m_synthetic_children_sp(), |
| 94 | m_type_validator_sp(), m_user_id_of_forced_summary(), |
| 95 | m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid), |
| 96 | m_value_checksum(), |
| 97 | m_preferred_display_language(lldb::eLanguageTypeUnknown), |
| 98 | m_language_flags(0), m_value_is_valid(false), m_value_did_change(false), |
| 99 | m_children_count_valid(false), m_old_value_valid(false), |
| 100 | m_is_deref_of_parent(false), m_is_array_item_for_pointer(false), |
| 101 | m_is_bitfield_for_scalar(false), m_is_child_at_offset(false), |
| 102 | m_is_getting_summary(false), |
| 103 | m_did_calculate_complete_objc_class_type(false), |
| 104 | m_is_synthetic_children_generated( |
| 105 | parent.m_is_synthetic_children_generated) { |
| 106 | m_manager->ManageObject(this); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | //---------------------------------------------------------------------- |
| 110 | // ValueObject constructor |
| 111 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | ValueObject::ValueObject(ExecutionContextScope *exe_scope, |
| 113 | AddressType child_ptr_or_ref_addr_type) |
| 114 | : UserID(++g_value_obj_uid), // Unique identifier for every value object |
| 115 | m_parent(NULL), m_root(NULL), m_update_point(exe_scope), m_name(), |
| 116 | m_data(), m_value(), m_error(), m_value_str(), m_old_value_str(), |
| 117 | m_location_str(), m_summary_str(), m_object_desc_str(), |
| 118 | m_validation_result(), m_manager(), m_children(), m_synthetic_children(), |
| 119 | m_dynamic_value(NULL), m_synthetic_value(NULL), m_deref_valobj(NULL), |
| 120 | m_format(eFormatDefault), m_last_format(eFormatDefault), |
| 121 | m_last_format_mgr_revision(0), m_type_summary_sp(), m_type_format_sp(), |
| 122 | m_synthetic_children_sp(), m_type_validator_sp(), |
| 123 | m_user_id_of_forced_summary(), |
| 124 | m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type), |
| 125 | m_value_checksum(), |
| 126 | m_preferred_display_language(lldb::eLanguageTypeUnknown), |
| 127 | m_language_flags(0), m_value_is_valid(false), m_value_did_change(false), |
| 128 | m_children_count_valid(false), m_old_value_valid(false), |
| 129 | m_is_deref_of_parent(false), m_is_array_item_for_pointer(false), |
| 130 | m_is_bitfield_for_scalar(false), m_is_child_at_offset(false), |
| 131 | m_is_getting_summary(false), |
| 132 | m_did_calculate_complete_objc_class_type(false), |
| 133 | m_is_synthetic_children_generated(false) { |
| 134 | m_manager = new ValueObjectManager(); |
| 135 | m_manager->ManageObject(this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | //---------------------------------------------------------------------- |
| 139 | // Destructor |
| 140 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | ValueObject::~ValueObject() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | bool ValueObject::UpdateValueIfNeeded(bool update_format) { |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | bool did_change_formats = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | if (update_format) |
| 148 | did_change_formats = UpdateFormatsIfNeeded(); |
Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 149 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 150 | // If this is a constant value, then our success is predicated on whether we |
| 151 | // have an error or not |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | if (GetIsConstant()) { |
| 153 | // if you are constant, things might still have changed behind your back |
| 154 | // (e.g. you are a frozen object and things have changed deeper than you |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 155 | // cared to freeze-dry yourself) in this case, your value has not changed, |
| 156 | // but "computed" entries might have, so you might now have a different |
| 157 | // summary, or a different object description. clear these so we will |
| 158 | // recompute them |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 159 | if (update_format && !did_change_formats) |
| 160 | ClearUserVisibleData(eClearUserVisibleDataItemsSummary | |
| 161 | eClearUserVisibleDataItemsDescription); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | return m_error.Success(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | bool first_update = IsChecksumEmpty(); |
| 166 | |
| 167 | if (NeedsUpdating()) { |
| 168 | m_update_point.SetUpdated(); |
| 169 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 170 | // Save the old value using swap to avoid a string copy which also will |
| 171 | // clear our m_value_str |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | if (m_value_str.empty()) { |
| 173 | m_old_value_valid = false; |
| 174 | } else { |
| 175 | m_old_value_valid = true; |
| 176 | m_old_value_str.swap(m_value_str); |
| 177 | ClearUserVisibleData(eClearUserVisibleDataItemsValue); |
| 178 | } |
| 179 | |
| 180 | ClearUserVisibleData(); |
| 181 | |
| 182 | if (IsInScope()) { |
| 183 | const bool value_was_valid = GetValueIsValid(); |
| 184 | SetValueDidChange(false); |
| 185 | |
| 186 | m_error.Clear(); |
| 187 | |
| 188 | // Call the pure virtual function to update the value |
| 189 | |
| 190 | bool need_compare_checksums = false; |
| 191 | llvm::SmallVector<uint8_t, 16> old_checksum; |
| 192 | |
| 193 | if (!first_update && CanProvideValue()) { |
| 194 | need_compare_checksums = true; |
| 195 | old_checksum.resize(m_value_checksum.size()); |
| 196 | std::copy(m_value_checksum.begin(), m_value_checksum.end(), |
| 197 | old_checksum.begin()); |
| 198 | } |
| 199 | |
| 200 | bool success = UpdateValue(); |
| 201 | |
| 202 | SetValueIsValid(success); |
| 203 | |
| 204 | if (success) { |
| 205 | const uint64_t max_checksum_size = 128; |
| 206 | m_data.Checksum(m_value_checksum, max_checksum_size); |
| 207 | } else { |
| 208 | need_compare_checksums = false; |
| 209 | m_value_checksum.clear(); |
| 210 | } |
| 211 | |
| 212 | assert(!need_compare_checksums || |
| 213 | (!old_checksum.empty() && !m_value_checksum.empty())); |
| 214 | |
| 215 | if (first_update) |
| 216 | SetValueDidChange(false); |
| 217 | else if (!m_value_did_change && success == false) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 218 | // The value wasn't gotten successfully, so we mark this as changed if |
| 219 | // the value used to be valid and now isn't |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | SetValueDidChange(value_was_valid); |
| 221 | } else if (need_compare_checksums) { |
| 222 | SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], |
| 223 | m_value_checksum.size())); |
| 224 | } |
| 225 | |
| 226 | } else { |
| 227 | m_error.SetErrorString("out of scope"); |
| 228 | } |
| 229 | } |
| 230 | return m_error.Success(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | bool ValueObject::UpdateFormatsIfNeeded() { |
| 234 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); |
| 235 | if (log) |
| 236 | log->Printf("[%s %p] checking for FormatManager revisions. ValueObject " |
| 237 | "rev: %d - Global rev: %d", |
| 238 | GetName().GetCString(), static_cast<void *>(this), |
| 239 | m_last_format_mgr_revision, |
| 240 | DataVisualization::GetCurrentRevision()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 241 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | bool any_change = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | if ((m_last_format_mgr_revision != DataVisualization::GetCurrentRevision())) { |
| 245 | m_last_format_mgr_revision = DataVisualization::GetCurrentRevision(); |
| 246 | any_change = true; |
| 247 | |
| 248 | SetValueFormat(DataVisualization::GetFormat(*this, eNoDynamicValues)); |
| 249 | SetSummaryFormat( |
| 250 | DataVisualization::GetSummaryFormat(*this, GetDynamicValueType())); |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 251 | #ifndef LLDB_DISABLE_PYTHON |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | SetSyntheticChildren( |
| 253 | DataVisualization::GetSyntheticChildren(*this, GetDynamicValueType())); |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 254 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType())); |
| 256 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 257 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | return any_change; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | void ValueObject::SetNeedsUpdate() { |
| 262 | m_update_point.SetNeedsUpdate(); |
| 263 | // We have to clear the value string here so ConstResult children will notice |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 264 | // if their values are changed by hand (i.e. with SetValueAsCString). |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | ClearUserVisibleData(eClearUserVisibleDataItemsValue); |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | void ValueObject::ClearDynamicTypeInformation() { |
| 269 | m_children_count_valid = false; |
| 270 | m_did_calculate_complete_objc_class_type = false; |
| 271 | m_last_format_mgr_revision = 0; |
| 272 | m_override_type = CompilerType(); |
| 273 | SetValueFormat(lldb::TypeFormatImplSP()); |
| 274 | SetSummaryFormat(lldb::TypeSummaryImplSP()); |
| 275 | SetSyntheticChildren(lldb::SyntheticChildrenSP()); |
Enrico Granata | 13ac0e2 | 2012-10-17 19:03:34 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | CompilerType ValueObject::MaybeCalculateCompleteType() { |
| 279 | CompilerType compiler_type(GetCompilerTypeImpl()); |
| 280 | |
| 281 | if (m_did_calculate_complete_objc_class_type) { |
| 282 | if (m_override_type.IsValid()) |
| 283 | return m_override_type; |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 284 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | return compiler_type; |
| 286 | } |
| 287 | |
| 288 | CompilerType class_type; |
| 289 | bool is_pointer_type = false; |
| 290 | |
| 291 | if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) { |
| 292 | is_pointer_type = true; |
| 293 | } else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) { |
| 294 | class_type = compiler_type; |
| 295 | } else { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 296 | return compiler_type; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | m_did_calculate_complete_objc_class_type = true; |
| 300 | |
| 301 | if (class_type) { |
| 302 | ConstString class_name(class_type.GetConstTypeName()); |
| 303 | |
| 304 | if (class_name) { |
| 305 | ProcessSP process_sp( |
| 306 | GetUpdatePoint().GetExecutionContextRef().GetProcessSP()); |
| 307 | |
| 308 | if (process_sp) { |
| 309 | ObjCLanguageRuntime *objc_language_runtime( |
| 310 | process_sp->GetObjCLanguageRuntime()); |
| 311 | |
| 312 | if (objc_language_runtime) { |
| 313 | TypeSP complete_objc_class_type_sp = |
| 314 | objc_language_runtime->LookupInCompleteClassCache(class_name); |
| 315 | |
| 316 | if (complete_objc_class_type_sp) { |
| 317 | CompilerType complete_class( |
| 318 | complete_objc_class_type_sp->GetFullCompilerType()); |
| 319 | |
| 320 | if (complete_class.GetCompleteType()) { |
| 321 | if (is_pointer_type) { |
| 322 | m_override_type = complete_class.GetPointerType(); |
| 323 | } else { |
| 324 | m_override_type = complete_class; |
| 325 | } |
| 326 | |
| 327 | if (m_override_type.IsValid()) |
| 328 | return m_override_type; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | return compiler_type; |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | CompilerType ValueObject::GetCompilerType() { |
| 339 | return MaybeCalculateCompleteType(); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | TypeImpl ValueObject::GetTypeImpl() { return TypeImpl(GetCompilerType()); } |
| 343 | |
| 344 | DataExtractor &ValueObject::GetDataExtractor() { |
| 345 | UpdateValueIfNeeded(false); |
| 346 | return m_data; |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 349 | const Status &ValueObject::GetError() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | UpdateValueIfNeeded(false); |
| 351 | return m_error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 354 | const ConstString &ValueObject::GetName() const { return m_name; } |
| 355 | |
| 356 | const char *ValueObject::GetLocationAsCString() { |
| 357 | return GetLocationAsCStringImpl(m_value, m_data); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 360 | const char *ValueObject::GetLocationAsCStringImpl(const Value &value, |
| 361 | const DataExtractor &data) { |
| 362 | if (UpdateValueIfNeeded(false)) { |
| 363 | if (m_location_str.empty()) { |
| 364 | StreamString sstr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 366 | Value::ValueType value_type = value.GetValueType(); |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 367 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 368 | switch (value_type) { |
| 369 | case Value::eValueTypeScalar: |
| 370 | case Value::eValueTypeVector: |
| 371 | if (value.GetContextType() == Value::eContextTypeRegisterInfo) { |
| 372 | RegisterInfo *reg_info = value.GetRegisterInfo(); |
| 373 | if (reg_info) { |
| 374 | if (reg_info->name) |
| 375 | m_location_str = reg_info->name; |
| 376 | else if (reg_info->alt_name) |
| 377 | m_location_str = reg_info->alt_name; |
| 378 | if (m_location_str.empty()) |
| 379 | m_location_str = (reg_info->encoding == lldb::eEncodingVector) |
| 380 | ? "vector" |
| 381 | : "scalar"; |
| 382 | } |
| 383 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | if (m_location_str.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 385 | m_location_str = |
| 386 | (value_type == Value::eValueTypeVector) ? "vector" : "scalar"; |
| 387 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 389 | case Value::eValueTypeLoadAddress: |
| 390 | case Value::eValueTypeFileAddress: |
| 391 | case Value::eValueTypeHostAddress: { |
| 392 | uint32_t addr_nibble_size = data.GetAddressByteSize() * 2; |
| 393 | sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, |
| 394 | value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 395 | m_location_str = sstr.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | } break; |
| 397 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 399 | } |
| 400 | return m_location_str.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 403 | Value &ValueObject::GetValue() { return m_value; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 404 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | const Value &ValueObject::GetValue() const { return m_value; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 407 | bool ValueObject::ResolveValue(Scalar &scalar) { |
| 408 | if (UpdateValueIfNeeded( |
| 409 | false)) // make sure that you are up to date before returning anything |
| 410 | { |
| 411 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 412 | Value tmp_value(m_value); |
| 413 | scalar = tmp_value.ResolveValue(&exe_ctx); |
| 414 | if (scalar.IsValid()) { |
| 415 | const uint32_t bitfield_bit_size = GetBitfieldBitSize(); |
| 416 | if (bitfield_bit_size) |
| 417 | return scalar.ExtractBitfield(bitfield_bit_size, |
| 418 | GetBitfieldBitOffset()); |
| 419 | return true; |
Enrico Granata | 6fd87d5 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 420 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 421 | } |
| 422 | return false; |
| 423 | } |
| 424 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 425 | bool ValueObject::IsLogicalTrue(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { |
| 427 | LazyBool is_logical_true = language->IsLogicalTrue(*this, error); |
| 428 | switch (is_logical_true) { |
| 429 | case eLazyBoolYes: |
| 430 | case eLazyBoolNo: |
| 431 | return (is_logical_true == true); |
| 432 | case eLazyBoolCalculate: |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | Scalar scalar_value; |
| 438 | |
| 439 | if (!ResolveValue(scalar_value)) { |
| 440 | error.SetErrorString("failed to get a scalar result"); |
Greg Clayton | dcad502 | 2011-12-29 01:26:56 +0000 | [diff] [blame] | 441 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | bool ret; |
| 445 | if (scalar_value.ULongLong(1) == 0) |
| 446 | ret = false; |
| 447 | else |
| 448 | ret = true; |
| 449 | error.Clear(); |
| 450 | return ret; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 453 | bool ValueObject::GetValueIsValid() const { return m_value_is_valid; } |
| 454 | |
| 455 | void ValueObject::SetValueIsValid(bool b) { m_value_is_valid = b; } |
| 456 | |
| 457 | bool ValueObject::GetValueDidChange() { return m_value_did_change; } |
| 458 | |
| 459 | void ValueObject::SetValueDidChange(bool value_changed) { |
| 460 | m_value_did_change = value_changed; |
| 461 | } |
| 462 | |
| 463 | ValueObjectSP ValueObject::GetChildAtIndex(size_t idx, bool can_create) { |
| 464 | ValueObjectSP child_sp; |
| 465 | // We may need to update our value if we are dynamic |
| 466 | if (IsPossibleDynamicType()) |
| 467 | UpdateValueIfNeeded(false); |
| 468 | if (idx < GetNumChildren()) { |
| 469 | // Check if we have already made the child value object? |
| 470 | if (can_create && !m_children.HasChildAtIndex(idx)) { |
| 471 | // No we haven't created the child at this index, so lets have our |
| 472 | // subclass do it and cache the result for quick future access. |
| 473 | m_children.SetChildAtIndex(idx, CreateChildAtIndex(idx, false, 0)); |
Enrico Granata | 407b5c6 | 2015-11-02 21:52:05 +0000 | [diff] [blame] | 474 | } |
Jim Ingham | 98e6daf | 2015-10-31 00:02:18 +0000 | [diff] [blame] | 475 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 476 | ValueObject *child = m_children.GetChildAtIndex(idx); |
| 477 | if (child != NULL) |
| 478 | return child->GetSP(); |
| 479 | } |
| 480 | return child_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 483 | lldb::ValueObjectSP |
Lang Hames | 088d001 | 2017-04-26 18:15:40 +0000 | [diff] [blame] | 484 | ValueObject::GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | size_t *index_of_error) { |
| 486 | if (idxs.size() == 0) |
| 487 | return GetSP(); |
| 488 | ValueObjectSP root(GetSP()); |
| 489 | for (size_t idx : idxs) { |
| 490 | root = root->GetChildAtIndex(idx, true); |
| 491 | if (!root) { |
| 492 | if (index_of_error) |
| 493 | *index_of_error = idx; |
| 494 | return root; |
Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 495 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 496 | } |
| 497 | return root; |
| 498 | } |
| 499 | |
| 500 | lldb::ValueObjectSP ValueObject::GetChildAtIndexPath( |
Lang Hames | 088d001 | 2017-04-26 18:15:40 +0000 | [diff] [blame] | 501 | llvm::ArrayRef<std::pair<size_t, bool>> idxs, size_t *index_of_error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | if (idxs.size() == 0) |
| 503 | return GetSP(); |
| 504 | ValueObjectSP root(GetSP()); |
| 505 | for (std::pair<size_t, bool> idx : idxs) { |
| 506 | root = root->GetChildAtIndex(idx.first, idx.second); |
| 507 | if (!root) { |
| 508 | if (index_of_error) |
| 509 | *index_of_error = idx.first; |
| 510 | return root; |
| 511 | } |
| 512 | } |
| 513 | return root; |
Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | lldb::ValueObjectSP |
Lang Hames | 088d001 | 2017-04-26 18:15:40 +0000 | [diff] [blame] | 517 | ValueObject::GetChildAtNamePath(llvm::ArrayRef<ConstString> names, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 518 | ConstString *name_of_error) { |
| 519 | if (names.size() == 0) |
| 520 | return GetSP(); |
| 521 | ValueObjectSP root(GetSP()); |
| 522 | for (ConstString name : names) { |
| 523 | root = root->GetChildMemberWithName(name, true); |
| 524 | if (!root) { |
| 525 | if (name_of_error) |
| 526 | *name_of_error = name; |
| 527 | return root; |
| 528 | } |
| 529 | } |
| 530 | return root; |
Enrico Granata | ef8dde6 | 2015-12-21 23:10:17 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 533 | lldb::ValueObjectSP ValueObject::GetChildAtNamePath( |
Lang Hames | 088d001 | 2017-04-26 18:15:40 +0000 | [diff] [blame] | 534 | llvm::ArrayRef<std::pair<ConstString, bool>> names, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 535 | ConstString *name_of_error) { |
| 536 | if (names.size() == 0) |
| 537 | return GetSP(); |
| 538 | ValueObjectSP root(GetSP()); |
| 539 | for (std::pair<ConstString, bool> name : names) { |
| 540 | root = root->GetChildMemberWithName(name.first, name.second); |
| 541 | if (!root) { |
| 542 | if (name_of_error) |
| 543 | *name_of_error = name.first; |
| 544 | return root; |
| 545 | } |
| 546 | } |
| 547 | return root; |
Enrico Granata | e2e220a | 2013-09-12 00:48:47 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 550 | size_t ValueObject::GetIndexOfChildWithName(const ConstString &name) { |
| 551 | bool omit_empty_base_classes = true; |
| 552 | return GetCompilerType().GetIndexOfChildWithName(name.GetCString(), |
| 553 | omit_empty_base_classes); |
Enrico Granata | e2e220a | 2013-09-12 00:48:47 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 556 | ValueObjectSP ValueObject::GetChildMemberWithName(const ConstString &name, |
| 557 | bool can_create) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 558 | // when getting a child by name, it could be buried inside some base classes |
| 559 | // (which really aren't part of the expression path), so we need a vector of |
| 560 | // indexes that can get us down to the correct child |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 561 | ValueObjectSP child_sp; |
| 562 | |
| 563 | // We may need to update our value if we are dynamic |
| 564 | if (IsPossibleDynamicType()) |
| 565 | UpdateValueIfNeeded(false); |
| 566 | |
| 567 | std::vector<uint32_t> child_indexes; |
| 568 | bool omit_empty_base_classes = true; |
| 569 | const size_t num_child_indexes = |
| 570 | GetCompilerType().GetIndexOfChildMemberWithName( |
| 571 | name.GetCString(), omit_empty_base_classes, child_indexes); |
| 572 | if (num_child_indexes > 0) { |
| 573 | std::vector<uint32_t>::const_iterator pos = child_indexes.begin(); |
| 574 | std::vector<uint32_t>::const_iterator end = child_indexes.end(); |
| 575 | |
| 576 | child_sp = GetChildAtIndex(*pos, can_create); |
| 577 | for (++pos; pos != end; ++pos) { |
| 578 | if (child_sp) { |
| 579 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex(*pos, can_create)); |
| 580 | child_sp = new_child_sp; |
| 581 | } else { |
| 582 | child_sp.reset(); |
| 583 | } |
Enrico Granata | e2e220a | 2013-09-12 00:48:47 +0000 | [diff] [blame] | 584 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | } |
| 586 | return child_sp; |
Enrico Granata | e2e220a | 2013-09-12 00:48:47 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | size_t ValueObject::GetNumChildren(uint32_t max) { |
| 590 | UpdateValueIfNeeded(); |
| 591 | |
| 592 | if (max < UINT32_MAX) { |
| 593 | if (m_children_count_valid) { |
| 594 | size_t children_count = m_children.GetChildrenCount(); |
| 595 | return children_count <= max ? children_count : max; |
| 596 | } else |
| 597 | return CalculateNumChildren(max); |
| 598 | } |
| 599 | |
| 600 | if (!m_children_count_valid) { |
| 601 | SetNumChildren(CalculateNumChildren()); |
| 602 | } |
| 603 | return m_children.GetChildrenCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 606 | bool ValueObject::MightHaveChildren() { |
| 607 | bool has_children = false; |
| 608 | const uint32_t type_info = GetTypeInfo(); |
| 609 | if (type_info) { |
| 610 | if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference)) |
| 611 | has_children = true; |
| 612 | } else { |
| 613 | has_children = GetNumChildren() > 0; |
| 614 | } |
| 615 | return has_children; |
Greg Clayton | 4a79207 | 2012-10-23 01:50:10 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | // Should only be called by ValueObject::GetNumChildren() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | void ValueObject::SetNumChildren(size_t num_children) { |
| 620 | m_children_count_valid = true; |
| 621 | m_children.SetChildrenCount(num_children); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 624 | void ValueObject::SetName(const ConstString &name) { m_name = name; } |
| 625 | |
| 626 | ValueObject *ValueObject::CreateChildAtIndex(size_t idx, |
| 627 | bool synthetic_array_member, |
| 628 | int32_t synthetic_index) { |
| 629 | ValueObject *valobj = NULL; |
| 630 | |
| 631 | bool omit_empty_base_classes = true; |
| 632 | bool ignore_array_bounds = synthetic_array_member; |
| 633 | std::string child_name_str; |
| 634 | uint32_t child_byte_size = 0; |
| 635 | int32_t child_byte_offset = 0; |
| 636 | uint32_t child_bitfield_bit_size = 0; |
| 637 | uint32_t child_bitfield_bit_offset = 0; |
| 638 | bool child_is_base_class = false; |
| 639 | bool child_is_deref_of_parent = false; |
| 640 | uint64_t language_flags = 0; |
| 641 | |
| 642 | const bool transparent_pointers = synthetic_array_member == false; |
| 643 | CompilerType child_compiler_type; |
| 644 | |
| 645 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 646 | |
| 647 | child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex( |
| 648 | &exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 649 | ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, |
| 650 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 651 | child_is_deref_of_parent, this, language_flags); |
| 652 | if (child_compiler_type) { |
| 653 | if (synthetic_index) |
| 654 | child_byte_offset += child_byte_size * synthetic_index; |
| 655 | |
| 656 | ConstString child_name; |
| 657 | if (!child_name_str.empty()) |
| 658 | child_name.SetCString(child_name_str.c_str()); |
| 659 | |
| 660 | valobj = new ValueObjectChild( |
| 661 | *this, child_compiler_type, child_name, child_byte_size, |
| 662 | child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, |
| 663 | child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, |
| 664 | language_flags); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | return valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 670 | bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, |
| 671 | std::string &destination, |
| 672 | lldb::LanguageType lang) { |
| 673 | return GetSummaryAsCString(summary_ptr, destination, |
| 674 | TypeSummaryOptions().SetLanguage(lang)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 677 | bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, |
| 678 | std::string &destination, |
| 679 | const TypeSummaryOptions &options) { |
| 680 | destination.clear(); |
| 681 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 682 | // ideally we would like to bail out if passing NULL, but if we do so we end |
| 683 | // up not providing the summary for function pointers anymore |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 684 | if (/*summary_ptr == NULL ||*/ m_is_getting_summary) |
| 685 | return false; |
| 686 | |
| 687 | m_is_getting_summary = true; |
| 688 | |
| 689 | TypeSummaryOptions actual_options(options); |
| 690 | |
| 691 | if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown) |
| 692 | actual_options.SetLanguage(GetPreferredDisplayLanguage()); |
| 693 | |
| 694 | // this is a hot path in code and we prefer to avoid setting this string all |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 695 | // too often also clearing out other information that we might care to see in |
| 696 | // a crash log. might be useful in very specific situations though. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 697 | /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. |
| 698 | Summary provider's description is %s", |
| 699 | GetTypeName().GetCString(), |
| 700 | GetName().GetCString(), |
| 701 | summary_ptr->GetDescription().c_str());*/ |
| 702 | |
| 703 | if (UpdateValueIfNeeded(false) && summary_ptr) { |
| 704 | if (HasSyntheticValue()) |
| 705 | m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on |
| 706 | // the synthetic children being |
| 707 | // up-to-date (e.g. ${svar%#}) |
| 708 | summary_ptr->FormatObject(this, destination, actual_options); |
| 709 | } |
| 710 | m_is_getting_summary = false; |
| 711 | return !destination.empty(); |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 714 | const char *ValueObject::GetSummaryAsCString(lldb::LanguageType lang) { |
| 715 | if (UpdateValueIfNeeded(true) && m_summary_str.empty()) { |
| 716 | TypeSummaryOptions summary_options; |
| 717 | summary_options.SetLanguage(lang); |
| 718 | GetSummaryAsCString(GetSummaryFormat().get(), m_summary_str, |
| 719 | summary_options); |
| 720 | } |
| 721 | if (m_summary_str.empty()) |
| 722 | return NULL; |
| 723 | return m_summary_str.c_str(); |
| 724 | } |
| 725 | |
| 726 | bool ValueObject::GetSummaryAsCString(std::string &destination, |
| 727 | const TypeSummaryOptions &options) { |
| 728 | return GetSummaryAsCString(GetSummaryFormat().get(), destination, options); |
| 729 | } |
| 730 | |
| 731 | bool ValueObject::IsCStringContainer(bool check_pointer) { |
| 732 | CompilerType pointee_or_element_compiler_type; |
| 733 | const Flags type_flags(GetTypeInfo(&pointee_or_element_compiler_type)); |
| 734 | bool is_char_arr_ptr(type_flags.AnySet(eTypeIsArray | eTypeIsPointer) && |
| 735 | pointee_or_element_compiler_type.IsCharType()); |
| 736 | if (!is_char_arr_ptr) |
| 737 | return false; |
| 738 | if (!check_pointer) |
| 739 | return true; |
| 740 | if (type_flags.Test(eTypeIsArray)) |
| 741 | return true; |
| 742 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| 743 | AddressType cstr_address_type = eAddressTypeInvalid; |
| 744 | cstr_address = GetAddressOf(true, &cstr_address_type); |
| 745 | return (cstr_address != LLDB_INVALID_ADDRESS); |
| 746 | } |
| 747 | |
| 748 | size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx, |
| 749 | uint32_t item_count) { |
| 750 | CompilerType pointee_or_element_compiler_type; |
| 751 | const uint32_t type_info = GetTypeInfo(&pointee_or_element_compiler_type); |
| 752 | const bool is_pointer_type = type_info & eTypeIsPointer; |
| 753 | const bool is_array_type = type_info & eTypeIsArray; |
| 754 | if (!(is_pointer_type || is_array_type)) |
| 755 | return 0; |
| 756 | |
| 757 | if (item_count == 0) |
| 758 | return 0; |
| 759 | |
| 760 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 761 | |
| 762 | const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize( |
| 763 | exe_ctx.GetBestExecutionContextScope()); |
| 764 | const uint64_t bytes = item_count * item_type_size; |
| 765 | const uint64_t offset = item_idx * item_type_size; |
| 766 | |
| 767 | if (item_idx == 0 && item_count == 1) // simply a deref |
| 768 | { |
| 769 | if (is_pointer_type) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 770 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 771 | ValueObjectSP pointee_sp = Dereference(error); |
| 772 | if (error.Fail() || pointee_sp.get() == NULL) |
| 773 | return 0; |
| 774 | return pointee_sp->GetData(data, error); |
| 775 | } else { |
| 776 | ValueObjectSP child_sp = GetChildAtIndex(0, true); |
| 777 | if (child_sp.get() == NULL) |
| 778 | return 0; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 779 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 780 | return child_sp->GetData(data, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 782 | return true; |
| 783 | } else /* (items > 1) */ |
| 784 | { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 785 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 786 | lldb_private::DataBufferHeap *heap_buf_ptr = NULL; |
| 787 | lldb::DataBufferSP data_sp(heap_buf_ptr = |
| 788 | new lldb_private::DataBufferHeap()); |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 789 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 790 | AddressType addr_type; |
| 791 | lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) |
| 792 | : GetAddressOf(true, &addr_type); |
| 793 | |
| 794 | switch (addr_type) { |
| 795 | case eAddressTypeFile: { |
| 796 | ModuleSP module_sp(GetModule()); |
| 797 | if (module_sp) { |
| 798 | addr = addr + offset; |
| 799 | Address so_addr; |
| 800 | module_sp->ResolveFileAddress(addr, so_addr); |
| 801 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 802 | Target *target = exe_ctx.GetTargetPtr(); |
| 803 | if (target) { |
| 804 | heap_buf_ptr->SetByteSize(bytes); |
| 805 | size_t bytes_read = target->ReadMemory( |
| 806 | so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); |
| 807 | if (error.Success()) { |
| 808 | data.SetData(data_sp); |
| 809 | return bytes_read; |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | } break; |
| 814 | case eAddressTypeLoad: { |
| 815 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 816 | Process *process = exe_ctx.GetProcessPtr(); |
| 817 | if (process) { |
| 818 | heap_buf_ptr->SetByteSize(bytes); |
| 819 | size_t bytes_read = process->ReadMemory( |
| 820 | addr + offset, heap_buf_ptr->GetBytes(), bytes, error); |
| 821 | if (error.Success() || bytes_read > 0) { |
| 822 | data.SetData(data_sp); |
| 823 | return bytes_read; |
| 824 | } |
| 825 | } |
| 826 | } break; |
| 827 | case eAddressTypeHost: { |
| 828 | const uint64_t max_bytes = |
| 829 | GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); |
| 830 | if (max_bytes > offset) { |
| 831 | size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes); |
| 832 | addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 833 | if (addr == 0 || addr == LLDB_INVALID_ADDRESS) |
| 834 | break; |
| 835 | heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read); |
| 836 | data.SetData(data_sp); |
| 837 | return bytes_read; |
| 838 | } |
| 839 | } break; |
| 840 | case eAddressTypeInvalid: |
| 841 | break; |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 842 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 843 | } |
| 844 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 847 | uint64_t ValueObject::GetData(DataExtractor &data, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 848 | UpdateValueIfNeeded(false); |
| 849 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 850 | error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); |
| 851 | if (error.Fail()) { |
| 852 | if (m_data.GetByteSize()) { |
| 853 | data = m_data; |
| 854 | error.Clear(); |
| 855 | return data.GetByteSize(); |
| 856 | } else { |
| 857 | return 0; |
| 858 | } |
| 859 | } |
| 860 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
| 861 | data.SetByteOrder(m_data.GetByteOrder()); |
| 862 | return data.GetByteSize(); |
Enrico Granata | 49bfafb | 2014-11-18 23:36:25 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 865 | bool ValueObject::SetData(DataExtractor &data, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 866 | error.Clear(); |
| 867 | // Make sure our value is up to date first so that our location and location |
| 868 | // type is valid. |
| 869 | if (!UpdateValueIfNeeded(false)) { |
| 870 | error.SetErrorString("unable to read value"); |
| 871 | return false; |
| 872 | } |
| 873 | |
| 874 | uint64_t count = 0; |
| 875 | const Encoding encoding = GetCompilerType().GetEncoding(count); |
| 876 | |
| 877 | const size_t byte_size = GetByteSize(); |
| 878 | |
| 879 | Value::ValueType value_type = m_value.GetValueType(); |
| 880 | |
| 881 | switch (value_type) { |
| 882 | case Value::eValueTypeScalar: { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 883 | Status set_error = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | m_value.GetScalar().SetValueFromData(data, encoding, byte_size); |
| 885 | |
| 886 | if (!set_error.Success()) { |
| 887 | error.SetErrorStringWithFormat("unable to set scalar value: %s", |
| 888 | set_error.AsCString()); |
| 889 | return false; |
| 890 | } |
| 891 | } break; |
| 892 | case Value::eValueTypeLoadAddress: { |
| 893 | // If it is a load address, then the scalar value is the storage location |
| 894 | // of the data, and we have to shove this value down to that load location. |
| 895 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 896 | Process *process = exe_ctx.GetProcessPtr(); |
| 897 | if (process) { |
| 898 | addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 899 | size_t bytes_written = process->WriteMemory( |
| 900 | target_addr, data.GetDataStart(), byte_size, error); |
| 901 | if (!error.Success()) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 902 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 903 | if (bytes_written != byte_size) { |
| 904 | error.SetErrorString("unable to write value to memory"); |
| 905 | return false; |
| 906 | } |
| 907 | } |
| 908 | } break; |
| 909 | case Value::eValueTypeHostAddress: { |
| 910 | // If it is a host address, then we stuff the scalar as a DataBuffer into |
| 911 | // the Value's data. |
| 912 | DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 913 | m_data.SetData(buffer_sp, 0); |
| 914 | data.CopyByteOrderedData(0, byte_size, |
| 915 | const_cast<uint8_t *>(m_data.GetDataStart()), |
| 916 | byte_size, m_data.GetByteOrder()); |
| 917 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 918 | } break; |
| 919 | case Value::eValueTypeFileAddress: |
| 920 | case Value::eValueTypeVector: |
| 921 | break; |
| 922 | } |
| 923 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 924 | // If we have reached this point, then we have successfully changed the |
| 925 | // value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 926 | SetNeedsUpdate(); |
| 927 | return true; |
| 928 | } |
| 929 | |
| 930 | static bool CopyStringDataToBufferSP(const StreamString &source, |
| 931 | lldb::DataBufferSP &destination) { |
| 932 | destination.reset(new DataBufferHeap(source.GetSize() + 1, 0)); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 933 | memcpy(destination->GetBytes(), source.GetString().data(), source.GetSize()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 934 | return true; |
| 935 | } |
| 936 | |
| 937 | std::pair<size_t, bool> |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 938 | ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 939 | uint32_t max_length, bool honor_array, |
| 940 | Format item_format) { |
| 941 | bool was_capped = false; |
| 942 | StreamString s; |
| 943 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 944 | Target *target = exe_ctx.GetTargetPtr(); |
| 945 | |
| 946 | if (!target) { |
| 947 | s << "<no target to read from>"; |
| 948 | error.SetErrorString("no target to read from"); |
| 949 | CopyStringDataToBufferSP(s, buffer_sp); |
| 950 | return {0, was_capped}; |
| 951 | } |
| 952 | |
| 953 | if (max_length == 0) |
| 954 | max_length = target->GetMaximumSizeOfStringSummary(); |
| 955 | |
| 956 | size_t bytes_read = 0; |
| 957 | size_t total_bytes_read = 0; |
| 958 | |
| 959 | CompilerType compiler_type = GetCompilerType(); |
| 960 | CompilerType elem_or_pointee_compiler_type; |
| 961 | const Flags type_flags(GetTypeInfo(&elem_or_pointee_compiler_type)); |
| 962 | if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer) && |
| 963 | elem_or_pointee_compiler_type.IsCharType()) { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 964 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 965 | AddressType cstr_address_type = eAddressTypeInvalid; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 966 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 967 | size_t cstr_len = 0; |
| 968 | bool capped_data = false; |
| 969 | const bool is_array = type_flags.Test(eTypeIsArray); |
| 970 | if (is_array) { |
| 971 | // We have an array |
| 972 | uint64_t array_size = 0; |
| 973 | if (compiler_type.IsArrayType(NULL, &array_size, NULL)) { |
| 974 | cstr_len = array_size; |
| 975 | if (cstr_len > max_length) { |
| 976 | capped_data = true; |
| 977 | cstr_len = max_length; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 978 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 979 | } |
| 980 | cstr_address = GetAddressOf(true, &cstr_address_type); |
| 981 | } else { |
| 982 | // We have a pointer |
| 983 | cstr_address = GetPointerValue(&cstr_address_type); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 984 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 985 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 986 | if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS) { |
| 987 | if (cstr_address_type == eAddressTypeHost && is_array) { |
| 988 | const char *cstr = GetDataExtractor().PeekCStr(0); |
| 989 | if (cstr == nullptr) { |
| 990 | s << "<invalid address>"; |
| 991 | error.SetErrorString("invalid address"); |
| 992 | CopyStringDataToBufferSP(s, buffer_sp); |
| 993 | return {0, was_capped}; |
Sean Callanan | ed185ab | 2013-04-19 19:47:32 +0000 | [diff] [blame] | 994 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | buffer_sp.reset(new DataBufferHeap(cstr_len, 0)); |
| 996 | memcpy(buffer_sp->GetBytes(), cstr, cstr_len); |
| 997 | return {cstr_len, was_capped}; |
| 998 | } else { |
| 999 | s << "<invalid address>"; |
| 1000 | error.SetErrorString("invalid address"); |
Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1001 | CopyStringDataToBufferSP(s, buffer_sp); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1002 | return {0, was_capped}; |
| 1003 | } |
Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1004 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1005 | |
| 1006 | Address cstr_so_addr(cstr_address); |
| 1007 | DataExtractor data; |
| 1008 | if (cstr_len > 0 && honor_array) { |
| 1009 | // I am using GetPointeeData() here to abstract the fact that some |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1010 | // ValueObjects are actually frozen pointers in the host but the pointed- |
| 1011 | // to data lives in the debuggee, and GetPointeeData() automatically |
| 1012 | // takes care of this |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1013 | GetPointeeData(data, 0, cstr_len); |
| 1014 | |
| 1015 | if ((bytes_read = data.GetByteSize()) > 0) { |
| 1016 | total_bytes_read = bytes_read; |
| 1017 | for (size_t offset = 0; offset < bytes_read; offset++) |
| 1018 | s.Printf("%c", *data.PeekData(offset, 1)); |
| 1019 | if (capped_data) |
| 1020 | was_capped = true; |
| 1021 | } |
| 1022 | } else { |
| 1023 | cstr_len = max_length; |
| 1024 | const size_t k_max_buf_size = 64; |
| 1025 | |
| 1026 | size_t offset = 0; |
| 1027 | |
| 1028 | int cstr_len_displayed = -1; |
| 1029 | bool capped_cstr = false; |
| 1030 | // I am using GetPointeeData() here to abstract the fact that some |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1031 | // ValueObjects are actually frozen pointers in the host but the pointed- |
| 1032 | // to data lives in the debuggee, and GetPointeeData() automatically |
| 1033 | // takes care of this |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1034 | while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) { |
| 1035 | total_bytes_read += bytes_read; |
| 1036 | const char *cstr = data.PeekCStr(0); |
| 1037 | size_t len = strnlen(cstr, k_max_buf_size); |
| 1038 | if (cstr_len_displayed < 0) |
| 1039 | cstr_len_displayed = len; |
| 1040 | |
| 1041 | if (len == 0) |
| 1042 | break; |
| 1043 | cstr_len_displayed += len; |
| 1044 | if (len > bytes_read) |
| 1045 | len = bytes_read; |
| 1046 | if (len > cstr_len) |
| 1047 | len = cstr_len; |
| 1048 | |
| 1049 | for (size_t offset = 0; offset < bytes_read; offset++) |
| 1050 | s.Printf("%c", *data.PeekData(offset, 1)); |
| 1051 | |
| 1052 | if (len < k_max_buf_size) |
| 1053 | break; |
| 1054 | |
| 1055 | if (len >= cstr_len) { |
| 1056 | capped_cstr = true; |
| 1057 | break; |
| 1058 | } |
| 1059 | |
| 1060 | cstr_len -= len; |
| 1061 | offset += len; |
| 1062 | } |
| 1063 | |
| 1064 | if (cstr_len_displayed >= 0) { |
| 1065 | if (capped_cstr) |
| 1066 | was_capped = true; |
| 1067 | } |
| 1068 | } |
| 1069 | } else { |
| 1070 | error.SetErrorString("not a string object"); |
| 1071 | s << "<not a string object>"; |
| 1072 | } |
| 1073 | CopyStringDataToBufferSP(s, buffer_sp); |
| 1074 | return {total_bytes_read, was_capped}; |
| 1075 | } |
| 1076 | |
| 1077 | std::pair<TypeValidatorResult, std::string> ValueObject::GetValidationStatus() { |
| 1078 | if (!UpdateValueIfNeeded(true)) |
| 1079 | return {TypeValidatorResult::Success, |
| 1080 | ""}; // not the validator's job to discuss update problems |
| 1081 | |
| 1082 | if (m_validation_result.hasValue()) |
| 1083 | return m_validation_result.getValue(); |
| 1084 | |
| 1085 | if (!m_type_validator_sp) |
| 1086 | return {TypeValidatorResult::Success, ""}; // no validator no failure |
| 1087 | |
| 1088 | auto outcome = m_type_validator_sp->FormatObject(this); |
| 1089 | |
| 1090 | return (m_validation_result = {outcome.m_result, outcome.m_message}) |
| 1091 | .getValue(); |
| 1092 | } |
| 1093 | |
| 1094 | const char *ValueObject::GetObjectDescription() { |
| 1095 | |
| 1096 | if (!UpdateValueIfNeeded(true)) |
| 1097 | return NULL; |
| 1098 | |
| 1099 | if (!m_object_desc_str.empty()) |
| 1100 | return m_object_desc_str.c_str(); |
| 1101 | |
| 1102 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1103 | Process *process = exe_ctx.GetProcessPtr(); |
| 1104 | if (process == NULL) |
| 1105 | return NULL; |
| 1106 | |
| 1107 | StreamString s; |
| 1108 | |
| 1109 | LanguageType language = GetObjectRuntimeLanguage(); |
| 1110 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 1111 | |
| 1112 | if (runtime == NULL) { |
| 1113 | // Aw, hell, if the things a pointer, or even just an integer, let's try |
| 1114 | // ObjC anyway... |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1115 | CompilerType compiler_type = GetCompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1116 | if (compiler_type) { |
| 1117 | bool is_signed; |
| 1118 | if (compiler_type.IsIntegerType(is_signed) || |
| 1119 | compiler_type.IsPointerType()) { |
| 1120 | runtime = process->GetLanguageRuntime(eLanguageTypeObjC); |
| 1121 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1122 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | if (runtime && runtime->GetObjectDescription(s, *this)) { |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1126 | m_object_desc_str.append(s.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | if (m_object_desc_str.empty()) |
| 1130 | return NULL; |
| 1131 | else |
| 1132 | return m_object_desc_str.c_str(); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1135 | bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format, |
| 1136 | std::string &destination) { |
| 1137 | if (UpdateValueIfNeeded(false)) |
| 1138 | return format.FormatObject(this, destination); |
| 1139 | else |
| 1140 | return false; |
Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1143 | bool ValueObject::GetValueAsCString(lldb::Format format, |
| 1144 | std::string &destination) { |
| 1145 | return GetValueAsCString(TypeFormatImpl_Format(format), destination); |
| 1146 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1148 | const char *ValueObject::GetValueAsCString() { |
| 1149 | if (UpdateValueIfNeeded(true)) { |
| 1150 | lldb::TypeFormatImplSP format_sp; |
| 1151 | lldb::Format my_format = GetFormat(); |
| 1152 | if (my_format == lldb::eFormatDefault) { |
| 1153 | if (m_type_format_sp) |
| 1154 | format_sp = m_type_format_sp; |
| 1155 | else { |
| 1156 | if (m_is_bitfield_for_scalar) |
| 1157 | my_format = eFormatUnsigned; |
| 1158 | else { |
| 1159 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) { |
| 1160 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 1161 | if (reg_info) |
| 1162 | my_format = reg_info->format; |
| 1163 | } else { |
| 1164 | my_format = GetValue().GetCompilerType().GetFormat(); |
| 1165 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1166 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1167 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1168 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1169 | if (my_format != m_last_format || m_value_str.empty()) { |
| 1170 | m_last_format = my_format; |
| 1171 | if (!format_sp) |
| 1172 | format_sp.reset(new TypeFormatImpl_Format(my_format)); |
| 1173 | if (GetValueAsCString(*format_sp.get(), m_value_str)) { |
| 1174 | if (!m_value_did_change && m_old_value_valid) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1175 | // The value was gotten successfully, so we consider the value as |
| 1176 | // changed if the value string differs |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1177 | SetValueDidChange(m_old_value_str != m_value_str); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1179 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1181 | } |
| 1182 | if (m_value_str.empty()) |
| 1183 | return NULL; |
| 1184 | return m_value_str.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1187 | // if > 8bytes, 0 is returned. this method should mostly be used to read |
| 1188 | // address values out of pointers |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1189 | uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) { |
| 1190 | // If our byte size is zero this is an aggregate type that has children |
| 1191 | if (CanProvideValue()) { |
| 1192 | Scalar scalar; |
| 1193 | if (ResolveValue(scalar)) { |
| 1194 | if (success) |
| 1195 | *success = true; |
| 1196 | return scalar.ULongLong(fail_value); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1197 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1198 | // fallthrough, otherwise... |
| 1199 | } |
Johnny Chen | 3f476c4 | 2012-06-05 19:37:43 +0000 | [diff] [blame] | 1200 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1201 | if (success) |
| 1202 | *success = false; |
| 1203 | return fail_value; |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1206 | int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) { |
| 1207 | // If our byte size is zero this is an aggregate type that has children |
| 1208 | if (CanProvideValue()) { |
| 1209 | Scalar scalar; |
| 1210 | if (ResolveValue(scalar)) { |
| 1211 | if (success) |
| 1212 | *success = true; |
| 1213 | return scalar.SLongLong(fail_value); |
Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1214 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1215 | // fallthrough, otherwise... |
| 1216 | } |
| 1217 | |
| 1218 | if (success) |
| 1219 | *success = false; |
| 1220 | return fail_value; |
Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1223 | // if any more "special cases" are added to |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1224 | // ValueObject::DumpPrintableRepresentation() please keep this call up to date |
| 1225 | // by returning true for your new special cases. We will eventually move to |
| 1226 | // checking this call result before trying to display special cases |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1227 | bool ValueObject::HasSpecialPrintableRepresentation( |
| 1228 | ValueObjectRepresentationStyle val_obj_display, Format custom_format) { |
| 1229 | Flags flags(GetTypeInfo()); |
| 1230 | if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && |
| 1231 | val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { |
| 1232 | if (IsCStringContainer(true) && |
| 1233 | (custom_format == eFormatCString || custom_format == eFormatCharArray || |
| 1234 | custom_format == eFormatChar || custom_format == eFormatVectorOfChar)) |
| 1235 | return true; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1236 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1237 | if (flags.Test(eTypeIsArray)) { |
| 1238 | if ((custom_format == eFormatBytes) || |
| 1239 | (custom_format == eFormatBytesWithASCII)) |
| 1240 | return true; |
| 1241 | |
| 1242 | if ((custom_format == eFormatVectorOfChar) || |
| 1243 | (custom_format == eFormatVectorOfFloat32) || |
| 1244 | (custom_format == eFormatVectorOfFloat64) || |
| 1245 | (custom_format == eFormatVectorOfSInt16) || |
| 1246 | (custom_format == eFormatVectorOfSInt32) || |
| 1247 | (custom_format == eFormatVectorOfSInt64) || |
| 1248 | (custom_format == eFormatVectorOfSInt8) || |
| 1249 | (custom_format == eFormatVectorOfUInt128) || |
| 1250 | (custom_format == eFormatVectorOfUInt16) || |
| 1251 | (custom_format == eFormatVectorOfUInt32) || |
| 1252 | (custom_format == eFormatVectorOfUInt64) || |
| 1253 | (custom_format == eFormatVectorOfUInt8)) |
| 1254 | return true; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1255 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1256 | } |
| 1257 | return false; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1260 | bool ValueObject::DumpPrintableRepresentation( |
| 1261 | Stream &s, ValueObjectRepresentationStyle val_obj_display, |
| 1262 | Format custom_format, PrintableRepresentationSpecialCases special, |
| 1263 | bool do_dump_error) { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1264 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1265 | Flags flags(GetTypeInfo()); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1266 | |
Enrico Granata | 65d86e4 | 2016-11-07 23:32:20 +0000 | [diff] [blame] | 1267 | bool allow_special = |
| 1268 | (special == ValueObject::PrintableRepresentationSpecialCases::eAllow); |
| 1269 | const bool only_special = false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1270 | |
| 1271 | if (allow_special) { |
| 1272 | if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && |
| 1273 | val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { |
| 1274 | // when being asked to get a printable display an array or pointer type |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1275 | // directly, try to "do the right thing" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1276 | |
| 1277 | if (IsCStringContainer(true) && |
| 1278 | (custom_format == eFormatCString || |
| 1279 | custom_format == eFormatCharArray || custom_format == eFormatChar || |
| 1280 | custom_format == |
| 1281 | eFormatVectorOfChar)) // print char[] & char* directly |
| 1282 | { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1283 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1284 | lldb::DataBufferSP buffer_sp; |
| 1285 | std::pair<size_t, bool> read_string = ReadPointedString( |
| 1286 | buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) || |
| 1287 | (custom_format == eFormatCharArray)); |
| 1288 | lldb_private::formatters::StringPrinter:: |
| 1289 | ReadBufferAndDumpToStreamOptions options(*this); |
| 1290 | options.SetData(DataExtractor( |
| 1291 | buffer_sp, lldb::eByteOrderInvalid, |
| 1292 | 8)); // none of this matters for a string - pass some defaults |
| 1293 | options.SetStream(&s); |
| 1294 | options.SetPrefixToken(0); |
| 1295 | options.SetQuote('"'); |
| 1296 | options.SetSourceSize(buffer_sp->GetByteSize()); |
| 1297 | options.SetIsTruncated(read_string.second); |
| 1298 | formatters::StringPrinter::ReadBufferAndDumpToStream< |
| 1299 | lldb_private::formatters::StringPrinter::StringElementType::ASCII>( |
| 1300 | options); |
| 1301 | return !error.Fail(); |
| 1302 | } |
| 1303 | |
| 1304 | if (custom_format == eFormatEnum) |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1305 | return false; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1306 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1307 | // this only works for arrays, because I have no way to know when the |
| 1308 | // pointed memory ends, and no special \0 end of data marker |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1309 | if (flags.Test(eTypeIsArray)) { |
| 1310 | if ((custom_format == eFormatBytes) || |
| 1311 | (custom_format == eFormatBytesWithASCII)) { |
| 1312 | const size_t count = GetNumChildren(); |
| 1313 | |
| 1314 | s << '['; |
| 1315 | for (size_t low = 0; low < count; low++) { |
| 1316 | |
| 1317 | if (low) |
| 1318 | s << ','; |
| 1319 | |
| 1320 | ValueObjectSP child = GetChildAtIndex(low, true); |
| 1321 | if (!child.get()) { |
| 1322 | s << "<invalid child>"; |
| 1323 | continue; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1324 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1325 | child->DumpPrintableRepresentation( |
| 1326 | s, ValueObject::eValueObjectRepresentationStyleValue, |
| 1327 | custom_format); |
| 1328 | } |
| 1329 | |
| 1330 | s << ']'; |
| 1331 | |
| 1332 | return true; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1333 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1334 | |
| 1335 | if ((custom_format == eFormatVectorOfChar) || |
| 1336 | (custom_format == eFormatVectorOfFloat32) || |
| 1337 | (custom_format == eFormatVectorOfFloat64) || |
| 1338 | (custom_format == eFormatVectorOfSInt16) || |
| 1339 | (custom_format == eFormatVectorOfSInt32) || |
| 1340 | (custom_format == eFormatVectorOfSInt64) || |
| 1341 | (custom_format == eFormatVectorOfSInt8) || |
| 1342 | (custom_format == eFormatVectorOfUInt128) || |
| 1343 | (custom_format == eFormatVectorOfUInt16) || |
| 1344 | (custom_format == eFormatVectorOfUInt32) || |
| 1345 | (custom_format == eFormatVectorOfUInt64) || |
| 1346 | (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes |
| 1347 | // with ASCII or any vector |
| 1348 | // format should be printed |
| 1349 | // directly |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1350 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1351 | const size_t count = GetNumChildren(); |
| 1352 | |
| 1353 | Format format = FormatManager::GetSingleItemFormat(custom_format); |
| 1354 | |
| 1355 | s << '['; |
| 1356 | for (size_t low = 0; low < count; low++) { |
| 1357 | |
| 1358 | if (low) |
| 1359 | s << ','; |
| 1360 | |
| 1361 | ValueObjectSP child = GetChildAtIndex(low, true); |
| 1362 | if (!child.get()) { |
| 1363 | s << "<invalid child>"; |
| 1364 | continue; |
Enrico Granata | 0dba9b3 | 2014-01-08 01:36:59 +0000 | [diff] [blame] | 1365 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1366 | child->DumpPrintableRepresentation( |
| 1367 | s, ValueObject::eValueObjectRepresentationStyleValue, format); |
| 1368 | } |
| 1369 | |
| 1370 | s << ']'; |
| 1371 | |
| 1372 | return true; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1373 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | if ((custom_format == eFormatBoolean) || |
| 1377 | (custom_format == eFormatBinary) || (custom_format == eFormatChar) || |
| 1378 | (custom_format == eFormatCharPrintable) || |
| 1379 | (custom_format == eFormatComplexFloat) || |
| 1380 | (custom_format == eFormatDecimal) || (custom_format == eFormatHex) || |
| 1381 | (custom_format == eFormatHexUppercase) || |
| 1382 | (custom_format == eFormatFloat) || (custom_format == eFormatOctal) || |
| 1383 | (custom_format == eFormatOSType) || |
| 1384 | (custom_format == eFormatUnicode16) || |
| 1385 | (custom_format == eFormatUnicode32) || |
| 1386 | (custom_format == eFormatUnsigned) || |
| 1387 | (custom_format == eFormatPointer) || |
| 1388 | (custom_format == eFormatComplexInteger) || |
| 1389 | (custom_format == eFormatComplex) || |
| 1390 | (custom_format == eFormatDefault)) // use the [] operator |
| 1391 | return false; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1392 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | if (only_special) |
| 1396 | return false; |
| 1397 | |
| 1398 | bool var_success = false; |
| 1399 | |
| 1400 | { |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1401 | llvm::StringRef str; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1402 | |
| 1403 | // this is a local stream that we are using to ensure that the data pointed |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1404 | // to by cstr survives long enough for us to copy it to its destination - |
| 1405 | // it is necessary to have this temporary storage area for cases where our |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1406 | // desired output is not backed by some other longer-term storage |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1407 | StreamString strm; |
| 1408 | |
| 1409 | if (custom_format != eFormatInvalid) |
| 1410 | SetFormat(custom_format); |
| 1411 | |
| 1412 | switch (val_obj_display) { |
| 1413 | case eValueObjectRepresentationStyleValue: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1414 | str = GetValueAsCString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1415 | break; |
| 1416 | |
| 1417 | case eValueObjectRepresentationStyleSummary: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1418 | str = GetSummaryAsCString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | case eValueObjectRepresentationStyleLanguageSpecific: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1422 | str = GetObjectDescription(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1423 | break; |
| 1424 | |
| 1425 | case eValueObjectRepresentationStyleLocation: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1426 | str = GetLocationAsCString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case eValueObjectRepresentationStyleChildrenCount: |
| 1430 | strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren()); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1431 | str = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1432 | break; |
| 1433 | |
| 1434 | case eValueObjectRepresentationStyleType: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1435 | str = GetTypeName().GetStringRef(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1436 | break; |
| 1437 | |
| 1438 | case eValueObjectRepresentationStyleName: |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1439 | str = GetName().GetStringRef(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | |
| 1442 | case eValueObjectRepresentationStyleExpressionPath: |
| 1443 | GetExpressionPath(strm, false); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1444 | str = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1445 | break; |
| 1446 | } |
| 1447 | |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1448 | if (str.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1449 | if (val_obj_display == eValueObjectRepresentationStyleValue) |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1450 | str = GetSummaryAsCString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1451 | else if (val_obj_display == eValueObjectRepresentationStyleSummary) { |
| 1452 | if (!CanProvideValue()) { |
| 1453 | strm.Printf("%s @ %s", GetTypeName().AsCString(), |
| 1454 | GetLocationAsCString()); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1455 | str = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1456 | } else |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1457 | str = GetValueAsCString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1461 | if (!str.empty()) |
| 1462 | s << str; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1463 | else { |
| 1464 | if (m_error.Fail()) { |
| 1465 | if (do_dump_error) |
| 1466 | s.Printf("<%s>", m_error.AsCString()); |
| 1467 | else |
| 1468 | return false; |
| 1469 | } else if (val_obj_display == eValueObjectRepresentationStyleSummary) |
| 1470 | s.PutCString("<no summary available>"); |
| 1471 | else if (val_obj_display == eValueObjectRepresentationStyleValue) |
| 1472 | s.PutCString("<no value available>"); |
| 1473 | else if (val_obj_display == |
| 1474 | eValueObjectRepresentationStyleLanguageSpecific) |
| 1475 | s.PutCString("<not a valid Objective-C object>"); // edit this if we |
| 1476 | // have other runtimes |
| 1477 | // that support a |
| 1478 | // description |
| 1479 | else |
| 1480 | s.PutCString("<no printable representation>"); |
| 1481 | } |
| 1482 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1483 | // we should only return false here if we could not do *anything* even if |
| 1484 | // we have an error message as output, that's a success from our callers' |
| 1485 | // perspective, so return true |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1486 | var_success = true; |
| 1487 | |
| 1488 | if (custom_format != eFormatInvalid) |
| 1489 | SetFormat(eFormatDefault); |
| 1490 | } |
| 1491 | |
| 1492 | return var_success; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1495 | addr_t ValueObject::GetAddressOf(bool scalar_is_load_address, |
| 1496 | AddressType *address_type) { |
| 1497 | // Can't take address of a bitfield |
| 1498 | if (IsBitfield()) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1499 | return LLDB_INVALID_ADDRESS; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1500 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1501 | if (!UpdateValueIfNeeded(false)) |
| 1502 | return LLDB_INVALID_ADDRESS; |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1503 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1504 | switch (m_value.GetValueType()) { |
| 1505 | case Value::eValueTypeScalar: |
| 1506 | case Value::eValueTypeVector: |
| 1507 | if (scalar_is_load_address) { |
| 1508 | if (address_type) |
| 1509 | *address_type = eAddressTypeLoad; |
| 1510 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1511 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1512 | break; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1513 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1514 | case Value::eValueTypeLoadAddress: |
| 1515 | case Value::eValueTypeFileAddress: { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1516 | if (address_type) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1517 | *address_type = m_value.GetValueAddressType(); |
| 1518 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1519 | } break; |
| 1520 | case Value::eValueTypeHostAddress: { |
| 1521 | if (address_type) |
| 1522 | *address_type = m_value.GetValueAddressType(); |
| 1523 | return LLDB_INVALID_ADDRESS; |
| 1524 | } break; |
| 1525 | } |
| 1526 | if (address_type) |
| 1527 | *address_type = eAddressTypeInvalid; |
| 1528 | return LLDB_INVALID_ADDRESS; |
| 1529 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1530 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1531 | addr_t ValueObject::GetPointerValue(AddressType *address_type) { |
| 1532 | addr_t address = LLDB_INVALID_ADDRESS; |
| 1533 | if (address_type) |
| 1534 | *address_type = eAddressTypeInvalid; |
| 1535 | |
| 1536 | if (!UpdateValueIfNeeded(false)) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1537 | return address; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1538 | |
| 1539 | switch (m_value.GetValueType()) { |
| 1540 | case Value::eValueTypeScalar: |
| 1541 | case Value::eValueTypeVector: |
| 1542 | address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1543 | break; |
| 1544 | |
| 1545 | case Value::eValueTypeHostAddress: |
| 1546 | case Value::eValueTypeLoadAddress: |
| 1547 | case Value::eValueTypeFileAddress: { |
| 1548 | lldb::offset_t data_offset = 0; |
| 1549 | address = m_data.GetPointer(&data_offset); |
| 1550 | } break; |
| 1551 | } |
| 1552 | |
| 1553 | if (address_type) |
| 1554 | *address_type = GetAddressTypeOfChildren(); |
| 1555 | |
| 1556 | return address; |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1559 | bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1560 | error.Clear(); |
| 1561 | // Make sure our value is up to date first so that our location and location |
| 1562 | // type is valid. |
| 1563 | if (!UpdateValueIfNeeded(false)) { |
| 1564 | error.SetErrorString("unable to read value"); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1565 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | uint64_t count = 0; |
| 1569 | const Encoding encoding = GetCompilerType().GetEncoding(count); |
| 1570 | |
| 1571 | const size_t byte_size = GetByteSize(); |
| 1572 | |
| 1573 | Value::ValueType value_type = m_value.GetValueType(); |
| 1574 | |
| 1575 | if (value_type == Value::eValueTypeScalar) { |
| 1576 | // If the value is already a scalar, then let the scalar change itself: |
| 1577 | m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); |
| 1578 | } else if (byte_size <= 16) { |
| 1579 | // If the value fits in a scalar, then make a new scalar and again let the |
| 1580 | // scalar code do the conversion, then figure out where to put the new |
| 1581 | // value. |
| 1582 | Scalar new_scalar; |
| 1583 | error = new_scalar.SetValueFromCString(value_str, encoding, byte_size); |
| 1584 | if (error.Success()) { |
| 1585 | switch (value_type) { |
| 1586 | case Value::eValueTypeLoadAddress: { |
| 1587 | // If it is a load address, then the scalar value is the storage |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1588 | // location of the data, and we have to shove this value down to that |
| 1589 | // load location. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1590 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1591 | Process *process = exe_ctx.GetProcessPtr(); |
| 1592 | if (process) { |
| 1593 | addr_t target_addr = |
| 1594 | m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1595 | size_t bytes_written = process->WriteScalarToMemory( |
| 1596 | target_addr, new_scalar, byte_size, error); |
| 1597 | if (!error.Success()) |
| 1598 | return false; |
| 1599 | if (bytes_written != byte_size) { |
| 1600 | error.SetErrorString("unable to write value to memory"); |
| 1601 | return false; |
| 1602 | } |
| 1603 | } |
| 1604 | } break; |
| 1605 | case Value::eValueTypeHostAddress: { |
| 1606 | // If it is a host address, then we stuff the scalar as a DataBuffer |
| 1607 | // into the Value's data. |
| 1608 | DataExtractor new_data; |
| 1609 | new_data.SetByteOrder(m_data.GetByteOrder()); |
| 1610 | |
| 1611 | DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 1612 | m_data.SetData(buffer_sp, 0); |
| 1613 | bool success = new_scalar.GetData(new_data); |
| 1614 | if (success) { |
| 1615 | new_data.CopyByteOrderedData( |
| 1616 | 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()), |
| 1617 | byte_size, m_data.GetByteOrder()); |
| 1618 | } |
| 1619 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 1620 | |
| 1621 | } break; |
| 1622 | case Value::eValueTypeFileAddress: |
| 1623 | case Value::eValueTypeScalar: |
| 1624 | case Value::eValueTypeVector: |
| 1625 | break; |
| 1626 | } |
| 1627 | } else { |
| 1628 | return false; |
| 1629 | } |
| 1630 | } else { |
| 1631 | // We don't support setting things bigger than a scalar at present. |
| 1632 | error.SetErrorString("unable to write aggregate data type"); |
| 1633 | return false; |
| 1634 | } |
| 1635 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1636 | // If we have reached this point, then we have successfully changed the |
| 1637 | // value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1638 | SetNeedsUpdate(); |
| 1639 | return true; |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1642 | bool ValueObject::GetDeclaration(Declaration &decl) { |
| 1643 | decl.Clear(); |
| 1644 | return false; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1647 | ConstString ValueObject::GetTypeName() { |
| 1648 | return GetCompilerType().GetConstTypeName(); |
Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1651 | ConstString ValueObject::GetDisplayTypeName() { return GetTypeName(); } |
| 1652 | |
| 1653 | ConstString ValueObject::GetQualifiedTypeName() { |
| 1654 | return GetCompilerType().GetConstQualifiedTypeName(); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1657 | LanguageType ValueObject::GetObjectRuntimeLanguage() { |
| 1658 | return GetCompilerType().GetMinimumLanguage(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1661 | void ValueObject::AddSyntheticChild(const ConstString &key, |
| 1662 | ValueObject *valobj) { |
| 1663 | m_synthetic_children[key] = valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1666 | ValueObjectSP ValueObject::GetSyntheticChild(const ConstString &key) const { |
| 1667 | ValueObjectSP synthetic_child_sp; |
| 1668 | std::map<ConstString, ValueObject *>::const_iterator pos = |
| 1669 | m_synthetic_children.find(key); |
| 1670 | if (pos != m_synthetic_children.end()) |
| 1671 | synthetic_child_sp = pos->second->GetSP(); |
| 1672 | return synthetic_child_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1675 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1676 | ValueObject::GetTypeInfo(CompilerType *pointee_or_element_compiler_type) { |
| 1677 | return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type); |
Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1680 | bool ValueObject::IsPointerType() { return GetCompilerType().IsPointerType(); } |
| 1681 | |
| 1682 | bool ValueObject::IsArrayType() { |
| 1683 | return GetCompilerType().IsArrayType(NULL, NULL, NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1686 | bool ValueObject::IsScalarType() { return GetCompilerType().IsScalarType(); } |
| 1687 | |
| 1688 | bool ValueObject::IsIntegerType(bool &is_signed) { |
| 1689 | return GetCompilerType().IsIntegerType(is_signed); |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1692 | bool ValueObject::IsPointerOrReferenceType() { |
| 1693 | return GetCompilerType().IsPointerOrReferenceType(); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1696 | bool ValueObject::IsPossibleDynamicType() { |
| 1697 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1698 | Process *process = exe_ctx.GetProcessPtr(); |
| 1699 | if (process) |
| 1700 | return process->IsPossibleDynamicValue(*this); |
| 1701 | else |
| 1702 | return GetCompilerType().IsPossibleDynamicType(NULL, true, true); |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1703 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1704 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1705 | bool ValueObject::IsRuntimeSupportValue() { |
| 1706 | Process *process(GetProcessSP().get()); |
| 1707 | if (process) { |
| 1708 | LanguageRuntime *runtime = |
| 1709 | process->GetLanguageRuntime(GetObjectRuntimeLanguage()); |
| 1710 | if (!runtime) |
| 1711 | runtime = process->GetObjCLanguageRuntime(); |
| 1712 | if (runtime) |
| 1713 | return runtime->IsRuntimeSupportValue(*this); |
| 1714 | } |
| 1715 | return false; |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1718 | bool ValueObject::IsNilReference() { |
| 1719 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { |
| 1720 | return language->IsNilReference(*this); |
| 1721 | } |
| 1722 | return false; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1725 | bool ValueObject::IsUninitializedReference() { |
| 1726 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { |
| 1727 | return language->IsUninitializedReference(*this); |
| 1728 | } |
| 1729 | return false; |
Enrico Granata | 9e7b388 | 2012-12-13 23:50:33 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1732 | // This allows you to create an array member using and index that doesn't not |
| 1733 | // fall in the normal bounds of the array. Many times structure can be defined |
| 1734 | // as: struct Collection { |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1735 | // uint32_t item_count; |
| 1736 | // Item item_array[0]; |
| 1737 | // }; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1738 | // The size of the "item_array" is 1, but many times in practice there are more |
| 1739 | // items in "item_array". |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1740 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1741 | ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, |
| 1742 | bool can_create) { |
| 1743 | ValueObjectSP synthetic_child_sp; |
| 1744 | if (IsPointerType() || IsArrayType()) { |
| 1745 | char index_str[64]; |
| 1746 | snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); |
| 1747 | ConstString index_const_str(index_str); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1748 | // Check if we have already created a synthetic array member in this valid |
| 1749 | // object. If we have we will re-use it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1750 | synthetic_child_sp = GetSyntheticChild(index_const_str); |
| 1751 | if (!synthetic_child_sp) { |
| 1752 | ValueObject *synthetic_child; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1753 | // We haven't made a synthetic array member for INDEX yet, so lets make |
| 1754 | // one and cache it for any future reference. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1755 | synthetic_child = CreateChildAtIndex(0, true, index); |
| 1756 | |
| 1757 | // Cache the value if we got one back... |
| 1758 | if (synthetic_child) { |
| 1759 | AddSyntheticChild(index_const_str, synthetic_child); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1760 | synthetic_child_sp = synthetic_child->GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1761 | synthetic_child_sp->SetName(ConstString(index_str)); |
| 1762 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
| 1763 | } |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1764 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1765 | } |
| 1766 | return synthetic_child_sp; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1769 | ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, |
| 1770 | bool can_create) { |
| 1771 | ValueObjectSP synthetic_child_sp; |
| 1772 | if (IsScalarType()) { |
| 1773 | char index_str[64]; |
| 1774 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 1775 | ConstString index_const_str(index_str); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1776 | // Check if we have already created a synthetic array member in this valid |
| 1777 | // object. If we have we will re-use it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1778 | synthetic_child_sp = GetSyntheticChild(index_const_str); |
| 1779 | if (!synthetic_child_sp) { |
| 1780 | uint32_t bit_field_size = to - from + 1; |
| 1781 | uint32_t bit_field_offset = from; |
| 1782 | if (GetDataExtractor().GetByteOrder() == eByteOrderBig) |
| 1783 | bit_field_offset = |
| 1784 | GetByteSize() * 8 - bit_field_size - bit_field_offset; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1785 | // We haven't made a synthetic array member for INDEX yet, so lets make |
| 1786 | // one and cache it for any future reference. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1787 | ValueObjectChild *synthetic_child = new ValueObjectChild( |
| 1788 | *this, GetCompilerType(), index_const_str, GetByteSize(), 0, |
| 1789 | bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, |
| 1790 | 0); |
| 1791 | |
| 1792 | // Cache the value if we got one back... |
| 1793 | if (synthetic_child) { |
| 1794 | AddSyntheticChild(index_const_str, synthetic_child); |
Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 1795 | synthetic_child_sp = synthetic_child->GetSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1796 | synthetic_child_sp->SetName(ConstString(index_str)); |
| 1797 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 1798 | } |
Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 1799 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1800 | } |
| 1801 | return synthetic_child_sp; |
Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1804 | ValueObjectSP ValueObject::GetSyntheticChildAtOffset( |
| 1805 | uint32_t offset, const CompilerType &type, bool can_create, |
| 1806 | ConstString name_const_str) { |
| 1807 | |
| 1808 | ValueObjectSP synthetic_child_sp; |
| 1809 | |
| 1810 | if (name_const_str.IsEmpty()) { |
| 1811 | char name_str[64]; |
| 1812 | snprintf(name_str, sizeof(name_str), "@%i", offset); |
| 1813 | name_const_str.SetCString(name_str); |
| 1814 | } |
| 1815 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1816 | // Check if we have already created a synthetic array member in this valid |
| 1817 | // object. If we have we will re-use it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1818 | synthetic_child_sp = GetSyntheticChild(name_const_str); |
| 1819 | |
| 1820 | if (synthetic_child_sp.get()) |
| 1821 | return synthetic_child_sp; |
| 1822 | |
| 1823 | if (!can_create) |
| 1824 | return ValueObjectSP(); |
| 1825 | |
| 1826 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1827 | |
| 1828 | ValueObjectChild *synthetic_child = new ValueObjectChild( |
| 1829 | *this, type, name_const_str, |
| 1830 | type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, |
| 1831 | false, false, eAddressTypeInvalid, 0); |
| 1832 | if (synthetic_child) { |
| 1833 | AddSyntheticChild(name_const_str, synthetic_child); |
| 1834 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1835 | synthetic_child_sp->SetName(name_const_str); |
| 1836 | synthetic_child_sp->m_is_child_at_offset = true; |
| 1837 | } |
| 1838 | return synthetic_child_sp; |
| 1839 | } |
| 1840 | |
| 1841 | ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, |
| 1842 | const CompilerType &type, |
| 1843 | bool can_create, |
| 1844 | ConstString name_const_str) { |
| 1845 | ValueObjectSP synthetic_child_sp; |
| 1846 | |
| 1847 | if (name_const_str.IsEmpty()) { |
| 1848 | char name_str[128]; |
| 1849 | snprintf(name_str, sizeof(name_str), "base%s@%i", |
| 1850 | type.GetTypeName().AsCString("<unknown>"), offset); |
| 1851 | name_const_str.SetCString(name_str); |
| 1852 | } |
| 1853 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1854 | // Check if we have already created a synthetic array member in this valid |
| 1855 | // object. If we have we will re-use it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1856 | synthetic_child_sp = GetSyntheticChild(name_const_str); |
| 1857 | |
| 1858 | if (synthetic_child_sp.get()) |
| 1859 | return synthetic_child_sp; |
| 1860 | |
| 1861 | if (!can_create) |
| 1862 | return ValueObjectSP(); |
| 1863 | |
| 1864 | const bool is_base_class = true; |
| 1865 | |
| 1866 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1867 | |
| 1868 | ValueObjectChild *synthetic_child = new ValueObjectChild( |
| 1869 | *this, type, name_const_str, |
| 1870 | type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, |
| 1871 | is_base_class, false, eAddressTypeInvalid, 0); |
| 1872 | if (synthetic_child) { |
| 1873 | AddSyntheticChild(name_const_str, synthetic_child); |
| 1874 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1875 | synthetic_child_sp->SetName(name_const_str); |
| 1876 | } |
| 1877 | return synthetic_child_sp; |
| 1878 | } |
Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 1879 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1880 | // your expression path needs to have a leading . or -> (unless it somehow |
| 1881 | // "looks like" an array, in which case it has a leading [ symbol). while the [ |
| 1882 | // is meaningful and should be shown to the user, . and -> are just parser |
| 1883 | // design, but by no means added information for the user.. strip them off |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1884 | static const char *SkipLeadingExpressionPathSeparators(const char *expression) { |
| 1885 | if (!expression || !expression[0]) |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1886 | return expression; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1887 | if (expression[0] == '.') |
| 1888 | return expression + 1; |
| 1889 | if (expression[0] == '-' && expression[1] == '>') |
| 1890 | return expression + 2; |
| 1891 | return expression; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1894 | ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1895 | ValueObject::GetSyntheticExpressionPathChild(const char *expression, |
| 1896 | bool can_create) { |
| 1897 | ValueObjectSP synthetic_child_sp; |
| 1898 | ConstString name_const_string(expression); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1899 | // Check if we have already created a synthetic array member in this valid |
| 1900 | // object. If we have we will re-use it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1901 | synthetic_child_sp = GetSyntheticChild(name_const_string); |
| 1902 | if (!synthetic_child_sp) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1903 | // We haven't made a synthetic array member for expression yet, so lets |
| 1904 | // make one and cache it for any future reference. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1905 | synthetic_child_sp = GetValueForExpressionPath( |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 1906 | expression, NULL, NULL, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1907 | GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal( |
| 1908 | GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 1909 | None)); |
| 1910 | |
| 1911 | // Cache the value if we got one back... |
| 1912 | if (synthetic_child_sp.get()) { |
| 1913 | // FIXME: this causes a "real" child to end up with its name changed to |
| 1914 | // the contents of expression |
| 1915 | AddSyntheticChild(name_const_string, synthetic_child_sp.get()); |
| 1916 | synthetic_child_sp->SetName( |
| 1917 | ConstString(SkipLeadingExpressionPathSeparators(expression))); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1918 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1919 | } |
| 1920 | return synthetic_child_sp; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1923 | void ValueObject::CalculateSyntheticValue(bool use_synthetic) { |
| 1924 | if (use_synthetic == false) |
| 1925 | return; |
| 1926 | |
| 1927 | TargetSP target_sp(GetTargetSP()); |
| 1928 | if (target_sp && target_sp->GetEnableSyntheticValue() == false) { |
| 1929 | m_synthetic_value = NULL; |
| 1930 | return; |
| 1931 | } |
| 1932 | |
| 1933 | lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp); |
| 1934 | |
| 1935 | if (!UpdateFormatsIfNeeded() && m_synthetic_value) |
| 1936 | return; |
| 1937 | |
| 1938 | if (m_synthetic_children_sp.get() == NULL) |
| 1939 | return; |
| 1940 | |
| 1941 | if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value) |
| 1942 | return; |
| 1943 | |
| 1944 | m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp); |
| 1945 | } |
| 1946 | |
| 1947 | void ValueObject::CalculateDynamicValue(DynamicValueType use_dynamic) { |
| 1948 | if (use_dynamic == eNoDynamicValues) |
| 1949 | return; |
| 1950 | |
| 1951 | if (!m_dynamic_value && !IsDynamic()) { |
| 1952 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 1953 | Process *process = exe_ctx.GetProcessPtr(); |
| 1954 | if (process && process->IsPossibleDynamicValue(*this)) { |
| 1955 | ClearDynamicTypeInformation(); |
| 1956 | m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic); |
Enrico Granata | c5bc412 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 1957 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1958 | } |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1961 | ValueObjectSP ValueObject::GetDynamicValue(DynamicValueType use_dynamic) { |
| 1962 | if (use_dynamic == eNoDynamicValues) |
| 1963 | return ValueObjectSP(); |
| 1964 | |
| 1965 | if (!IsDynamic() && m_dynamic_value == NULL) { |
| 1966 | CalculateDynamicValue(use_dynamic); |
| 1967 | } |
| 1968 | if (m_dynamic_value) |
| 1969 | return m_dynamic_value->GetSP(); |
| 1970 | else |
| 1971 | return ValueObjectSP(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1974 | ValueObjectSP ValueObject::GetStaticValue() { return GetSP(); } |
| 1975 | |
| 1976 | lldb::ValueObjectSP ValueObject::GetNonSyntheticValue() { return GetSP(); } |
| 1977 | |
| 1978 | ValueObjectSP ValueObject::GetSyntheticValue(bool use_synthetic) { |
| 1979 | if (use_synthetic == false) |
| 1980 | return ValueObjectSP(); |
| 1981 | |
| 1982 | CalculateSyntheticValue(use_synthetic); |
| 1983 | |
| 1984 | if (m_synthetic_value) |
| 1985 | return m_synthetic_value->GetSP(); |
| 1986 | else |
| 1987 | return ValueObjectSP(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1988 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1989 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1990 | bool ValueObject::HasSyntheticValue() { |
| 1991 | UpdateFormatsIfNeeded(); |
Jim Ingham | 60dbabb | 2011-12-08 19:44:08 +0000 | [diff] [blame] | 1992 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1993 | if (m_synthetic_children_sp.get() == NULL) |
| 1994 | return false; |
Enrico Granata | 886147f | 2012-05-08 18:47:08 +0000 | [diff] [blame] | 1995 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1996 | CalculateSyntheticValue(true); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1997 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1998 | if (m_synthetic_value) |
| 1999 | return true; |
| 2000 | else |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2001 | return false; |
| 2002 | } |
| 2003 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2004 | bool ValueObject::GetBaseClassPath(Stream &s) { |
| 2005 | if (IsBaseClass()) { |
| 2006 | bool parent_had_base_class = |
| 2007 | GetParent() && GetParent()->GetBaseClassPath(s); |
| 2008 | CompilerType compiler_type = GetCompilerType(); |
| 2009 | std::string cxx_class_name; |
| 2010 | bool this_had_base_class = |
| 2011 | ClangASTContext::GetCXXClassName(compiler_type, cxx_class_name); |
| 2012 | if (this_had_base_class) { |
| 2013 | if (parent_had_base_class) |
| 2014 | s.PutCString("::"); |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 2015 | s.PutCString(cxx_class_name); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2016 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2017 | return parent_had_base_class || this_had_base_class; |
| 2018 | } |
| 2019 | return false; |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2020 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2021 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2022 | ValueObject *ValueObject::GetNonBaseClassParent() { |
| 2023 | if (GetParent()) { |
| 2024 | if (GetParent()->IsBaseClass()) |
| 2025 | return GetParent()->GetNonBaseClassParent(); |
| 2026 | else |
| 2027 | return GetParent(); |
| 2028 | } |
| 2029 | return NULL; |
| 2030 | } |
Enrico Granata | a3c8f04 | 2014-08-19 22:29:08 +0000 | [diff] [blame] | 2031 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2032 | bool ValueObject::IsBaseClass(uint32_t &depth) { |
| 2033 | if (!IsBaseClass()) { |
| 2034 | depth = 0; |
| 2035 | return false; |
| 2036 | } |
| 2037 | if (GetParent()) { |
| 2038 | GetParent()->IsBaseClass(depth); |
| 2039 | depth = depth + 1; |
Enrico Granata | a3c8f04 | 2014-08-19 22:29:08 +0000 | [diff] [blame] | 2040 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2041 | } |
| 2042 | // TODO: a base of no parent? weird.. |
| 2043 | depth = 1; |
| 2044 | return true; |
Enrico Granata | a3c8f04 | 2014-08-19 22:29:08 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2047 | void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, |
| 2048 | GetExpressionPathFormat epformat) { |
| 2049 | // synthetic children do not actually "exist" as part of the hierarchy, and |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2050 | // sometimes they are consed up in ways that don't make sense from an |
| 2051 | // underlying language/API standpoint. So, use a special code path here to |
| 2052 | // return something that can hopefully be used in expression |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2053 | if (m_is_synthetic_children_generated) { |
| 2054 | UpdateValueIfNeeded(); |
| 2055 | |
| 2056 | if (m_value.GetValueType() == Value::eValueTypeLoadAddress) { |
| 2057 | if (IsPointerOrReferenceType()) { |
| 2058 | s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"), |
| 2059 | GetValueAsUnsigned(0)); |
Enrico Granata | 986fa5f | 2014-12-09 21:41:16 +0000 | [diff] [blame] | 2060 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2061 | } else { |
| 2062 | uint64_t load_addr = |
| 2063 | m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 2064 | if (load_addr != LLDB_INVALID_ADDRESS) { |
| 2065 | s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"), |
| 2066 | load_addr); |
| 2067 | return; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2068 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2069 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2070 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2071 | |
| 2072 | if (CanProvideValue()) { |
| 2073 | s.Printf("((%s)%s)", GetTypeName().AsCString("void"), |
| 2074 | GetValueAsCString()); |
| 2075 | return; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2076 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2077 | |
| 2078 | return; |
| 2079 | } |
| 2080 | |
| 2081 | const bool is_deref_of_parent = IsDereferenceOfParent(); |
| 2082 | |
| 2083 | if (is_deref_of_parent && |
| 2084 | epformat == eGetExpressionPathFormatDereferencePointers) { |
| 2085 | // this is the original format of GetExpressionPath() producing code like |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2086 | // *(a_ptr).memberName, which is entirely fine, until you put this into |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2087 | // StackFrame::GetValueForVariableExpressionPath() which prefers to see |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2088 | // a_ptr->memberName. the eHonorPointers mode is meant to produce strings |
| 2089 | // in this latter format |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2090 | s.PutCString("*("); |
| 2091 | } |
| 2092 | |
| 2093 | ValueObject *parent = GetParent(); |
| 2094 | |
| 2095 | if (parent) |
| 2096 | parent->GetExpressionPath(s, qualify_cxx_base_classes, epformat); |
| 2097 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2098 | // if we are a deref_of_parent just because we are synthetic array members |
| 2099 | // made up to allow ptr[%d] syntax to work in variable printing, then add our |
| 2100 | // name ([%d]) to the expression path |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2101 | if (m_is_array_item_for_pointer && |
| 2102 | epformat == eGetExpressionPathFormatHonorPointers) |
| 2103 | s.PutCString(m_name.AsCString()); |
| 2104 | |
| 2105 | if (!IsBaseClass()) { |
| 2106 | if (!is_deref_of_parent) { |
| 2107 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 2108 | if (non_base_class_parent && |
| 2109 | !non_base_class_parent->GetName().IsEmpty()) { |
| 2110 | CompilerType non_base_class_parent_compiler_type = |
| 2111 | non_base_class_parent->GetCompilerType(); |
| 2112 | if (non_base_class_parent_compiler_type) { |
| 2113 | if (parent && parent->IsDereferenceOfParent() && |
| 2114 | epformat == eGetExpressionPathFormatHonorPointers) { |
| 2115 | s.PutCString("->"); |
| 2116 | } else { |
| 2117 | const uint32_t non_base_class_parent_type_info = |
| 2118 | non_base_class_parent_compiler_type.GetTypeInfo(); |
| 2119 | |
| 2120 | if (non_base_class_parent_type_info & eTypeIsPointer) { |
| 2121 | s.PutCString("->"); |
| 2122 | } else if ((non_base_class_parent_type_info & eTypeHasChildren) && |
| 2123 | !(non_base_class_parent_type_info & eTypeIsArray)) { |
| 2124 | s.PutChar('.'); |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | const char *name = GetName().GetCString(); |
| 2131 | if (name) { |
| 2132 | if (qualify_cxx_base_classes) { |
| 2133 | if (GetBaseClassPath(s)) |
| 2134 | s.PutCString("::"); |
| 2135 | } |
| 2136 | s.PutCString(name); |
| 2137 | } |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | if (is_deref_of_parent && |
| 2142 | epformat == eGetExpressionPathFormatDereferencePointers) { |
| 2143 | s.PutChar(')'); |
| 2144 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2147 | ValueObjectSP ValueObject::GetValueForExpressionPath( |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2148 | llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2149 | ExpressionPathEndResultType *final_value_type, |
| 2150 | const GetValueForExpressionPathOptions &options, |
| 2151 | ExpressionPathAftermath *final_task_on_target) { |
Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2153 | ExpressionPathScanEndReason dummy_reason_to_stop = |
| 2154 | ValueObject::eExpressionPathScanEndReasonUnknown; |
| 2155 | ExpressionPathEndResultType dummy_final_value_type = |
| 2156 | ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2157 | ExpressionPathAftermath dummy_final_task_on_target = |
| 2158 | ValueObject::eExpressionPathAftermathNothing; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2160 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl( |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2161 | expression, reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2162 | final_value_type ? final_value_type : &dummy_final_value_type, options, |
| 2163 | final_task_on_target ? final_task_on_target |
| 2164 | : &dummy_final_task_on_target); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2166 | if (!final_task_on_target || |
| 2167 | *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) |
| 2168 | return ret_val; |
| 2169 | |
| 2170 | if (ret_val.get() && |
| 2171 | ((final_value_type ? *final_value_type : dummy_final_value_type) == |
| 2172 | eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress |
| 2173 | // of plain objects |
| 2174 | { |
| 2175 | if ((final_task_on_target ? *final_task_on_target |
| 2176 | : dummy_final_task_on_target) == |
| 2177 | ValueObject::eExpressionPathAftermathDereference) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2178 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2179 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 2180 | if (error.Fail() || !final_value.get()) { |
| 2181 | if (reason_to_stop) |
| 2182 | *reason_to_stop = |
| 2183 | ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 2184 | if (final_value_type) |
| 2185 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2186 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2187 | } else { |
| 2188 | if (final_task_on_target) |
| 2189 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| 2190 | return final_value; |
| 2191 | } |
| 2192 | } |
| 2193 | if (*final_task_on_target == |
| 2194 | ValueObject::eExpressionPathAftermathTakeAddress) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2195 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2196 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 2197 | if (error.Fail() || !final_value.get()) { |
| 2198 | if (reason_to_stop) |
| 2199 | *reason_to_stop = |
| 2200 | ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; |
| 2201 | if (final_value_type) |
| 2202 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2203 | return ValueObjectSP(); |
| 2204 | } else { |
| 2205 | if (final_task_on_target) |
| 2206 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| 2207 | return final_value; |
| 2208 | } |
| 2209 | } |
| 2210 | } |
| 2211 | return ret_val; // final_task_on_target will still have its original value, so |
| 2212 | // you know I did not do it |
| 2213 | } |
| 2214 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2215 | ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2216 | llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2217 | ExpressionPathEndResultType *final_result, |
| 2218 | const GetValueForExpressionPathOptions &options, |
| 2219 | ExpressionPathAftermath *what_next) { |
| 2220 | ValueObjectSP root = GetSP(); |
| 2221 | |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2222 | if (!root) |
| 2223 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2224 | |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2225 | llvm::StringRef remainder = expression; |
Zachary Turner | 655c452 | 2016-11-18 06:34:45 +0000 | [diff] [blame] | 2226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2227 | while (true) { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2228 | llvm::StringRef temp_expression = remainder; |
Zachary Turner | 655c452 | 2016-11-18 06:34:45 +0000 | [diff] [blame] | 2229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2230 | CompilerType root_compiler_type = root->GetCompilerType(); |
| 2231 | CompilerType pointee_compiler_type; |
| 2232 | Flags pointee_compiler_type_info; |
| 2233 | |
| 2234 | Flags root_compiler_type_info( |
| 2235 | root_compiler_type.GetTypeInfo(&pointee_compiler_type)); |
| 2236 | if (pointee_compiler_type) |
| 2237 | pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); |
| 2238 | |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2239 | if (temp_expression.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2240 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 2241 | return root; |
| 2242 | } |
| 2243 | |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2244 | switch (temp_expression.front()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2245 | case '-': { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2246 | temp_expression = temp_expression.drop_front(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2247 | if (options.m_check_dot_vs_arrow_syntax && |
| 2248 | root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to |
| 2249 | // use -> on a |
| 2250 | // non-pointer and I |
| 2251 | // must catch the error |
| 2252 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2253 | *reason_to_stop = |
| 2254 | ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot; |
| 2255 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2256 | return ValueObjectSP(); |
| 2257 | } |
| 2258 | if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to |
| 2259 | // extract an ObjC IVar |
| 2260 | // when this is forbidden |
| 2261 | root_compiler_type_info.Test(eTypeIsPointer) && |
| 2262 | options.m_no_fragile_ivar) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2263 | *reason_to_stop = |
| 2264 | ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed; |
| 2265 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2266 | return ValueObjectSP(); |
| 2267 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2268 | if (!temp_expression.startswith(">")) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2269 | *reason_to_stop = |
| 2270 | ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2271 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2272 | return ValueObjectSP(); |
| 2273 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2274 | } |
| 2275 | LLVM_FALLTHROUGH; |
| 2276 | case '.': // or fallthrough from -> |
| 2277 | { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2278 | if (options.m_check_dot_vs_arrow_syntax && |
| 2279 | temp_expression.front() == '.' && |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2280 | root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to |
| 2281 | // use . on a pointer |
| 2282 | // and I must catch the |
| 2283 | // error |
| 2284 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2285 | *reason_to_stop = |
| 2286 | ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow; |
| 2287 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2288 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2289 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2290 | temp_expression = temp_expression.drop_front(); // skip . or > |
| 2291 | |
| 2292 | size_t next_sep_pos = temp_expression.find_first_of("-.[", 1); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2293 | ConstString child_name; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2294 | if (next_sep_pos == llvm::StringRef::npos) // if no other separator just |
| 2295 | // expand this last layer |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2296 | { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2297 | child_name.SetString(temp_expression); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2298 | ValueObjectSP child_valobj_sp = |
| 2299 | root->GetChildMemberWithName(child_name, true); |
| 2300 | |
| 2301 | if (child_valobj_sp.get()) // we know we are done, so just return |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2302 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2303 | *reason_to_stop = |
| 2304 | ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 2305 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2306 | return child_valobj_sp; |
| 2307 | } else { |
| 2308 | switch (options.m_synthetic_children_traversal) { |
| 2309 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2310 | None: |
| 2311 | break; |
| 2312 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2313 | FromSynthetic: |
| 2314 | if (root->IsSynthetic()) { |
| 2315 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2316 | if (child_valobj_sp.get()) |
| 2317 | child_valobj_sp = |
| 2318 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2319 | } |
| 2320 | break; |
| 2321 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2322 | ToSynthetic: |
| 2323 | if (!root->IsSynthetic()) { |
| 2324 | child_valobj_sp = root->GetSyntheticValue(); |
| 2325 | if (child_valobj_sp.get()) |
| 2326 | child_valobj_sp = |
| 2327 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2328 | } |
| 2329 | break; |
| 2330 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2331 | Both: |
| 2332 | if (root->IsSynthetic()) { |
| 2333 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2334 | if (child_valobj_sp.get()) |
| 2335 | child_valobj_sp = |
| 2336 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2337 | } else { |
| 2338 | child_valobj_sp = root->GetSyntheticValue(); |
| 2339 | if (child_valobj_sp.get()) |
| 2340 | child_valobj_sp = |
| 2341 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2342 | } |
| 2343 | break; |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | // if we are here and options.m_no_synthetic_children is true, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2348 | // child_valobj_sp is going to be a NULL SP, so we hit the "else" |
| 2349 | // branch, and return an error |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2350 | if (child_valobj_sp.get()) // if it worked, just return |
| 2351 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2352 | *reason_to_stop = |
| 2353 | ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 2354 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2355 | return child_valobj_sp; |
| 2356 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2357 | *reason_to_stop = |
| 2358 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2359 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2360 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2361 | } |
| 2362 | } else // other layers do expand |
| 2363 | { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2364 | llvm::StringRef next_separator = temp_expression.substr(next_sep_pos); |
| 2365 | |
| 2366 | child_name.SetString(temp_expression.slice(0, next_sep_pos)); |
| 2367 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2368 | ValueObjectSP child_valobj_sp = |
| 2369 | root->GetChildMemberWithName(child_name, true); |
| 2370 | if (child_valobj_sp.get()) // store the new root and move on |
| 2371 | { |
| 2372 | root = child_valobj_sp; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2373 | remainder = next_separator; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2374 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2375 | continue; |
| 2376 | } else { |
| 2377 | switch (options.m_synthetic_children_traversal) { |
| 2378 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2379 | None: |
| 2380 | break; |
| 2381 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2382 | FromSynthetic: |
| 2383 | if (root->IsSynthetic()) { |
| 2384 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2385 | if (child_valobj_sp.get()) |
| 2386 | child_valobj_sp = |
| 2387 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2388 | } |
| 2389 | break; |
| 2390 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2391 | ToSynthetic: |
| 2392 | if (!root->IsSynthetic()) { |
| 2393 | child_valobj_sp = root->GetSyntheticValue(); |
| 2394 | if (child_valobj_sp.get()) |
| 2395 | child_valobj_sp = |
| 2396 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2397 | } |
| 2398 | break; |
| 2399 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2400 | Both: |
| 2401 | if (root->IsSynthetic()) { |
| 2402 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2403 | if (child_valobj_sp.get()) |
| 2404 | child_valobj_sp = |
| 2405 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2406 | } else { |
| 2407 | child_valobj_sp = root->GetSyntheticValue(); |
| 2408 | if (child_valobj_sp.get()) |
| 2409 | child_valobj_sp = |
| 2410 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2411 | } |
| 2412 | break; |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | // if we are here and options.m_no_synthetic_children is true, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2417 | // child_valobj_sp is going to be a NULL SP, so we hit the "else" |
| 2418 | // branch, and return an error |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2419 | if (child_valobj_sp.get()) // if it worked, move on |
| 2420 | { |
| 2421 | root = child_valobj_sp; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2422 | remainder = next_separator; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2423 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2424 | continue; |
| 2425 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2426 | *reason_to_stop = |
| 2427 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2428 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2429 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | break; |
| 2433 | } |
| 2434 | case '[': { |
| 2435 | if (!root_compiler_type_info.Test(eTypeIsArray) && |
| 2436 | !root_compiler_type_info.Test(eTypeIsPointer) && |
| 2437 | !root_compiler_type_info.Test( |
| 2438 | eTypeIsVector)) // if this is not a T[] nor a T* |
| 2439 | { |
| 2440 | if (!root_compiler_type_info.Test( |
| 2441 | eTypeIsScalar)) // if this is not even a scalar... |
| 2442 | { |
| 2443 | if (options.m_synthetic_children_traversal == |
| 2444 | GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: |
| 2445 | None) // ...only chance left is synthetic |
| 2446 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2447 | *reason_to_stop = |
| 2448 | ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; |
| 2449 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2450 | return ValueObjectSP(); |
| 2451 | } |
| 2452 | } else if (!options.m_allow_bitfields_syntax) // if this is a scalar, |
| 2453 | // check that we can |
| 2454 | // expand bitfields |
| 2455 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2456 | *reason_to_stop = |
| 2457 | ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; |
| 2458 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2459 | return ValueObjectSP(); |
| 2460 | } |
| 2461 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2462 | if (temp_expression[1] == |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2463 | ']') // if this is an unbounded range it only works for arrays |
| 2464 | { |
| 2465 | if (!root_compiler_type_info.Test(eTypeIsArray)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2466 | *reason_to_stop = |
| 2467 | ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; |
| 2468 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2469 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2470 | } else // even if something follows, we cannot expand unbounded ranges, |
| 2471 | // just let the caller do it |
| 2472 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2473 | *reason_to_stop = |
| 2474 | ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; |
| 2475 | *final_result = |
| 2476 | ValueObject::eExpressionPathEndResultTypeUnboundedRange; |
| 2477 | return root; |
| 2478 | } |
| 2479 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2480 | |
| 2481 | size_t close_bracket_position = temp_expression.find(']', 1); |
| 2482 | if (close_bracket_position == |
| 2483 | llvm::StringRef::npos) // if there is no ], this is a syntax error |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2484 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2485 | *reason_to_stop = |
| 2486 | ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2487 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2488 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2489 | } |
Zachary Turner | c2d5558 | 2016-11-18 03:51:19 +0000 | [diff] [blame] | 2490 | |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2491 | llvm::StringRef bracket_expr = |
| 2492 | temp_expression.slice(1, close_bracket_position); |
| 2493 | |
| 2494 | // If this was an empty expression it would have been caught by the if |
| 2495 | // above. |
| 2496 | assert(!bracket_expr.empty()); |
| 2497 | |
| 2498 | if (!bracket_expr.contains('-')) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2499 | // if no separator, this is of the form [N]. Note that this cannot be |
| 2500 | // an unbounded range of the form [], because that case was handled |
Zachary Turner | c2d5558 | 2016-11-18 03:51:19 +0000 | [diff] [blame] | 2501 | // above with an unconditional return. |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2502 | unsigned long index = 0; |
| 2503 | if (bracket_expr.getAsInteger(0, index)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2504 | *reason_to_stop = |
| 2505 | ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2506 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2507 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2508 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2509 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2510 | // from here on we do have a valid index |
| 2511 | if (root_compiler_type_info.Test(eTypeIsArray)) { |
| 2512 | ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); |
| 2513 | if (!child_valobj_sp) |
| 2514 | child_valobj_sp = root->GetSyntheticArrayMember(index, true); |
| 2515 | if (!child_valobj_sp) |
| 2516 | if (root->HasSyntheticValue() && |
| 2517 | root->GetSyntheticValue()->GetNumChildren() > index) |
| 2518 | child_valobj_sp = |
| 2519 | root->GetSyntheticValue()->GetChildAtIndex(index, true); |
| 2520 | if (child_valobj_sp) { |
| 2521 | root = child_valobj_sp; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2522 | remainder = |
| 2523 | temp_expression.substr(close_bracket_position + 1); // skip ] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2524 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2525 | continue; |
| 2526 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2527 | *reason_to_stop = |
| 2528 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2529 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2530 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2531 | } |
| 2532 | } else if (root_compiler_type_info.Test(eTypeIsPointer)) { |
| 2533 | if (*what_next == |
| 2534 | ValueObject:: |
| 2535 | eExpressionPathAftermathDereference && // if this is a |
| 2536 | // ptr-to-scalar, I |
| 2537 | // am accessing it |
| 2538 | // by index and I |
| 2539 | // would have |
| 2540 | // deref'ed anyway, |
| 2541 | // then do it now |
| 2542 | // and use this as |
| 2543 | // a bitfield |
| 2544 | pointee_compiler_type_info.Test(eTypeIsScalar)) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2545 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2546 | root = root->Dereference(error); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2547 | if (error.Fail() || !root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2548 | *reason_to_stop = |
| 2549 | ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 2550 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2551 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2552 | } else { |
| 2553 | *what_next = eExpressionPathAftermathNothing; |
| 2554 | continue; |
| 2555 | } |
| 2556 | } else { |
| 2557 | if (root->GetCompilerType().GetMinimumLanguage() == |
| 2558 | eLanguageTypeObjC && |
| 2559 | pointee_compiler_type_info.AllClear(eTypeIsPointer) && |
| 2560 | root->HasSyntheticValue() && |
| 2561 | (options.m_synthetic_children_traversal == |
| 2562 | GetValueForExpressionPathOptions:: |
| 2563 | SyntheticChildrenTraversal::ToSynthetic || |
| 2564 | options.m_synthetic_children_traversal == |
| 2565 | GetValueForExpressionPathOptions:: |
| 2566 | SyntheticChildrenTraversal::Both)) { |
| 2567 | root = root->GetSyntheticValue()->GetChildAtIndex(index, true); |
| 2568 | } else |
| 2569 | root = root->GetSyntheticArrayMember(index, true); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2570 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2571 | *reason_to_stop = |
| 2572 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2573 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2574 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2575 | } else { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2576 | remainder = |
| 2577 | temp_expression.substr(close_bracket_position + 1); // skip ] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2578 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2579 | continue; |
| 2580 | } |
| 2581 | } |
| 2582 | } else if (root_compiler_type_info.Test(eTypeIsScalar)) { |
| 2583 | root = root->GetSyntheticBitFieldChild(index, index, true); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2584 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2585 | *reason_to_stop = |
| 2586 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2587 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2588 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2589 | } else // we do not know how to expand members of bitfields, so we |
| 2590 | // just return and let the caller do any further processing |
| 2591 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2592 | *reason_to_stop = ValueObject:: |
| 2593 | eExpressionPathScanEndReasonBitfieldRangeOperatorMet; |
| 2594 | *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; |
| 2595 | return root; |
| 2596 | } |
| 2597 | } else if (root_compiler_type_info.Test(eTypeIsVector)) { |
| 2598 | root = root->GetChildAtIndex(index, true); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2599 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2600 | *reason_to_stop = |
| 2601 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2602 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 2603 | return ValueObjectSP(); |
| 2604 | } else { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2605 | remainder = |
| 2606 | temp_expression.substr(close_bracket_position + 1); // skip ] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2607 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2608 | continue; |
| 2609 | } |
| 2610 | } else if (options.m_synthetic_children_traversal == |
| 2611 | GetValueForExpressionPathOptions:: |
| 2612 | SyntheticChildrenTraversal::ToSynthetic || |
| 2613 | options.m_synthetic_children_traversal == |
| 2614 | GetValueForExpressionPathOptions:: |
| 2615 | SyntheticChildrenTraversal::Both) { |
| 2616 | if (root->HasSyntheticValue()) |
| 2617 | root = root->GetSyntheticValue(); |
| 2618 | else if (!root->IsSynthetic()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2619 | *reason_to_stop = |
| 2620 | ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; |
| 2621 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2622 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2623 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2624 | // if we are here, then root itself is a synthetic VO.. should be |
| 2625 | // good to go |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2626 | |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2627 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2628 | *reason_to_stop = |
| 2629 | ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; |
| 2630 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2631 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2632 | } |
| 2633 | root = root->GetChildAtIndex(index, true); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2634 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2635 | *reason_to_stop = |
| 2636 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2637 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2638 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2639 | } else { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2640 | remainder = |
| 2641 | temp_expression.substr(close_bracket_position + 1); // skip ] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2642 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 2643 | continue; |
| 2644 | } |
| 2645 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2646 | *reason_to_stop = |
| 2647 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2648 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2649 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2650 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2651 | } else { |
| 2652 | // we have a low and a high index |
| 2653 | llvm::StringRef sleft, sright; |
| 2654 | unsigned long low_index, high_index; |
| 2655 | std::tie(sleft, sright) = bracket_expr.split('-'); |
| 2656 | if (sleft.getAsInteger(0, low_index) || |
| 2657 | sright.getAsInteger(0, high_index)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2658 | *reason_to_stop = |
| 2659 | ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2660 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2661 | return nullptr; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2662 | } |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2663 | |
| 2664 | if (low_index > high_index) // swap indices if required |
| 2665 | std::swap(low_index, high_index); |
Zachary Turner | c2d5558 | 2016-11-18 03:51:19 +0000 | [diff] [blame] | 2666 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2667 | if (root_compiler_type_info.Test( |
| 2668 | eTypeIsScalar)) // expansion only works for scalars |
| 2669 | { |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2670 | root = root->GetSyntheticBitFieldChild(low_index, high_index, true); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2671 | if (!root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2672 | *reason_to_stop = |
| 2673 | ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2674 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2675 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2676 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2677 | *reason_to_stop = ValueObject:: |
| 2678 | eExpressionPathScanEndReasonBitfieldRangeOperatorMet; |
| 2679 | *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; |
| 2680 | return root; |
| 2681 | } |
| 2682 | } else if (root_compiler_type_info.Test( |
| 2683 | eTypeIsPointer) && // if this is a ptr-to-scalar, I am |
| 2684 | // accessing it by index and I would |
| 2685 | // have deref'ed anyway, then do it |
| 2686 | // now and use this as a bitfield |
| 2687 | *what_next == |
| 2688 | ValueObject::eExpressionPathAftermathDereference && |
| 2689 | pointee_compiler_type_info.Test(eTypeIsScalar)) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2690 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2691 | root = root->Dereference(error); |
Zachary Turner | 2a3d10a | 2016-11-18 19:23:39 +0000 | [diff] [blame] | 2692 | if (error.Fail() || !root) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2693 | *reason_to_stop = |
| 2694 | ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 2695 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2696 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2697 | } else { |
| 2698 | *what_next = ValueObject::eExpressionPathAftermathNothing; |
| 2699 | continue; |
| 2700 | } |
| 2701 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2702 | *reason_to_stop = |
| 2703 | ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; |
| 2704 | *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange; |
| 2705 | return root; |
| 2706 | } |
| 2707 | } |
| 2708 | break; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2709 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2710 | default: // some non-separator is in the way |
| 2711 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2712 | *reason_to_stop = |
| 2713 | ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2714 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
Zachary Turner | d2daca7 | 2016-11-18 17:55:04 +0000 | [diff] [blame] | 2715 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2716 | } |
| 2717 | } |
| 2718 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2721 | void ValueObject::LogValueObject(Log *log) { |
| 2722 | if (log) |
| 2723 | return LogValueObject(log, DumpValueObjectOptions(*this)); |
Enrico Granata | 538a88a | 2014-10-09 18:24:30 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2726 | void ValueObject::LogValueObject(Log *log, |
| 2727 | const DumpValueObjectOptions &options) { |
| 2728 | if (log) { |
| 2729 | StreamString s; |
| 2730 | Dump(s, options); |
| 2731 | if (s.GetSize()) |
| 2732 | log->PutCString(s.GetData()); |
| 2733 | } |
Greg Clayton | 759e744 | 2014-07-19 00:12:57 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2736 | void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); } |
Chaoren Lin | d7bdc27 | 2015-07-31 00:35:40 +0000 | [diff] [blame] | 2737 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2738 | void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) { |
| 2739 | ValueObjectPrinter printer(this, &s, options); |
| 2740 | printer.PrintValueObject(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2743 | ValueObjectSP ValueObject::CreateConstantValue(const ConstString &name) { |
| 2744 | ValueObjectSP valobj_sp; |
| 2745 | |
| 2746 | if (UpdateValueIfNeeded(false) && m_error.Success()) { |
| 2747 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2748 | |
| 2749 | DataExtractor data; |
| 2750 | data.SetByteOrder(m_data.GetByteOrder()); |
| 2751 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
| 2752 | |
| 2753 | if (IsBitfield()) { |
| 2754 | Value v(Scalar(GetValueAsUnsigned(UINT64_MAX))); |
| 2755 | m_error = v.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); |
| 2756 | } else |
| 2757 | m_error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); |
| 2758 | |
| 2759 | valobj_sp = ValueObjectConstResult::Create( |
| 2760 | exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data, |
| 2761 | GetAddressOf()); |
| 2762 | } |
| 2763 | |
| 2764 | if (!valobj_sp) { |
| 2765 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2766 | valobj_sp = ValueObjectConstResult::Create( |
| 2767 | exe_ctx.GetBestExecutionContextScope(), m_error); |
| 2768 | } |
| 2769 | return valobj_sp; |
| 2770 | } |
| 2771 | |
| 2772 | ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable( |
| 2773 | lldb::DynamicValueType dynValue, bool synthValue) { |
| 2774 | ValueObjectSP result_sp(GetSP()); |
| 2775 | |
| 2776 | switch (dynValue) { |
| 2777 | case lldb::eDynamicCanRunTarget: |
| 2778 | case lldb::eDynamicDontRunTarget: { |
| 2779 | if (!result_sp->IsDynamic()) { |
| 2780 | if (result_sp->GetDynamicValue(dynValue)) |
| 2781 | result_sp = result_sp->GetDynamicValue(dynValue); |
| 2782 | } |
| 2783 | } break; |
| 2784 | case lldb::eNoDynamicValues: { |
| 2785 | if (result_sp->IsDynamic()) { |
| 2786 | if (result_sp->GetStaticValue()) |
| 2787 | result_sp = result_sp->GetStaticValue(); |
| 2788 | } |
| 2789 | } break; |
| 2790 | } |
| 2791 | |
| 2792 | if (synthValue) { |
| 2793 | if (!result_sp->IsSynthetic()) { |
| 2794 | if (result_sp->GetSyntheticValue()) |
| 2795 | result_sp = result_sp->GetSyntheticValue(); |
| 2796 | } |
| 2797 | } else { |
| 2798 | if (result_sp->IsSynthetic()) { |
| 2799 | if (result_sp->GetNonSyntheticValue()) |
| 2800 | result_sp = result_sp->GetNonSyntheticValue(); |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | return result_sp; |
| 2805 | } |
| 2806 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2807 | ValueObjectSP ValueObject::Dereference(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2808 | if (m_deref_valobj) |
| 2809 | return m_deref_valobj->GetSP(); |
| 2810 | |
| 2811 | const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); |
| 2812 | if (is_pointer_or_reference_type) { |
| 2813 | bool omit_empty_base_classes = true; |
| 2814 | bool ignore_array_bounds = false; |
| 2815 | |
| 2816 | std::string child_name_str; |
| 2817 | uint32_t child_byte_size = 0; |
| 2818 | int32_t child_byte_offset = 0; |
| 2819 | uint32_t child_bitfield_bit_size = 0; |
| 2820 | uint32_t child_bitfield_bit_offset = 0; |
| 2821 | bool child_is_base_class = false; |
| 2822 | bool child_is_deref_of_parent = false; |
| 2823 | const bool transparent_pointers = false; |
| 2824 | CompilerType compiler_type = GetCompilerType(); |
| 2825 | CompilerType child_compiler_type; |
| 2826 | uint64_t language_flags; |
| 2827 | |
| 2828 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2829 | |
| 2830 | child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex( |
| 2831 | &exe_ctx, 0, transparent_pointers, omit_empty_base_classes, |
| 2832 | ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, |
| 2833 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 2834 | child_is_deref_of_parent, this, language_flags); |
| 2835 | if (child_compiler_type && child_byte_size) { |
| 2836 | ConstString child_name; |
| 2837 | if (!child_name_str.empty()) |
| 2838 | child_name.SetCString(child_name_str.c_str()); |
| 2839 | |
| 2840 | m_deref_valobj = new ValueObjectChild( |
| 2841 | *this, child_compiler_type, child_name, child_byte_size, |
| 2842 | child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, |
| 2843 | child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, |
| 2844 | language_flags); |
| 2845 | } |
Tamas Berghammer | 4c08fe2 | 2017-03-31 20:23:22 +0000 | [diff] [blame] | 2846 | } else if (HasSyntheticValue()) { |
| 2847 | m_deref_valobj = |
| 2848 | GetSyntheticValue() |
| 2849 | ->GetChildMemberWithName(ConstString("$$dereference$$"), true) |
| 2850 | .get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | if (m_deref_valobj) { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2854 | error.Clear(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2855 | return m_deref_valobj->GetSP(); |
| 2856 | } else { |
| 2857 | StreamString strm; |
| 2858 | GetExpressionPath(strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2859 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2860 | if (is_pointer_or_reference_type) |
| 2861 | error.SetErrorStringWithFormat("dereference failed: (%s) %s", |
| 2862 | GetTypeName().AsCString("<invalid type>"), |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 2863 | strm.GetData()); |
Sean Callanan | ed185ab | 2013-04-19 19:47:32 +0000 | [diff] [blame] | 2864 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2865 | error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", |
| 2866 | GetTypeName().AsCString("<invalid type>"), |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 2867 | strm.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2868 | return ValueObjectSP(); |
| 2869 | } |
| 2870 | } |
| 2871 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2872 | ValueObjectSP ValueObject::AddressOf(Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2873 | if (m_addr_of_valobj_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2874 | return m_addr_of_valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2875 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2876 | AddressType address_type = eAddressTypeInvalid; |
| 2877 | const bool scalar_is_load_address = false; |
| 2878 | addr_t addr = GetAddressOf(scalar_is_load_address, &address_type); |
| 2879 | error.Clear(); |
| 2880 | if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) { |
| 2881 | switch (address_type) { |
| 2882 | case eAddressTypeInvalid: { |
| 2883 | StreamString expr_path_strm; |
| 2884 | GetExpressionPath(expr_path_strm, true); |
| 2885 | error.SetErrorStringWithFormat("'%s' is not in memory", |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 2886 | expr_path_strm.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2887 | } break; |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2888 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2889 | case eAddressTypeFile: |
| 2890 | case eAddressTypeLoad: { |
| 2891 | CompilerType compiler_type = GetCompilerType(); |
| 2892 | if (compiler_type) { |
| 2893 | std::string name(1, '&'); |
| 2894 | name.append(m_name.AsCString("")); |
| 2895 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2896 | m_addr_of_valobj_sp = ValueObjectConstResult::Create( |
| 2897 | exe_ctx.GetBestExecutionContextScope(), |
| 2898 | compiler_type.GetPointerType(), ConstString(name.c_str()), addr, |
| 2899 | eAddressTypeInvalid, m_data.GetAddressByteSize()); |
| 2900 | } |
| 2901 | } break; |
| 2902 | default: |
| 2903 | break; |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2904 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2905 | } else { |
| 2906 | StreamString expr_path_strm; |
| 2907 | GetExpressionPath(expr_path_strm, true); |
| 2908 | error.SetErrorStringWithFormat("'%s' doesn't have a valid address", |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 2909 | expr_path_strm.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | return m_addr_of_valobj_sp; |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2915 | ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) { |
| 2916 | return ValueObjectCast::Create(*this, GetName(), compiler_type); |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
Tamas Berghammer | 4fbb55b | 2017-03-31 20:48:00 +0000 | [diff] [blame] | 2919 | lldb::ValueObjectSP ValueObject::Clone(const ConstString &new_name) { |
| 2920 | return ValueObjectCast::Create(*this, new_name, GetCompilerType()); |
| 2921 | } |
| 2922 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2923 | ValueObjectSP ValueObject::CastPointerType(const char *name, |
| 2924 | CompilerType &compiler_type) { |
| 2925 | ValueObjectSP valobj_sp; |
| 2926 | AddressType address_type; |
| 2927 | addr_t ptr_value = GetPointerValue(&address_type); |
| 2928 | |
| 2929 | if (ptr_value != LLDB_INVALID_ADDRESS) { |
| 2930 | Address ptr_addr(ptr_value); |
| 2931 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2932 | valobj_sp = ValueObjectMemory::Create( |
| 2933 | exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type); |
| 2934 | } |
| 2935 | return valobj_sp; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2938 | ValueObjectSP ValueObject::CastPointerType(const char *name, TypeSP &type_sp) { |
| 2939 | ValueObjectSP valobj_sp; |
| 2940 | AddressType address_type; |
| 2941 | addr_t ptr_value = GetPointerValue(&address_type); |
| 2942 | |
| 2943 | if (ptr_value != LLDB_INVALID_ADDRESS) { |
| 2944 | Address ptr_addr(ptr_value); |
| 2945 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 2946 | valobj_sp = ValueObjectMemory::Create( |
| 2947 | exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp); |
| 2948 | } |
| 2949 | return valobj_sp; |
| 2950 | } |
| 2951 | |
| 2952 | ValueObject::EvaluationPoint::EvaluationPoint() |
| 2953 | : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) {} |
| 2954 | |
| 2955 | ValueObject::EvaluationPoint::EvaluationPoint(ExecutionContextScope *exe_scope, |
| 2956 | bool use_selected) |
| 2957 | : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) { |
| 2958 | ExecutionContext exe_ctx(exe_scope); |
| 2959 | TargetSP target_sp(exe_ctx.GetTargetSP()); |
| 2960 | if (target_sp) { |
| 2961 | m_exe_ctx_ref.SetTargetSP(target_sp); |
| 2962 | ProcessSP process_sp(exe_ctx.GetProcessSP()); |
| 2963 | if (!process_sp) |
| 2964 | process_sp = target_sp->GetProcessSP(); |
| 2965 | |
| 2966 | if (process_sp) { |
| 2967 | m_mod_id = process_sp->GetModID(); |
| 2968 | m_exe_ctx_ref.SetProcessSP(process_sp); |
| 2969 | |
| 2970 | ThreadSP thread_sp(exe_ctx.GetThreadSP()); |
| 2971 | |
| 2972 | if (!thread_sp) { |
| 2973 | if (use_selected) |
| 2974 | thread_sp = process_sp->GetThreadList().GetSelectedThread(); |
| 2975 | } |
| 2976 | |
| 2977 | if (thread_sp) { |
| 2978 | m_exe_ctx_ref.SetThreadSP(thread_sp); |
| 2979 | |
| 2980 | StackFrameSP frame_sp(exe_ctx.GetFrameSP()); |
| 2981 | if (!frame_sp) { |
| 2982 | if (use_selected) |
| 2983 | frame_sp = thread_sp->GetSelectedFrame(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2984 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2985 | if (frame_sp) |
| 2986 | m_exe_ctx_ref.SetFrameSP(frame_sp); |
| 2987 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2988 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2989 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2992 | ValueObject::EvaluationPoint::EvaluationPoint( |
| 2993 | const ValueObject::EvaluationPoint &rhs) |
| 2994 | : m_mod_id(), m_exe_ctx_ref(rhs.m_exe_ctx_ref), m_needs_update(true) {} |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2995 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2996 | ValueObject::EvaluationPoint::~EvaluationPoint() {} |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2997 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2998 | // This function checks the EvaluationPoint against the current process state. |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2999 | // If the current state matches the evaluation point, or the evaluation point |
| 3000 | // is already invalid, then we return false, meaning "no change". If the |
| 3001 | // current state is different, we update our state, and return true meaning |
| 3002 | // "yes, change". If we did see a change, we also set m_needs_update to true, |
| 3003 | // so future calls to NeedsUpdate will return true. exe_scope will be set to |
| 3004 | // the current execution context scope. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3005 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3006 | bool ValueObject::EvaluationPoint::SyncWithProcessState( |
| 3007 | bool accept_invalid_exe_ctx) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3008 | // Start with the target, if it is NULL, then we're obviously not going to |
| 3009 | // get any further: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3010 | const bool thread_and_frame_only_if_stopped = true; |
| 3011 | ExecutionContext exe_ctx( |
| 3012 | m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); |
| 3013 | |
| 3014 | if (exe_ctx.GetTargetPtr() == NULL) |
| 3015 | return false; |
| 3016 | |
| 3017 | // If we don't have a process nothing can change. |
| 3018 | Process *process = exe_ctx.GetProcessPtr(); |
| 3019 | if (process == NULL) |
| 3020 | return false; |
| 3021 | |
| 3022 | // If our stop id is the current stop ID, nothing has changed: |
| 3023 | ProcessModID current_mod_id = process->GetModID(); |
| 3024 | |
| 3025 | // If the current stop id is 0, either we haven't run yet, or the process |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3026 | // state has been cleared. In either case, we aren't going to be able to sync |
| 3027 | // with the process state. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3028 | if (current_mod_id.GetStopID() == 0) |
| 3029 | return false; |
| 3030 | |
| 3031 | bool changed = false; |
| 3032 | const bool was_valid = m_mod_id.IsValid(); |
| 3033 | if (was_valid) { |
| 3034 | if (m_mod_id == current_mod_id) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3035 | // Everything is already up to date in this object, no need to update the |
| 3036 | // execution context scope. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3037 | changed = false; |
| 3038 | } else { |
| 3039 | m_mod_id = current_mod_id; |
| 3040 | m_needs_update = true; |
| 3041 | changed = true; |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | // Now re-look up the thread and frame in case the underlying objects have |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3046 | // gone away & been recreated. That way we'll be sure to return a valid |
| 3047 | // exe_scope. If we used to have a thread or a frame but can't find it |
| 3048 | // anymore, then mark ourselves as invalid. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3049 | |
| 3050 | if (!accept_invalid_exe_ctx) { |
| 3051 | if (m_exe_ctx_ref.HasThreadRef()) { |
| 3052 | ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP()); |
| 3053 | if (thread_sp) { |
| 3054 | if (m_exe_ctx_ref.HasFrameRef()) { |
| 3055 | StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP()); |
| 3056 | if (!frame_sp) { |
| 3057 | // We used to have a frame, but now it is gone |
| 3058 | SetInvalid(); |
| 3059 | changed = was_valid; |
| 3060 | } |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3061 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3062 | } else { |
| 3063 | // We used to have a thread, but now it is gone |
| 3064 | SetInvalid(); |
| 3065 | changed = was_valid; |
| 3066 | } |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3067 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3068 | } |
Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 3069 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3070 | return changed; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3073 | void ValueObject::EvaluationPoint::SetUpdated() { |
| 3074 | ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); |
| 3075 | if (process_sp) |
| 3076 | m_mod_id = process_sp->GetModID(); |
| 3077 | m_needs_update = false; |
Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 3078 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3079 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3080 | void ValueObject::ClearUserVisibleData(uint32_t clear_mask) { |
| 3081 | if ((clear_mask & eClearUserVisibleDataItemsValue) == |
| 3082 | eClearUserVisibleDataItemsValue) |
| 3083 | m_value_str.clear(); |
| 3084 | |
| 3085 | if ((clear_mask & eClearUserVisibleDataItemsLocation) == |
| 3086 | eClearUserVisibleDataItemsLocation) |
| 3087 | m_location_str.clear(); |
| 3088 | |
| 3089 | if ((clear_mask & eClearUserVisibleDataItemsSummary) == |
| 3090 | eClearUserVisibleDataItemsSummary) |
| 3091 | m_summary_str.clear(); |
| 3092 | |
| 3093 | if ((clear_mask & eClearUserVisibleDataItemsDescription) == |
| 3094 | eClearUserVisibleDataItemsDescription) |
| 3095 | m_object_desc_str.clear(); |
| 3096 | |
| 3097 | if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == |
| 3098 | eClearUserVisibleDataItemsSyntheticChildren) { |
| 3099 | if (m_synthetic_value) |
| 3100 | m_synthetic_value = NULL; |
| 3101 | } |
| 3102 | |
| 3103 | if ((clear_mask & eClearUserVisibleDataItemsValidator) == |
| 3104 | eClearUserVisibleDataItemsValidator) |
| 3105 | m_validation_result.reset(); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3106 | } |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3108 | SymbolContextScope *ValueObject::GetSymbolContextScope() { |
| 3109 | if (m_parent) { |
| 3110 | if (!m_parent->IsPointerOrReferenceType()) |
| 3111 | return m_parent->GetSymbolContextScope(); |
| 3112 | } |
| 3113 | return NULL; |
Enrico Granata | 972be53 | 2014-12-17 21:18:43 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3116 | lldb::ValueObjectSP |
| 3117 | ValueObject::CreateValueObjectFromExpression(llvm::StringRef name, |
| 3118 | llvm::StringRef expression, |
| 3119 | const ExecutionContext &exe_ctx) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3120 | return CreateValueObjectFromExpression(name, expression, exe_ctx, |
| 3121 | EvaluateExpressionOptions()); |
| 3122 | } |
Enrico Granata | 972be53 | 2014-12-17 21:18:43 +0000 | [diff] [blame] | 3123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3124 | lldb::ValueObjectSP ValueObject::CreateValueObjectFromExpression( |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3125 | llvm::StringRef name, llvm::StringRef expression, |
| 3126 | const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3127 | lldb::ValueObjectSP retval_sp; |
| 3128 | lldb::TargetSP target_sp(exe_ctx.GetTargetSP()); |
| 3129 | if (!target_sp) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3130 | return retval_sp; |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3131 | if (expression.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3132 | return retval_sp; |
| 3133 | target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(), |
| 3134 | retval_sp, options); |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3135 | if (retval_sp && !name.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3136 | retval_sp->SetName(ConstString(name)); |
| 3137 | return retval_sp; |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3140 | lldb::ValueObjectSP ValueObject::CreateValueObjectFromAddress( |
| 3141 | llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, |
| 3142 | CompilerType type) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3143 | if (type) { |
| 3144 | CompilerType pointer_type(type.GetPointerType()); |
| 3145 | if (pointer_type) { |
| 3146 | lldb::DataBufferSP buffer( |
| 3147 | new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t))); |
| 3148 | lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create( |
| 3149 | exe_ctx.GetBestExecutionContextScope(), pointer_type, |
| 3150 | ConstString(name), buffer, exe_ctx.GetByteOrder(), |
| 3151 | exe_ctx.GetAddressByteSize())); |
| 3152 | if (ptr_result_valobj_sp) { |
| 3153 | ptr_result_valobj_sp->GetValue().SetValueType( |
| 3154 | Value::eValueTypeLoadAddress); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 3155 | Status err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3156 | ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err); |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3157 | if (ptr_result_valobj_sp && !name.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3158 | ptr_result_valobj_sp->SetName(ConstString(name)); |
| 3159 | } |
| 3160 | return ptr_result_valobj_sp; |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3161 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3162 | } |
| 3163 | return lldb::ValueObjectSP(); |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3166 | lldb::ValueObjectSP ValueObject::CreateValueObjectFromData( |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3167 | llvm::StringRef name, const DataExtractor &data, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3168 | const ExecutionContext &exe_ctx, CompilerType type) { |
| 3169 | lldb::ValueObjectSP new_value_sp; |
| 3170 | new_value_sp = ValueObjectConstResult::Create( |
| 3171 | exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data, |
| 3172 | LLDB_INVALID_ADDRESS); |
| 3173 | new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); |
Zachary Turner | aa5611f | 2016-11-13 03:29:46 +0000 | [diff] [blame] | 3174 | if (new_value_sp && !name.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3175 | new_value_sp->SetName(ConstString(name)); |
| 3176 | return new_value_sp; |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 3177 | } |
Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 3178 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3179 | ModuleSP ValueObject::GetModule() { |
| 3180 | ValueObject *root(GetRoot()); |
| 3181 | if (root != this) |
| 3182 | return root->GetModule(); |
| 3183 | return lldb::ModuleSP(); |
| 3184 | } |
| 3185 | |
| 3186 | ValueObject *ValueObject::GetRoot() { |
| 3187 | if (m_root) |
| 3188 | return m_root; |
| 3189 | return (m_root = FollowParentChain([](ValueObject *vo) -> bool { |
| 3190 | return (vo->m_parent != nullptr); |
| 3191 | })); |
| 3192 | } |
| 3193 | |
| 3194 | ValueObject * |
| 3195 | ValueObject::FollowParentChain(std::function<bool(ValueObject *)> f) { |
| 3196 | ValueObject *vo = this; |
| 3197 | while (vo) { |
| 3198 | if (f(vo) == false) |
| 3199 | break; |
| 3200 | vo = vo->m_parent; |
| 3201 | } |
| 3202 | return vo; |
| 3203 | } |
| 3204 | |
| 3205 | AddressType ValueObject::GetAddressTypeOfChildren() { |
| 3206 | if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) { |
| 3207 | ValueObject *root(GetRoot()); |
Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 3208 | if (root != this) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3209 | return root->GetAddressTypeOfChildren(); |
| 3210 | } |
| 3211 | return m_address_type_of_ptr_or_ref_children; |
Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3214 | lldb::DynamicValueType ValueObject::GetDynamicValueType() { |
| 3215 | ValueObject *with_dv_info = this; |
| 3216 | while (with_dv_info) { |
| 3217 | if (with_dv_info->HasDynamicValueTypeInfo()) |
| 3218 | return with_dv_info->GetDynamicValueTypeImpl(); |
| 3219 | with_dv_info = with_dv_info->m_parent; |
| 3220 | } |
| 3221 | return lldb::eNoDynamicValues; |
Enrico Granata | de61eba | 2015-01-22 03:07:34 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3224 | lldb::Format ValueObject::GetFormat() const { |
| 3225 | const ValueObject *with_fmt_info = this; |
| 3226 | while (with_fmt_info) { |
| 3227 | if (with_fmt_info->m_format != lldb::eFormatDefault) |
| 3228 | return with_fmt_info->m_format; |
| 3229 | with_fmt_info = with_fmt_info->m_parent; |
| 3230 | } |
| 3231 | return m_format; |
Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3234 | lldb::LanguageType ValueObject::GetPreferredDisplayLanguage() { |
| 3235 | lldb::LanguageType type = m_preferred_display_language; |
| 3236 | if (m_preferred_display_language == lldb::eLanguageTypeUnknown) { |
| 3237 | if (GetRoot()) { |
| 3238 | if (GetRoot() == this) { |
| 3239 | if (StackFrameSP frame_sp = GetFrameSP()) { |
| 3240 | const SymbolContext &sc( |
| 3241 | frame_sp->GetSymbolContext(eSymbolContextCompUnit)); |
| 3242 | if (CompileUnit *cu = sc.comp_unit) |
| 3243 | type = cu->GetLanguage(); |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 3244 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3245 | } else { |
| 3246 | type = GetRoot()->GetPreferredDisplayLanguage(); |
| 3247 | } |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 3248 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3249 | } |
| 3250 | return (m_preferred_display_language = type); // only compute it once |
Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3253 | void ValueObject::SetPreferredDisplayLanguage(lldb::LanguageType lt) { |
| 3254 | m_preferred_display_language = lt; |
Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3257 | void ValueObject::SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType lt) { |
| 3258 | if (m_preferred_display_language == lldb::eLanguageTypeUnknown) |
| 3259 | SetPreferredDisplayLanguage(lt); |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 3260 | } |
| 3261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3262 | bool ValueObject::CanProvideValue() { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3263 | // we need to support invalid types as providers of values because some bare- |
| 3264 | // board debugging scenarios have no notion of types, but still manage to |
| 3265 | // have raw numeric values for things like registers. sigh. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3266 | const CompilerType &type(GetCompilerType()); |
| 3267 | return (false == type.IsValid()) || |
| 3268 | (0 != (type.GetTypeInfo() & eTypeHasValue)); |
Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3271 | bool ValueObject::IsChecksumEmpty() { return m_value_checksum.empty(); } |
| 3272 | |
| 3273 | ValueObjectSP ValueObject::Persist() { |
| 3274 | if (!UpdateValueIfNeeded()) |
| 3275 | return nullptr; |
| 3276 | |
| 3277 | TargetSP target_sp(GetTargetSP()); |
| 3278 | if (!target_sp) |
| 3279 | return nullptr; |
| 3280 | |
| 3281 | PersistentExpressionState *persistent_state = |
| 3282 | target_sp->GetPersistentExpressionStateForLanguage( |
| 3283 | GetPreferredDisplayLanguage()); |
| 3284 | |
| 3285 | if (!persistent_state) |
| 3286 | return nullptr; |
| 3287 | |
Adrian Prantl | 03219f7 | 2018-04-30 23:59:17 +0000 | [diff] [blame] | 3288 | auto prefix = persistent_state->GetPersistentVariablePrefix(); |
| 3289 | ConstString name = |
| 3290 | persistent_state->GetNextPersistentVariableName(*target_sp, prefix); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3291 | |
| 3292 | ValueObjectSP const_result_sp = |
| 3293 | ValueObjectConstResult::Create(target_sp.get(), GetValue(), name); |
| 3294 | |
| 3295 | ExpressionVariableSP clang_var_sp = |
| 3296 | persistent_state->CreatePersistentVariable(const_result_sp); |
| 3297 | clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp; |
| 3298 | clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference; |
| 3299 | |
| 3300 | return clang_var_sp->GetValueObject(); |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 3301 | } |
Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 3302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3303 | bool ValueObject::IsSyntheticChildrenGenerated() { |
| 3304 | return m_is_synthetic_children_generated; |
Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 3305 | } |
Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 3306 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3307 | void ValueObject::SetSyntheticChildrenGenerated(bool b) { |
| 3308 | m_is_synthetic_children_generated = b; |
Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3311 | uint64_t ValueObject::GetLanguageFlags() { return m_language_flags; } |
Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 3312 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3313 | void ValueObject::SetLanguageFlags(uint64_t flags) { m_language_flags = flags; } |
Greg Clayton | 8369b28 | 2016-12-28 21:22:37 +0000 | [diff] [blame] | 3314 | |
| 3315 | ValueObjectManager::ValueObjectManager(lldb::ValueObjectSP in_valobj_sp, |
| 3316 | lldb::DynamicValueType use_dynamic, |
| 3317 | bool use_synthetic) : m_root_valobj_sp(), |
| 3318 | m_user_valobj_sp(), m_use_dynamic(use_dynamic), m_stop_id(UINT32_MAX), |
| 3319 | m_use_synthetic(use_synthetic) { |
| 3320 | if (!in_valobj_sp) |
| 3321 | return; |
| 3322 | // If the user passes in a value object that is dynamic or synthetic, then |
| 3323 | // water it down to the static type. |
| 3324 | m_root_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(lldb::eNoDynamicValues, false); |
| 3325 | } |
| 3326 | |
| 3327 | bool ValueObjectManager::IsValid() const { |
| 3328 | if (!m_root_valobj_sp) |
| 3329 | return false; |
| 3330 | lldb::TargetSP target_sp = GetTargetSP(); |
| 3331 | if (target_sp) |
| 3332 | return target_sp->IsValid(); |
| 3333 | return false; |
| 3334 | } |
| 3335 | |
| 3336 | lldb::ValueObjectSP ValueObjectManager::GetSP() { |
| 3337 | lldb::ProcessSP process_sp = GetProcessSP(); |
| 3338 | if (!process_sp) |
| 3339 | return lldb::ValueObjectSP(); |
| 3340 | |
| 3341 | const uint32_t current_stop_id = process_sp->GetLastNaturalStopID(); |
| 3342 | if (current_stop_id == m_stop_id) |
| 3343 | return m_user_valobj_sp; |
| 3344 | |
| 3345 | m_stop_id = current_stop_id; |
| 3346 | |
| 3347 | if (!m_root_valobj_sp) { |
| 3348 | m_user_valobj_sp.reset(); |
| 3349 | return m_root_valobj_sp; |
| 3350 | } |
| 3351 | |
| 3352 | m_user_valobj_sp = m_root_valobj_sp; |
| 3353 | |
| 3354 | if (m_use_dynamic != lldb::eNoDynamicValues) { |
| 3355 | lldb::ValueObjectSP dynamic_sp = m_user_valobj_sp->GetDynamicValue(m_use_dynamic); |
| 3356 | if (dynamic_sp) |
| 3357 | m_user_valobj_sp = dynamic_sp; |
| 3358 | } |
| 3359 | |
| 3360 | if (m_use_synthetic) { |
| 3361 | lldb::ValueObjectSP synthetic_sp = m_user_valobj_sp->GetSyntheticValue(m_use_synthetic); |
| 3362 | if (synthetic_sp) |
| 3363 | m_user_valobj_sp = synthetic_sp; |
| 3364 | } |
| 3365 | |
| 3366 | return m_user_valobj_sp; |
| 3367 | } |
| 3368 | |
| 3369 | void ValueObjectManager::SetUseDynamic(lldb::DynamicValueType use_dynamic) { |
| 3370 | if (use_dynamic != m_use_dynamic) { |
| 3371 | m_use_dynamic = use_dynamic; |
| 3372 | m_user_valobj_sp.reset(); |
| 3373 | m_stop_id = UINT32_MAX; |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | void ValueObjectManager::SetUseSynthetic(bool use_synthetic) { |
| 3378 | if (m_use_synthetic != use_synthetic) { |
| 3379 | m_use_synthetic = use_synthetic; |
| 3380 | m_user_valobj_sp.reset(); |
| 3381 | m_stop_id = UINT32_MAX; |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | lldb::TargetSP ValueObjectManager::GetTargetSP() const { |
| 3386 | if (!m_root_valobj_sp) |
| 3387 | return m_root_valobj_sp->GetTargetSP(); |
| 3388 | return lldb::TargetSP(); |
| 3389 | } |
| 3390 | |
| 3391 | lldb::ProcessSP ValueObjectManager::GetProcessSP() const { |
| 3392 | if (m_root_valobj_sp) |
| 3393 | return m_root_valobj_sp->GetProcessSP(); |
| 3394 | return lldb::ProcessSP(); |
| 3395 | } |
| 3396 | |
| 3397 | lldb::ThreadSP ValueObjectManager::GetThreadSP() const { |
| 3398 | if (m_root_valobj_sp) |
| 3399 | return m_root_valobj_sp->GetThreadSP(); |
| 3400 | return lldb::ThreadSP(); |
| 3401 | } |
| 3402 | |
| 3403 | lldb::StackFrameSP ValueObjectManager::GetFrameSP() const { |
| 3404 | if (m_root_valobj_sp) |
| 3405 | return m_root_valobj_sp->GetFrameSP(); |
| 3406 | return lldb::StackFrameSP(); |
| 3407 | } |
| 3408 | |