From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tltnLNO7hl8iJAAAWB0awg (envelope-from ) for ; Wed, 14 Oct 2020 04:50:27 -0400 Received: by simark.ca (Postfix, from userid 112) id A0B341EF6F; Wed, 14 Oct 2020 04:50:27 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,FREEMAIL_FROM, MAILING_LIST_MULTI,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 408D51E58C for ; Wed, 14 Oct 2020 04:50:26 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8DD73854822; Wed, 14 Oct 2020 08:50:25 +0000 (GMT) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id BF8913854811 for ; Wed, 14 Oct 2020 08:50:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BF8913854811 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gmx.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=n54@gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1602665420; bh=V568agKQkPyhzAJqq15DYZHT/Ozc/WcZ5coP9DFWkwM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=bPP4P4pad0XKOoZdkgRr0gVj8ZD8p8r9lKvy8pCbKwsIjp7ppImxzF4TY46SNfFAh pArbB9tOlklIDs91rAyH2O0lfqeKch9GMCfxCo3Z45Ke23W3WR8pMVJpMKRXbQFzJB lQEsxdz03Bi32KpQNyuoEG4aS+Dk28lOOpIXDqKU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([89.79.191.25]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MzhnH-1kFbkT2qfZ-00vh1d; Wed, 14 Oct 2020 10:50:20 +0200 From: Kamil Rytarowski To: gdb-patches@sourceware.org Subject: [PATCH] Limit the switch_to_thread() calls in startup_inferior() Date: Wed, 14 Oct 2020 10:49:40 +0200 Message-Id: <20201014084940.1289-1-n54@gmx.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Ap3W0W0UtgJmxJzJLmjcfe4BnPCsgD0uFSdALyh/yJe9qTBySR9 BhFp2cnj9EEdszp1sM61C1UgBtv3nEajo9bA1ouHD9mRUrUb6O8CgLfs+1rGpHdEs67UrnI yupA4q62uqzm/ssbCL0ZmH3nP/GYlcVjyE8SvJV/K+QHpMcPIUWOE5NtzSQejTTP8pVA7QU gAc+NmGbVz8GGu2zuoi1g== X-UI-Out-Filterresults: notjunk:1;V03:K0:d/+kmk6rMd0=:jU0p7ez07+MBnSgX5PXSgG aCTPFD8fwIgOEGi3slKOMTZRijCT2WcANrc+FOtKfot9Gt+z05Yt4pVAfrPz+5v+wEagfnk0W LhN2MwZhu1Lkh3nlw+9WrFu0Nc5luqrnTxl0qESSnlZYogfaiPwIYwmkUwKtssRiF91/iND/q mw8fwpeYflAx5kcoIxann7pS6mU8Jt9UO1GQdDRx4LJ1sjgot506eQlZ6D/UQIId+TO6TniXC Rb+HHdY2vfHhD4eDKbWMFrX2WmEtplchL7s+nNv/aIod9gE1E2Qa/oMAIr37ZO01uxXxSYgL2 kZ30JS8EYVvsZxVGTmlH0WTNeGrnW1GCrXRz1PY8UsLiREURhpnMlIXauiSMY4b94Ej4eIJeq oS4XA74Yh2BpphLfpnpbYIarac2tVKKzhfJk5Sb5KSaM1xgldJnC6DKI3HXPizC9+7QLUSc+/ WZ/peV1l+FED0R25+jJELjmwxZNyVeCOKBbX0Pz1rysD+aUuTvFMyM11TD1gqr5Zp1DVxYmyy QlyUfUrhF6ht3XqxllRXBccCEieP6eUoKn8wa+tf5o2G5a97mQAnMmjKfnYtRMBcoa33l+L3h V21FnzW51E0TokcJHBxdcEQaodqBTHDDsxc4fWL6e2IGn+s2dPpTUYsIxLzcyrh+XfsXQTduh e41PCMFTuYd3LNeCgVWs8T3cQ0U9xXDKVfMCHEe/IoIQ7Pli1FAwH/aeelFHZ1XCz/9qB7YRD kJYDgpJskf72SjI1IOozx5XlVBZe6j9tOAxoydSqjuKdBcgskxklmbPu2llVEhECShh1KDirp 2s8GFRIxHoWNWFeGFaBe8YrnCa1tKPqWzVSwOZZ2efAvLAMwlYVQLZ+j7DGvLJgMIwWNb8/H8 Q4K5/dVj0m6MXahu2MRyBwwtPpVakhh6bCkqhkQ/I0xOLBRK7A+N96DbONciU8mKV86rvS8/C 2t+v3al+as0ZHLBxyYrLSip/fuLzYd8yBV13zsv0YGzMGh83AekxapFOt149BCtODR9PhQCog IqGqFzK6YTjyxrqd2A6kYtyqlOfTAP2DJ76SuyznNfkbDM860csaIxFHllzTUVmUoZ7MOC0ii 87RsVQs8PUhWN+plgOC6OPReC96go9/Kq9zulo+Jcf4aklQJ3wNvArcgj7VVpcop+JrG3EMyH +1Du//OWGtqoTdtiT77jRgPNwINZwus6+nAKU4orsUTkN4tlWrl3u1Z43eHFBbMR5HAGst+oo RwSTof3zwhd+sMq+I/e8zYM2OJsv5cedyxeU3KScG5GLc8IC/NQOBQP52DGU= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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=3D0 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=3Dtcsh /usr/bin/gdb echo (gdb) r Starting program: /bin/echo /usr/src/external/gpl3/gdb/lib/libgdb/../../dist/gdb/thread.c:1309: intern= al-error: void switch_to_thread(thread_info*): Assertion `thr !=3D NULL' f= ailed. A problem internal to GDB has been detected, further debugging may prove unreliable. And the core-dump is as follows: (top-gdb) bt During symbol reading: incomplete CFI data; unspecified registers (e.g., r= ax) at 0x7f7ff5b698a4 file=3D0x135314f "../../gdb/thread.c", line=3D1309, fmt=3D0x1353069 "%= s: Assertion `%s' failed.", ap=3D0x7f7fffffdc08) at ../../gdb/utils.c:414 at ../../gdb/inf-ptrace.c:117 args=3D0x0, from_tty=3D1, run_how=3DRUN_NORMAL) at ../../gdb/infcmd.c:493 =2D-Type for more, q to quit, c to continue without paging-- =2D-- gdb/nat/fork-inferior.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index 7ba0126871d..b6c20a8fac1 100644 =2D-- a/gdb/nat/fork-inferior.c +++ b/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 =3D ws.value.sig; - switch_to_thread (proc_target, event_ptid); + /* Ignore gracefully the !TRAP signals intercepted from the shell. = */ + if (resume_signal =3D=3D GDB_SIGNAL_TRAP) + switch_to_thread (proc_target, event_ptid); break; } =2D- 2.28.0