From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id B32553887025 for ; Tue, 14 Apr 2020 17:54:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B32553887025 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-395-GTmTtlhXNY-qaAcYNR3jNg-1; Tue, 14 Apr 2020 13:54:42 -0400 X-MC-Unique: GTmTtlhXNY-qaAcYNR3jNg-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 2B69818C35A7 for ; Tue, 14 Apr 2020 17:54:41 +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 9A07C5C1A2 for ; Tue, 14 Apr 2020 17:54:40 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 07/28] Don't write to inferior_ptid in infrun.c Date: Tue, 14 Apr 2020 18:54:13 +0100 Message-Id: <20200414175434.8047-8-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=-28.7 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:54:45 -0000 gdb/ChangeLog: yyyy-mm-dd Pedro Alves =09* infrun.c (generic_mourn_inferior): Use switch_to_thread instead =09of writing to inferior_ptid. =09(scoped_restore_exited_inferior): Delete. =09(handle_vfork_child_exec_or_exit): Simplify using =09scoped_restore_current_pspace_and_thread. Use switch_to_thread =09instead of writing to inferior_ptid. =09(THREAD_STOPPED_BY): Delete. =09(thread_stopped_by_watchpoint, thread_stopped_by_sw_breakpoint) =09(thread_stopped_by_hw_breakpoint): Delete. =09(save_waitstatus): Use =09scoped_restore_current_thread+switch_to_thread, and call =09target_stopped_by_watchpoint instead of =09thread_stopped_by_watchpoint, target_stopped_by_sw_breakpoint =09instead of thread_stopped_by_sw_breakpoint, and =09target_stopped_by_hw_breakpoint instead of =09thread_stopped_by_hw_breakpoint. =09(handle_inferior_event) =09: Don't write to =09inferior_ptid directly, nor =09set_current_inferior/set_current_program_space. Use =09switch_to_thread / switch_to_inferior_no_thread instead. --- gdb/infrun.c | 101 +++++++++++++++++++++++--------------------------------= ---- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 8ff34c382d..631cd90ae3 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -484,8 +484,8 @@ holding the child stopped. Try \"set detach-on-fork\" = or \ =09 switch_to_no_thread (); =09 child_inf->symfile_flags =3D SYMFILE_NO_READ; =09 push_target (parent_inf->process_target ()); -=09 add_thread_silent (child_inf->process_target (), child_ptid); -=09 inferior_ptid =3D child_ptid; +=09 thread_info *child_thr +=09 =3D add_thread_silent (child_inf->process_target (), child_ptid); =20 =09 /* If this is a vfork child, then the address-space is =09 shared with the parent. */ @@ -503,6 +503,11 @@ holding the child stopped. Try \"set detach-on-fork\"= or \ =09 child_inf->pending_detach =3D 0; =09 parent_inf->vfork_child =3D child_inf; =09 parent_inf->pending_detach =3D 0; + +=09 /* Now that the inferiors and program spaces are all +=09=09 wired up, we can switch to the child thread (which +=09=09 switches inferior and program space too). */ +=09 switch_to_thread (child_thr); =09 } =09 else =09 { @@ -512,6 +517,10 @@ holding the child stopped. Try \"set detach-on-fork\"= or \ =09 set_current_program_space (child_inf->pspace); =09 clone_program_space (child_inf->pspace, parent_inf->pspace); =20 +=09 /* solib_create_inferior_hook relies on the current +=09=09 thread. */ +=09 switch_to_thread (child_thr); + =09 /* Let the shared library layer (e.g., solib-svr4) learn =09=09 about this new process, relocate the cloned exec, pull =09=09 in shared libraries, and install the solib event @@ -627,8 +636,7 @@ holding the child stopped. Try \"set detach-on-fork\" = or \ =09push_target (target); } =20 - add_thread_silent (target, child_ptid); - inferior_ptid =3D child_ptid; + thread_info *child_thr =3D add_thread_silent (target, child_ptid); =20 /* If this is a vfork child, then the address-space is shared =09 with the parent. If we detached from the parent, then we can @@ -656,6 +664,8 @@ holding the child stopped. Try \"set detach-on-fork\" = or \ =09 the core, this wouldn't be required. */ =09 solib_create_inferior_hook (0); =09} + + switch_to_thread (child_thr); } =20 return target_follow_fork (follow_child, detach_fork); @@ -897,22 +907,6 @@ proceed_after_vfork_done (struct thread_info *thread, return 0; } =20 -/* Save/restore inferior_ptid, current program space and current - inferior. Only use this if the current context points at an exited - inferior (and therefore there's no current thread to save). */ -class scoped_restore_exited_inferior -{ -public: - scoped_restore_exited_inferior () - : m_saved_ptid (&inferior_ptid) - {} - -private: - scoped_restore_tmpl m_saved_ptid; - scoped_restore_current_program_space m_pspace; - scoped_restore_current_inferior m_inferior; -}; - /* Called whenever we notice an exec or exit event, to handle detaching or resuming a vfork parent. */ =20 @@ -935,7 +929,6 @@ handle_vfork_child_exec_or_exit (int exec) =09 time. */ if (vfork_parent->pending_detach) =09{ -=09 struct thread_info *tp; =09 struct program_space *pspace; =09 struct address_space *aspace; =20 @@ -943,20 +936,10 @@ handle_vfork_child_exec_or_exit (int exec) =20 =09 vfork_parent->pending_detach =3D 0; =20 -=09 gdb::optional -=09 maybe_restore_inferior; -=09 gdb::optional -=09 maybe_restore_thread; - -=09 /* If we're handling a child exit, then inferior_ptid points -=09 at the inferior's pid, not to a thread. */ -=09 if (!exec) -=09 maybe_restore_inferior.emplace (); -=09 else -=09 maybe_restore_thread.emplace (); +=09 scoped_restore_current_pspace_and_thread restore_thread; =20 =09 /* We're letting loose of the parent. */ -=09 tp =3D any_live_thread_of_inferior (vfork_parent); +=09 thread_info *tp =3D any_live_thread_of_inferior (vfork_parent); =09 switch_to_thread (tp); =20 =09 /* We're about to detach from the parent, which implicitly @@ -1025,11 +1008,11 @@ handle_vfork_child_exec_or_exit (int exec) =09 go ahead and create a new one for this exiting =09 inferior. */ =20 -=09 /* Switch to null_ptid while running clone_program_space, so +=09 /* Switch to no-thread while running clone_program_space, so =09 that clone_program_space doesn't want to read the =09 selected frame of a dead process. */ -=09 scoped_restore restore_ptid -=09 =3D make_scoped_restore (&inferior_ptid, null_ptid); +=09 scoped_restore_current_thread restore_thread; +=09 switch_to_no_thread (); =20 =09 inf->pspace =3D new program_space (maybe_new_address_space ()); =09 inf->aspace =3D inf->pspace->aspace; @@ -4612,25 +4595,6 @@ wait_one () } } =20 -/* Generate a wrapper for target_stopped_by_REASON that works on PTID - instead of the current thread. */ -#define THREAD_STOPPED_BY(REASON)=09=09\ -static int=09=09=09=09=09\ -thread_stopped_by_ ## REASON (ptid_t ptid)=09\ -{=09=09=09=09=09=09\ - scoped_restore save_inferior_ptid =3D make_scoped_restore (&inferior_pti= d); \ - inferior_ptid =3D ptid;=09=09=09=09\ -=09=09=09=09=09=09\ - return target_stopped_by_ ## REASON ();=09\ -} - -/* Generate thread_stopped_by_watchpoint. */ -THREAD_STOPPED_BY (watchpoint) -/* Generate thread_stopped_by_sw_breakpoint. */ -THREAD_STOPPED_BY (sw_breakpoint) -/* Generate thread_stopped_by_hw_breakpoint. */ -THREAD_STOPPED_BY (hw_breakpoint) - /* Save the thread's event and stop reason to process it later. */ =20 static void @@ -4662,19 +4626,22 @@ save_waitstatus (struct thread_info *tp, const targ= et_waitstatus *ws) =20 adjust_pc_after_break (tp, &tp->suspend.waitstatus); =20 - if (thread_stopped_by_watchpoint (tp->ptid)) + scoped_restore_current_thread restore_thread; + switch_to_thread (tp); + + if (target_stopped_by_watchpoint ()) =09{ =09 tp->suspend.stop_reason =09 =3D TARGET_STOPPED_BY_WATCHPOINT; =09} else if (target_supports_stopped_by_sw_breakpoint () -=09 && thread_stopped_by_sw_breakpoint (tp->ptid)) +=09 && target_stopped_by_sw_breakpoint ()) =09{ =09 tp->suspend.stop_reason =09 =3D TARGET_STOPPED_BY_SW_BREAKPOINT; =09} else if (target_supports_stopped_by_hw_breakpoint () -=09 && thread_stopped_by_hw_breakpoint (tp->ptid)) +=09 && target_stopped_by_hw_breakpoint ()) =09{ =09 tp->suspend.stop_reason =09 =3D TARGET_STOPPED_BY_HW_BREAKPOINT; @@ -5268,9 +5235,21 @@ handle_inferior_event (struct execution_control_stat= e *ecs) =20 case TARGET_WAITKIND_EXITED: case TARGET_WAITKIND_SIGNALLED: - inferior_ptid =3D ecs->ptid; - set_current_inferior (find_inferior_ptid (ecs->target, ecs->ptid)); - set_current_program_space (current_inferior ()->pspace); + { +=09/* Depending on the system, ecs->ptid may point to a thread or +=09 to a process. On some targets, target_mourn_inferior may +=09 need to have access to the just-exited thread. That is the +=09 case of GNU/Linux's "checkpoint" support, for example. +=09 Call the switch_to_xxx routine as appropriate. */ +=09thread_info *thr =3D find_thread_ptid (ecs->target, ecs->ptid); +=09if (thr !=3D nullptr) +=09 switch_to_thread (thr); +=09else +=09 { +=09 inferior *inf =3D find_inferior_ptid (ecs->target, ecs->ptid); +=09 switch_to_inferior_no_thread (inf); +=09 } + } handle_vfork_child_exec_or_exit (0); target_terminal::ours ();=09/* Must do this before mourn anyway. */ =20 --=20 2.14.5