gdb: Eliminate the 'stop_pc' global

In my multi-target work, I need to add a few more
scoped_restore_current_thread and switch_to_thread calls in some
places, and in some lower-level places I was fighting against the fact
that switch_to_thread reads/refreshes the stop_pc global.

Instead of piling on workarounds, let's just finally eliminate the
stop_pc global.  We already have the per-thread
thread_info->suspend.stop_pc field, so it's mainly a matter of using
that more/instead.

gdb/ChangeLog:
2018-06-28  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct thread_suspend_state) <stop_pc>: Extend
	comments.
	(switch_to_thread_no_regs): Adjust comment.
	* infcmd.c (stop_pc): Delete.
	(post_create_inferior, info_program_command): Replace references
	to stop_pc with references to thread_info->suspend.stop_pc.
	* inferior.h (stop_pc): Delete declaration.
	* infrun.c (proceed, handle_syscall_event, fill_in_stop_func)
	(handle_inferior_event_1, handle_signal_stop)
	(process_event_stop_test, keep_going_stepped_thread)
	(handle_step_into_function, handle_step_into_function_backward)
	(print_stop_location): Replace references to stop_pc with
	references to thread_info->suspend.stop_pc.
	(struct infcall_suspend_state) <stop_pc>: Delete field.
	(save_infcall_suspend_state, restore_infcall_suspend_state):
	Remove references to inf_stat->stop_pc.
	* linux-fork.c (fork_load_infrun_state): Likewise.
	* record-btrace.c (record_btrace_set_replay): Likewise.
	* record-full.c (record_full_goto_entry): Likewise.
	* remote.c (print_one_stopped_thread): Likewise.
	* target.c (target_resume): Extend comment.
	* thread.c (set_executing_thread): New.
	(set_executing): Use it.
	(switch_to_thread_no_regs, switch_to_no_thread, switch_to_thread):
	Remove references to stop_pc.
This commit is contained in:
Pedro Alves 2018-06-28 20:18:24 +01:00
parent ecdc3a72c8
commit f2ffa92bbc
11 changed files with 139 additions and 79 deletions

View file

@ -918,6 +918,18 @@ is_executing (ptid_t ptid)
return tp->executing;
}
/* Helper for set_executing. Set's the thread's 'executing' field
from EXECUTING, and if EXECUTING is true also clears the thread's
stop_pc. */
static void
set_executing_thread (thread_info *thr, bool executing)
{
thr->executing = executing;
if (executing)
thr->suspend.stop_pc = ~(CORE_ADDR) 0;
}
void
set_executing (ptid_t ptid, int executing)
{
@ -928,13 +940,13 @@ set_executing (ptid_t ptid, int executing)
{
for (tp = thread_list; tp; tp = tp->next)
if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
tp->executing = executing;
set_executing_thread (tp, executing);
}
else
{
tp = find_thread_ptid (ptid);
gdb_assert (tp);
tp->executing = executing;
set_executing_thread (tp, executing);
}
/* It only takes one running thread to spawn more threads.*/
@ -1328,7 +1340,6 @@ switch_to_thread_no_regs (struct thread_info *thread)
set_current_inferior (inf);
inferior_ptid = thread->ptid;
stop_pc = ~(CORE_ADDR) 0;
}
/* See gdbthread.h. */
@ -1341,7 +1352,6 @@ switch_to_no_thread ()
inferior_ptid = null_ptid;
reinit_frame_cache ();
stop_pc = ~(CORE_ADDR) 0;
}
/* See gdbthread.h. */
@ -1357,13 +1367,6 @@ switch_to_thread (thread_info *thr)
switch_to_thread_no_regs (thr);
reinit_frame_cache ();
/* We don't check for is_stopped, because we're called at times
while in the TARGET_RUNNING state, e.g., while handling an
internal event. */
if (thr->state != THREAD_EXITED
&& !thr->executing)
stop_pc = regcache_read_pc (get_thread_regcache (thr));
}
/* See common/common-gdbthread.h. */