From patchwork Wed Mar 16 18:25:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Don Breazeal X-Patchwork-Id: 11354 Received: (qmail 83071 invoked by alias); 16 Mar 2016 18:26:05 -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 83054 invoked by uid 89); 16 Mar 2016 18:26:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=ten X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 16 Mar 2016 18:25:53 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1agG8l-00022h-0Y from Don_Breazeal@mentor.com ; Wed, 16 Mar 2016 11:25:51 -0700 Received: from build4-lucid-cs (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Wed, 16 Mar 2016 11:25:51 -0700 Received: by build4-lucid-cs (Postfix, from userid 1905) id 84B7D412BA; Wed, 16 Mar 2016 11:25:50 -0700 (PDT) From: Don Breazeal To: , Subject: Re: [PATCH v2 2/3] PR remote/19496, interrupted syscall in forking-threads-plus-bkpt Date: Wed, 16 Mar 2016 11:25:50 -0700 Message-ID: <1458152750-25119-1-git-send-email-donb@codesourcery.com> In-Reply-To: <56E80648.4000703@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes On 3/15/2016 5:55 AM, Pedro Alves wrote: > Hi Don, > > On 02/11/2016 12:28 AM, Don Breazeal wrote: > ---snip--- > > Use with_timeout_factor instead so that the timeout is properly restored, > and put it around the problematic test, only, instead of basically > around the whole test case. I think that'll be the "inferior 1 exited" > test? Thanks Pedro. This is done in the patch below. OK to push? --Don This patch addresses "fork:Interrupted system call" (or wait:) failures in gdb.threads/forking-threads-plus-breakpoint.exp. The test program spawns ten threads, each of which do ten fork/waitpid sequences. The cause of the problem was that when one of the fork children exited before the corresponding fork parent could initiate its waitpid for that child, a SIGCHLD and/or SIGSTOP was delivered and interrupted a fork or waitpid in another thread. The fix was to wrap the system calls in a loop to retry the call if it was interrupted, like: do { pid = fork (); } while (pid == -1 && errno == EINTR); Since this is a Linux-only test I figure it is OK to use errno and EINTR. I tried a number of alternative fixes using SIG_IGN, SA_RESTART, pthread_sigblock, and bsd_signal, but none of these worked as well. Tested on Nios II Linux target with x86 Linux host. gdb/testsuite/ChangeLog: 2016-03-16 Don Breazeal * gdb.threads/forking-threads-plus-breakpoint.c (thread_forks): Retry fork and waitpid on interrupted system call errors. * gdb.threads/forking-threads-plus-breakpoint.exp: (do_test): Use with_timeout_factor to increase timeout to 90. --- .../gdb.threads/forking-threads-plus-breakpoint.c | 14 +++++++++- .../forking-threads-plus-breakpoint.exp | 27 +++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.c b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.c index fc64d93..c169e18 100644 --- a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.c +++ b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.c @@ -22,6 +22,7 @@ #include #include #include +#include /* Number of threads. Each thread continuously spawns a fork and wait for it. If we have another thread continuously start a step over, @@ -49,14 +50,23 @@ thread_forks (void *arg) { pid_t pid; - pid = fork (); + do + { + pid = fork (); + } + while (pid == -1 && errno == EINTR); if (pid > 0) { int status; /* Parent. */ - pid = waitpid (pid, &status, 0); + do + { + pid = waitpid (pid, &status, 0); + } + while (pid == -1 && errno == EINTR); + if (pid == -1) { perror ("wait"); diff --git a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp index 3d8b308..9c700bf 100644 --- a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp +++ b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp @@ -72,6 +72,7 @@ proc do_test { cond_bp_target detach_on_fork displaced } { global decimal gdb_prompt global linenum global is_remote_target + global timeout set saved_gdbflags $GDBFLAGS set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""] @@ -115,18 +116,20 @@ proc do_test { cond_bp_target detach_on_fork displaced } { set fork_count 0 set ok 0 - set test "inferior 1 exited" - gdb_test_multiple "" $test { - -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { - set ok 1 - pass $test - } - -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" { - incr fork_count - if {$fork_count <= 100} { - exp_continue - } else { - fail "$test (too many forks)" + with_timeout_factor 90 { + set test "inferior 1 exited" + gdb_test_multiple "" $test { + -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { + set ok 1 + pass $test + } + -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" { + incr fork_count + if {$fork_count <= 100} { + exp_continue + } else { + fail "$test (too many forks)" + } } } }