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