delete &f;
*/
-inline all_threads_safe_range
-all_threads_safe ()
+inline all_matching_threads_safe_range
+all_threads_safe (process_stratum_target *proc_target = nullptr,
+ ptid_t filter_ptid = minus_one_ptid)
{
- all_threads_iterator begin (all_threads_iterator::begin_t {});
- all_threads_safe_iterator safe_begin (std::move (begin));
+ all_matching_threads_iterator begin (proc_target, filter_ptid);
+ all_matching_threads_safe_iterator safe_begin (std::move (begin));
- return all_threads_safe_range (std::move (safe_begin));
+ return all_matching_threads_safe_range (std::move (safe_begin));
}
extern int thread_count (process_stratum_target *proc_target);
follow_exec (ptid_t ptid, const char *exec_file_target)
{
int pid = ptid.pid ();
- ptid_t process_ptid;
+ ptid_t process_ptid (pid);
/* Switch terminal for any messages produced e.g. by
breakpoint_re_set. */
them. Deleting them now rather than at the next user-visible
stop provides a nicer sequence of events for user and MI
notifications. */
- for (thread_info &th : all_threads_safe ())
- if (th.ptid.pid () == pid && th.ptid != ptid)
+ process_stratum_target *target = current_inferior ()->process_target ();
+ for (thread_info &th : all_threads_safe (target, process_ptid))
+ if (th.ptid != ptid)
delete_thread (&th);
/* We also need to clear any left over stale state for the
update_breakpoints_after_exec ();
/* What is this a.out's name? */
- process_ptid = ptid_t (pid);
gdb_printf (_("%s is executing new program: %s\n"),
target_pid_to_str (process_ptid).c_str (),
exec_file_target);
/* CONTEXT now holds the current thread list on the remote
target end. Delete GDB-side threads no longer found on the
target. */
- for (thread_info &tp : all_threads_safe ())
- {
- if (tp.inf->process_target () != this)
- continue;
-
- if (!context.contains_thread (tp.ptid))
- {
- /* Do not remove the thread if it is the last thread in
- the inferior. This situation happens when we have a
- pending exit process status to process. Otherwise we
- may end up with a seemingly live inferior (i.e. pid
- != 0) that has no threads. */
- if (has_single_non_exited_thread (tp.inf))
- continue;
+ for (thread_info &tp : all_threads_safe (this))
+ if (!context.contains_thread (tp.ptid))
+ {
+ /* Do not remove the thread if it is the last thread in
+ the inferior. This situation happens when we have a
+ pending exit process status to process. Otherwise we
+ may end up with a seemingly live inferior (i.e. pid
+ != 0) that has no threads. */
+ if (has_single_non_exited_thread (tp.inf))
+ continue;
- /* Do not remove the thread if we've requested to be
- notified of its exit. For example, the thread may be
- displaced stepping, infrun will need to handle the
- exit event, and displaced stepping info is recorded
- in the thread object. If we deleted the thread now,
- we'd lose that info. */
- if ((tp.thread_options () & GDB_THREAD_OPTION_EXIT) != 0)
- continue;
+ /* Do not remove the thread if we've requested to be
+ notified of its exit. For example, the thread may be
+ displaced stepping, infrun will need to handle the
+ exit event, and displaced stepping info is recorded
+ in the thread object. If we deleted the thread now,
+ we'd lose that info. */
+ if ((tp.thread_options () & GDB_THREAD_OPTION_EXIT) != 0)
+ continue;
- /* Not found. */
- delete_thread (&tp);
- }
- }
+ /* Not found. */
+ delete_thread (&tp);
+ }
/* Remove any unreported fork/vfork/clone child threads from
CONTEXT so that we don't interfere with follow
using inf_non_exited_threads_iterator
= filtered_iterator<inf_threads_iterator, non_exited_thread_filter>;
-/* Iterate over all threads of all inferiors, safely. */
+/* Iterate over all threads that are matched by the wrapped
+ iterator, safely. */
-using all_threads_safe_iterator
- = basic_safe_iterator<all_threads_iterator>;
+using all_matching_threads_safe_iterator
+ = basic_safe_iterator<all_matching_threads_iterator>;
/* Iterate over all threads of an inferior, safely. */
using safe_inf_threads_range = iterator_range<safe_inf_threads_iterator>;
/* A range adapter that makes it possible to iterate over all threads
- with range-for "safely". I.e., it is safe to delete the
- currently-iterated thread. */
+ that are matched by the given iterator with range-for "safely". I.e.,
+ it is safe to delete the currently-iterated thread. */
-using all_threads_safe_range = iterator_range<all_threads_safe_iterator>;
+using all_matching_threads_safe_range
+ = iterator_range<all_matching_threads_safe_iterator>;
/* A range adapter that makes it possible to iterate over all threads
that match a PTID filter with range-for. */