GNU Binutils with patches for OS216
Révision | 7fdeda6cd99c4998d2211a3f54b591d73c0b1a8b (tree) |
---|---|
l'heure | 2020-06-04 04:19:06 |
Auteur | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
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.
@@ -485,8 +485,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \ | ||
485 | 485 | switch_to_no_thread (); |
486 | 486 | child_inf->symfile_flags = SYMFILE_NO_READ; |
487 | 487 | 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); | |
490 | 490 | |
491 | 491 | /* If this is a vfork child, then the address-space is |
492 | 492 | shared with the parent. */ |
@@ -504,6 +504,11 @@ holding the child stopped. Try \"set detach-on-fork\" or \ | ||
504 | 504 | child_inf->pending_detach = 0; |
505 | 505 | parent_inf->vfork_child = child_inf; |
506 | 506 | 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); | |
507 | 512 | } |
508 | 513 | else |
509 | 514 | { |
@@ -513,6 +518,10 @@ holding the child stopped. Try \"set detach-on-fork\" or \ | ||
513 | 518 | set_current_program_space (child_inf->pspace); |
514 | 519 | clone_program_space (child_inf->pspace, parent_inf->pspace); |
515 | 520 | |
521 | + /* solib_create_inferior_hook relies on the current | |
522 | + thread. */ | |
523 | + switch_to_thread (child_thr); | |
524 | + | |
516 | 525 | /* Let the shared library layer (e.g., solib-svr4) learn |
517 | 526 | about this new process, relocate the cloned exec, pull |
518 | 527 | in shared libraries, and install the solib event |
@@ -628,8 +637,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ | ||
628 | 637 | push_target (target); |
629 | 638 | } |
630 | 639 | |
631 | - add_thread_silent (target, child_ptid); | |
632 | - inferior_ptid = child_ptid; | |
640 | + thread_info *child_thr = add_thread_silent (target, child_ptid); | |
633 | 641 | |
634 | 642 | /* If this is a vfork child, then the address-space is shared |
635 | 643 | 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 \ | ||
657 | 665 | the core, this wouldn't be required. */ |
658 | 666 | solib_create_inferior_hook (0); |
659 | 667 | } |
668 | + | |
669 | + switch_to_thread (child_thr); | |
660 | 670 | } |
661 | 671 | |
662 | 672 | return target_follow_fork (follow_child, detach_fork); |
@@ -904,22 +914,6 @@ proceed_after_vfork_done (struct thread_info *thread, | ||
904 | 914 | return 0; |
905 | 915 | } |
906 | 916 | |
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 | - | |
923 | 917 | /* Called whenever we notice an exec or exit event, to handle |
924 | 918 | detaching or resuming a vfork parent. */ |
925 | 919 |
@@ -942,7 +936,6 @@ handle_vfork_child_exec_or_exit (int exec) | ||
942 | 936 | time. */ |
943 | 937 | if (vfork_parent->pending_detach) |
944 | 938 | { |
945 | - struct thread_info *tp; | |
946 | 939 | struct program_space *pspace; |
947 | 940 | struct address_space *aspace; |
948 | 941 |
@@ -950,20 +943,10 @@ handle_vfork_child_exec_or_exit (int exec) | ||
950 | 943 | |
951 | 944 | vfork_parent->pending_detach = 0; |
952 | 945 | |
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; | |
964 | 947 | |
965 | 948 | /* 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); | |
967 | 950 | switch_to_thread (tp); |
968 | 951 | |
969 | 952 | /* We're about to detach from the parent, which implicitly |
@@ -1032,11 +1015,11 @@ handle_vfork_child_exec_or_exit (int exec) | ||
1032 | 1015 | go ahead and create a new one for this exiting |
1033 | 1016 | inferior. */ |
1034 | 1017 | |
1035 | - /* Switch to null_ptid while running clone_program_space, so | |
1018 | + /* Switch to no-thread while running clone_program_space, so | |
1036 | 1019 | that clone_program_space doesn't want to read the |
1037 | 1020 | 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 (); | |
1040 | 1023 | |
1041 | 1024 | inf->pspace = new program_space (maybe_new_address_space ()); |
1042 | 1025 | inf->aspace = inf->pspace->aspace; |
@@ -4622,25 +4605,6 @@ wait_one () | ||
4622 | 4605 | } |
4623 | 4606 | } |
4624 | 4607 | |
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 | - | |
4644 | 4608 | /* Save the thread's event and stop reason to process it later. */ |
4645 | 4609 | |
4646 | 4610 | static void |
@@ -4672,19 +4636,22 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus *ws) | ||
4672 | 4636 | |
4673 | 4637 | adjust_pc_after_break (tp, &tp->suspend.waitstatus); |
4674 | 4638 | |
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 ()) | |
4676 | 4643 | { |
4677 | 4644 | tp->suspend.stop_reason |
4678 | 4645 | = TARGET_STOPPED_BY_WATCHPOINT; |
4679 | 4646 | } |
4680 | 4647 | else if (target_supports_stopped_by_sw_breakpoint () |
4681 | - && thread_stopped_by_sw_breakpoint (tp->ptid)) | |
4648 | + && target_stopped_by_sw_breakpoint ()) | |
4682 | 4649 | { |
4683 | 4650 | tp->suspend.stop_reason |
4684 | 4651 | = TARGET_STOPPED_BY_SW_BREAKPOINT; |
4685 | 4652 | } |
4686 | 4653 | else if (target_supports_stopped_by_hw_breakpoint () |
4687 | - && thread_stopped_by_hw_breakpoint (tp->ptid)) | |
4654 | + && target_stopped_by_hw_breakpoint ()) | |
4688 | 4655 | { |
4689 | 4656 | tp->suspend.stop_reason |
4690 | 4657 | = TARGET_STOPPED_BY_HW_BREAKPOINT; |
@@ -5338,9 +5305,21 @@ handle_inferior_event (struct execution_control_state *ecs) | ||
5338 | 5305 | |
5339 | 5306 | case TARGET_WAITKIND_EXITED: |
5340 | 5307 | 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 | + } | |
5344 | 5323 | handle_vfork_child_exec_or_exit (0); |
5345 | 5324 | target_terminal::ours (); /* Must do this before mourn anyway. */ |
5346 | 5325 |