Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1 | //===-- ValueObjectDynamicValue.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 | |
| 11 | #include "lldb/Core/ValueObjectDynamicValue.h" |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
| 16 | // Project includes |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Module.h" |
| 19 | #include "lldb/Core/ValueObjectList.h" |
| 20 | #include "lldb/Core/Value.h" |
| 21 | #include "lldb/Core/ValueObject.h" |
| 22 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/CompilerType.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 24 | #include "lldb/Symbol/ObjectFile.h" |
| 25 | #include "lldb/Symbol/SymbolContext.h" |
| 26 | #include "lldb/Symbol/Type.h" |
| 27 | #include "lldb/Symbol/Variable.h" |
| 28 | |
| 29 | #include "lldb/Target/ExecutionContext.h" |
| 30 | #include "lldb/Target/LanguageRuntime.h" |
| 31 | #include "lldb/Target/Process.h" |
| 32 | #include "lldb/Target/RegisterContext.h" |
| 33 | #include "lldb/Target/Target.h" |
| 34 | #include "lldb/Target/Thread.h" |
| 35 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 36 | using namespace lldb_private; |
| 37 | |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 38 | ValueObjectDynamicValue::ValueObjectDynamicValue (ValueObject &parent, lldb::DynamicValueType use_dynamic) : |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 39 | ValueObject(parent), |
| 40 | m_address (), |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 41 | m_dynamic_type_info(), |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 42 | m_use_dynamic (use_dynamic) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 43 | { |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 44 | SetName (parent.GetName()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ValueObjectDynamicValue::~ValueObjectDynamicValue() |
| 48 | { |
| 49 | m_owning_valobj_sp.reset(); |
| 50 | } |
| 51 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 52 | CompilerType |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 53 | ValueObjectDynamicValue::GetCompilerTypeImpl () |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 54 | { |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 55 | const bool success = UpdateValueIfNeeded(false); |
| 56 | if (success) |
| 57 | { |
| 58 | if (m_dynamic_type_info.HasType()) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 59 | return m_value.GetCompilerType(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 60 | else |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 61 | return m_parent->GetCompilerType(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 62 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 63 | return m_parent->GetCompilerType(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | ConstString |
| 67 | ValueObjectDynamicValue::GetTypeName() |
| 68 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 69 | const bool success = UpdateValueIfNeeded(false); |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 70 | if (success) |
| 71 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 72 | if (m_dynamic_type_info.HasName()) |
| 73 | return m_dynamic_type_info.GetName(); |
| 74 | } |
| 75 | return m_parent->GetTypeName(); |
| 76 | } |
| 77 | |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 78 | TypeImpl |
| 79 | ValueObjectDynamicValue::GetTypeImpl () |
| 80 | { |
| 81 | const bool success = UpdateValueIfNeeded(false); |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 82 | if (success && m_type_impl.IsValid()) |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 83 | { |
| 84 | return m_type_impl; |
| 85 | } |
| 86 | return m_parent->GetTypeImpl(); |
| 87 | } |
| 88 | |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 89 | ConstString |
| 90 | ValueObjectDynamicValue::GetQualifiedTypeName() |
| 91 | { |
| 92 | const bool success = UpdateValueIfNeeded(false); |
| 93 | if (success) |
| 94 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 95 | if (m_dynamic_type_info.HasName()) |
| 96 | return m_dynamic_type_info.GetName(); |
| 97 | } |
Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 98 | return m_parent->GetQualifiedTypeName(); |
| 99 | } |
| 100 | |
| 101 | ConstString |
| 102 | ValueObjectDynamicValue::GetDisplayTypeName() |
| 103 | { |
| 104 | const bool success = UpdateValueIfNeeded(false); |
| 105 | if (success) |
| 106 | { |
| 107 | if (m_dynamic_type_info.HasType()) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 108 | return GetCompilerType().GetDisplayTypeName(); |
Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 109 | if (m_dynamic_type_info.HasName()) |
| 110 | return m_dynamic_type_info.GetName(); |
| 111 | } |
| 112 | return m_parent->GetDisplayTypeName(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 115 | size_t |
Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 116 | ValueObjectDynamicValue::CalculateNumChildren(uint32_t max) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 117 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 118 | const bool success = UpdateValueIfNeeded(false); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 119 | if (success && m_dynamic_type_info.HasType()) |
Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 120 | { |
| 121 | auto children_count = GetCompilerType().GetNumChildren (true); |
| 122 | return children_count <= max ? children_count : max; |
| 123 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 124 | else |
Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 125 | return m_parent->GetNumChildren(max); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 128 | uint64_t |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 129 | ValueObjectDynamicValue::GetByteSize() |
| 130 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 131 | const bool success = UpdateValueIfNeeded(false); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 132 | if (success && m_dynamic_type_info.HasType()) |
Enrico Granata | 9543803 | 2015-10-14 22:44:30 +0000 | [diff] [blame] | 133 | { |
| 134 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 135 | return m_value.GetValueByteSize(nullptr, &exe_ctx); |
| 136 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 137 | else |
| 138 | return m_parent->GetByteSize(); |
| 139 | } |
| 140 | |
| 141 | lldb::ValueType |
| 142 | ValueObjectDynamicValue::GetValueType() const |
| 143 | { |
| 144 | return m_parent->GetValueType(); |
| 145 | } |
| 146 | |
| 147 | bool |
| 148 | ValueObjectDynamicValue::UpdateValue () |
| 149 | { |
| 150 | SetValueIsValid (false); |
| 151 | m_error.Clear(); |
| 152 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 153 | if (!m_parent->UpdateValueIfNeeded(false)) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 154 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 155 | // The dynamic value failed to get an error, pass the error along |
| 156 | if (m_error.Success() && m_parent->GetError().Fail()) |
| 157 | m_error = m_parent->GetError(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 158 | return false; |
| 159 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 160 | |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 161 | // Setting our type_sp to NULL will route everything back through our |
| 162 | // parent which is equivalent to not using dynamic values. |
| 163 | if (m_use_dynamic == lldb::eNoDynamicValues) |
| 164 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 165 | m_dynamic_type_info.Clear(); |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 166 | return true; |
| 167 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 168 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 169 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 170 | Target *target = exe_ctx.GetTargetPtr(); |
| 171 | if (target) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 172 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 173 | m_data.SetByteOrder(target->GetArchitecture().GetByteOrder()); |
| 174 | m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 175 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 176 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 177 | // First make sure our Type and/or Address haven't changed: |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 178 | Process *process = exe_ctx.GetProcessPtr(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 179 | if (!process) |
| 180 | return false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 181 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 182 | TypeAndOrName class_type_or_name; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 183 | Address dynamic_address; |
| 184 | bool found_dynamic_type = false; |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 185 | Value::ValueType value_type; |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 186 | |
| 187 | LanguageRuntime *runtime = nullptr; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 188 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 189 | lldb::LanguageType known_type = m_parent->GetObjectRuntimeLanguage(); |
| 190 | if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) |
| 191 | { |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 192 | runtime = process->GetLanguageRuntime (known_type); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 193 | if (runtime) |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 194 | found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 195 | } |
| 196 | else |
| 197 | { |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 198 | runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); |
| 199 | if (runtime) |
| 200 | found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 201 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 202 | if (!found_dynamic_type) |
| 203 | { |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 204 | runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); |
| 205 | if (runtime) |
| 206 | found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 209 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 210 | // Getting the dynamic value may have run the program a bit, and so marked us as needing updating, but we really |
| 211 | // don't... |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 212 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 213 | m_update_point.SetUpdated(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 214 | |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 215 | if (runtime && found_dynamic_type) |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 216 | { |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 217 | if (class_type_or_name.HasType()) |
| 218 | { |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 219 | m_type_impl = TypeImpl(m_parent->GetCompilerType(), |
Enrico Granata | 7eed487 | 2015-09-22 19:58:02 +0000 | [diff] [blame] | 220 | runtime->FixUpDynamicType(class_type_or_name, *m_parent).GetCompilerType()); |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 221 | } |
| 222 | else |
| 223 | { |
| 224 | m_type_impl.Clear(); |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | m_type_impl.Clear(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 230 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 231 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 232 | // If we don't have a dynamic type, then make ourselves just a echo of our parent. |
| 233 | // Or we could return false, and make ourselves an echo of our parent? |
| 234 | if (!found_dynamic_type) |
| 235 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 236 | if (m_dynamic_type_info) |
Enrico Granata | 75badc4 | 2012-11-27 23:50:00 +0000 | [diff] [blame] | 237 | SetValueDidChange(true); |
Enrico Granata | bd83b87 | 2012-11-27 23:28:32 +0000 | [diff] [blame] | 238 | ClearDynamicTypeInformation(); |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 239 | m_dynamic_type_info.Clear(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 240 | m_value = m_parent->GetValue(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 241 | m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 242 | return m_error.Success(); |
| 243 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 244 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 245 | Value old_value(m_value); |
| 246 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 247 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 248 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 249 | bool has_changed_type = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 250 | |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 251 | if (!m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 252 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 253 | m_dynamic_type_info = class_type_or_name; |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 254 | has_changed_type = true; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 255 | } |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 256 | else if (class_type_or_name != m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 257 | { |
| 258 | // We are another type, we need to tear down our children... |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 259 | m_dynamic_type_info = class_type_or_name; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 260 | SetValueDidChange (true); |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 261 | has_changed_type = true; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 262 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 263 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 264 | if (has_changed_type) |
| 265 | ClearDynamicTypeInformation (); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 266 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 267 | if (!m_address.IsValid() || m_address != dynamic_address) |
| 268 | { |
| 269 | if (m_address.IsValid()) |
| 270 | SetValueDidChange (true); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 271 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 272 | // We've moved, so we should be fine... |
| 273 | m_address = dynamic_address; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 274 | lldb::TargetSP target_sp (GetTargetSP()); |
| 275 | lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 276 | m_value.GetScalar() = load_address; |
| 277 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 278 | |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 279 | if (runtime) |
Enrico Granata | 7eed487 | 2015-09-22 19:58:02 +0000 | [diff] [blame] | 280 | m_dynamic_type_info = runtime->FixUpDynamicType(m_dynamic_type_info, *m_parent); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 281 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 282 | //m_value.SetContext (Value::eContextTypeClangType, corrected_type); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 283 | m_value.SetCompilerType (m_dynamic_type_info.GetCompilerType()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 284 | |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 285 | m_value.SetValueType(value_type); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 286 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 287 | if (has_changed_type && log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 288 | log->Printf("[%s %p] has a new dynamic type %s", GetName().GetCString(), |
| 289 | static_cast<void*>(this), GetTypeName().GetCString()); |
| 290 | |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 291 | if (m_address.IsValid() && m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 292 | { |
| 293 | // The variable value is in the Scalar value inside the m_value. |
| 294 | // We can point our m_data right to it. |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 295 | m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 296 | if (m_error.Success()) |
| 297 | { |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 298 | if (!CanProvideValue()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 299 | { |
| 300 | // this value object represents an aggregate type whose |
| 301 | // children have values, but this object does not. So we |
| 302 | // say we are changed if our location has changed. |
| 303 | SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); |
| 304 | } |
| 305 | |
| 306 | SetValueIsValid (true); |
| 307 | return true; |
| 308 | } |
| 309 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 310 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 311 | // We get here if we've failed above... |
| 312 | SetValueIsValid (false); |
| 313 | return false; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | bool |
| 319 | ValueObjectDynamicValue::IsInScope () |
| 320 | { |
| 321 | return m_parent->IsInScope(); |
| 322 | } |
| 323 | |
Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 324 | bool |
| 325 | ValueObjectDynamicValue::SetValueFromCString (const char *value_str, Error& error) |
| 326 | { |
| 327 | if (!UpdateValueIfNeeded(false)) |
| 328 | { |
| 329 | error.SetErrorString("unable to read value"); |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | uint64_t my_value = GetValueAsUnsigned(UINT64_MAX); |
| 334 | uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX); |
| 335 | |
| 336 | if (my_value == UINT64_MAX || parent_value == UINT64_MAX) |
| 337 | { |
| 338 | error.SetErrorString("unable to read value"); |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | // if we are at an offset from our parent, in order to set ourselves correctly we would need |
| 343 | // to change the new value so that it refers to the correct dynamic type. we choose not to deal |
| 344 | // with that - if anything more than a value overwrite is required, you should be using the |
| 345 | // expression parser instead of the value editing facility |
| 346 | if (my_value != parent_value) |
| 347 | { |
| 348 | // but NULL'ing out a value should always be allowed |
| 349 | if (strcmp(value_str,"0")) |
| 350 | { |
| 351 | error.SetErrorString("unable to modify dynamic value, use 'expression' command"); |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | bool ret_val = m_parent->SetValueFromCString(value_str,error); |
| 357 | SetNeedsUpdate(); |
| 358 | return ret_val; |
| 359 | } |
Sean Callanan | 389823e | 2013-04-13 01:21:23 +0000 | [diff] [blame] | 360 | |
| 361 | bool |
| 362 | ValueObjectDynamicValue::SetData (DataExtractor &data, Error &error) |
| 363 | { |
| 364 | if (!UpdateValueIfNeeded(false)) |
| 365 | { |
| 366 | error.SetErrorString("unable to read value"); |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | uint64_t my_value = GetValueAsUnsigned(UINT64_MAX); |
| 371 | uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX); |
| 372 | |
| 373 | if (my_value == UINT64_MAX || parent_value == UINT64_MAX) |
| 374 | { |
| 375 | error.SetErrorString("unable to read value"); |
| 376 | return false; |
| 377 | } |
| 378 | |
| 379 | // if we are at an offset from our parent, in order to set ourselves correctly we would need |
| 380 | // to change the new value so that it refers to the correct dynamic type. we choose not to deal |
| 381 | // with that - if anything more than a value overwrite is required, you should be using the |
| 382 | // expression parser instead of the value editing facility |
| 383 | if (my_value != parent_value) |
| 384 | { |
| 385 | // but NULL'ing out a value should always be allowed |
| 386 | lldb::offset_t offset = 0; |
| 387 | |
| 388 | if (data.GetPointer(&offset) != 0) |
| 389 | { |
| 390 | error.SetErrorString("unable to modify dynamic value, use 'expression' command"); |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | bool ret_val = m_parent->SetData(data, error); |
| 396 | SetNeedsUpdate(); |
| 397 | return ret_val; |
| 398 | } |
Siva Chandra | 9851b1f | 2015-08-18 17:56:06 +0000 | [diff] [blame] | 399 | |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 400 | void |
| 401 | ValueObjectDynamicValue::SetPreferredDisplayLanguage (lldb::LanguageType lang) |
| 402 | { |
| 403 | this->ValueObject::SetPreferredDisplayLanguage(lang); |
| 404 | if (m_parent) |
| 405 | m_parent->SetPreferredDisplayLanguage(lang); |
| 406 | } |
| 407 | |
| 408 | lldb::LanguageType |
| 409 | ValueObjectDynamicValue::GetPreferredDisplayLanguage () |
| 410 | { |
| 411 | if (m_preferred_display_language == lldb::eLanguageTypeUnknown) |
| 412 | { |
| 413 | if (m_parent) |
| 414 | return m_parent->GetPreferredDisplayLanguage(); |
| 415 | return lldb::eLanguageTypeUnknown; |
| 416 | } |
| 417 | else |
| 418 | return m_preferred_display_language; |
| 419 | } |
| 420 | |
Siva Chandra | 9851b1f | 2015-08-18 17:56:06 +0000 | [diff] [blame] | 421 | bool |
| 422 | ValueObjectDynamicValue::GetDeclaration (Declaration &decl) |
| 423 | { |
| 424 | if (m_parent) |
| 425 | return m_parent->GetDeclaration(decl); |
| 426 | |
| 427 | return ValueObject::GetDeclaration(decl); |
| 428 | } |
Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame^] | 429 | |
| 430 | uint64_t |
| 431 | ValueObjectDynamicValue::GetLanguageFlags () |
| 432 | { |
| 433 | if (m_parent) |
| 434 | return m_parent->GetLanguageFlags(); |
| 435 | return this->ValueObject::GetLanguageFlags(); |
| 436 | } |
| 437 | |
| 438 | void |
| 439 | ValueObjectDynamicValue::SetLanguageFlags (uint64_t flags) |
| 440 | { |
| 441 | if (m_parent) |
| 442 | m_parent->SetLanguageFlags(flags); |
| 443 | else |
| 444 | this->ValueObject::SetLanguageFlags(flags); |
| 445 | } |