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

Commit f2ffa92

Browse files
committed
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 <[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.
1 parent ecdc3a7 commit f2ffa92

11 files changed

+139
-79
lines changed

gdb/ChangeLog

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
2018-06-28 Pedro Alves <[email protected]>
2+
3+
* gdbthread.h (struct thread_suspend_state) <stop_pc>: Extend
4+
comments.
5+
(switch_to_thread_no_regs): Adjust comment.
6+
* infcmd.c (stop_pc): Delete.
7+
(post_create_inferior, info_program_command): Replace references
8+
to stop_pc with references to thread_info->suspend.stop_pc.
9+
* inferior.h (stop_pc): Delete declaration.
10+
* infrun.c (proceed, handle_syscall_event, fill_in_stop_func)
11+
(handle_inferior_event_1, handle_signal_stop)
12+
(process_event_stop_test, keep_going_stepped_thread)
13+
(handle_step_into_function, handle_step_into_function_backward)
14+
(print_stop_location): Replace references to stop_pc with
15+
references to thread_info->suspend.stop_pc.
16+
(struct infcall_suspend_state) <stop_pc>: Delete field.
17+
(save_infcall_suspend_state, restore_infcall_suspend_state):
18+
Remove references to inf_stat->stop_pc.
19+
* linux-fork.c (fork_load_infrun_state): Likewise.
20+
* record-btrace.c (record_btrace_set_replay): Likewise.
21+
* record-full.c (record_full_goto_entry): Likewise.
22+
* remote.c (print_one_stopped_thread): Likewise.
23+
* target.c (target_resume): Extend comment.
24+
* thread.c (set_executing_thread): New.
25+
(set_executing): Use it.
26+
(switch_to_thread_no_regs, switch_to_no_thread, switch_to_thread):
27+
Remove references to stop_pc.
28+
129
2018-06-28 Pedro Alves <[email protected]>
230

331
* infrun.c (handle_inferior_event_1) <TARGET_WAITKIND_EXECD>:

gdb/gdbthread.h

+14-6
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,19 @@ struct thread_suspend_state
168168

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

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

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

505513
/* Marks or clears thread(s) PTID as resumed. If PTID is

gdb/infcmd.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ static char *inferior_io_terminal_scratch;
9494

9595
ptid_t inferior_ptid;
9696

97-
/* Address at which inferior stopped. */
98-
99-
CORE_ADDR stop_pc;
100-
10197
/* Nonzero if stopped due to completion of a stack dummy routine. */
10298

10399
enum stop_stack_kind stop_stack_dummy;
@@ -448,10 +444,12 @@ post_create_inferior (struct target_ops *target, int from_tty)
448444
/* Now that we know the register layout, retrieve current PC. But
449445
if the PC is unavailable (e.g., we're opening a core file with
450446
missing registers info), ignore it. */
451-
stop_pc = 0;
447+
thread_info *thr = inferior_thread ();
448+
449+
thr->suspend.stop_pc = 0;
452450
TRY
453451
{
454-
stop_pc = regcache_read_pc (get_current_regcache ());
452+
thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());
455453
}
456454
CATCH (ex, RETURN_MASK_ERROR)
457455
{
@@ -2108,7 +2106,7 @@ info_program_command (const char *args, int from_tty)
21082106

21092107
target_files_info ();
21102108
printf_filtered (_("Program stopped at %s.\n"),
2111-
paddress (target_gdbarch (), stop_pc));
2109+
paddress (target_gdbarch (), tp->suspend.stop_pc));
21122110
if (tp->control.stop_step)
21132111
printf_filtered (_("It stopped after being stepped.\n"));
21142112
else if (stat != 0)

gdb/inferior.h

-4
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ extern void prepare_execution_command (struct target_ops *target,
208208
the target is started up with a shell. */
209209
extern int startup_with_shell;
210210

211-
/* Address at which inferior stopped. */
212-
213-
extern CORE_ADDR stop_pc;
214-
215211
/* Nonzero if stopped due to completion of a stack dummy routine. */
216212

217213
extern enum stop_stack_kind stop_stack_dummy;

0 commit comments

Comments
 (0)