Index: lldb/source/Core/ValueObjectRegister.cpp =================================================================== --- lldb/source/Core/ValueObjectRegister.cpp +++ 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) { Index: lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py =================================================================== --- lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py +++ lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py @@ -133,6 +133,30 @@ 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: lldb.SBTarget = self.dbg.CreateTarget("linux-x86_64.out") + process: lldb.SBProcess = target.LoadCore("linux-x86_64.core") + self.assertTrue(process, PROCESS_IS_VALID) + + thread: lldb.SBThread = process.GetSelectedThread() + self.assertTrue(thread) + + frame: lldb.SBFrame = thread.GetSelectedFrame() + self.assertTrue(frame) + + reg_value: lldb.SBValue = frame.FindRegister('eax') + if not reg_value.IsValid(): + return + + 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