Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Josip Seketa <josip.seketa@gmail.com>
To: gdb-patches@sourceware.org
Cc: Tom de Vries <tdevries@suse.de>
Subject: [PATCH] gdb: make the timeout of wait_to_die_with_timeout work again
Date: Fri, 06 Nov 2026 18:48:12 +0000	[thread overview]
Message-ID: <179399089244.2913892.12199627156587618491@gmail.com> (raw)

wait_to_die_with_timeout sets an alarm and relies on SIGALRM to
interrupt waitpid.
Commit a9791f1438a ("[gdb] Use gdb::waitpid more often") changed that
call to gdb::waitpid, which retries on EINTR, so the wait no longer
ends.

Its only callers are in pipe_close, which gives the command 5 seconds
to exit before sending SIGTERM.
So a "target remote | command" whose command does not exit when GDB
closes the connection now hangs GDB, at detach or after a Ctrl-C.

Use plain waitpid again for the call with a timeout.
---
Reproduce, with a command that is still alive after gdbserver exits:

  $ gdb -batch -ex "target remote | sh -c 'gdbserver - ./prog; sleep 30'" -ex detach

master takes 30.7 s, waiting for the sleep.
With this patch: 11.2 s, because the 5 s limit ends the wait.

Bisected by building a9791f1438a and its parent 658a03e9e, with a
stub that does not exit when GDB closes the connection, 3 runs each:
the parent ends after 5.0 s, a9791f1438a was still hanging when I
killed it at 25 s.
Master with this patch: 5.1 s.

Any signal can end this wait early, as it could before a9791f1438a.
At worst the command gets SIGTERM sooner.

gdb.threads/pending-fork-event-detach-ns.exp on native-stdio-gdbserver
shows it too: it hangs after "Ending remote debugging." on master, in
5 of 5 runs, and passes with this patch, 5 of 5, alternated.

Tested on x86-64 GNU/Linux, with my other pipe patches: gdb.base,
gdb.server, gdb.threads, gdb.mi, gdb.multi and gdb.python on
native-stdio-gdbserver, native-gdbserver and
native-extended-gdbserver, compared with master test by test.

I have no FSF copyright assignment.

 gdb/utils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index 4d03ccd5c..e53e7cc2b 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3338,7 +3338,9 @@ wait_to_die_with_timeout (pid_t pid, int *status, int timeout)
       alarm (timeout);
 #endif
 
-      waitpid_result = gdb::waitpid (pid, status, 0);
+      /* Not gdb::waitpid: it retries on EINTR, and SIGALRM interrupting
+	 this call is what ends the wait.  */
+      waitpid_result = ::waitpid (pid, status, 0);
 
 #ifdef SIGALRM
       alarm (0);
-- 
2.56.0


                 reply	other threads:[~2026-11-06 18:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179399089244.2913892.12199627156587618491@gmail.com \
    --to=josip.seketa@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox