From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id JwggGa2l62qCtRsAWB0awg (envelope-from ) for ; Wed, 04 Nov 2026 16:37:49 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Qduo+aPR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 50E511E043; Wed, 04 Nov 2026 16:37:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FORGED_GMAIL_RCVD,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 510ED1E043 for ; Wed, 04 Nov 2026 16:37:48 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00B1E4BA2E38 for ; Wed, 4 Nov 2026 21:37:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00B1E4BA2E38 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Qduo+aPR Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 088724BA2E16 for ; Wed, 4 Nov 2026 21:37:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 088724BA2E16 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 088724BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793828242; cv=none; b=cLz/rd/owOtqRev8fl5fbvjPKQR9/nBE2QgYnpGOY1S824I0xvGVztJc8yZJ65SsKQ361tjUyY+IBJJT6OIAI585x5w7BrxFLGYhOU6FuEBFpXNhy8qBBfsxUGgF6mSYXsR5kfAW8Ok+tKsIZqC7cUzL1jLAPF6ejRj+z/OZaxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793828242; c=relaxed/simple; bh=i/GYu1CqOUDfzdpRujWbwQ+SZi5MfSOU8SBqkTVURDc=; h=DKIM-Signature:To:Date:Message-ID:MIME-Version:From:Subject; b=juAF0Ap6AwX+WDzUX9OY+qWtde8OmWg6kSqsRY9LFGp0ubQoUvnbD3eDYkk+WzjAymDs9KuLsUp1VsszRW3gX15hdnkIYgNXnqRb1pvy25ek2JthkCovrbUu3am54Kyyr7vWBqRfEDc45UkThf04vuuJOTDEVXED+D+xY92hsco= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Qduo+aPR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 088724BA2E16 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-48afbd2c386so826760f8f.3 for ; Wed, 04 Nov 2026 13:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793828241; x=1794433041; darn=sourceware.org; h=subject:from:content-transfer-encoding:content-type:mime-version :message-id:date:cc:to:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VtgAIAI1fV2II7KLDFUIgReootNdZYG9ivyIqZl3SnI=; b=Qduo+aPRBs0Evyz8JZRdiGB4ESGpyCAOj+EltygYmA9IjhgMbao+xuPll6y04H2Dcq ZT1q5YcZDZh++h2irQha7MnhTTj3ODSK0NvEKarN0RGeFEoK8zS+2zturdZR7XKK8uyV /06OCTiFMjHPFgJdUGF+3k0xosrRBNRto6M00l1/EJS3E5t4V/bY249Hij5Js/DhySK0 QcaGA2VuXPLYEbut9psQqdXWcI3/7hMDCHQcyIAg2zqWOExFLYaQ5msS8PuBv2SNzBPe xHiJaat5FU6WvG4Jy54Cs8Gz1LoCyHhz1ZAG2lrpHTn0uYRUH4u1j0KReLx4U1itJdhO BfOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793828241; x=1794433041; h=subject:from:content-transfer-encoding:content-type:mime-version :message-id:date:cc:to:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=VtgAIAI1fV2II7KLDFUIgReootNdZYG9ivyIqZl3SnI=; b=T1yqCyjxnMNLj2/04qEzEF3/UaYtCeTZK5lhXN6dm8oqXhC8ZI5xI8qyU28prRMxxi cTOJ8uw8zrrnQcSdYl/SN7tj4jdQtY/xpsNjbYk10Cu8r3aMUIo2z2LABZPqLj5Zeo4y hqy4IapaAlrqtI3ZIlIQfQf3fgKuAUhkhce988JyWIKTcILdhRopGbuOPHE+nH4P7B87 Rq7YbIEXkdFlZD8n/FSl+ePtj+i4bDp+SAJrCoEyKX/LmvcB4vu+LSJvYxZNuxTfCJyR ZHf8S9l2YyXJ0WbVsXE3VAqGCX0DaTgO3sQ53YZo7UpoZwpumKThC0NOsEDve9HSuRke 7TTw== X-Gm-Message-State: APuU4Z9zwRcPr3QuZSpjXbdhHwI/gwt+AAE58FaC/+8vIQT1Ha4vqaIP h6R/wqgvUGb8gv/aC6/ecVBA24IlxFP0XvciTk1NdXQwUQCTyDC4zaZEBya/9w== X-Gm-Gg: AYBFou0iD7Rs7uadwWhIlMkjmyKCF6Suh4mTTghjnTg8mwAIPkfD71NTpLH+WUs/07X WUbevpzb8wqT60U2Ug7EHp4ZkpbkIl7+qo6nCipa24vnDOdEvPBHzrbHHYwD0TFMAX/KIfZU+nk 0n4GO1210yYGjoVagcaMujWefYerfAabPo+o3kcF+LnONcE6qviEY/ckmN5lcFWvPpUiIr2pFH3 OvE2SrrqFrxSveTkqgaEKI/dpwh9UITj43KqGX15h/EwzhVIplotCy7738yi8CIUYlY61VFwREv 9T+dtcdFCu9B7pEQ5kH/sTrrAOosyAzvshhmhgMLxOExS7OykO7PAW5xAH34Y3EtddeNq9b2h1E yhaCIb6qm8p0GCy1xCxtcWBX+0ZyxAm5hjRBviw/PpFao/O7G0jTmcZfLmC1FU4/CXyt2MaUBFe Otd9o+x1M5GwVZI3ROsKdDtKwMQ5PhubQsNUigv/QBTqvwTfU61d/qLZV5LonnawHYIButJR8Ej 3xAmUosA4d6uGXrj0ykNYw83GjlvqSXghCiHS3OHXRPayJsCQ1Xu6cQaSW2WECqwSrifg+Q2UFI XhwRKAm2hLOkf7nyskELIqHoq5VOyZ7yweWKSg6aMk3v1l44FVKY X-Received: by 2002:a5d:5d09:0:b0:48e:4835:de5f with SMTP id ffacd0b85a97d-48e6e4fcf2amr36627365f8f.47.1793828240707; Wed, 04 Nov 2026 13:37:20 -0800 (PST) Received: from [127.0.1.1] ([45.150.175.51]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48fed92a753sm6753899f8f.45.2026.11.04.13.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2026 13:37:20 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Date: Wed, 04 Nov 2026 21:36:59 +0000 Message-ID: <179382821911.358872.8271312658591136533@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Josip Seketa Subject: [PATCH] gdb: print a pipe command's stderr when the connection is reset 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 With "target remote | command", if the command writes an error to stderr and exits without reading what GDB sent it, GDB's next read fails with ECONNRESET: the command's end of the socketpair was closed with unread data. GDB then prints only: Remote communication error. Target disconnected: error while reading: Connection reset by peer. and the command's own error message is lost. This is a regression from commit 0da23004a ("Change serial_readchar to throw"). Since then ser_unix_read_prim throws on a read error, so generic_readchar no longer reaches its ser_base_read_error_fd call. pipe_close then closes the error fd without reading it. Before that commit, the message was printed before the error. Fix it in pipe_close: once the command has exited, print what is left on its stderr before closing the error fd. This covers every way the connection ends, and prints nothing twice, since ser_base_read_error_fd only shows what has not been read yet. gdb.server/server-empty-exec-name.exp was written after the regression and expects nothing between "Remote debugging using" and the error. gdbserver's own message ("No program to debug", "Exiting") is now shown there, so the test expects it. --- Reproduce (GDB 18.1 and master 10ae2343): $ gdb -batch -ex "target remote | sh -c 'echo refused >&2; exit 1'" Remote communication error. Target disconnected: error while reading: Connection reset by peer. Built at 0da23004a's parent, d69939bde, the same prints "refused" first. At 0da23004a and on master it does not. With this patch it does again. If the command reads its stdin before exiting, the read gets end of file instead, and the message was and is printed. Tested on x86-64 GNU/Linux: make check TESTS="gdb.server/*.exp" with --target_board=native-stdio-gdbserver and native-gdbserver, master and patched. No new failures; the one FAIL of both (gdb.server/non-existing-program.exp: gdbserver exits cleanly) is unchanged. server-empty-exec-name.exp passes 16 of 16 with the patch; with the updated test, unpatched GDB fails its 4 "start gdbserver over stdin" tests. Also checked by hand: 200 lines of stderr are all printed, and a grandchild that keeps stderr open does not delay the close (the error fd is non-blocking). I have no FSF copyright assignment. gdb/ser-base.c | 4 ++-- gdb/ser-base.h | 5 +++++ gdb/ser-pipe.c | 7 +++++++ gdb/testsuite/gdb.server/server-empty-exec-name.exp | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gdb/ser-base.c b/gdb/ser-base.c index e9c86889..9464165d 100644 --- a/gdb/ser-base.c +++ b/gdb/ser-base.c @@ -256,9 +256,9 @@ ser_base_wait_for (struct serial *scb, int timeout) } } -/* Read any error output we might have. */ +/* See ser-base.h. */ -static void +void ser_base_read_error_fd (struct serial *scb, int close_fd) { if (scb->error_fd != -1) diff --git a/gdb/ser-base.h b/gdb/ser-base.h index 667df4e3..87ea9f52 100644 --- a/gdb/ser-base.h +++ b/gdb/ser-base.h @@ -25,6 +25,11 @@ struct serial; struct ui_file; +/* Read any error output we might have on SCB's error fd, and print + it. If CLOSE_FD, close the error fd at end of file. */ + +extern void ser_base_read_error_fd (struct serial *scb, int close_fd); + extern int generic_readchar (struct serial *scb, int timeout, int (*do_readchar) (struct serial *scb, int timeout)); diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c index 3b755a84..ff2c2ae1 100644 --- a/gdb/ser-pipe.c +++ b/gdb/ser-pipe.c @@ -185,6 +185,13 @@ pipe_close (struct serial *scb) #endif } + /* The command has exited: print what it wrote to stderr and GDB + has not shown yet. A read error on SCB->fd, e.g. ECONNRESET + when the command exits without reading what GDB sent, throws + before generic_readchar gets to read the error fd, so this + output would otherwise be lost. */ + ser_base_read_error_fd (scb, 1); + if (scb->error_fd != -1) close (scb->error_fd); scb->error_fd = -1; diff --git a/gdb/testsuite/gdb.server/server-empty-exec-name.exp b/gdb/testsuite/gdb.server/server-empty-exec-name.exp index 85801427..f21adaa5 100644 --- a/gdb/testsuite/gdb.server/server-empty-exec-name.exp +++ b/gdb/testsuite/gdb.server/server-empty-exec-name.exp @@ -83,6 +83,8 @@ foreach_with_prefix proto { extended-remote remote } { gdb_test "target $proto | ${::gdbserver} $server_flag --once - \"\"${args}" \ [multi_line \ "Remote debugging using \\| \[^\r\n\]+" \ + "No program to debug" \ + "Exiting" \ "Remote communication error\\. Target disconnected: .*"] \ "start gdbserver over stdin" -- 2.56.0