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 |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 116 | ValueObjectDynamicValue::CalculateNumChildren() |
| 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()) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 120 | return GetCompilerType().GetNumChildren (true); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 121 | else |
| 122 | return m_parent->GetNumChildren(); |
| 123 | } |
| 124 | |
Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 125 | uint64_t |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 126 | ValueObjectDynamicValue::GetByteSize() |
| 127 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 128 | const bool success = UpdateValueIfNeeded(false); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 129 | if (success && m_dynamic_type_info.HasType()) |
Enrico Granata | 951bdd5 | 2015-01-28 01:09:45 +0000 | [diff] [blame] | 130 | return m_value.GetValueByteSize(nullptr); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 131 | else |
| 132 | return m_parent->GetByteSize(); |
| 133 | } |
| 134 | |
| 135 | lldb::ValueType |
| 136 | ValueObjectDynamicValue::GetValueType() const |
| 137 | { |
| 138 | return m_parent->GetValueType(); |
| 139 | } |
| 140 | |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 141 | |
| 142 | static TypeAndOrName |
| 143 | FixupTypeAndOrName (const TypeAndOrName& type_andor_name, |
| 144 | ValueObject& parent) |
| 145 | { |
| 146 | TypeAndOrName ret(type_andor_name); |
| 147 | if (type_andor_name.HasType()) |
| 148 | { |
| 149 | // The type will always be the type of the dynamic object. If our parent's type was a pointer, |
| 150 | // then our type should be a pointer to the type of the dynamic object. If a reference, then the original type |
| 151 | // should be okay... |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 152 | CompilerType orig_type = type_andor_name.GetCompilerType(); |
| 153 | CompilerType corrected_type = orig_type; |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 154 | if (parent.IsPointerType()) |
| 155 | corrected_type = orig_type.GetPointerType (); |
| 156 | else if (parent.IsPointerOrReferenceType()) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 157 | corrected_type = orig_type.GetLValueReferenceType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 158 | ret.SetCompilerType(corrected_type); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 159 | } |
| 160 | else /*if (m_dynamic_type_info.HasName())*/ |
| 161 | { |
| 162 | // If we are here we need to adjust our dynamic type name to include the correct & or * symbol |
| 163 | std::string corrected_name (type_andor_name.GetName().GetCString()); |
| 164 | if (parent.IsPointerType()) |
| 165 | corrected_name.append(" *"); |
| 166 | else if (parent.IsPointerOrReferenceType()) |
| 167 | corrected_name.append(" &"); |
Enrico Granata | fcf0c4e | 2013-10-31 22:42:00 +0000 | [diff] [blame] | 168 | // the parent type should be a correctly pointer'ed or referenc'ed type |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 169 | ret.SetCompilerType(parent.GetCompilerType()); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 170 | ret.SetName(corrected_name.c_str()); |
| 171 | } |
| 172 | return ret; |
| 173 | } |
| 174 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 175 | bool |
| 176 | ValueObjectDynamicValue::UpdateValue () |
| 177 | { |
| 178 | SetValueIsValid (false); |
| 179 | m_error.Clear(); |
| 180 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 181 | if (!m_parent->UpdateValueIfNeeded(false)) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 182 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 183 | // The dynamic value failed to get an error, pass the error along |
| 184 | if (m_error.Success() && m_parent->GetError().Fail()) |
| 185 | m_error = m_parent->GetError(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 186 | return false; |
| 187 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 188 | |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 189 | // Setting our type_sp to NULL will route everything back through our |
| 190 | // parent which is equivalent to not using dynamic values. |
| 191 | if (m_use_dynamic == lldb::eNoDynamicValues) |
| 192 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 193 | m_dynamic_type_info.Clear(); |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 194 | return true; |
| 195 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 196 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 197 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 198 | Target *target = exe_ctx.GetTargetPtr(); |
| 199 | if (target) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 200 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 201 | m_data.SetByteOrder(target->GetArchitecture().GetByteOrder()); |
| 202 | m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 203 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 204 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 205 | // First make sure our Type and/or Address haven't changed: |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 206 | Process *process = exe_ctx.GetProcessPtr(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 207 | if (!process) |
| 208 | return false; |
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 | TypeAndOrName class_type_or_name; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 211 | Address dynamic_address; |
| 212 | bool found_dynamic_type = false; |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 213 | Value::ValueType value_type; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 214 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 215 | lldb::LanguageType known_type = m_parent->GetObjectRuntimeLanguage(); |
| 216 | if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) |
| 217 | { |
| 218 | LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); |
| 219 | if (runtime) |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 220 | 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] | 221 | } |
| 222 | else |
| 223 | { |
| 224 | LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); |
| 225 | if (cpp_runtime) |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 226 | found_dynamic_type = cpp_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] | 227 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 228 | if (!found_dynamic_type) |
| 229 | { |
| 230 | LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); |
| 231 | if (objc_runtime) |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 232 | found_dynamic_type = objc_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] | 233 | } |
| 234 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 235 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 236 | // Getting the dynamic value may have run the program a bit, and so marked us as needing updating, but we really |
| 237 | // don't... |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 238 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 239 | m_update_point.SetUpdated(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 240 | |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 241 | if (found_dynamic_type) |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 242 | { |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 243 | if (class_type_or_name.HasType()) |
| 244 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 245 | m_type_impl = TypeImpl(m_parent->GetCompilerType(),FixupTypeAndOrName(class_type_or_name, *m_parent).GetCompilerType()); |
Enrico Granata | df7c7f9 | 2013-10-29 17:42:02 +0000 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
| 249 | m_type_impl.Clear(); |
| 250 | } |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | m_type_impl.Clear(); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 255 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 256 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 257 | // If we don't have a dynamic type, then make ourselves just a echo of our parent. |
| 258 | // Or we could return false, and make ourselves an echo of our parent? |
| 259 | if (!found_dynamic_type) |
| 260 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 261 | if (m_dynamic_type_info) |
Enrico Granata | 75badc4 | 2012-11-27 23:50:00 +0000 | [diff] [blame] | 262 | SetValueDidChange(true); |
Enrico Granata | bd83b87 | 2012-11-27 23:28:32 +0000 | [diff] [blame] | 263 | ClearDynamicTypeInformation(); |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 264 | m_dynamic_type_info.Clear(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 265 | m_value = m_parent->GetValue(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 266 | m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 267 | return m_error.Success(); |
| 268 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 269 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 270 | Value old_value(m_value); |
| 271 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 272 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 273 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 274 | bool has_changed_type = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 275 | |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 276 | if (!m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 277 | { |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 278 | m_dynamic_type_info = class_type_or_name; |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 279 | has_changed_type = true; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 280 | } |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 281 | else if (class_type_or_name != m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 282 | { |
| 283 | // We are another type, we need to tear down our children... |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 284 | m_dynamic_type_info = class_type_or_name; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 285 | SetValueDidChange (true); |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 286 | has_changed_type = true; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 287 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 288 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 289 | if (has_changed_type) |
| 290 | ClearDynamicTypeInformation (); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 291 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 292 | if (!m_address.IsValid() || m_address != dynamic_address) |
| 293 | { |
| 294 | if (m_address.IsValid()) |
| 295 | SetValueDidChange (true); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 296 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 297 | // We've moved, so we should be fine... |
| 298 | m_address = dynamic_address; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 299 | lldb::TargetSP target_sp (GetTargetSP()); |
| 300 | lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 301 | m_value.GetScalar() = load_address; |
| 302 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 303 | |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 304 | m_dynamic_type_info = FixupTypeAndOrName(m_dynamic_type_info, *m_parent); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 305 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 306 | //m_value.SetContext (Value::eContextTypeClangType, corrected_type); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 307 | m_value.SetCompilerType (m_dynamic_type_info.GetCompilerType()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 308 | |
Enrico Granata | 0b6003f | 2015-09-17 22:56:38 +0000 | [diff] [blame] | 309 | m_value.SetValueType(value_type); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 310 | |
Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 311 | if (has_changed_type && log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 312 | log->Printf("[%s %p] has a new dynamic type %s", GetName().GetCString(), |
| 313 | static_cast<void*>(this), GetTypeName().GetCString()); |
| 314 | |
Enrico Granata | f7b1a34 | 2013-01-23 01:17:27 +0000 | [diff] [blame] | 315 | if (m_address.IsValid() && m_dynamic_type_info) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 316 | { |
| 317 | // The variable value is in the Scalar value inside the m_value. |
| 318 | // We can point our m_data right to it. |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 319 | m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get()); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 320 | if (m_error.Success()) |
| 321 | { |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 322 | if (!CanProvideValue()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 323 | { |
| 324 | // this value object represents an aggregate type whose |
| 325 | // children have values, but this object does not. So we |
| 326 | // say we are changed if our location has changed. |
| 327 | SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); |
| 328 | } |
| 329 | |
| 330 | SetValueIsValid (true); |
| 331 | return true; |
| 332 | } |
| 333 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 334 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 335 | // We get here if we've failed above... |
| 336 | SetValueIsValid (false); |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | |
| 342 | bool |
| 343 | ValueObjectDynamicValue::IsInScope () |
| 344 | { |
| 345 | return m_parent->IsInScope(); |
| 346 | } |
| 347 | |
Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 348 | bool |
| 349 | ValueObjectDynamicValue::SetValueFromCString (const char *value_str, Error& error) |
| 350 | { |
| 351 | if (!UpdateValueIfNeeded(false)) |
| 352 | { |
| 353 | error.SetErrorString("unable to read value"); |
| 354 | return false; |
| 355 | } |
| 356 | |
| 357 | uint64_t my_value = GetValueAsUnsigned(UINT64_MAX); |
| 358 | uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX); |
| 359 | |
| 360 | if (my_value == UINT64_MAX || parent_value == UINT64_MAX) |
| 361 | { |
| 362 | error.SetErrorString("unable to read value"); |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | // if we are at an offset from our parent, in order to set ourselves correctly we would need |
| 367 | // to change the new value so that it refers to the correct dynamic type. we choose not to deal |
| 368 | // with that - if anything more than a value overwrite is required, you should be using the |
| 369 | // expression parser instead of the value editing facility |
| 370 | if (my_value != parent_value) |
| 371 | { |
| 372 | // but NULL'ing out a value should always be allowed |
| 373 | if (strcmp(value_str,"0")) |
| 374 | { |
| 375 | error.SetErrorString("unable to modify dynamic value, use 'expression' command"); |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | bool ret_val = m_parent->SetValueFromCString(value_str,error); |
| 381 | SetNeedsUpdate(); |
| 382 | return ret_val; |
| 383 | } |
Sean Callanan | 389823e | 2013-04-13 01:21:23 +0000 | [diff] [blame] | 384 | |
| 385 | bool |
| 386 | ValueObjectDynamicValue::SetData (DataExtractor &data, Error &error) |
| 387 | { |
| 388 | if (!UpdateValueIfNeeded(false)) |
| 389 | { |
| 390 | error.SetErrorString("unable to read value"); |
| 391 | return false; |
| 392 | } |
| 393 | |
| 394 | uint64_t my_value = GetValueAsUnsigned(UINT64_MAX); |
| 395 | uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX); |
| 396 | |
| 397 | if (my_value == UINT64_MAX || parent_value == UINT64_MAX) |
| 398 | { |
| 399 | error.SetErrorString("unable to read value"); |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | // if we are at an offset from our parent, in order to set ourselves correctly we would need |
| 404 | // to change the new value so that it refers to the correct dynamic type. we choose not to deal |
| 405 | // with that - if anything more than a value overwrite is required, you should be using the |
| 406 | // expression parser instead of the value editing facility |
| 407 | if (my_value != parent_value) |
| 408 | { |
| 409 | // but NULL'ing out a value should always be allowed |
| 410 | lldb::offset_t offset = 0; |
| 411 | |
| 412 | if (data.GetPointer(&offset) != 0) |
| 413 | { |
| 414 | error.SetErrorString("unable to modify dynamic value, use 'expression' command"); |
| 415 | return false; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | bool ret_val = m_parent->SetData(data, error); |
| 420 | SetNeedsUpdate(); |
| 421 | return ret_val; |
| 422 | } |
Siva Chandra | 9851b1f | 2015-08-18 17:56:06 +0000 | [diff] [blame] | 423 | |
| 424 | bool |
| 425 | ValueObjectDynamicValue::GetDeclaration (Declaration &decl) |
| 426 | { |
| 427 | if (m_parent) |
| 428 | return m_parent->GetDeclaration(decl); |
| 429 | |
| 430 | return ValueObject::GetDeclaration(decl); |
| 431 | } |