void thread_change_ptid (process_stratum_target *targ,
ptid_t old_ptid, ptid_t new_ptid);
-/* Callback function type for function for_each_thread. */
-
-using for_each_thread_callback_ftype
- = gdb::function_view<void (thread_info *)>;
-
-/* Call CALLBACK once for each known thread.
-
- CALLBACK must not delete the thread. To delete threads, use:
-
- for (thread_info &t : all_threads_safe ())
- if (some_condition ())
- delete &t;
-*/
-
-extern void for_each_thread (for_each_thread_callback_ftype callback);
-
/* Callback function type for function find_thread. */
using find_thread_callback_ftype = gdb::function_view<bool (thread_info *)>;
run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
}
-static void
-proceed_thread_callback (struct thread_info *thread)
-{
- /* We go through all threads individually instead of compressing
- into a single target `resume_all' request, because some threads
- may be stopped in internal breakpoints/events, or stopped waiting
- for its turn in the displaced stepping queue (that is, they are
- running from the user's perspective but internally stopped). The
- target side has no idea about why the thread is stopped, so a
- `resume_all' command would resume too much. If/when GDB gains a
- way to tell the target `hold this thread stopped until I say
- otherwise', then we can optimize this. */
- if (thread->state () != THREAD_STOPPED)
- return;
-
- if (!thread->inf->has_execution ())
- return;
-
- switch_to_thread (thread);
- clear_proceed_status (0);
- proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
-}
-
static void
ensure_valid_thread (void)
{
scoped_disable_commit_resumed disable_commit_resumed
("continue all threads in non-stop");
- for_each_thread (proceed_thread_callback);
+ for (auto &thread : all_threads ())
+ {
+ /* We go through all threads individually instead of compressing
+ into a single target `resume_all' request, because some threads
+ may be stopped in internal breakpoints/events, or stopped waiting
+ for its turn in the displaced stepping queue (that is, they are
+ running from the user's perspective but internally stopped). The
+ target side has no idea about why the thread is stopped, so a
+ `resume_all' command would resume too much. If/when GDB gains a
+ way to tell the target `hold this thread stopped until I say
+ otherwise', then we can optimize this. */
+ if (thread.state () != THREAD_STOPPED)
+ continue;
+
+ if (!thread.inf->has_execution ())
+ continue;
+
+ switch_to_thread (&thread);
+ clear_proceed_status (0);
+ proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
+ }
if (current_ui->prompt_state == PROMPT_BLOCKED)
{
- /* If all threads in the target were already running,
- proceed_thread_callback ends up never calling proceed,
- and so nothing calls this to put the inferior's terminal
- settings in effect and remove stdin from the event loop,
- which we must when running a foreground command. E.g.:
+ /* If all threads in the target were already running, the
+ above ends up never calling proceed, and so nothing calls
+ this to put the inferior's terminal settings in effect
+ and remove stdin from the event loop, which we must when
+ running a foreground command. E.g.:
(gdb) c -a&
Continuing.
pid = inf->pid;
}
- for_each_thread ([&] (struct thread_info *thread)
- {
- proceed_thread (thread, pid);
- });
+ for (auto &thread : all_threads ())
+ proceed_thread (&thread, pid);
disable_commit_resumed.reset_and_commit ();
}
else
scoped_disable_commit_resumed disable_commit_resumed
("interrupting all threads of thread group");
- for_each_thread ([&] (struct thread_info *thread)
+ for (auto &thread : all_threads ())
{
- if (thread->state () != THREAD_RUNNING)
- return;
+ if (thread.state () != THREAD_RUNNING)
+ continue;
- if (thread->ptid.pid () != inf->pid)
- return;
+ if (thread.ptid.pid () != inf->pid)
+ continue;
- target_stop (thread->ptid);
- });
+ target_stop (thread.ptid);
+ }
}
else
{
if (inferior->pid != 0)
{
- for_each_thread ([&] (struct thread_info *ti)
- {
- if (ti->ptid.pid () == inferior->pid)
- {
- int core = target_core_of_thread (ti->ptid);
+ for (auto &ti : all_threads ())
+ if (ti.ptid.pid () == inferior->pid)
+ {
+ int core = target_core_of_thread (ti.ptid);
- if (core != -1)
- cores.insert (core);
- }
- });
+ if (core != -1)
+ cores.insert (core);
+ }
}
if (!cores.empty ())