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