From patchwork Tue Nov 26 17:11:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36225 Received: (qmail 96298 invoked by alias); 26 Nov 2019 17:12:13 -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 95114 invoked by uid 89); 26 Nov 2019 17:12:04 -0000 Authentication-Results: sourceware.org; auth=none 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 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2019 17:12:01 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 16A7C2030C; Tue, 26 Nov 2019 12:12:01 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id A2F0D211F7 for ; Tue, 26 Nov 2019 12:11:33 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 6C0F828173 for ; Tue, 26 Nov 2019 12:11:33 -0500 (EST) X-Gerrit-PatchSet: 1 Date: Tue, 26 Nov 2019 12:11:33 -0500 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Introduce fetch_pending_stop X-Gerrit-Change-Id: I2d289dbf3ab17ae5c13c59afdf89b724301e962f X-Gerrit-Change-Number: 718 X-Gerrit-ChangeURL: X-Gerrit-Commit: b1c035ca385d978c29fddf92398fbe27f752c685 References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/718 ...................................................................... Introduce fetch_pending_stop This introduces a new "fetch_pending_stop" function and changes gdb to use it. This function removes the first matching pending stop from the list of such stops. 2019-11-26 Tom Tromey * windows-nat.c (get_windows_debug_event): Use fetch_pending_stop. * nat/windows-nat.h (fetch_pending_stop): Declare. * nat/windows-nat.c (fetch_pending_stop): New function. Change-Id: I2d289dbf3ab17ae5c13c59afdf89b724301e962f --- M gdb/ChangeLog M gdb/nat/windows-nat.c M gdb/nat/windows-nat.h M gdb/windows-nat.c 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c4e5f2b..29ef0db 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2019-11-26 Tom Tromey + * windows-nat.c (get_windows_debug_event): Use + fetch_pending_stop. + * nat/windows-nat.h (fetch_pending_stop): Declare. + * nat/windows-nat.c (fetch_pending_stop): New function. + +2019-11-26 Tom Tromey + * windows-nat.c (windows_continue): Use matching_pending_stop and continue_last_debug_event. * nat/windows-nat.h (matching_pending_stop) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 81663df..126a329 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -323,6 +323,34 @@ /* See nat/windows-nat.h. */ +gdb::optional +fetch_pending_stop (bool debug_events) +{ + gdb::optional result; + for (auto iter = pending_stops.begin (); + iter != pending_stops.end (); + ++iter) + { + if (desired_stop_thread_id == -1 + || desired_stop_thread_id == iter->thread_id) + { + result = *iter; + current_event = iter->event; + + DEBUG_EVENTS (("get_windows_debug_event - " + "pending stop found in 0x%x (desired=0x%x)\n", + iter->thread_id, desired_stop_thread_id)); + + pending_stops.erase (iter); + break; + } + } + + return result; +} + +/* See nat/windows-nat.h. */ + BOOL continue_last_debug_event (DWORD continue_status, bool debug_events) { diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 1427885..702aebc 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -21,6 +21,7 @@ #include +#include "gdbsupport/gdb_optional.h" #include "target/waitstatus.h" namespace windows_nat @@ -218,6 +219,12 @@ extern bool matching_pending_stop (bool debug_events); +/* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so, + remove it from the list of pending stops, set 'current_event', and + return it. Otherwise, return an empty optional. */ + +extern gdb::optional fetch_pending_stop (bool debug_events); + /* A simple wrapper for ContinueDebugEvent that continues the last waited-for event. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 45ba15e..bbae172 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1323,29 +1323,18 @@ /* If there is a relevant pending stop, report it now. See the comment by the definition of "pending_stops" for details on why this is needed. */ - for (auto iter = pending_stops.begin (); - iter != pending_stops.end (); - ++iter) + gdb::optional stop = fetch_pending_stop (debug_events); + if (stop.has_value ()) { - if (desired_stop_thread_id == -1 - || desired_stop_thread_id == iter->thread_id) - { - thread_id = iter->thread_id; - *ourstatus = iter->status; - current_event = iter->event; + thread_id = stop->thread_id; + *ourstatus = stop->status; - inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0); - current_windows_thread = thread_rec (inferior_ptid, - INVALIDATE_CONTEXT); - current_windows_thread->reload_context = 1; + inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0); + current_windows_thread = thread_rec (inferior_ptid, + INVALIDATE_CONTEXT); + current_windows_thread->reload_context = 1; - DEBUG_EVENTS (("get_windows_debug_event - " - "pending stop found in 0x%x (desired=0x%x)\n", - thread_id, desired_stop_thread_id)); - - pending_stops.erase (iter); - return thread_id; - } + return thread_id; } last_sig = GDB_SIGNAL_0;