From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 077173945C04 for ; Tue, 14 Apr 2020 17:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 077173945C04 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-RVX-q0MmNg2lUQtU_QqqsA-1; Tue, 14 Apr 2020 13:54:56 -0400 X-MC-Unique: RVX-q0MmNg2lUQtU_QqqsA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41071107ACC9 for ; Tue, 14 Apr 2020 17:54:55 +0000 (UTC) Received: from cascais.Home (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C84759F9AC for ; Tue, 14 Apr 2020 17:54:54 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 25/28] Don't write to inferior_ptid in windows-nat.c, part II Date: Tue, 14 Apr 2020 18:54:31 +0100 Message-Id: <20200414175434.8047-26-palves@redhat.com> In-Reply-To: <20200414175434.8047-1-palves@redhat.com> References: <20200414175434.8047-1-palves@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-29.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: Tue, 14 Apr 2020 17:55:00 -0000 Writing to inferior_ptid in windows_nat_target::get_windows_debug_event is just incorrect and not necessary. We'll report the event to GDB's core, which then takes care of switching inferior_ptid / current thread. Related (see windows_nat_target::get_windows_debug_event), there's also a "current_windows_thread" global that is just begging to get out of sync with core GDB's current thread. This patch removes it. gdbserver already does not have an equivalent global in win32-low.cc. gdb/ChangeLog: yyyy-mm-dd Pedro Alves =09* nat/windows-nat.c (current_windows_thread): Remove. =09* nat/windows-nat.h (current_windows_thread): Remove. =09* windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint): =09Adjust. =09(display_selectors): Adjust to fetch the current =09windows_thread_info based on inferior_ptid. =09(fake_create_process): No longer write to current_windows_thread. =09(windows_nat_target::get_windows_debug_event): =09Don't set inferior_ptid or current_windows_thread. =09(windows_nat_target::wait): Adjust to not rely on =09current_windows_thread. =09(windows_nat_target::detach): Use switch_to_no_thread instead of =09writing to inferior_ptid directly. --- gdb/nat/windows-nat.c | 1 - gdb/nat/windows-nat.h | 3 --- gdb/windows-nat.c | 62 ++++++++++++++++++++++++++---------------------= ---- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index cd7c1d177c..a382b9edb9 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -36,7 +36,6 @@ DEBUG_EVENT current_event; ContinueDebugEvent. */ static DEBUG_EVENT last_wait_event; =20 -windows_thread_info *current_windows_thread; DWORD desired_stop_thread_id =3D -1; std::vector pending_stops; EXCEPTION_RECORD siginfo_er; diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index aea1519672..dc27827d9c 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -168,9 +168,6 @@ extern enum gdb_signal last_sig; stop. */ extern DEBUG_EVENT current_event; =20 -/* Info on currently selected thread */ -extern windows_thread_info *current_windows_thread; - /* The ID of the thread for which we anticipate a stop event. Normally this is -1, meaning we'll accept an event in any thread. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 1bbebf00b9..78e7e31c67 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -317,7 +317,9 @@ struct windows_nat_target final : public x86_nat_target= =20 bool stopped_by_sw_breakpoint () override { - return current_windows_thread->stopped_at_software_breakpoint; + windows_thread_info *th + =3D thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); + return th->stopped_at_software_breakpoint; } =20 bool supports_stopped_by_sw_breakpoint () override @@ -1125,11 +1127,15 @@ display_selector (HANDLE thread, DWORD sel) static void display_selectors (const char * args, int from_tty) { - if (!current_windows_thread) + if (inferior_ptid =3D=3D null_ptid) { puts_filtered ("Impossible to display selectors now.\n"); return; } + + windows_thread_info *current_windows_thread + =3D thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); + if (!args) { #ifdef __x86_64__ @@ -1338,12 +1344,11 @@ fake_create_process (void) (unsigned) GetLastError ()); /* We can not debug anything in that case. */ } - current_windows_thread - =3D windows_add_thread (ptid_t (current_event.dwProcessId, -=09=09=09=09 current_event.dwThreadId, 0), -=09=09=09 current_event.u.CreateThread.hThread, -=09=09=09 current_event.u.CreateThread.lpThreadLocalBase, -=09=09=09 true /* main_thread_p */); + windows_add_thread (ptid_t (current_event.dwProcessId, 0, +=09=09=09 current_event.dwThreadId), +=09=09 current_event.u.CreateThread.hThread, +=09=09 current_event.u.CreateThread.lpThreadLocalBase, +=09=09 true /* main_thread_p */); return current_event.dwThreadId; } =20 @@ -1516,10 +1521,9 @@ windows_nat_target::get_windows_debug_event (int pid= , thread_id =3D stop->thread_id; *ourstatus =3D stop->status; =20 - inferior_ptid =3D ptid_t (current_event.dwProcessId, thread_id, 0); - current_windows_thread =3D thread_rec (inferior_ptid, -=09=09=09=09=09 INVALIDATE_CONTEXT); - current_windows_thread->reload_context =3D 1; + ptid_t ptid (current_event.dwProcessId, thread_id); + th =3D thread_rec (ptid, INVALIDATE_CONTEXT); + th->reload_context =3D 1; =20 return thread_id; } @@ -1734,14 +1738,6 @@ windows_nat_target::get_windows_debug_event (int pid= , thread_id =3D 0; CHECK (windows_continue (continue_status, desired_stop_thread_id, 0)= ); } - else - { - inferior_ptid =3D ptid_t (current_event.dwProcessId, thread_id, 0); - current_windows_thread =3D th; - if (!current_windows_thread) -=09current_windows_thread =3D thread_rec (inferior_ptid, -=09=09=09=09=09 INVALIDATE_CONTEXT); - } =20 out: return thread_id; @@ -1798,16 +1794,22 @@ windows_nat_target::wait (ptid_t ptid, struct targe= t_waitstatus *ourstatus, =09{ =09 ptid_t result =3D ptid_t (current_event.dwProcessId, retval, 0); =20 -=09 if (current_windows_thread !=3D nullptr) +=09 if (ourstatus->kind !=3D TARGET_WAITKIND_EXITED +=09 && ourstatus->kind !=3D TARGET_WAITKIND_SIGNALLED) =09 { -=09 current_windows_thread->stopped_at_software_breakpoint =3D false; -=09 if (current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT -=09=09 && ((current_event.u.Exception.ExceptionRecord.ExceptionCode -=09=09 =3D=3D EXCEPTION_BREAKPOINT) -=09=09 || (current_event.u.Exception.ExceptionRecord.ExceptionCode -=09=09=09 =3D=3D STATUS_WX86_BREAKPOINT)) -=09=09 && windows_initialization_done) -=09=09current_windows_thread->stopped_at_software_breakpoint =3D true; +=09 windows_thread_info *th =3D thread_rec (result, INVALIDATE_CONTEX= T); + +=09 if (th !=3D nullptr) +=09=09{ +=09=09 th->stopped_at_software_breakpoint =3D false; +=09=09 if (current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT +=09=09 && ((current_event.u.Exception.ExceptionRecord.ExceptionCode +=09=09=09 =3D=3D EXCEPTION_BREAKPOINT) +=09=09=09 || (current_event.u.Exception.ExceptionRecord.ExceptionCode +=09=09=09 =3D=3D STATUS_WX86_BREAKPOINT)) +=09=09 && windows_initialization_done) +=09=09 th->stopped_at_software_breakpoint =3D true; +=09=09} =09 } =20 =09 return result; @@ -2166,7 +2168,7 @@ windows_nat_target::detach (inferior *inf, int from_t= ty) } =20 x86_cleanup_dregs (); - inferior_ptid =3D null_ptid; + switch_to_no_thread (); detach_inferior (inf); =20 maybe_unpush_target (); --=20 2.14.5