• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂7fdeda6cd99c4998d2211a3f54b591d73c0b1a8b (tree)
時間2020-06-04 04:19:06
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

Don't write to inferior_ptid in infrun.c

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>

* infrun.c (generic_mourn_inferior): Use switch_to_thread instead
of writing to inferior_ptid.
(scoped_restore_exited_inferior): Delete.
(handle_vfork_child_exec_or_exit): Simplify using
scoped_restore_current_pspace_and_thread. Use switch_to_thread
instead of writing to inferior_ptid.
(THREAD_STOPPED_BY): Delete.
(thread_stopped_by_watchpoint, thread_stopped_by_sw_breakpoint)
(thread_stopped_by_hw_breakpoint): Delete.
(save_waitstatus): Use
scoped_restore_current_thread+switch_to_thread, and call
target_stopped_by_watchpoint instead of
thread_stopped_by_watchpoint, target_stopped_by_sw_breakpoint
instead of thread_stopped_by_sw_breakpoint, and
target_stopped_by_hw_breakpoint instead of
thread_stopped_by_hw_breakpoint.
(handle_inferior_event)
<TARGET_WAITKIND_EXITED/TARGET_WAITKIND_SIGNALLED>: Don't write to
inferior_ptid directly, nor
set_current_inferior/set_current_program_space. Use
switch_to_thread / switch_to_inferior_no_thread instead.

Change Summary

差異

--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -485,8 +485,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \
485485 switch_to_no_thread ();
486486 child_inf->symfile_flags = SYMFILE_NO_READ;
487487 push_target (parent_inf->process_target ());
488- add_thread_silent (child_inf->process_target (), child_ptid);
489- inferior_ptid = child_ptid;
488+ thread_info *child_thr
489+ = add_thread_silent (child_inf->process_target (), child_ptid);
490490
491491 /* If this is a vfork child, then the address-space is
492492 shared with the parent. */
@@ -504,6 +504,11 @@ holding the child stopped. Try \"set detach-on-fork\" or \
504504 child_inf->pending_detach = 0;
505505 parent_inf->vfork_child = child_inf;
506506 parent_inf->pending_detach = 0;
507+
508+ /* Now that the inferiors and program spaces are all
509+ wired up, we can switch to the child thread (which
510+ switches inferior and program space too). */
511+ switch_to_thread (child_thr);
507512 }
508513 else
509514 {
@@ -513,6 +518,10 @@ holding the child stopped. Try \"set detach-on-fork\" or \
513518 set_current_program_space (child_inf->pspace);
514519 clone_program_space (child_inf->pspace, parent_inf->pspace);
515520
521+ /* solib_create_inferior_hook relies on the current
522+ thread. */
523+ switch_to_thread (child_thr);
524+
516525 /* Let the shared library layer (e.g., solib-svr4) learn
517526 about this new process, relocate the cloned exec, pull
518527 in shared libraries, and install the solib event
@@ -628,8 +637,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \
628637 push_target (target);
629638 }
630639
631- add_thread_silent (target, child_ptid);
632- inferior_ptid = child_ptid;
640+ thread_info *child_thr = add_thread_silent (target, child_ptid);
633641
634642 /* If this is a vfork child, then the address-space is shared
635643 with the parent. If we detached from the parent, then we can
@@ -657,6 +665,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \
657665 the core, this wouldn't be required. */
658666 solib_create_inferior_hook (0);
659667 }
668+
669+ switch_to_thread (child_thr);
660670 }
661671
662672 return target_follow_fork (follow_child, detach_fork);
@@ -904,22 +914,6 @@ proceed_after_vfork_done (struct thread_info *thread,
904914 return 0;
905915 }
906916
907-/* Save/restore inferior_ptid, current program space and current
908- inferior. Only use this if the current context points at an exited
909- inferior (and therefore there's no current thread to save). */
910-class scoped_restore_exited_inferior
911-{
912-public:
913- scoped_restore_exited_inferior ()
914- : m_saved_ptid (&inferior_ptid)
915- {}
916-
917-private:
918- scoped_restore_tmpl<ptid_t> m_saved_ptid;
919- scoped_restore_current_program_space m_pspace;
920- scoped_restore_current_inferior m_inferior;
921-};
922-
923917 /* Called whenever we notice an exec or exit event, to handle
924918 detaching or resuming a vfork parent. */
925919
@@ -942,7 +936,6 @@ handle_vfork_child_exec_or_exit (int exec)
942936 time. */
943937 if (vfork_parent->pending_detach)
944938 {
945- struct thread_info *tp;
946939 struct program_space *pspace;
947940 struct address_space *aspace;
948941
@@ -950,20 +943,10 @@ handle_vfork_child_exec_or_exit (int exec)
950943
951944 vfork_parent->pending_detach = 0;
952945
953- gdb::optional<scoped_restore_exited_inferior>
954- maybe_restore_inferior;
955- gdb::optional<scoped_restore_current_pspace_and_thread>
956- maybe_restore_thread;
957-
958- /* If we're handling a child exit, then inferior_ptid points
959- at the inferior's pid, not to a thread. */
960- if (!exec)
961- maybe_restore_inferior.emplace ();
962- else
963- maybe_restore_thread.emplace ();
946+ scoped_restore_current_pspace_and_thread restore_thread;
964947
965948 /* We're letting loose of the parent. */
966- tp = any_live_thread_of_inferior (vfork_parent);
949+ thread_info *tp = any_live_thread_of_inferior (vfork_parent);
967950 switch_to_thread (tp);
968951
969952 /* We're about to detach from the parent, which implicitly
@@ -1032,11 +1015,11 @@ handle_vfork_child_exec_or_exit (int exec)
10321015 go ahead and create a new one for this exiting
10331016 inferior. */
10341017
1035- /* Switch to null_ptid while running clone_program_space, so
1018+ /* Switch to no-thread while running clone_program_space, so
10361019 that clone_program_space doesn't want to read the
10371020 selected frame of a dead process. */
1038- scoped_restore restore_ptid
1039- = make_scoped_restore (&inferior_ptid, null_ptid);
1021+ scoped_restore_current_thread restore_thread;
1022+ switch_to_no_thread ();
10401023
10411024 inf->pspace = new program_space (maybe_new_address_space ());
10421025 inf->aspace = inf->pspace->aspace;
@@ -4622,25 +4605,6 @@ wait_one ()
46224605 }
46234606 }
46244607
4625-/* Generate a wrapper for target_stopped_by_REASON that works on PTID
4626- instead of the current thread. */
4627-#define THREAD_STOPPED_BY(REASON) \
4628-static int \
4629-thread_stopped_by_ ## REASON (ptid_t ptid) \
4630-{ \
4631- scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); \
4632- inferior_ptid = ptid; \
4633- \
4634- return target_stopped_by_ ## REASON (); \
4635-}
4636-
4637-/* Generate thread_stopped_by_watchpoint. */
4638-THREAD_STOPPED_BY (watchpoint)
4639-/* Generate thread_stopped_by_sw_breakpoint. */
4640-THREAD_STOPPED_BY (sw_breakpoint)
4641-/* Generate thread_stopped_by_hw_breakpoint. */
4642-THREAD_STOPPED_BY (hw_breakpoint)
4643-
46444608 /* Save the thread's event and stop reason to process it later. */
46454609
46464610 static void
@@ -4672,19 +4636,22 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
46724636
46734637 adjust_pc_after_break (tp, &tp->suspend.waitstatus);
46744638
4675- if (thread_stopped_by_watchpoint (tp->ptid))
4639+ scoped_restore_current_thread restore_thread;
4640+ switch_to_thread (tp);
4641+
4642+ if (target_stopped_by_watchpoint ())
46764643 {
46774644 tp->suspend.stop_reason
46784645 = TARGET_STOPPED_BY_WATCHPOINT;
46794646 }
46804647 else if (target_supports_stopped_by_sw_breakpoint ()
4681- && thread_stopped_by_sw_breakpoint (tp->ptid))
4648+ && target_stopped_by_sw_breakpoint ())
46824649 {
46834650 tp->suspend.stop_reason
46844651 = TARGET_STOPPED_BY_SW_BREAKPOINT;
46854652 }
46864653 else if (target_supports_stopped_by_hw_breakpoint ()
4687- && thread_stopped_by_hw_breakpoint (tp->ptid))
4654+ && target_stopped_by_hw_breakpoint ())
46884655 {
46894656 tp->suspend.stop_reason
46904657 = TARGET_STOPPED_BY_HW_BREAKPOINT;
@@ -5338,9 +5305,21 @@ handle_inferior_event (struct execution_control_state *ecs)
53385305
53395306 case TARGET_WAITKIND_EXITED:
53405307 case TARGET_WAITKIND_SIGNALLED:
5341- inferior_ptid = ecs->ptid;
5342- set_current_inferior (find_inferior_ptid (ecs->target, ecs->ptid));
5343- set_current_program_space (current_inferior ()->pspace);
5308+ {
5309+ /* Depending on the system, ecs->ptid may point to a thread or
5310+ to a process. On some targets, target_mourn_inferior may
5311+ need to have access to the just-exited thread. That is the
5312+ case of GNU/Linux's "checkpoint" support, for example.
5313+ Call the switch_to_xxx routine as appropriate. */
5314+ thread_info *thr = find_thread_ptid (ecs->target, ecs->ptid);
5315+ if (thr != nullptr)
5316+ switch_to_thread (thr);
5317+ else
5318+ {
5319+ inferior *inf = find_inferior_ptid (ecs->target, ecs->ptid);
5320+ switch_to_inferior_no_thread (inf);
5321+ }
5322+ }
53445323 handle_vfork_child_exec_or_exit (0);
53455324 target_terminal::ours (); /* Must do this before mourn anyway. */
53465325