From patchwork Wed Jul 29 14:23:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 7914 Received: (qmail 2156 invoked by alias); 29 Jul 2015 14:23:06 -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 2140 invoked by uid 89); 29 Jul 2015 14:23:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 29 Jul 2015 14:23:04 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 6984BB6E6D; Wed, 29 Jul 2015 14:23:03 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6TEN0BL013439; Wed, 29 Jul 2015 10:23:01 -0400 Message-ID: <55B8E1C4.9080605@redhat.com> Date: Wed, 29 Jul 2015 15:23:00 +0100 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Don Breazeal , "Breazeal, Don" , Simon Marchi CC: GDB Patches Subject: Re: [PATCH 3/N] remote follow fork and spurious child stops in non-stop mode References: <1437672294-29351-1-git-send-email-palves@redhat.com> <55B1308E.4020700@redhat.com> <55B2875E.1070504@codesourcery.com> <55B8D34F.5060002@redhat.com> <55B8D765.9010003@redhat.com> In-Reply-To: <55B8D765.9010003@redhat.com> On 07/29/2015 02:38 PM, Pedro Alves wrote: > Ignore the "SIGTRAP" mention in "SEL: Found 2 SIGTRAP events", > it's "two events". And the one that was picked was a process > exit. But the tail end of linux_wait_1 isn't expecting that > can happen. > This seems to fix it (and ends up making the code a little more like linux-nat.c). I'm running it through the testsuite. -------- From: Pedro Alves Date: 2015-07-29 14:40:04 +0100 fix --- gdb/gdbserver/linux-low.c | 67 ++++++++++++++++++++++++++------------------- gdb/gdbserver/linux-low.h | 11 +++---- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 9eaa912..99a44f9 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -264,6 +264,7 @@ static int linux_wait_for_event (ptid_t ptid, int *wstat, int options); static struct lwp_info *add_lwp (ptid_t ptid); static int linux_stopped_by_watchpoint (void); static void mark_lwp_dead (struct lwp_info *lwp, int wstat); +static int lwp_is_marked_dead (struct lwp_info *lwp); static void proceed_all_lwps (void); static int finish_step_over (struct lwp_info *lwp); static int kill_lwp (unsigned long lwpid, int signo); @@ -755,9 +756,9 @@ add_lwp (ptid_t ptid) { struct lwp_info *lwp; - lwp = (struct lwp_info *) xmalloc (sizeof (*lwp)); - memset (lwp, 0, sizeof (*lwp)); + lwp = (struct lwp_info *) xcalloc (1, sizeof (*lwp)); + lwp->waitstatus.kind = TARGET_WAITKIND_IGNORE; if (the_low_target.new_thread != NULL) the_low_target.new_thread (lwp); @@ -1397,7 +1398,7 @@ linux_thread_alive (ptid_t ptid) exited but we still haven't been able to report it to GDB, we'll hold on to the last lwp of the dead process. */ if (lwp != NULL) - return !lwp->dead; + return !lwp_is_marked_dead (lwp); else return 0; } @@ -2741,20 +2742,6 @@ ignore_event (struct target_waitstatus *ourstatus) return null_ptid; } -/* Return non-zero if WAITSTATUS reflects an extended linux - event. Otherwise, return zero. */ - -static int -extended_event_reported (const struct target_waitstatus *waitstatus) -{ - if (waitstatus == NULL) - return 0; - - return (waitstatus->kind == TARGET_WAITKIND_FORKED - || waitstatus->kind == TARGET_WAITKIND_VFORKED - || waitstatus->kind == TARGET_WAITKIND_VFORK_DONE); -} - /* Wait for process, returns status. */ static ptid_t @@ -3122,7 +3109,7 @@ linux_wait_1 (ptid_t ptid, || (gdb_breakpoint_here (event_child->stop_pc) && gdb_condition_true_at_breakpoint (event_child->stop_pc) && gdb_no_commands_at_breakpoint (event_child->stop_pc)) - || extended_event_reported (&event_child->waitstatus)); + || event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE); run_breakpoint_commands (event_child->stop_pc); @@ -3144,9 +3131,11 @@ linux_wait_1 (ptid_t ptid, paddress (event_child->stop_pc), paddress (event_child->step_range_start), paddress (event_child->step_range_end)); - if (extended_event_reported (&event_child->waitstatus)) + if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE) { - char *str = target_waitstatus_to_string (ourstatus); + char *str; + + str = target_waitstatus_to_string (&event_child->waitstatus); debug_printf ("LWP %ld: extended event with waitstatus %s\n", lwpid_of (get_lwp_thread (event_child)), str); xfree (str); @@ -3260,12 +3249,11 @@ linux_wait_1 (ptid_t ptid, unstop_all_lwps (1, event_child); } - if (extended_event_reported (&event_child->waitstatus)) + if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE) { - /* If the reported event is a fork, vfork or exec, let GDB know. */ - ourstatus->kind = event_child->waitstatus.kind; - ourstatus->value = event_child->waitstatus.value; - + /* If the reported event is an exit, fork, vfork or exec, let + GDB know. */ + *ourstatus = event_child->waitstatus; /* Clear the event lwp's waitstatus since we handled it already. */ event_child->waitstatus.kind = TARGET_WAITKIND_IGNORE; } @@ -3473,13 +3461,23 @@ suspend_and_send_sigstop_callback (struct inferior_list_entry *entry, static void mark_lwp_dead (struct lwp_info *lwp, int wstat) { - /* It's dead, really. */ - lwp->dead = 1; - /* Store the exit status for later. */ lwp->status_pending_p = 1; lwp->status_pending = wstat; + /* Store in waitstatus as well, as there's nothing else to process + for this event. */ + if (WIFEXITED (wstat)) + { + lwp->waitstatus.kind = TARGET_WAITKIND_EXITED; + lwp->waitstatus.value.integer = WEXITSTATUS (wstat); + } + else if (WIFSIGNALED (wstat)) + { + lwp->waitstatus.kind = TARGET_WAITKIND_SIGNALLED; + lwp->waitstatus.value.sig = gdb_signal_from_host (WTERMSIG (wstat)); + } + /* Prevent trying to stop it. */ lwp->stopped = 1; @@ -3487,6 +3485,17 @@ mark_lwp_dead (struct lwp_info *lwp, int wstat) lwp->stop_expected = 0; } +/* Return true if LWP has exited already, and has a pending exit event + to report to GDB. */ + +static int +lwp_is_marked_dead (struct lwp_info *lwp) +{ + return (lwp->status_pending_p + && (WIFEXITED (lwp->status_pending) + || WIFSIGNALED (lwp->status_pending))); +} + /* Wait for all children to stop for the SIGSTOPs we just queued. */ static void @@ -3603,7 +3612,7 @@ lwp_running (struct inferior_list_entry *entry, void *data) struct thread_info *thread = (struct thread_info *) entry; struct lwp_info *lwp = get_thread_lwp (thread); - if (lwp->dead) + if (lwp_is_marked_dead (lwp)) return 0; if (lwp->stopped) return 0; diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h index 3300da9..0f2421b 100644 --- a/gdb/gdbserver/linux-low.h +++ b/gdb/gdbserver/linux-low.h @@ -266,16 +266,13 @@ struct lwp_info event already received in a wait()). */ int stopped; - /* If this flag is set, the lwp is known to be dead already (exit - event already received in a wait(), and is cached in - status_pending). */ - int dead; - /* When stopped is set, the last wait status recorded for this lwp. */ int last_status; - /* This is used to store extended ptrace event information until - it is reported to GDB. */ + /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for + this LWP's last event, to pass to GDB without any further + processing. This is used to store extended ptrace event + information or exit status until it can be reported to GDB. */ struct target_waitstatus waitstatus; /* When stopped is set, this is where the lwp last stopped, with