virtual bool Execute ( Args& command, CommandReturnObject &result ) { DataExtractor reg_data; ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); RegisterContext *reg_context = exe_ctx.GetRegisterContext (); if (reg_context) { if (command.GetArgumentCount() != 2) { result.AppendError ("register write takes exactly 2 arguments: <reg-name> <value>"); result.SetStatus (eReturnStatusFailed); } else { const char *reg_name = command.GetArgumentAtIndex(0); const char *value_str = command.GetArgumentAtIndex(1); const RegisterInfo *reg_info = reg_context->GetRegisterInfoByName(reg_name); if (reg_info) { Scalar scalar; Error error(scalar.SetValueFromCString (value_str, reg_info->encoding, reg_info->byte_size)); if (error.Success()) { if (reg_context->WriteRegisterValue(reg_info->kinds[eRegisterKindLLDB], scalar)) { result.SetStatus (eReturnStatusSuccessFinishNoResult); return true; } } else { result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s': %s\n", reg_name, value_str, error.AsCString()); result.SetStatus (eReturnStatusFailed); } } else { result.AppendErrorWithFormat ("Register not found for '%s'.\n", reg_name); result.SetStatus (eReturnStatusFailed); } } } else { result.AppendError ("no current frame"); result.SetStatus (eReturnStatusFailed); } return result.Succeeded(); }
TEST(ScalarTest, SetValueFromCString) { Scalar a; EXPECT_THAT_ERROR( a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 8).ToError(), Succeeded()); EXPECT_EQ(1234567890123ull, a); EXPECT_THAT_ERROR( a.SetValueFromCString("-1234567890123", lldb::eEncodingSint, 8).ToError(), Succeeded()); EXPECT_EQ(-1234567890123ll, a); EXPECT_THAT_ERROR( a.SetValueFromCString("asdf", lldb::eEncodingSint, 8).ToError(), Failed()); EXPECT_THAT_ERROR( a.SetValueFromCString("asdf", lldb::eEncodingUint, 8).ToError(), Failed()); EXPECT_THAT_ERROR( a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 4).ToError(), Failed()); EXPECT_THAT_ERROR(a.SetValueFromCString("123456789012345678901234567890", lldb::eEncodingUint, 8) .ToError(), Failed()); EXPECT_THAT_ERROR( a.SetValueFromCString("-123", lldb::eEncodingUint, 8).ToError(), Failed()); }