Call restore_original_signal_state after GDB forks. When I run GDB under Valgrind, GDB seems to segfault displaying: Fatal signal: Segmentation fault ----- Backtrace ----- 0x2803f7 ??? 0x3c9696 ??? 0x3c9899 ??? 0x55f8fcf ??? 0x486c000 ??? --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. warning: linux_ptrace_test_ret_to_nx: PC 0x5821c09d is neither near return address 0x486c000 nor is the return instruction 0x4f8f4a! but then, acts like nothing happened and excutes normally. This is because it's the child from linux_ptrace_test_ret_to_nx that segfaults and parent GDB carries on normally. Restore the original signal states to not to print confusing backtrace. After restoring, only such warning is displayed: warning: linux_ptrace_test_ret_to_nx: WSTOPSIG 19 is neither SIGTRAP nor SIGSEGV!
diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c index 0510b39..f73058b 100644 --- a/gdb/nat/linux-ptrace.c +++ b/gdb/nat/linux-ptrace.c
@@ -23,6 +23,7 @@ #include <sys/procfs.h> #endif #include "gdbsupport/eintr.h" +#include "gdbsupport/signals-state-save-restore.h" /* Stores the ptrace options supported by the running kernel. A value of -1 means we did not check for features yet. A value @@ -148,6 +149,9 @@ linux_ptrace_test_ret_to_nx (void) return; case 0: + /* Set signal handlers to their default because it doesn't make sense + to call GDB-specific handlers any more in the child process. */ + restore_original_signals_state (); l = ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) NULL, (PTRACE_TYPE_ARG4) NULL); if (l != 0)