Skip to content

Commit 1c96b46

Browse files
committed
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!
1 parent f601ffb commit 1c96b46

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

gdb/nat/linux-ptrace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sys/procfs.h>
2424
#endif
2525
#include "gdbsupport/eintr.h"
26+
#include "gdbsupport/signals-state-save-restore.h"
2627

2728
/* Stores the ptrace options supported by the running kernel.
2829
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)
148149
return;
149150

150151
case 0:
152+
/* Set signal handlers to their default because it doesn't make sense
153+
to call GDB-specific handlers any more in the child process. */
154+
restore_original_signals_state ();
151155
l = ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) NULL,
152156
(PTRACE_TYPE_ARG4) NULL);
153157
if (l != 0)

0 commit comments

Comments
 (0)