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