From: Philippe Waroquiers Date: Sat, 13 Apr 2019 07:13:53 +0000 (+0200) Subject: Fix GDB 8.3 regression crash when registers cannot be modified. X-Git-Tag: gdb-8.3-release~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf9a7cea9c88de232f07151614562f81b52630a0;p=thirdparty%2Fbinutils-gdb.git Fix GDB 8.3 regression crash when registers cannot be modified. This crash was detected when using GDB with the valgrind gdbserver. To reproduce: valgrind sleep 10000 In another window: gdb target remote | vgdb p printf("make sleep print something\n") => terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR' Aborted The problem is that the valgrind gdbserver does not allow to change registers when the inferior is blocked in a system call. GDB then raises an exception. The exception causes the destructor of typedef std::unique_ptr infcall_suspend_state_up; to be called. This destructor itself tries to restore the value of the registers, and fails similarly. We must catch the exception in the destructor to avoid crashing GDB. If the destructor encounters a problem, no warning is produced if there is an uncaught exception, as in this case, the user will already be informed of a problem via this exception. With this change, no crash anymore, and all the valgrind 3.15 tests pass succesfully. Note: when this patch is approved, I will push an equivalent patch on master, but with TRY/CATCH/e.message () replaced by try/catch/e.what (). gdb/ChangeLog 2019-04-19 Philippe Waroquiers * inferior.h (struct infcall_suspend_state_deleter): Catch exception in destructor to avoid crash. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 44e0e1eed03..8a4da983b3e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-04-19 Philippe Waroquiers + + * inferior.h (struct infcall_suspend_state_deleter): + Catch exception in destructor to avoid crash. + 2019-04-12 Eli Zaretskii * utils.c (prompt_for_continue): Don't restore the styling at the diff --git a/gdb/inferior.h b/gdb/inferior.h index 2d1bb97a283..4d84afac6af 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -68,7 +68,19 @@ struct infcall_suspend_state_deleter { void operator() (struct infcall_suspend_state *state) const { - restore_infcall_suspend_state (state); + TRY + { + restore_infcall_suspend_state (state); + } + CATCH (e, RETURN_MASK_ALL) + { + /* If we are restoring the inferior state due to an exception, + some error message will be printed. So, only warn the user + when we cannot restore during normal execution. */ + if (!std::uncaught_exception ()) + warning (_("Failed to restore inferior state: %s"), e.message); + } + END_CATCH } };