public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [gdb/testsuite] Fix hang in fork-running-state.c
@ 2018-06-12 15:51 Tom de Vries
  2018-06-13 12:10 ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2018-06-12 15:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

Hi,

When I run make check:
...
$ cd build/gdb
$ make check 2>&1 | tee ../CHECKLOG.gdb
...
I see after ~30m the summary of the test run printed, but make still hangs.

This seems to be due to some sleeping processes:
...
$ ps  fx | grep fork-run
 6475 ?        S      0:00 gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 6451 ?        S      0:00 gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 6427 ?        S      0:00 gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
...

Killing the sleeping processes like this:
...
kill -9 $(ps -A  | grep fork-running-st | awk '{print $1}')
...
allows make to finish.

If I isolate one debug session from fork-running-state.exp that causes one of
these sleeping processes, we get:
...
(gdb) set non-stop on
(gdb) break main
Breakpoint 1 at 0x400665: file src/gdb/testsuite/gdb.base/fork-running-state.c, line 52.
(gdb) run 
Starting program: build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state 

Breakpoint 1, main () at src/gdb/testsuite/gdb.base/fork-running-state.c:52
52        save_parent = getpid ();
(gdb) set detach-on-fork on
(gdb) set follow-fork parent
(gdb) continue &
Continuing.
[Detaching after fork from child process 18797]
(gdb) info threads
  Id   Target Id         Frame 
* 1    process 18793 "fork-running-st" (running)
(gdb) set print inferior-events off
(gdb) kill inferior 1
...
So, AFAIU, the hanging process is the child process that gdb detaches from.

There's an alarm set in main before the fork, but alarms are not preserved in
the fork child:
...
$ man alarm
   ...
NOTES
       Alarms created by alarm() are preserved across execve(2) and are not inherited by children created via fork(2).
...
So, AFAIU, once the parent is killed, there's no alarm to terminate the child.

The patch fixes this by moving the setting of the alarm into the
fork_main/fork_child functions, making sure that an alarm will trigger for
the child.

Tested with make check on x86_64.

OK for trunk?

Thanks,
- Tom

[gdb/testsuite] Fix hang in fork-running-state.c

2018-06-12  Tom de Vries  <tdevries@suse.de>

	PR testsuite/23269
	* gdb.base/fork-running-state.c (main): Move setting of alarm ...
	(fork_child): ... here, and ...
	(fork_parent): ... here.

---
 gdb/testsuite/gdb.base/fork-running-state.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.base/fork-running-state.c b/gdb/testsuite/gdb.base/fork-running-state.c
index 8ea4739609..65ca942ea0 100644
--- a/gdb/testsuite/gdb.base/fork-running-state.c
+++ b/gdb/testsuite/gdb.base/fork-running-state.c
@@ -27,6 +27,9 @@ int save_parent;
 static int
 fork_child (void)
 {
+  /* Don't run forever.  */
+  alarm (180);
+
   while (1)
     pause ();
 
@@ -38,6 +41,9 @@ fork_child (void)
 static int
 fork_parent (void)
 {
+  /* Don't run forever.  */
+  alarm (180);
+
   while (1)
     pause ();
 
@@ -51,9 +57,6 @@ main (void)
 
   save_parent = getpid ();
 
-  /* Don't run forever.  */
-  alarm (180);
-
   /* The parent and child should basically run forever without
      tripping on any debug event.  We want to check that GDB updates
      the parent and child running states correctly right after the

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-14 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 15:51 [gdb/testsuite] Fix hang in fork-running-state.c Tom de Vries
2018-06-13 12:10 ` Pedro Alves
2018-06-14 12:59   ` [PATCH] Avoid gdb.base/fork-running-state.exp lingering processes (Re: [gdb/testsuite] Fix hang in fork-running-state.c) Pedro Alves
2018-06-14 16:07     ` Tom de Vries
2018-06-14 16:44       ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).