From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 7NZtOhGcD2iubgoAWB0awg (envelope-from ) for ; Mon, 28 Apr 2025 11:17:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1745853457; bh=17PoF4UhQQniZq7PbmBd/yQqTE9T0lWVctmRVGObmFY=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=l7RpWzrUBufa5X/pOJzoM6XKdU4PPMUP/0je8olx3cc8IXYwouHDGCdIsZC1zQ94D MQST+RQpJpfSza5F3CIXsO1KjzFe3fo+L+V5krAC38cZl7dW3/3DVIg5yKTExYHwic IatQXskZaCA0ukhqkkGN8RQVISv8tWE7noCjtPLQ= Received: by simark.ca (Postfix, from userid 112) id DF6341E10E; Mon, 28 Apr 2025 11:17:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=N5f/zsML; dkim=pass (1024-bit key) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=gjMFeETw; dkim-atps=neutral Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 72F8F1E0C0 for ; Mon, 28 Apr 2025 11:17:37 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13B383857B94 for ; Mon, 28 Apr 2025 15:17:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13B383857B94 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=N5f/zsML; dkim=pass (1024-bit key) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=gjMFeETw Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id CA5CC3858C60 for ; Mon, 28 Apr 2025 15:17:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA5CC3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CA5CC3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745853424; cv=none; b=XsCzw92Evoqp+2BTWjmjNbQMUOzhxDujcUybhX6FGG6HLjFQW4AGMbDkRb9GQPFSA33k0XEv8JXztDK6xUZZKvcOPSccas8FK+xz2vLLX49tQsbjT5aIGdZSJ/mRzkQQu0hnvuRyF2iUdXDn+RRTA89CKd7t2JbVsWcDtj2rgkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745853424; c=relaxed/simple; bh=17PoF4UhQQniZq7PbmBd/yQqTE9T0lWVctmRVGObmFY=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=SeaCx74PWxyYzd27B1wM7wbNIi/oRohYKZ4evjcxshPmSkrexCPeD1JOhnQveFjbbRF5c92oyz30qcaYHxhSUUQMz6BcD4aKGTkfZkvYS1euu9wo2VrRyLHkH7NOcw9XC/R/E6U7fstvSjqn3CDuGVJEeia0janehPPOh64EsTI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA5CC3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1745853424; bh=17PoF4UhQQniZq7PbmBd/yQqTE9T0lWVctmRVGObmFY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=N5f/zsMLiu13UQzpF4zmCjSx8VEmf+uR3IB7UkQBWOiIdnJPYo+SNNAljXmhPheY8 9KjnBLcWDBoNIaUUjxfa51sPT20CsANi13jtVnqiirnGaytzOefT2bn6GiAZmtIMKX zd3l33/bEqIk0Xg6glG7cBOcbuzORMNCNU3oAZ1s= Received: by simark.ca (Postfix, from userid 112) id 7EAEF1E10E; Mon, 28 Apr 2025 11:17:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1745853423; bh=17PoF4UhQQniZq7PbmBd/yQqTE9T0lWVctmRVGObmFY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=gjMFeETwUNJAofps6t/PYVP9+OqVbzEB+7oxtBhmov/FMgdvaq4SCXUtclPbDJ+Eb wY97v8c3mUPAht8xGEUvsa0/SsG5uc0mcyhs54UKbn2EDbE1wOKFxhA/0idpZS5Wog hol677gRe84miHu0fojRfCvuUCcm10IwEFCxIJPM= Received: from [172.16.0.192] (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2D4211E0C0; Mon, 28 Apr 2025 11:17:03 -0400 (EDT) Message-ID: <4d29d800-175e-453f-9743-4413431d3c56@simark.ca> Date: Mon, 28 Apr 2025 11:17:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] [gdb] Fix sig_write for null gdb_stderr To: Tom de Vries , gdb-patches@sourceware.org References: <20250425171845.9934-1-tdevries@suse.de> <20250425171845.9934-2-tdevries@suse.de> Content-Language: fr From: Simon Marchi In-Reply-To: <20250425171845.9934-2-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 4/25/25 1:18 PM, Tom de Vries wrote: > When running test-case gdb.tui/tui-layout-asm.exp with target board > dwarf5-fission-debug-types, the test-case fails and I get a core dump: > ... > # of unexpected core files 1 > ... > > Looking at the backtrace of the core file, what seems to be happening is that: > - gdbpy_flush attempts to flush gdb_stdout, which is nullptr > - that causes a segfault > - gdb intercepts this and starts to handle it using handle_fatal_signal > - handle_fatal_signal calls sig_write, which attempts to write to gdb_stderr, > which is nullptr, > - that causes another segfault > - gdb exits > > I managed to reproduce the problem by the following trigger patch in > stdin_event_handler: > ... > - if (error) > + if (1 || error) > { > current_ui = main_ui; > ui->unregister_file_handler (); > - if (main_ui == ui) > + if (1 || main_ui == ui) > { > gdb_printf (gdb_stderr, _("error detected on stdin\n")); > + gdb_stderr = nullptr; > + gdb_stdout = nullptr; > + gdb_stdlog = nullptr; > quit_command ((char *) 0, 0); > } > ... > which gives us: > ... > $ gdb > (gdb) error detected on stdin > Segmentation fault (core dumped) > $ q > ... > > Fix sig_write to handle the case that gdb_stderr == nullptr, such that we get > instead: > ... > $ gdb > (gdb) error detected on stdin > > Fatal signal: Segmentation fault > ----- Backtrace ----- > ... > --------------------- > 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: > . > > Segmentation fault (core dumped) > $ q > ... > > Tested on x86_64-linux. > --- > gdb/bt-utils.c | 30 +++++++++++++++++++++--------- > gdb/event-top.c | 13 +++++++++++-- > 2 files changed, 32 insertions(+), 11 deletions(-) > > diff --git a/gdb/bt-utils.c b/gdb/bt-utils.c > index 8e782450ae9..9e9f680f9ea 100644 > --- a/gdb/bt-utils.c > +++ b/gdb/bt-utils.c > @@ -55,7 +55,10 @@ libbacktrace_error (void *data, const char *errmsg, int errnum) > > const auto sig_write = [] (const char *msg) -> void > { > - gdb_stderr->write_async_safe (msg, strlen (msg)); > + if (gdb_stderr == nullptr || gdb_stderr->fd () == -1) > + std::ignore = ::write (2, msg, strlen (msg)); TIL about std::ignore. Is it possible to factor out the lambdas: const auto sig_write = [] (const char *msg) -> void { if (gdb_stderr == nullptr || gdb_stderr->fd () == -1) std::ignore = ::write (2, msg, strlen (msg)); else gdb_stderr->write_async_safe (msg, strlen (msg)); }; to a function? At first glance they all seem to be the same. Otherwise, LGTM. Approved-By: Simon Marchi Simon