From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id 4BC2D3AAA08A 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 455C3561B1; 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 itQxhkJAkovw; 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 019E0561B4; Fri, 13 Mar 2020 15:09:03 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 22/29] Share some inferior-related Windows code Date: Fri, 13 Mar 2020 13:08:48 -0600 Message-Id: <20200313190855.28662-23-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, 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 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. gdb/ChangeLog 2020-03-13 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. gdbserver/ChangeLog 2020-03-13 Tom Tromey * win32-low.c (child_continue): Call continue_last_debug_event. --- gdb/ChangeLog | 10 +++++++++ gdb/nat/windows-nat.c | 46 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 13 ++++++++++++ gdb/windows-nat.c | 28 +++---------------------- gdbserver/ChangeLog | 4 ++++ gdbserver/win32-low.cc | 7 +------ 6 files changed, 77 insertions(+), 31 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 6bbf41c7b13..2c2454b6f6f 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -37,6 +37,10 @@ DWORD desired_stop_thread_id = -1; std::vector pending_stops; EXCEPTION_RECORD siginfo_er; +/* 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 () { CloseHandle (h); @@ -312,4 +316,46 @@ handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptions) #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 (const 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 a4e0b39fcab..0e9316577ba 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -225,6 +225,19 @@ typedef enum 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. If DEBUG_EVENTS is true, logging will be + enabled. */ + +extern bool matching_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. */ + +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 a9656a8c91b..67655dc46e4 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1239,28 +1239,8 @@ windows_continue (DWORD continue_status, int id, int killed) 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 (const 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; - } - } - - 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")); + if (matching_pending_stop (debug_events)) + return TRUE; for (windows_thread_info *th : thread_list) if (id == -1 || id == (int) th->tid) @@ -1333,9 +1313,7 @@ windows_continue (DWORD continue_status, int id, int killed) 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" diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 7018083746b..33f64700153 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -433,12 +433,7 @@ child_continue (DWORD continue_status, int thread_id) }); 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. */ -- 2.21.1