Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ValueObjectVariable.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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | #include "lldb/Core/ValueObjectVariable.h" |
| 11 | |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Address.h" // for Address |
| 13 | #include "lldb/Core/AddressRange.h" // for AddressRange |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Value.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/DWARFExpression.h" // for DWARFExpression |
| 17 | #include "lldb/Symbol/Declaration.h" // for Declaration |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/ObjectFile.h" |
| 20 | #include "lldb/Symbol/SymbolContext.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolContextScope.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/Type.h" |
| 23 | #include "lldb/Symbol/Variable.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/ExecutionContext.h" |
| 25 | #include "lldb/Target/Process.h" |
| 26 | #include "lldb/Target/RegisterContext.h" |
| 27 | #include "lldb/Target/Target.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 28 | #include "lldb/Utility/DataExtractor.h" // for DataExtractor |
| 29 | #include "lldb/Utility/RegisterValue.h" |
| 30 | #include "lldb/Utility/Scalar.h" // for Scalar, operator!= |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 31 | #include "lldb/Utility/Status.h" // for Status |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 32 | #include "lldb/lldb-private-enumerations.h" // for AddressType::eAddressTy... |
| 33 | #include "lldb/lldb-types.h" // for addr_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/StringRef.h" // for StringRef |
| 36 | |
| 37 | #include <assert.h> // for assert |
| 38 | #include <memory> // for shared_ptr |
| 39 | |
| 40 | namespace lldb_private { |
| 41 | class ExecutionContextScope; |
| 42 | } |
| 43 | namespace lldb_private { |
| 44 | class StackFrame; |
| 45 | } |
| 46 | namespace lldb_private { |
| 47 | struct RegisterInfo; |
| 48 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | using namespace lldb_private; |
| 50 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 51 | lldb::ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | ValueObjectVariable::Create(ExecutionContextScope *exe_scope, |
| 53 | const lldb::VariableSP &var_sp) { |
| 54 | return (new ValueObjectVariable(exe_scope, var_sp))->GetSP(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | ValueObjectVariable::ValueObjectVariable(ExecutionContextScope *exe_scope, |
| 58 | const lldb::VariableSP &var_sp) |
| 59 | : ValueObject(exe_scope), m_variable_sp(var_sp) { |
| 60 | // Do not attempt to construct one of these objects with no variable! |
| 61 | assert(m_variable_sp.get() != NULL); |
| 62 | m_name = var_sp->GetName(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | ValueObjectVariable::~ValueObjectVariable() {} |
| 66 | |
| 67 | CompilerType ValueObjectVariable::GetCompilerTypeImpl() { |
| 68 | Type *var_type = m_variable_sp->GetType(); |
| 69 | if (var_type) |
| 70 | return var_type->GetForwardCompilerType(); |
| 71 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | ConstString ValueObjectVariable::GetTypeName() { |
| 75 | Type *var_type = m_variable_sp->GetType(); |
| 76 | if (var_type) |
| 77 | return var_type->GetName(); |
| 78 | return ConstString(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | ConstString ValueObjectVariable::GetDisplayTypeName() { |
| 82 | Type *var_type = m_variable_sp->GetType(); |
| 83 | if (var_type) |
| 84 | return var_type->GetForwardCompilerType().GetDisplayTypeName(); |
| 85 | return ConstString(); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | ConstString ValueObjectVariable::GetQualifiedTypeName() { |
| 89 | Type *var_type = m_variable_sp->GetType(); |
| 90 | if (var_type) |
| 91 | return var_type->GetQualifiedName(); |
| 92 | return ConstString(); |
Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | size_t ValueObjectVariable::CalculateNumChildren(uint32_t max) { |
| 96 | CompilerType type(GetCompilerType()); |
| 97 | |
| 98 | if (!type.IsValid()) |
| 99 | return 0; |
| 100 | |
| 101 | const bool omit_empty_base_classes = true; |
| 102 | auto child_count = type.GetNumChildren(omit_empty_base_classes); |
| 103 | return child_count <= max ? child_count : max; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | uint64_t ValueObjectVariable::GetByteSize() { |
| 107 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 108 | |
| 109 | CompilerType type(GetCompilerType()); |
| 110 | |
| 111 | if (!type.IsValid()) |
| 112 | return 0; |
| 113 | |
| 114 | return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | lldb::ValueType ValueObjectVariable::GetValueType() const { |
| 118 | if (m_variable_sp) |
| 119 | return m_variable_sp->GetScope(); |
| 120 | return lldb::eValueTypeInvalid; |
| 121 | } |
| 122 | |
| 123 | bool ValueObjectVariable::UpdateValue() { |
| 124 | SetValueIsValid(false); |
| 125 | m_error.Clear(); |
| 126 | |
| 127 | Variable *variable = m_variable_sp.get(); |
| 128 | DWARFExpression &expr = variable->LocationExpression(); |
| 129 | |
| 130 | if (variable->GetLocationIsConstantValueData()) { |
| 131 | // expr doesn't contain DWARF bytes, it contains the constant variable |
| 132 | // value bytes themselves... |
| 133 | if (expr.GetExpressionData(m_data)) |
| 134 | m_value.SetContext(Value::eContextTypeVariable, variable); |
| 135 | else |
| 136 | m_error.SetErrorString("empty constant data"); |
| 137 | // constant bytes can't be edited - sorry |
| 138 | m_resolved_value.SetContext(Value::eContextTypeInvalid, NULL); |
| 139 | } else { |
| 140 | lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS; |
Enrico Granata | 951bdd5 | 2015-01-28 01:09:45 +0000 | [diff] [blame] | 141 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | Target *target = exe_ctx.GetTargetPtr(); |
| 144 | if (target) { |
| 145 | m_data.SetByteOrder(target->GetArchitecture().GetByteOrder()); |
| 146 | m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); |
Greg Clayton | f5fb427 | 2010-09-18 04:00:06 +0000 | [diff] [blame] | 147 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | if (expr.IsLocationList()) { |
| 150 | SymbolContext sc; |
| 151 | variable->CalculateSymbolContext(&sc); |
| 152 | if (sc.function) |
| 153 | loclist_base_load_addr = |
| 154 | sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress( |
| 155 | target); |
| 156 | } |
| 157 | Value old_value(m_value); |
Tamas Berghammer | bba2c83 | 2017-08-16 11:45:10 +0000 | [diff] [blame] | 158 | if (expr.Evaluate(&exe_ctx, nullptr, loclist_base_load_addr, nullptr, |
| 159 | nullptr, m_value, &m_error)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | m_resolved_value = m_value; |
| 161 | m_value.SetContext(Value::eContextTypeVariable, variable); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | CompilerType compiler_type = GetCompilerType(); |
| 164 | if (compiler_type.IsValid()) |
| 165 | m_value.SetCompilerType(compiler_type); |
Greg Clayton | 3a95b5b | 2014-12-19 01:28:42 +0000 | [diff] [blame] | 166 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | Value::ValueType value_type = m_value.GetValueType(); |
Greg Clayton | 3a95b5b | 2014-12-19 01:28:42 +0000 | [diff] [blame] | 168 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | Process *process = exe_ctx.GetProcessPtr(); |
| 170 | const bool process_is_alive = process && process->IsAlive(); |
| 171 | const uint32_t type_info = compiler_type.GetTypeInfo(); |
| 172 | const bool is_pointer_or_ref = |
| 173 | (type_info & (lldb::eTypeIsPointer | lldb::eTypeIsReference)) != 0; |
| 174 | |
| 175 | switch (value_type) { |
| 176 | case Value::eValueTypeFileAddress: |
| 177 | // If this type is a pointer, then its children will be considered load |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 178 | // addresses if the pointer or reference is dereferenced, but only if |
| 179 | // the process is alive. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | // |
| 181 | // There could be global variables like in the following code: |
| 182 | // struct LinkedListNode { Foo* foo; LinkedListNode* next; }; |
| 183 | // Foo g_foo1; |
| 184 | // Foo g_foo2; |
| 185 | // LinkedListNode g_second_node = { &g_foo2, NULL }; |
| 186 | // LinkedListNode g_first_node = { &g_foo1, &g_second_node }; |
| 187 | // |
| 188 | // When we aren't running, we should be able to look at these variables |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 189 | // using the "target variable" command. Children of the "g_first_node" |
| 190 | // always will be of the same address type as the parent. But children |
| 191 | // of the "next" member of LinkedListNode will become load addresses if |
| 192 | // we have a live process, or remain what a file address if it what a |
| 193 | // file address. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | if (process_is_alive && is_pointer_or_ref) |
| 195 | SetAddressTypeOfChildren(eAddressTypeLoad); |
| 196 | else |
| 197 | SetAddressTypeOfChildren(eAddressTypeFile); |
| 198 | break; |
| 199 | case Value::eValueTypeHostAddress: |
| 200 | // Same as above for load addresses, except children of pointer or refs |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 201 | // are always load addresses. Host addresses are used to store freeze |
| 202 | // dried variables. If this type is a struct, the entire struct |
| 203 | // contents will be copied into the heap of the |
Bruce Mitchener | 4ebdee0 | 2018-05-29 09:10:46 +0000 | [diff] [blame] | 204 | // LLDB process, but we do not currently follow any pointers. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | if (is_pointer_or_ref) |
| 206 | SetAddressTypeOfChildren(eAddressTypeLoad); |
| 207 | else |
| 208 | SetAddressTypeOfChildren(eAddressTypeHost); |
| 209 | break; |
| 210 | case Value::eValueTypeLoadAddress: |
| 211 | case Value::eValueTypeScalar: |
| 212 | case Value::eValueTypeVector: |
| 213 | SetAddressTypeOfChildren(eAddressTypeLoad); |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | switch (value_type) { |
| 218 | case Value::eValueTypeVector: |
| 219 | // fall through |
| 220 | case Value::eValueTypeScalar: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 221 | // The variable value is in the Scalar value inside the m_value. We can |
| 222 | // point our m_data right to it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 223 | m_error = |
| 224 | m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); |
| 225 | break; |
| 226 | |
| 227 | case Value::eValueTypeFileAddress: |
| 228 | case Value::eValueTypeLoadAddress: |
| 229 | case Value::eValueTypeHostAddress: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 230 | // The DWARF expression result was an address in the inferior process. |
| 231 | // If this variable is an aggregate type, we just need the address as |
| 232 | // the main value as all child variable objects will rely upon this |
| 233 | // location and add an offset and then read their own values as needed. |
| 234 | // If this variable is a simple type, we read all data for it into |
| 235 | // m_data. Make sure this type has a value before we try and read it |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 236 | |
| 237 | // If we have a file address, convert it to a load address if we can. |
Adrian Prantl | b51804e | 2018-05-03 23:32:47 +0000 | [diff] [blame] | 238 | if (value_type == Value::eValueTypeFileAddress && process_is_alive) |
| 239 | m_value.ConvertToLoadAddress(GetModule().get(), target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | |
| 241 | if (!CanProvideValue()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 242 | // this value object represents an aggregate type whose children have |
| 243 | // values, but this object does not. So we say we are changed if our |
| 244 | // location has changed. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | SetValueDidChange(value_type != old_value.GetValueType() || |
| 246 | m_value.GetScalar() != old_value.GetScalar()); |
| 247 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 248 | // Copy the Value and set the context to use our Variable so it can |
| 249 | // extract read its value into m_data appropriately |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | Value value(m_value); |
| 251 | value.SetContext(Value::eContextTypeVariable, variable); |
| 252 | m_error = |
| 253 | value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); |
| 254 | |
| 255 | SetValueDidChange(value_type != old_value.GetValueType() || |
| 256 | m_value.GetScalar() != old_value.GetScalar()); |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 257 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | break; |
| 259 | } |
| 260 | |
| 261 | SetValueIsValid(m_error.Success()); |
| 262 | } else { |
| 263 | // could not find location, won't allow editing |
| 264 | m_resolved_value.SetContext(Value::eContextTypeInvalid, NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 266 | } |
| 267 | return m_error.Success(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | bool ValueObjectVariable::IsInScope() { |
| 271 | const ExecutionContextRef &exe_ctx_ref = GetExecutionContextRef(); |
| 272 | if (exe_ctx_ref.HasFrameRef()) { |
| 273 | ExecutionContext exe_ctx(exe_ctx_ref); |
| 274 | StackFrame *frame = exe_ctx.GetFramePtr(); |
| 275 | if (frame) { |
| 276 | return m_variable_sp->IsInScope(frame); |
| 277 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 278 | // This ValueObject had a frame at one time, but now we can't locate it, |
| 279 | // so return false since we probably aren't in scope. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | return false; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 281 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 282 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 283 | // We have a variable that wasn't tied to a frame, which means it is a global |
| 284 | // and is always in scope. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | return true; |
| 286 | } |
| 287 | |
| 288 | lldb::ModuleSP ValueObjectVariable::GetModule() { |
| 289 | if (m_variable_sp) { |
| 290 | SymbolContextScope *sc_scope = m_variable_sp->GetSymbolContextScope(); |
| 291 | if (sc_scope) { |
| 292 | return sc_scope->CalculateSymbolContextModule(); |
| 293 | } |
| 294 | } |
| 295 | return lldb::ModuleSP(); |
| 296 | } |
| 297 | |
| 298 | SymbolContextScope *ValueObjectVariable::GetSymbolContextScope() { |
| 299 | if (m_variable_sp) |
| 300 | return m_variable_sp->GetSymbolContextScope(); |
| 301 | return NULL; |
| 302 | } |
| 303 | |
| 304 | bool ValueObjectVariable::GetDeclaration(Declaration &decl) { |
| 305 | if (m_variable_sp) { |
| 306 | decl = m_variable_sp->GetDeclaration(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 307 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 308 | } |
| 309 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 312 | const char *ValueObjectVariable::GetLocationAsCString() { |
| 313 | if (m_resolved_value.GetContextType() == Value::eContextTypeRegisterInfo) |
| 314 | return GetLocationAsCStringImpl(m_resolved_value, m_data); |
| 315 | else |
| 316 | return ValueObject::GetLocationAsCString(); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | bool ValueObjectVariable::SetValueFromCString(const char *value_str, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 320 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 321 | if (!UpdateValueIfNeeded()) { |
| 322 | error.SetErrorString("unable to update value before writing"); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 323 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if (m_resolved_value.GetContextType() == Value::eContextTypeRegisterInfo) { |
| 327 | RegisterInfo *reg_info = m_resolved_value.GetRegisterInfo(); |
| 328 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 329 | RegisterContext *reg_ctx = exe_ctx.GetRegisterContext(); |
| 330 | RegisterValue reg_value; |
| 331 | if (!reg_info || !reg_ctx) { |
| 332 | error.SetErrorString("unable to retrieve register info"); |
| 333 | return false; |
| 334 | } |
Zachary Turner | ac96f66 | 2016-11-17 23:47:31 +0000 | [diff] [blame] | 335 | error = reg_value.SetValueFromString(reg_info, llvm::StringRef(value_str)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 336 | if (error.Fail()) |
| 337 | return false; |
| 338 | if (reg_ctx->WriteRegister(reg_info, reg_value)) { |
| 339 | SetNeedsUpdate(); |
| 340 | return true; |
| 341 | } else { |
| 342 | error.SetErrorString("unable to write back to register"); |
| 343 | return false; |
| 344 | } |
| 345 | } else |
| 346 | return ValueObject::SetValueFromCString(value_str, error); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 347 | } |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 348 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 349 | bool ValueObjectVariable::SetData(DataExtractor &data, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | if (!UpdateValueIfNeeded()) { |
| 351 | error.SetErrorString("unable to update value before writing"); |
| 352 | return false; |
| 353 | } |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 354 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 355 | if (m_resolved_value.GetContextType() == Value::eContextTypeRegisterInfo) { |
| 356 | RegisterInfo *reg_info = m_resolved_value.GetRegisterInfo(); |
| 357 | ExecutionContext exe_ctx(GetExecutionContextRef()); |
| 358 | RegisterContext *reg_ctx = exe_ctx.GetRegisterContext(); |
| 359 | RegisterValue reg_value; |
| 360 | if (!reg_info || !reg_ctx) { |
| 361 | error.SetErrorString("unable to retrieve register info"); |
| 362 | return false; |
Sean Callanan | 6826d22 | 2014-01-18 01:13:50 +0000 | [diff] [blame] | 363 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 364 | error = reg_value.SetValueFromData(reg_info, data, 0, true); |
| 365 | if (error.Fail()) |
| 366 | return false; |
| 367 | if (reg_ctx->WriteRegister(reg_info, reg_value)) { |
| 368 | SetNeedsUpdate(); |
| 369 | return true; |
| 370 | } else { |
| 371 | error.SetErrorString("unable to write back to register"); |
| 372 | return false; |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 373 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | } else |
| 375 | return ValueObject::SetData(data, error); |
Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 376 | } |