@@ -7110,6 +7110,9 @@ process_event_stop_test (struct execution_control_state *ecs)
7110
7110
keep_going (ecs );
7111
7111
}
7112
7112
7113
+ static bool restart_stepped_thread (process_stratum_target * resume_target ,
7114
+ ptid_t resume_ptid );
7115
+
7113
7116
/* In all-stop mode, if we're currently stepping but have stopped in
7114
7117
some other thread, we may need to switch back to the stepped
7115
7118
thread. Returns true we set the inferior running, false if we left
@@ -7120,8 +7123,6 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs)
7120
7123
{
7121
7124
if (!target_is_non_stop_p ())
7122
7125
{
7123
- struct thread_info * stepping_thread ;
7124
-
7125
7126
/* If any thread is blocked on some internal breakpoint, and we
7126
7127
simply need to step over that breakpoint to get it going
7127
7128
again, do that first. */
@@ -7184,78 +7185,136 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs)
7184
7185
if (!signal_program [ecs -> event_thread -> suspend .stop_signal ])
7185
7186
ecs -> event_thread -> suspend .stop_signal = GDB_SIGNAL_0 ;
7186
7187
7187
- /* Do all pending step-overs before actually proceeding with
7188
- step/next/etc. */
7189
- if (start_step_over ())
7188
+ if (restart_stepped_thread (ecs -> target , ecs -> ptid ))
7190
7189
{
7191
7190
prepare_to_wait (ecs );
7192
7191
return true;
7193
7192
}
7194
7193
7195
- /* Look for the stepping/nexting thread. */
7196
- stepping_thread = NULL;
7194
+ switch_to_thread ( ecs -> event_thread );
7195
+ }
7197
7196
7198
- for (thread_info * tp : all_non_exited_threads ())
7199
- {
7200
- switch_to_thread_no_regs (tp );
7197
+ return false;
7198
+ }
7201
7199
7202
- /* Ignore threads of processes the caller is not
7203
- resuming. */
7204
- if (!sched_multi
7205
- && (tp -> inf -> process_target () != ecs -> target
7206
- || tp -> inf -> pid != ecs -> ptid .pid ()))
7207
- continue ;
7200
+ /* Look for the thread that was stepping, and resume it.
7201
+ RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7202
+ is resuming. Return true if a thread was started, false
7203
+ otherwise. */
7208
7204
7209
- /* When stepping over a breakpoint, we lock all threads
7210
- except the one that needs to move past the breakpoint.
7211
- If a non-event thread has this set, the "incomplete
7212
- step-over" check above should have caught it earlier. */
7213
- if (tp -> control .trap_expected )
7214
- {
7215
- internal_error (__FILE__ , __LINE__ ,
7216
- "[%s] has inconsistent state: "
7217
- "trap_expected=%d\n" ,
7218
- target_pid_to_str (tp -> ptid ).c_str (),
7219
- tp -> control .trap_expected );
7220
- }
7205
+ static bool
7206
+ restart_stepped_thread (process_stratum_target * resume_target ,
7207
+ ptid_t resume_ptid )
7208
+ {
7209
+ /* Do all pending step-overs before actually proceeding with
7210
+ step/next/etc. */
7211
+ if (start_step_over ())
7212
+ return true;
7221
7213
7222
- /* Did we find the stepping thread? */
7223
- if (tp -> control .step_range_end )
7224
- {
7225
- /* Yep. There should only one though. */
7226
- gdb_assert (stepping_thread == NULL );
7214
+ for (thread_info * tp : all_threads_safe ())
7215
+ {
7216
+ if (tp -> state == THREAD_EXITED )
7217
+ continue ;
7218
+
7219
+ if (tp -> suspend .waitstatus_pending_p )
7220
+ continue ;
7227
7221
7228
- /* The event thread is handled at the top, before we
7229
- enter this loop. */
7230
- gdb_assert (tp != ecs -> event_thread );
7222
+ /* Ignore threads of processes the caller is not
7223
+ resuming. */
7224
+ if (!sched_multi
7225
+ && (tp -> inf -> process_target () != resume_target
7226
+ || tp -> inf -> pid != resume_ptid .pid ()))
7227
+ continue ;
7231
7228
7232
- /* If some thread other than the event thread is
7233
- stepping, then scheduler locking can't be in effect,
7234
- otherwise we wouldn't have resumed the current event
7235
- thread in the first place. */
7236
- gdb_assert (!schedlock_applies (tp ));
7229
+ if (tp -> control .trap_expected )
7230
+ {
7231
+ infrun_debug_printf ("switching back to stepped thread (step-over)" );
7237
7232
7238
- stepping_thread = tp ;
7239
- }
7233
+ if ( keep_going_stepped_thread ( tp ))
7234
+ return true;
7240
7235
}
7236
+ }
7237
+
7238
+ for (thread_info * tp : all_threads_safe ())
7239
+ {
7240
+ if (tp -> state == THREAD_EXITED )
7241
+ continue ;
7242
+
7243
+ if (tp -> suspend .waitstatus_pending_p )
7244
+ continue ;
7241
7245
7242
- if (stepping_thread != NULL )
7246
+ /* Ignore threads of processes the caller is not
7247
+ resuming. */
7248
+ if (!sched_multi
7249
+ && (tp -> inf -> process_target () != resume_target
7250
+ || tp -> inf -> pid != resume_ptid .pid ()))
7251
+ continue ;
7252
+
7253
+ /* Did we find the stepping thread? */
7254
+ if (tp -> control .step_range_end )
7243
7255
{
7244
- infrun_debug_printf ("switching back to stepped thread" );
7256
+ infrun_debug_printf ("switching back to stepped thread (stepping) " );
7245
7257
7246
- if (keep_going_stepped_thread (stepping_thread ))
7247
- {
7248
- prepare_to_wait (ecs );
7249
- return true;
7250
- }
7258
+ if (keep_going_stepped_thread (tp ))
7259
+ return true;
7251
7260
}
7252
-
7253
- switch_to_thread (ecs -> event_thread );
7254
7261
}
7255
7262
7256
7263
return false;
7257
7264
}
7258
7265
7266
+ /* See infrun.h. */
7267
+
7268
+ void
7269
+ restart_after_all_stop_detach (process_stratum_target * proc_target )
7270
+ {
7271
+ /* Note we don't check target_is_non_stop_p() here, because the
7272
+ current inferior may no longer have a process_stratum target
7273
+ pushed, as we just detached. */
7274
+
7275
+ /* See if we have a THREAD_RUNNING thread that need to be
7276
+ re-resumed. If we have any thread that is already executing,
7277
+ then we don't need to resume the target -- it is already been
7278
+ resumed. With the remote target (in all-stop), it's even
7279
+ impossible to issue another resumption if the target is already
7280
+ resumed, until the target reports a stop. */
7281
+ for (thread_info * thr : all_threads (proc_target ))
7282
+ {
7283
+ if (thr -> state != THREAD_RUNNING )
7284
+ continue ;
7285
+
7286
+ /* If we have any thread that is already executing, then we
7287
+ don't need to resume the target -- it is already been
7288
+ resumed. */
7289
+ if (thr -> executing )
7290
+ return ;
7291
+
7292
+ /* If we have a pending event to process, skip resuming the
7293
+ target and go straight to processing it. */
7294
+ if (thr -> resumed && thr -> suspend .waitstatus_pending_p )
7295
+ return ;
7296
+ }
7297
+
7298
+ /* Alright, we need to re-resume the target. If a thread was
7299
+ stepping, we need to restart it stepping. */
7300
+ if (restart_stepped_thread (proc_target , minus_one_ptid ))
7301
+ return ;
7302
+
7303
+ /* Otherwise, find the first THREAD_RUNNING thread and resume
7304
+ it. */
7305
+ for (thread_info * thr : all_threads (proc_target ))
7306
+ {
7307
+ if (thr -> state != THREAD_RUNNING )
7308
+ continue ;
7309
+
7310
+ execution_control_state ecs ;
7311
+ reset_ecs (& ecs , thr );
7312
+ switch_to_thread (thr );
7313
+ keep_going (& ecs );
7314
+ return ;
7315
+ }
7316
+ }
7317
+
7259
7318
/* Set a previously stepped thread back to stepping. Returns true on
7260
7319
success, false if the resume is not possible (e.g., the thread
7261
7320
vanished). */
0 commit comments