Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
gdb: Eliminate the 'stop_pc' global
Browse files Browse the repository at this point in the history
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  <[email protected]>

	* 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.
  • Loading branch information
palves committed Jun 28, 2018
1 parent ecdc3a7 commit f2ffa92
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 79 deletions.
28 changes: 28 additions & 0 deletions gdb/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
2018-06-28 Pedro Alves <[email protected]>

* 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.

2018-06-28 Pedro Alves <[email protected]>

* infrun.c (handle_inferior_event_1) <TARGET_WAITKIND_EXECD>:
Expand Down
20 changes: 14 additions & 6 deletions gdb/gdbthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,19 @@ struct thread_suspend_state

/* Record the pc of the thread the last time it stopped. (This is
not the current thread's PC as that may have changed since the
last stop, e.g., "return" command, or "p $pc = 0xf000"). This is
used in coordination with stop_reason and waitstatus_pending_p:
if the thread's PC is changed since it last stopped, a pending
breakpoint waitstatus is discarded. */
last stop, e.g., "return" command, or "p $pc = 0xf000").
- If the thread's PC has not changed since the thread last
stopped, then proceed skips a breakpoint at the current PC,
otherwise we let the thread run into the breakpoint.
- If the thread has an unprocessed event pending, as indicated by
waitstatus_pending_p, this is used in coordination with
stop_reason: if the thread's PC has changed since the thread
last stopped, a pending breakpoint waitstatus is discarded.
- If the thread is running, this is set to -1, to avoid leaving
it with a stale value, to make it easier to catch bugs. */
CORE_ADDR stop_pc;
};

Expand Down Expand Up @@ -498,8 +507,7 @@ extern void switch_to_thread (struct thread_info *thr);
/* Switch context to no thread selected. */
extern void switch_to_no_thread ();

/* Switch from one thread to another. Does not read registers and
sets STOP_PC to -1. */
/* Switch from one thread to another. Does not read registers. */
extern void switch_to_thread_no_regs (struct thread_info *thread);

/* Marks or clears thread(s) PTID as resumed. If PTID is
Expand Down
12 changes: 5 additions & 7 deletions gdb/infcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ static char *inferior_io_terminal_scratch;

ptid_t inferior_ptid;

/* Address at which inferior stopped. */

CORE_ADDR stop_pc;

/* Nonzero if stopped due to completion of a stack dummy routine. */

enum stop_stack_kind stop_stack_dummy;
Expand Down Expand Up @@ -448,10 +444,12 @@ post_create_inferior (struct target_ops *target, int from_tty)
/* Now that we know the register layout, retrieve current PC. But
if the PC is unavailable (e.g., we're opening a core file with
missing registers info), ignore it. */
stop_pc = 0;
thread_info *thr = inferior_thread ();

thr->suspend.stop_pc = 0;
TRY
{
stop_pc = regcache_read_pc (get_current_regcache ());
thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());
}
CATCH (ex, RETURN_MASK_ERROR)
{
Expand Down Expand Up @@ -2108,7 +2106,7 @@ info_program_command (const char *args, int from_tty)

target_files_info ();
printf_filtered (_("Program stopped at %s.\n"),
paddress (target_gdbarch (), stop_pc));
paddress (target_gdbarch (), tp->suspend.stop_pc));
if (tp->control.stop_step)
printf_filtered (_("It stopped after being stepped.\n"));
else if (stat != 0)
Expand Down
4 changes: 0 additions & 4 deletions gdb/inferior.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ extern void prepare_execution_command (struct target_ops *target,
the target is started up with a shell. */
extern int startup_with_shell;

/* Address at which inferior stopped. */

extern CORE_ADDR stop_pc;

/* Nonzero if stopped due to completion of a stack dummy routine. */

extern enum stop_stack_kind stop_stack_dummy;
Expand Down
Loading

0 comments on commit f2ffa92

Please sign in to comment.