From 375c4062710e14d02610de809f386c69f59b3d9e Mon Sep 17 00:00:00 2001 From: kamil Date: Wed, 14 Oct 2020 14:02:43 +0000 Subject: [PATCH] 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 --- external/gpl3/gdb/dist/gdb/nat/fork-inferior.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c b/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c index 7ba0126871dd..b6c20a8fac10 100644 --- a/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c +++ b/external/gpl3/gdb/dist/gdb/nat/fork-inferior.c @@ -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; }