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