diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp --- a/lldb/source/Core/ValueObjectRegister.cpp +++ b/lldb/source/Core/ValueObjectRegister.cpp @@ -269,26 +269,30 @@ // The new value will be in the m_data. Copy that into our register value. error = m_reg_value.SetValueFromString(&m_reg_info, llvm::StringRef(value_str)); - if (error.Success()) { - if (m_reg_ctx_sp->WriteRegister(&m_reg_info, m_reg_value)) { - SetNeedsUpdate(); - return true; - } else - return false; - } else + if (!error.Success()) return false; + + if (!m_reg_ctx_sp->WriteRegister(&m_reg_info, m_reg_value)) { + error.SetErrorString("unable to write back to register"); + return false; + } + + SetNeedsUpdate(); + return true; } bool ValueObjectRegister::SetData(DataExtractor &data, Status &error) { error = m_reg_value.SetValueFromData(&m_reg_info, data, 0, false); - if (error.Success()) { - if (m_reg_ctx_sp->WriteRegister(&m_reg_info, m_reg_value)) { - SetNeedsUpdate(); - return true; - } else - return false; - } else + if (!error.Success()) return false; + + if (!m_reg_ctx_sp->WriteRegister(&m_reg_info, m_reg_value)) { + error.SetErrorString("unable to write back to register"); + return false; + } + + SetNeedsUpdate(); + return true; } bool ValueObjectRegister::ResolveValue(Scalar &scalar) { diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py --- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py +++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py @@ -133,6 +133,29 @@ self.assertEqual(len(bytesread), 16) self.dbg.DeleteTarget(target) + @skipIfLLVMTargetMissing("X86") + def test_write_register(self): + """Test that writing to register results in an error and that error + message is set.""" + target = self.dbg.CreateTarget("linux-x86_64.out") + process = target.LoadCore("linux-x86_64.core") + self.assertTrue(process, PROCESS_IS_VALID) + + thread = process.GetSelectedThread() + self.assertTrue(thread) + + frame = thread.GetSelectedFrame() + self.assertTrue(frame) + + reg_value = frame.FindRegister('eax') + self.assertTrue(reg_value) + + error = lldb.SBError() + success = reg_value.SetValueFromCString('10', error) + self.assertFalse(success) + self.assertTrue(error.Fail()) + self.assertIsNotNone(error.GetCString()) + @skipIfLLVMTargetMissing("X86") def test_FPR_SSE(self): # check x86_64 core file