From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 9706B3AAA08D for ; Fri, 13 Mar 2020 19:09:04 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 90D62561B5; Fri, 13 Mar 2020 15:09:04 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id sejfzsN5EScd; Fri, 13 Mar 2020 15:09:04 -0400 (EDT) Received: from murgatroyd.Home (184-96-250-69.hlrn.qwest.net [184.96.250.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 4E868561B4; Fri, 13 Mar 2020 15:09:04 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 23/29] Introduce fetch_pending_stop Date: Fri, 13 Mar 2020 13:08:49 -0600 Message-Id: <20200313190855.28662-24-tromey@adacore.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200313190855.28662-1-tromey@adacore.com> References: <20200313190855.28662-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-25.0 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2020 19:09:05 -0000 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. gdb/ChangeLog 2020-03-13 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. --- gdb/ChangeLog | 7 +++++++ gdb/nat/windows-nat.c | 28 ++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 7 +++++++ gdb/windows-nat.c | 29 +++++++++-------------------- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 2c2454b6f6f..823471eb4da 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -343,6 +343,34 @@ matching_pending_stop (bool debug_events) /* 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 0e9316577ba..68b72d4bbd2 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -22,6 +22,7 @@ #include #include +#include "gdbsupport/gdb_optional.h" #include "target/waitstatus.h" namespace windows_nat @@ -231,6 +232,12 @@ extern handle_exception_result handle_exception 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. If DEBUG_EVENTS is true, logging will be enabled. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 67655dc46e4..9a1dd49a42b 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1522,29 +1522,18 @@ windows_nat_target::get_windows_debug_event (int pid, /* 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; - - 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; + thread_id = stop->thread_id; + *ourstatus = stop->status; - DEBUG_EVENTS (("get_windows_debug_event - " - "pending stop found in 0x%x (desired=0x%x)\n", - thread_id, desired_stop_thread_id)); + 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; - pending_stops.erase (iter); - return thread_id; - } + return thread_id; } last_sig = GDB_SIGNAL_0; -- 2.21.1