Module Name:    src
Committed By:   kamil
Date:           Wed Oct 14 14:02:43 UTC 2020

Modified Files:
        src/external/gpl3/gdb/dist/gdb/nat: fork-inferior.c

Log Message:
Limit the switch_to_thread() calls in startup_inferior()

Do not jump over the threads during the startup unless we encounter
TARGET_WAITKIND_STOPPED with SIGTRAP or TARGET_WAITKIND_EXECD.

Otherwise whenever a startup-with-shell processes signals on the
startup stage, it might indicate to switch to a non-existing
thread or a special-thread number (target lwp=0 on NetBSD means
that a signal was directed to all threads within a process).

This caused a crash with tcsh on NetBSD, where the tcsh shell
runs startup detection of the hostname. This action involves
spwaning a new process through fork.

GDB crashes this way:
$ SHELL=tcsh /usr/bin/gdb echo
(gdb) r
Starting program: /bin/echo
/usr/src/external/gpl3/gdb/lib/libgdb/../../dist/gdb/thread.c:1309:
internal-error: void switch_to_thread(thread_info*):
Assertion `thr != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

This patch has been submitted upstream for review:

https://sourceware.org/pipermail/gdb-patches/2020-October/172558.html


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.2 -r1.2 \
    src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c
diff -u src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c:1.1.1.2 src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c:1.2
--- src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c:1.1.1.2	Tue Sep 15 01:43:40 2020
+++ src/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c	Wed Oct 14 14:02:43 2020
@@ -503,7 +503,6 @@ startup_inferior (process_stratum_target
 	  case TARGET_WAITKIND_SYSCALL_ENTRY:
 	  case TARGET_WAITKIND_SYSCALL_RETURN:
 	    /* Ignore gracefully during startup of the inferior.  */
-	    switch_to_thread (proc_target, event_ptid);
 	    break;
 
 	  case TARGET_WAITKIND_SIGNALLED:
@@ -536,7 +535,9 @@ startup_inferior (process_stratum_target
 
 	  case TARGET_WAITKIND_STOPPED:
 	    resume_signal = ws.value.sig;
-	    switch_to_thread (proc_target, event_ptid);
+	    /* Ignore gracefully the !TRAP signals intercepted from the shell.  */
+	    if (resume_signal == GDB_SIGNAL_TRAP)
+	      switch_to_thread (proc_target, event_ptid);
 	    break;
 	}
 

Reply via email to