From patchwork Tue Oct 29 17:57:56 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: 35433 Received: (qmail 115875 invoked by alias); 29 Oct 2019 18:05:55 -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 114593 invoked by uid 89); 29 Oct 2019 18:05:54 -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, 29 Oct 2019 18:05:52 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id EE21220555; Tue, 29 Oct 2019 13:58:10 -0400 (EDT) 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 8118F21350 for ; Tue, 29 Oct 2019 13:57:56 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 625C020AF6 for ; Tue, 29 Oct 2019 13:57:56 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Tue, 29 Oct 2019 13:57:56 -0400 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Share some inferior-related Windows code X-Gerrit-Change-Id: I5ba2447e8811fd0a3c96591472f8d84818fe2e53 X-Gerrit-Change-Number: 426 X-Gerrit-ChangeURL: X-Gerrit-Commit: 26d3c2e6b19f8d3ff52b93820c4d976050e1f260 References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-74-g460fb0f7e9 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/426 ...................................................................... Share some inferior-related Windows code This adds a couple of functions to nat/windows-nat.c and changes gdb and gdbserver to use them. One function checks the list of pending stops for a match (not yet used by gdbserver, but will be in a subsequent patch); and the other is a wrapper for ContinueDebugEvent that always uses the last "real" stop event. Change-Id: I5b1d1c89483153891b547de2bc14aa75748b50a4 gdb/ChangeLog 2019-10-29 Tom Tromey * windows-nat.c (windows_continue): Use matching_pending_stop and continue_last_debug_event. * nat/windows-nat.h (matching_pending_stop) (continue_last_debug_event): Declare. * nat/windows-nat.c (DEBUG_EVENTS): New define. (matching_pending_stop, continue_last_debug_event): New functions. gdb/gdbserver/ChangeLog 2019-10-29 Tom Tromey * win32-low.c (child_continue): Call continue_last_debug_event. Change-Id: I5ba2447e8811fd0a3c96591472f8d84818fe2e53 --- M gdb/ChangeLog M gdb/gdbserver/ChangeLog M gdb/gdbserver/win32-low.c M gdb/nat/windows-nat.c M gdb/nat/windows-nat.h M gdb/windows-nat.c 6 files changed, 75 insertions(+), 30 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index acc6961..0d38851 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2019-10-29 Tom Tromey + * windows-nat.c (windows_continue): Use matching_pending_stop and + continue_last_debug_event. + * nat/windows-nat.h (matching_pending_stop) + (continue_last_debug_event): Declare. + * nat/windows-nat.c (DEBUG_EVENTS): New define. + (matching_pending_stop, continue_last_debug_event): New + functions. + +2019-10-29 Tom Tromey + * windows-nat.c (MS_VC_EXCEPTION): Move to nat/windows-nat.c. (handle_exception_result): Move to nat/windows-nat.h. (DEBUG_EXCEPTION_SIMPLE): Remove. diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 050202b..40262d0 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,9 @@ 2019-10-29 Tom Tromey + * win32-low.c (child_continue): Call continue_last_debug_event. + +2019-10-29 Tom Tromey + * win32-low.c (handle_exception): Remove. (windows_nat::handle_ms_vc_exception): New function. (get_child_debug_event): Add "continue_status" parameter. diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 1340e85..b58f6f6 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -433,12 +433,7 @@ }); faked_breakpoint = 0; - if (!ContinueDebugEvent (current_event.dwProcessId, - current_event.dwThreadId, - continue_status)) - return FALSE; - - return TRUE; + return continue_last_debug_event (continue_status, debug_threads); } /* Fetch register(s) from the current thread context. */ diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 3647014..163e3b1 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -34,6 +34,9 @@ std::vector pending_stops; bool last_stop_was_breakpoint = false; +/* Note that 'debug_events' must be locally defined in the relevant + functions. */ +#define DEBUG_EVENTS(x) if (debug_events) debug_printf x windows_thread_info::~windows_thread_info () { @@ -292,4 +295,46 @@ #undef DEBUG_EXCEPTION_SIMPLE } +/* See nat/windows-nat.h. */ + +bool +matching_pending_stop (bool debug_events) +{ + /* If there are pending stops, and we might plausibly hit one of + them, we don't want to actually continue the inferior -- we just + want to report the stop. In this case, we just pretend to + continue. See the comment by the definition of "pending_stops" + for details on why this is needed. */ + for (auto &item : pending_stops) + { + if (desired_stop_thread_id == -1 + || desired_stop_thread_id == item.thread_id) + { + DEBUG_EVENTS (("windows_continue - pending stop anticipated, " + "desired=0x%x, item=0x%x\n", + desired_stop_thread_id, item.thread_id)); + return true; + } + } + + return false; +} + +/* See nat/windows-nat.h. */ + +BOOL +continue_last_debug_event (DWORD continue_status, bool debug_events) +{ + DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=0x%x, %s);\n", + (unsigned) last_wait_event.dwProcessId, + (unsigned) last_wait_event.dwThreadId, + continue_status == DBG_CONTINUE ? + "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED")); + + return ContinueDebugEvent (last_wait_event.dwProcessId, + last_wait_event.dwThreadId, + continue_status); +} + + } diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index a089602..42e2e75 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -211,6 +211,17 @@ extern handle_exception_result handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptions); +/* Return true if there is a pending stop matching + desired_stop_thread_id. */ + +extern bool matching_pending_stop (bool debug_events); + +/* A simple wrapper for ContinueDebugEvent that continues the last + waited-for event. */ + +extern BOOL continue_last_debug_event (DWORD continue_status, + bool debug_events); + } #endif diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 0136b50..6884411 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1081,30 +1081,12 @@ desired_stop_thread_id = id; - /* If there are pending stops, and we might plausibly hit one of - them, we don't want to actually continue the inferior -- we just - want to report the stop. In this case, we just pretend to - continue. See the comment by the definition of "pending_stops" - for details on why this is needed. */ - for (auto &item : pending_stops) + if (matching_pending_stop (debug_events)) { - if (desired_stop_thread_id == -1 - || desired_stop_thread_id == item.thread_id) - { - DEBUG_EVENTS (("windows_continue - pending stop anticipated, " - "desired=0x%x, item=0x%x\n", - desired_stop_thread_id, item.thread_id)); - debug_registers_changed = 0; - return TRUE; - } + debug_registers_changed = 0; + return TRUE; } - DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=0x%x, %s);\n", - (unsigned) last_wait_event.dwProcessId, - (unsigned) last_wait_event.dwThreadId, - continue_status == DBG_CONTINUE ? - "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED")); - for (windows_thread_info *th : thread_list) if (id == -1 || id == (int) th->tid) { @@ -1143,9 +1125,7 @@ th->suspend (); } - res = ContinueDebugEvent (last_wait_event.dwProcessId, - last_wait_event.dwThreadId, - continue_status); + res = continue_last_debug_event (continue_status, debug_events); if (!res) error (_("Failed to resume program execution"