diff options
author | Enrico Granata <egranata@apple.com> | 2012-05-08 21:25:06 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2012-05-08 21:25:06 +0000 |
commit | 07a4ac22edd3f08cb460a651a2318d9bf5090ba1 (patch) | |
tree | a93b477d2a4d4e7b9e2e396229cbe3721a410c20 /lldb/source/Core | |
parent | 8d2a77de631dad32cb462e85f5cc935418cbf48d (diff) | |
download | bcm5719-llvm-07a4ac22edd3f08cb460a651a2318d9bf5090ba1.tar.gz bcm5719-llvm-07a4ac22edd3f08cb460a651a2318d9bf5090ba1.zip |
<rdar://problem/11239650> Fixing a bug where the SetValueFromCString() method failed to operate on dynamic values. The fix consists in making the set operation fall through to the parent. We only actually allow this if the dynamic value is at a 0-offset from the parent, or the new value is 0. Other scenarios would need agreement on the actual meaning of the set operation (do we keep offsetting? do we just assume the user knows what they are doing?) so we prevent them, and let the expression parser deal with the complexity
llvm-svn: 156422
Diffstat (limited to 'lldb/source/Core')
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 17 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectDynamicValue.cpp | 36 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectRegister.cpp | 4 |
3 files changed, 51 insertions, 6 deletions
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index b0b1a67095a..cd41f1d689f 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1591,12 +1591,16 @@ ValueObject::GetPointerValue (AddressType *address_type) } bool -ValueObject::SetValueFromCString (const char *value_str) +ValueObject::SetValueFromCString (const char *value_str, Error& error) { + error.Clear(); // Make sure our value is up to date first so that our location and location // type is valid. if (!UpdateValueIfNeeded(false)) + { + error.SetErrorString("unable to read value"); return false; + } uint32_t count = 0; Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); @@ -1615,7 +1619,6 @@ ValueObject::SetValueFromCString (const char *value_str) // If the value fits in a scalar, then make a new scalar and again let the // scalar code do the conversion, then figure out where to put the new value. Scalar new_scalar; - Error error; error = new_scalar.SetValueFromCString (value_str, encoding, byte_size); if (error.Success()) { @@ -1634,8 +1637,13 @@ ValueObject::SetValueFromCString (const char *value_str) new_scalar, byte_size, error); - if (!error.Success() || bytes_written != byte_size) - return false; + if (!error.Success()) + return false; + if (bytes_written != byte_size) + { + error.SetErrorString("unable to write value to memory"); + return false; + } } } break; @@ -1673,6 +1681,7 @@ ValueObject::SetValueFromCString (const char *value_str) else { // We don't support setting things bigger than a scalar at present. + error.SetErrorString("unable to write aggregate data type"); return false; } diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp index 6fd4ee88592..e3f27fc0bb9 100644 --- a/lldb/source/Core/ValueObjectDynamicValue.cpp +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp @@ -359,3 +359,39 @@ ValueObjectDynamicValue::IsInScope () return m_parent->IsInScope(); } +bool +ValueObjectDynamicValue::SetValueFromCString (const char *value_str, Error& error) +{ + if (!UpdateValueIfNeeded(false)) + { + error.SetErrorString("unable to read value"); + return false; + } + + uint64_t my_value = GetValueAsUnsigned(UINT64_MAX); + uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX); + + if (my_value == UINT64_MAX || parent_value == UINT64_MAX) + { + error.SetErrorString("unable to read value"); + return false; + } + + // if we are at an offset from our parent, in order to set ourselves correctly we would need + // to change the new value so that it refers to the correct dynamic type. we choose not to deal + // with that - if anything more than a value overwrite is required, you should be using the + // expression parser instead of the value editing facility + if (my_value != parent_value) + { + // but NULL'ing out a value should always be allowed + if (strcmp(value_str,"0")) + { + error.SetErrorString("unable to modify dynamic value, use 'expression' command"); + return false; + } + } + + bool ret_val = m_parent->SetValueFromCString(value_str,error); + SetNeedsUpdate(); + return ret_val; +} diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp index 2df5af6d320..2f2959dd1fe 100644 --- a/lldb/source/Core/ValueObjectRegister.cpp +++ b/lldb/source/Core/ValueObjectRegister.cpp @@ -404,10 +404,10 @@ ValueObjectRegister::UpdateValue () } bool -ValueObjectRegister::SetValueFromCString (const char *value_str) +ValueObjectRegister::SetValueFromCString (const char *value_str, Error& error) { // The new value will be in the m_data. Copy that into our register value. - Error error = m_reg_value.SetValueFromCString (&m_reg_info, value_str); + error = m_reg_value.SetValueFromCString (&m_reg_info, value_str); if (error.Success()) { if (m_reg_ctx_sp->WriteRegister (&m_reg_info, m_reg_value)) |