Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: make the timeout of wait_to_die_with_timeout work again
@ 2026-11-06 18:48 Josip Seketa
  0 siblings, 0 replies; only message in thread
From: Josip Seketa @ 2026-11-06 18:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom de Vries

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-06 18:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 18:48 [PATCH] gdb: make the timeout of wait_to_die_with_timeout work again Josip Seketa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox