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
This commit is contained in:
kamil 2020-10-14 14:02:43 +00:00
parent 69c88affdd
commit 375c406271

View File

@ -503,7 +503,6 @@ startup_inferior (process_stratum_target *proc_target, pid_t pid, int ntraps,
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 *proc_target, pid_t pid, int ntraps,
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;
}