From patchwork Tue Jun 12 15:51:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 27754 Received: (qmail 111698 invoked by alias); 12 Jun 2018 15:51:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 111683 invoked by uid 89); 12 Jun 2018 15:51:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=Frame, 30m, moving, Continuing X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Jun 2018 15:51:37 +0000 Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 74DC0AF88; Tue, 12 Jun 2018 15:51:35 +0000 (UTC) Date: Tue, 12 Jun 2018 17:51:34 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [gdb/testsuite] Fix hang in fork-running-state.c Message-ID: <20180612155134.7fninj4us5lq4hfc@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes 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 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