gdb: change inf_threads_iterator to yield references

When adding reference_to_pointer_iterator, I saw it as a temporary
thing, to not have to do a codebase-wide change right away.  Remove it
from inf_threads_iterator and adjust all the users.

It's very possible that I forgot to update some spots in the files I
can't compile, but it will be very easy to fix if that happens.

Change-Id: Iddc462fecfaafb6a9861d185b217bc714e7dc651
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Simon Marchi
2025-09-03 10:49:57 -04:00
committed by Simon Marchi
parent 7f1cdb3e37
commit 1ad8737b3c
30 changed files with 350 additions and 353 deletions

View File

@@ -293,10 +293,10 @@ void
aarch64_notify_debug_reg_change (ptid_t ptid, aarch64_notify_debug_reg_change (ptid_t ptid,
int is_watchpoint, unsigned int idx) int is_watchpoint, unsigned int idx)
{ {
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
{ {
if (tp->ptid.lwp_p ()) if (tp.ptid.lwp_p ())
aarch64_debug_pending_threads.emplace (tp->ptid.lwp ()); aarch64_debug_pending_threads.emplace (tp.ptid.lwp ());
} }
} }

View File

@@ -775,18 +775,18 @@ amd_dbgapi_target::resume (ptid_t scope_ptid, int step, enum gdb_signal signo)
/* Disable forward progress requirement. */ /* Disable forward progress requirement. */
require_forward_progress (scope_ptid, proc_target, false); require_forward_progress (scope_ptid, proc_target, false);
for (thread_info *thread : all_non_exited_threads (proc_target, scope_ptid)) for (thread_info &thread : all_non_exited_threads (proc_target, scope_ptid))
{ {
if (!ptid_is_gpu (thread->ptid)) if (!ptid_is_gpu (thread.ptid))
continue; continue;
amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (thread->ptid); amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (thread.ptid);
amd_dbgapi_status_t status; amd_dbgapi_status_t status;
wave_info &wi = get_thread_wave_info (thread); wave_info &wi = get_thread_wave_info (&thread);
amd_dbgapi_resume_mode_t &resume_mode = wi.last_resume_mode; amd_dbgapi_resume_mode_t &resume_mode = wi.last_resume_mode;
amd_dbgapi_exceptions_t wave_exception; amd_dbgapi_exceptions_t wave_exception;
if (thread->ptid == inferior_ptid) if (thread.ptid == inferior_ptid)
{ {
resume_mode = (step resume_mode = (step
? AMD_DBGAPI_RESUME_MODE_SINGLE_STEP ? AMD_DBGAPI_RESUME_MODE_SINGLE_STEP
@@ -934,10 +934,10 @@ amd_dbgapi_target::stop (ptid_t ptid)
for (auto *inf : all_inferiors (proc_target)) for (auto *inf : all_inferiors (proc_target))
/* Use the threads_safe iterator since stop_one_thread may delete the /* Use the threads_safe iterator since stop_one_thread may delete the
thread if it has exited. */ thread if it has exited. */
for (auto *thread : inf->threads_safe ()) for (auto &thread : inf->threads_safe ())
if (thread->state != THREAD_EXITED && thread->ptid.matches (ptid) if (thread.state != THREAD_EXITED && thread.ptid.matches (ptid)
&& ptid_is_gpu (thread->ptid)) && ptid_is_gpu (thread.ptid))
stop_one_thread (thread); stop_one_thread (&thread);
} }
/* Callback for our async event handler. */ /* Callback for our async event handler. */
@@ -1883,15 +1883,15 @@ amd_dbgapi_target::update_thread_list ()
/* Prune the wave_ids that already have a thread_info. Any thread_info /* Prune the wave_ids that already have a thread_info. Any thread_info
which does not have a corresponding wave_id represents a wave which which does not have a corresponding wave_id represents a wave which
is gone at this point and should be deleted. */ is gone at this point and should be deleted. */
for (thread_info *tp : inf->threads_safe ()) for (thread_info &tp : inf->threads_safe ())
if (ptid_is_gpu (tp->ptid) && tp->state != THREAD_EXITED) if (ptid_is_gpu (tp.ptid) && tp.state != THREAD_EXITED)
{ {
auto it = threads.find (tp->ptid.tid ()); auto it = threads.find (tp.ptid.tid ());
if (it == threads.end ()) if (it == threads.end ())
{ {
auto wave_id = get_amd_dbgapi_wave_id (tp->ptid); auto wave_id = get_amd_dbgapi_wave_id (tp.ptid);
wave_info &wi = get_thread_wave_info (tp); wave_info &wi = get_thread_wave_info (&tp);
/* Waves that were stepping or in progress of being /* Waves that were stepping or in progress of being
stopped are guaranteed to report a stopped are guaranteed to report a
@@ -1912,7 +1912,7 @@ amd_dbgapi_target::update_thread_list ()
{ {
amd_dbgapi_debug_printf ("wave_%ld disappeared, deleting it", amd_dbgapi_debug_printf ("wave_%ld disappeared, deleting it",
wave_id.handle); wave_id.handle);
delete_thread_silent (tp); delete_thread_silent (&tp);
} }
} }
else else
@@ -2117,7 +2117,7 @@ amd_dbgapi_inferior_forked (inferior *parent_inf, inferior *child_inf,
if (fork_kind != TARGET_WAITKIND_VFORKED) if (fork_kind != TARGET_WAITKIND_VFORKED)
{ {
scoped_restore_current_thread restore_thread; scoped_restore_current_thread restore_thread;
switch_to_thread (*child_inf->threads ().begin ()); switch_to_thread (&*child_inf->threads ().begin ());
attach_amd_dbgapi (child_inf); attach_amd_dbgapi (child_inf);
} }
} }

View File

@@ -624,8 +624,8 @@ breakpoints_should_be_inserted_now (void)
/* Don't remove breakpoints yet if, even though all threads are /* Don't remove breakpoints yet if, even though all threads are
stopped, we still have events to process. */ stopped, we still have events to process. */
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
if (tp->resumed () && tp->has_pending_waitstatus ()) if (tp.resumed () && tp.has_pending_waitstatus ())
return 1; return 1;
} }
return 0; return 0;

View File

@@ -2365,8 +2365,8 @@ btrace_free_objfile (struct objfile *objfile)
{ {
DEBUG ("free objfile"); DEBUG ("free objfile");
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
btrace_clear (tp); btrace_clear (&tp);
} }
/* See btrace.h. */ /* See btrace.h. */

View File

@@ -1690,7 +1690,7 @@ darwin_attach_pid (struct inferior *inf)
static struct thread_info * static struct thread_info *
thread_info_from_private_thread_info (darwin_thread_info *pti) thread_info_from_private_thread_info (darwin_thread_info *pti)
{ {
for (struct thread_info *it : all_threads ()) for (struct thread_info &it : all_threads ())
{ {
darwin_thread_info *iter_pti = get_darwin_thread_info (it); darwin_thread_info *iter_pti = get_darwin_thread_info (it);

View File

@@ -100,12 +100,12 @@ elf_none_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
gcore_elf_build_thread_register_notes (gdbarch, signalled_thr, gcore_elf_build_thread_register_notes (gdbarch, signalled_thr,
stop_signal, obfd, &note_data, stop_signal, obfd, &note_data,
note_size); note_size);
for (thread_info *thr : current_inferior ()->non_exited_threads ()) for (thread_info &thr : current_inferior ()->non_exited_threads ())
{ {
if (thr == signalled_thr) if (&thr == signalled_thr)
continue; continue;
gcore_elf_build_thread_register_notes (gdbarch, thr, stop_signal, obfd, gcore_elf_build_thread_register_notes (gdbarch, &thr, stop_signal, obfd,
&note_data, note_size); &note_data, note_size);
} }

View File

@@ -1203,7 +1203,7 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
return; return;
} }
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
/* If ptid is a specific LWP, suspend all other LWPs in the /* If ptid is a specific LWP, suspend all other LWPs in the
process, otherwise resume all LWPs in the process.. */ process, otherwise resume all LWPs in the process.. */
@@ -1887,7 +1887,7 @@ fbsd_nat_target::detach_fork_children (inferior *inf)
{ {
/* Detach any child processes associated with pending fork events in /* Detach any child processes associated with pending fork events in
threads belonging to this process. */ threads belonging to this process. */
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
detach_fork_children (tp); detach_fork_children (tp);
/* Unwind state associated with any pending events. Reset /* Unwind state associated with any pending events. Reset

View File

@@ -722,12 +722,12 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
enum gdb_signal stop_signal = signalled_thr->stop_signal (); enum gdb_signal stop_signal = signalled_thr->stop_signal ();
gcore_elf_build_thread_register_notes (gdbarch, signalled_thr, stop_signal, gcore_elf_build_thread_register_notes (gdbarch, signalled_thr, stop_signal,
obfd, &note_data, note_size); obfd, &note_data, note_size);
for (thread_info *thr : current_inferior ()->non_exited_threads ()) for (thread_info &thr : current_inferior ()->non_exited_threads ())
{ {
if (thr == signalled_thr) if (&thr == signalled_thr)
continue; continue;
gcore_elf_build_thread_register_notes (gdbarch, thr, stop_signal, gcore_elf_build_thread_register_notes (gdbarch, &thr, stop_signal,
obfd, &note_data, note_size); obfd, &note_data, note_size);
} }

View File

@@ -850,9 +850,9 @@ gcore_find_signalled_thread ()
&& curr_thr->stop_signal () != GDB_SIGNAL_0) && curr_thr->stop_signal () != GDB_SIGNAL_0)
return curr_thr; return curr_thr;
for (thread_info *thr : current_inferior ()->non_exited_threads ()) for (thread_info &thr : current_inferior ()->non_exited_threads ())
if (thr->stop_signal () != GDB_SIGNAL_0) if (thr.stop_signal () != GDB_SIGNAL_0)
return thr; return &thr;
/* Default to the current thread, unless it has exited. */ /* Default to the current thread, unless it has exited. */
if (curr_thr->state != THREAD_EXITED) if (curr_thr->state != THREAD_EXITED)

View File

@@ -35,6 +35,7 @@ struct symtab;
#include "gdbsupport/forward-scope-exit.h" #include "gdbsupport/forward-scope-exit.h"
#include "displaced-stepping.h" #include "displaced-stepping.h"
#include "gdbsupport/intrusive_list.h" #include "gdbsupport/intrusive_list.h"
#include "gdbsupport/reference-to-pointer-iterator.h"
#include "thread-fsm.h" #include "thread-fsm.h"
#include "language.h" #include "language.h"
@@ -747,7 +748,7 @@ extern struct thread_info *iterate_over_threads (thread_callback_func);
Used like this, it walks over all threads of all inferiors of all Used like this, it walks over all threads of all inferiors of all
targets: targets:
for (thread_info *thr : all_threads ()) for (thread_info &thr : all_threads ())
{ .... } { .... }
FILTER_PTID can be used to filter out threads that don't match. FILTER_PTID can be used to filter out threads that don't match.

View File

@@ -1203,20 +1203,20 @@ signal_command (const char *signum_exp, int from_tty)
thread_info *current = inferior_thread (); thread_info *current = inferior_thread ();
for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid)) for (thread_info &tp : all_non_exited_threads (resume_target, resume_ptid))
{ {
if (tp == current) if (&tp == current)
continue; continue;
if (tp->stop_signal () != GDB_SIGNAL_0 if (tp.stop_signal () != GDB_SIGNAL_0
&& signal_pass_state (tp->stop_signal ())) && signal_pass_state (tp.stop_signal ()))
{ {
if (!must_confirm) if (!must_confirm)
gdb_printf (_("Note:\n")); gdb_printf (_("Note:\n"));
gdb_printf (_(" Thread %s previously stopped with signal %s, %s.\n"), gdb_printf (_(" Thread %s previously stopped with signal %s, %s.\n"),
print_thread_id (tp), print_thread_id (&tp),
gdb_signal_to_name (tp->stop_signal ()), gdb_signal_to_name (tp.stop_signal ()),
gdb_signal_to_string (tp->stop_signal ())); gdb_signal_to_string (tp.stop_signal ()));
must_confirm = 1; must_confirm = 1;
} }
} }
@@ -2479,12 +2479,12 @@ proceed_after_attach (inferior *inf)
/* Backup current thread and selected frame. */ /* Backup current thread and selected frame. */
scoped_restore_current_thread restore_thread; scoped_restore_current_thread restore_thread;
for (thread_info *thread : inf->non_exited_threads ()) for (thread_info &thread : inf->non_exited_threads ())
if (!thread->executing () if (!thread.executing ()
&& !thread->stop_requested && !thread.stop_requested
&& thread->stop_signal () == GDB_SIGNAL_0) && thread.stop_signal () == GDB_SIGNAL_0)
{ {
switch_to_thread (thread); switch_to_thread (&thread);
clear_proceed_status (0); clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
} }
@@ -2588,10 +2588,10 @@ attach_post_wait (int from_tty, enum attach_post_wait_mode mode)
stop. For consistency, always select the thread with stop. For consistency, always select the thread with
lowest GDB number, which should be the main thread, if it lowest GDB number, which should be the main thread, if it
still exists. */ still exists. */
for (thread_info *thread : current_inferior ()->non_exited_threads ()) for (thread_info &thread : current_inferior ()->non_exited_threads ())
if (thread->inf->num < lowest->inf->num if (thread.inf->num < lowest->inf->num
|| thread->per_inf_num < lowest->per_inf_num) || thread.per_inf_num < lowest->per_inf_num)
lowest = thread; lowest = &thread;
switch_to_thread (lowest); switch_to_thread (lowest);
} }

View File

@@ -104,8 +104,8 @@ inferior::unpush_target (struct target_ops *t)
{ {
process_stratum_target *proc_target = as_process_stratum_target (t); process_stratum_target *proc_target = as_process_stratum_target (t);
for (thread_info *thread : this->non_exited_threads ()) for (thread_info &thread : this->non_exited_threads ())
proc_target->maybe_remove_resumed_with_pending_wait_status (thread); proc_target->maybe_remove_resumed_with_pending_wait_status (&thread);
} }
return m_target_stack.unpush (t); return m_target_stack.unpush (t);
@@ -458,7 +458,7 @@ number_of_live_inferiors (process_stratum_target *proc_target)
for (inferior *inf : all_non_exited_inferiors (proc_target)) for (inferior *inf : all_non_exited_inferiors (proc_target))
if (inf->has_execution ()) if (inf->has_execution ())
for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ()) for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
{ {
/* Found a live thread in this inferior, go to the next /* Found a live thread in this inferior, go to the next
inferior. */ inferior. */

View File

@@ -469,7 +469,7 @@ public:
/* Returns a range adapter covering the inferior's threads, /* Returns a range adapter covering the inferior's threads,
including exited threads. Used like this: including exited threads. Used like this:
for (thread_info *thr : inf->threads ()) for (thread_info &thr : inf->threads ())
{ .... } { .... }
*/ */
inf_threads_range threads () inf_threads_range threads ()
@@ -478,7 +478,7 @@ public:
/* Returns a range adapter covering the inferior's non-exited /* Returns a range adapter covering the inferior's non-exited
threads. Used like this: threads. Used like this:
for (thread_info *thr : inf->non_exited_threads ()) for (thread_info &thr : inf->non_exited_threads ())
{ .... } { .... }
*/ */
inf_non_exited_threads_range non_exited_threads () inf_non_exited_threads_range non_exited_threads ()
@@ -488,9 +488,9 @@ public:
used with range-for, safely. I.e., it is safe to delete the used with range-for, safely. I.e., it is safe to delete the
currently-iterated thread, like this: currently-iterated thread, like this:
for (thread_info *t : inf->threads_safe ()) for (thread_info &t : inf->threads_safe ())
if (some_condition ()) if (some_condition ())
delete f; delete &f;
*/ */
inline safe_inf_threads_range threads_safe () inline safe_inf_threads_range threads_safe ()
{ return safe_inf_threads_range (this->thread_list.begin ()); } { return safe_inf_threads_range (this->thread_list.begin ()); }

View File

@@ -546,15 +546,15 @@ child_interrupt (struct target_ops *self)
{ {
/* Interrupt the first inferior that has a resumed thread. */ /* Interrupt the first inferior that has a resumed thread. */
thread_info *resumed = NULL; thread_info *resumed = NULL;
for (thread_info *thr : all_non_exited_threads ()) for (thread_info &thr : all_non_exited_threads ())
{ {
if (thr->executing ()) if (thr.executing ())
{ {
resumed = thr; resumed = &thr;
break; break;
} }
if (thr->has_pending_waitstatus ()) if (thr.has_pending_waitstatus ())
resumed = thr; resumed = &thr;
} }
if (resumed != NULL) if (resumed != NULL)

View File

@@ -723,7 +723,7 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"),
if (!follow_child && !sched_multi) if (!follow_child && !sched_multi)
maybe_restore.emplace (); maybe_restore.emplace ();
switch_to_thread (*child_inf->threads ().begin ()); switch_to_thread (&*child_inf->threads ().begin ());
post_create_inferior (0, child_has_new_pspace); post_create_inferior (0, child_has_new_pspace);
} }
@@ -778,23 +778,23 @@ follow_fork ()
switch back to it, to tell the target to follow it (in either switch back to it, to tell the target to follow it (in either
direction). We'll afterwards refuse to resume, and inform direction). We'll afterwards refuse to resume, and inform
the user what happened. */ the user what happened. */
for (thread_info *tp : all_non_exited_threads (resume_target, for (thread_info &tp : all_non_exited_threads (resume_target,
resume_ptid)) resume_ptid))
{ {
if (tp == cur_thr) if (&tp == cur_thr)
continue; continue;
/* follow_fork_inferior clears tp->pending_follow, and below /* follow_fork_inferior clears tp->pending_follow, and below
we'll need the value after the follow_fork_inferior we'll need the value after the follow_fork_inferior
call. */ call. */
target_waitkind kind = tp->pending_follow.kind (); target_waitkind kind = tp.pending_follow.kind ();
if (kind != TARGET_WAITKIND_SPURIOUS) if (kind != TARGET_WAITKIND_SPURIOUS)
{ {
infrun_debug_printf ("need to follow-fork [%s] first", infrun_debug_printf ("need to follow-fork [%s] first",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
switch_to_thread (tp); switch_to_thread (&tp);
/* Set up inferior(s) as specified by the caller, and /* Set up inferior(s) as specified by the caller, and
tell the target to do whatever is necessary to follow tell the target to do whatever is necessary to follow
@@ -1144,8 +1144,8 @@ handle_vfork_child_exec_or_exit (int exec)
infrun_debug_printf ("resuming vfork parent process %d", infrun_debug_printf ("resuming vfork parent process %d",
resume_parent->pid); resume_parent->pid);
for (thread_info *thread : resume_parent->threads ()) for (thread_info &thread : resume_parent->threads ())
proceed_after_vfork_done (thread); proceed_after_vfork_done (&thread);
} }
} }
} }
@@ -1668,8 +1668,8 @@ infrun_inferior_execd (inferior *exec_inf, inferior *follow_inf)
stepping buffer bytes. */ stepping buffer bytes. */
follow_inf->displaced_step_state.reset (); follow_inf->displaced_step_state.reset ();
for (thread_info *thread : follow_inf->threads ()) for (thread_info &thread : follow_inf->threads ())
thread->displaced_step_state.reset (); thread.displaced_step_state.reset ();
/* Since an in-line step is done with everything else stopped, if there was /* Since an in-line step is done with everything else stopped, if there was
one in progress at the time of the exec, it must have been the exec'ing one in progress at the time of the exec, it must have been the exec'ing
@@ -1973,10 +1973,10 @@ static bool
any_thread_needs_target_thread_events (process_stratum_target *target, any_thread_needs_target_thread_events (process_stratum_target *target,
ptid_t resume_ptid) ptid_t resume_ptid)
{ {
for (thread_info *tp : all_non_exited_threads (target, resume_ptid)) for (thread_info &tp : all_non_exited_threads (target, resume_ptid))
if (displaced_step_in_progress_thread (tp) if (displaced_step_in_progress_thread (&tp)
|| schedlock_applies (tp) || schedlock_applies (&tp)
|| tp->thread_fsm () != nullptr) || tp.thread_fsm () != nullptr)
return true; return true;
return false; return false;
} }
@@ -2617,10 +2617,10 @@ do_target_resume (ptid_t resume_ptid, bool step, enum gdb_signal sig)
if (resume_ptid != inferior_ptid && target_supports_set_thread_options (0)) if (resume_ptid != inferior_ptid && target_supports_set_thread_options (0))
{ {
process_stratum_target *resume_target = tp->inf->process_target (); process_stratum_target *resume_target = tp->inf->process_target ();
for (thread_info *thr_iter : all_non_exited_threads (resume_target, for (thread_info &thr_iter : all_non_exited_threads (resume_target,
resume_ptid)) resume_ptid))
if (thr_iter != tp) if (&thr_iter != tp)
thr_iter->set_thread_options (0); thr_iter.set_thread_options (0);
} }
infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s", infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
@@ -3129,8 +3129,8 @@ clear_proceed_status (int step)
/* In all-stop mode, delete the per-thread status of all threads /* In all-stop mode, delete the per-thread status of all threads
we're about to resume, implicitly and explicitly. */ we're about to resume, implicitly and explicitly. */
for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid)) for (thread_info &tp : all_non_exited_threads (resume_target, resume_ptid))
clear_proceed_status_thread (tp); clear_proceed_status_thread (&tp);
} }
if (inferior_ptid != null_ptid) if (inferior_ptid != null_ptid)
@@ -3711,25 +3711,25 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
threads. */ threads. */
if (!non_stop && !schedlock_applies (cur_thr)) if (!non_stop && !schedlock_applies (cur_thr))
{ {
for (thread_info *tp : all_non_exited_threads (resume_target, for (thread_info &tp : all_non_exited_threads (resume_target,
resume_ptid)) resume_ptid))
{ {
switch_to_thread_no_regs (tp); switch_to_thread_no_regs (&tp);
/* Ignore the current thread here. It's handled /* Ignore the current thread here. It's handled
afterwards. */ afterwards. */
if (tp == cur_thr) if (&tp == cur_thr)
continue; continue;
if (!thread_still_needs_step_over (tp)) if (!thread_still_needs_step_over (&tp))
continue; continue;
gdb_assert (!thread_is_in_step_over_chain (tp)); gdb_assert (!thread_is_in_step_over_chain (&tp));
infrun_debug_printf ("need to step-over [%s] first", infrun_debug_printf ("need to step-over [%s] first",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
global_thread_step_over_chain_enqueue (tp); global_thread_step_over_chain_enqueue (&tp);
} }
switch_to_thread (cur_thr); switch_to_thread (cur_thr);
@@ -3769,11 +3769,11 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
/* In all-stop, but the target is always in non-stop mode. /* In all-stop, but the target is always in non-stop mode.
Start all other threads that are implicitly resumed too. */ Start all other threads that are implicitly resumed too. */
for (thread_info *tp : all_non_exited_threads (resume_target, for (thread_info &tp : all_non_exited_threads (resume_target,
resume_ptid)) resume_ptid))
{ {
switch_to_thread_no_regs (tp); switch_to_thread_no_regs (&tp);
proceed_resume_thread_checked (tp); proceed_resume_thread_checked (&tp);
} }
} }
else else
@@ -3876,33 +3876,33 @@ infrun_thread_stop_requested (ptid_t ptid)
but the user/frontend doesn't know about that yet (e.g., the but the user/frontend doesn't know about that yet (e.g., the
thread had been temporarily paused for some step-over), set up thread had been temporarily paused for some step-over), set up
for reporting the stop now. */ for reporting the stop now. */
for (thread_info *tp : all_threads (curr_target, ptid)) for (thread_info &tp : all_threads (curr_target, ptid))
{ {
if (tp->state != THREAD_RUNNING) if (tp.state != THREAD_RUNNING)
continue; continue;
if (tp->executing ()) if (tp.executing ())
continue; continue;
/* Remove matching threads from the step-over queue, so /* Remove matching threads from the step-over queue, so
start_step_over doesn't try to resume them start_step_over doesn't try to resume them
automatically. */ automatically. */
if (thread_is_in_step_over_chain (tp)) if (thread_is_in_step_over_chain (&tp))
global_thread_step_over_chain_remove (tp); global_thread_step_over_chain_remove (&tp);
/* If the thread is stopped, but the user/frontend doesn't /* If the thread is stopped, but the user/frontend doesn't
know about that yet, queue a pending event, as if the know about that yet, queue a pending event, as if the
thread had just stopped now. Unless the thread already had thread had just stopped now. Unless the thread already had
a pending event. */ a pending event. */
if (!tp->has_pending_waitstatus ()) if (!tp.has_pending_waitstatus ())
{ {
target_waitstatus ws; target_waitstatus ws;
ws.set_stopped (GDB_SIGNAL_0); ws.set_stopped (GDB_SIGNAL_0);
tp->set_pending_waitstatus (ws); tp.set_pending_waitstatus (ws);
} }
/* Clear the inline-frame state, since we're re-processing the /* Clear the inline-frame state, since we're re-processing the
stop. */ stop. */
clear_inline_frame_state (tp); clear_inline_frame_state (&tp);
/* If this thread was paused because some other thread was /* If this thread was paused because some other thread was
doing an inline-step over, let that finish first. Once doing an inline-step over, let that finish first. Once
@@ -3914,7 +3914,7 @@ infrun_thread_stop_requested (ptid_t ptid)
/* Otherwise we can process the (new) pending event now. Set /* Otherwise we can process the (new) pending event now. Set
it so this pending event is considered by it so this pending event is considered by
do_target_wait. */ do_target_wait. */
tp->set_resumed (true); tp.set_resumed (true);
} }
} }
@@ -3950,8 +3950,8 @@ for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func)
else else
{ {
/* In all-stop mode, all threads have stopped. */ /* In all-stop mode, all threads have stopped. */
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
func (tp); func (&tp);
} }
} }
@@ -4327,20 +4327,20 @@ prepare_for_detach (void)
/* Stop threads currently displaced stepping, aborting it. */ /* Stop threads currently displaced stepping, aborting it. */
for (thread_info *thr : inf->non_exited_threads ()) for (thread_info &thr : inf->non_exited_threads ())
{ {
if (thr->displaced_step_state.in_progress ()) if (thr.displaced_step_state.in_progress ())
{ {
if (thr->executing ()) if (thr.executing ())
{ {
if (!thr->stop_requested) if (!thr.stop_requested)
{ {
target_stop (thr->ptid); target_stop (thr.ptid);
thr->stop_requested = true; thr.stop_requested = true;
} }
} }
else else
thr->set_resumed (false); thr.set_resumed (false);
} }
} }
@@ -5458,9 +5458,9 @@ handle_one (const wait_one_event &event)
{ {
int pid = event.ptid.pid (); int pid = event.ptid.pid ();
inferior *inf = find_inferior_pid (event.target, pid); inferior *inf = find_inferior_pid (event.target, pid);
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
t = tp; t = &tp;
break; break;
} }
@@ -5729,9 +5729,9 @@ stop_all_threads (const char *reason, inferior *inf)
/* Go through all threads looking for threads that we need /* Go through all threads looking for threads that we need
to tell the target to stop. */ to tell the target to stop. */
for (thread_info *t : all_non_exited_threads ()) for (thread_info &t : all_non_exited_threads ())
{ {
if (inf != nullptr && t->inf != inf) if (inf != nullptr && t.inf != inf)
continue; continue;
/* For a single-target setting with an all-stop target, /* For a single-target setting with an all-stop target,
@@ -5741,38 +5741,38 @@ stop_all_threads (const char *reason, inferior *inf)
targets' threads. This should be fine due to the targets' threads. This should be fine due to the
protection of 'check_multi_target_resumption'. */ protection of 'check_multi_target_resumption'. */
switch_to_thread_no_regs (t); switch_to_thread_no_regs (&t);
if (!target_is_non_stop_p ()) if (!target_is_non_stop_p ())
continue; continue;
if (t->executing ()) if (t.executing ())
{ {
/* If already stopping, don't request a stop again. /* If already stopping, don't request a stop again.
We just haven't seen the notification yet. */ We just haven't seen the notification yet. */
if (!t->stop_requested) if (!t.stop_requested)
{ {
infrun_debug_printf (" %s executing, need stop", infrun_debug_printf (" %s executing, need stop",
t->ptid.to_string ().c_str ()); t.ptid.to_string ().c_str ());
target_stop (t->ptid); target_stop (t.ptid);
t->stop_requested = true; t.stop_requested = true;
} }
else else
{ {
infrun_debug_printf (" %s executing, already stopping", infrun_debug_printf (" %s executing, already stopping",
t->ptid.to_string ().c_str ()); t.ptid.to_string ().c_str ());
} }
if (t->stop_requested) if (t.stop_requested)
waits_needed++; waits_needed++;
} }
else else
{ {
infrun_debug_printf (" %s not executing", infrun_debug_printf (" %s not executing",
t->ptid.to_string ().c_str ()); t.ptid.to_string ().c_str ());
/* The thread may be not executing, but still be /* The thread may be not executing, but still be
resumed with a pending status to process. */ resumed with a pending status to process. */
t->set_resumed (false); t.set_resumed (false);
} }
} }
@@ -5886,21 +5886,21 @@ handle_no_resumed (struct execution_control_state *ecs)
whether to report it to the user. */ whether to report it to the user. */
bool ignore_event = false; bool ignore_event = false;
for (thread_info *thread : all_non_exited_threads ()) for (thread_info &thread : all_non_exited_threads ())
{ {
if (swap_terminal && thread->executing ()) if (swap_terminal && thread.executing ())
{ {
if (thread->inf != curr_inf) if (thread.inf != curr_inf)
{ {
target_terminal::ours (); target_terminal::ours ();
switch_to_thread (thread); switch_to_thread (&thread);
target_terminal::inferior (); target_terminal::inferior ();
} }
swap_terminal = false; swap_terminal = false;
} }
if (!ignore_event && thread->resumed ()) if (!ignore_event && thread.resumed ())
{ {
/* Either there were no unwaited-for children left in the /* Either there were no unwaited-for children left in the
target at some point, but there are now, or some target target at some point, but there are now, or some target
@@ -6059,8 +6059,8 @@ handle_thread_exited (execution_control_state *ecs)
thread. */ thread. */
return handle_as_no_resumed (); return handle_as_no_resumed ();
} }
thread_info *non_exited_thread = *range.begin (); thread_info &non_exited_thread = *range.begin ();
switch_to_thread (non_exited_thread); switch_to_thread (&non_exited_thread);
insert_breakpoints (); insert_breakpoints ();
resume (GDB_SIGNAL_0); resume (GDB_SIGNAL_0);
} }
@@ -6615,83 +6615,83 @@ restart_threads (struct thread_info *event_thread, inferior *inf)
/* In case the instruction just stepped spawned a new thread. */ /* In case the instruction just stepped spawned a new thread. */
update_thread_list (); update_thread_list ();
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
{ {
if (inf != nullptr && tp->inf != inf) if (inf != nullptr && tp.inf != inf)
continue; continue;
if (tp->inf->detaching) if (tp.inf->detaching)
{ {
infrun_debug_printf ("restart threads: [%s] inferior detaching", infrun_debug_printf ("restart threads: [%s] inferior detaching",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
continue; continue;
} }
switch_to_thread_no_regs (tp); switch_to_thread_no_regs (&tp);
if (tp == event_thread) if (&tp == event_thread)
{ {
infrun_debug_printf ("restart threads: [%s] is event thread", infrun_debug_printf ("restart threads: [%s] is event thread",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
continue; continue;
} }
if (!(tp->state == THREAD_RUNNING || tp->control.in_infcall)) if (!(tp.state == THREAD_RUNNING || tp.control.in_infcall))
{ {
infrun_debug_printf ("restart threads: [%s] not meant to be running", infrun_debug_printf ("restart threads: [%s] not meant to be running",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
continue; continue;
} }
if (tp->resumed ()) if (tp.resumed ())
{ {
infrun_debug_printf ("restart threads: [%s] resumed", infrun_debug_printf ("restart threads: [%s] resumed",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
gdb_assert (tp->executing () || tp->has_pending_waitstatus ()); gdb_assert (tp.executing () || tp.has_pending_waitstatus ());
continue; continue;
} }
if (thread_is_in_step_over_chain (tp)) if (thread_is_in_step_over_chain (&tp))
{ {
infrun_debug_printf ("restart threads: [%s] needs step-over", infrun_debug_printf ("restart threads: [%s] needs step-over",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
gdb_assert (!tp->resumed ()); gdb_assert (!tp.resumed ());
continue; continue;
} }
if (tp->has_pending_waitstatus ()) if (tp.has_pending_waitstatus ())
{ {
infrun_debug_printf ("restart threads: [%s] has pending status", infrun_debug_printf ("restart threads: [%s] has pending status",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
tp->set_resumed (true); tp.set_resumed (true);
continue; continue;
} }
gdb_assert (!tp->stop_requested); gdb_assert (!tp.stop_requested);
/* If some thread needs to start a step-over at this point, it /* If some thread needs to start a step-over at this point, it
should still be in the step-over queue, and thus skipped should still be in the step-over queue, and thus skipped
above. */ above. */
if (thread_still_needs_step_over (tp)) if (thread_still_needs_step_over (&tp))
{ {
internal_error ("thread [%s] needs a step-over, but not in " internal_error ("thread [%s] needs a step-over, but not in "
"step-over queue\n", "step-over queue\n",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
} }
if (currently_stepping (tp)) if (currently_stepping (&tp))
{ {
infrun_debug_printf ("restart threads: [%s] was stepping", infrun_debug_printf ("restart threads: [%s] was stepping",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
keep_going_stepped_thread (tp); keep_going_stepped_thread (&tp);
} }
else else
{ {
infrun_debug_printf ("restart threads: [%s] continuing", infrun_debug_printf ("restart threads: [%s] continuing",
tp->ptid.to_string ().c_str ()); tp.ptid.to_string ().c_str ());
execution_control_state ecs (tp); execution_control_state ecs (&tp);
switch_to_thread (tp); switch_to_thread (&tp);
keep_going_pass_signal (&ecs); keep_going_pass_signal (&ecs);
} }
} }
@@ -8515,20 +8515,20 @@ restart_after_all_stop_detach (process_stratum_target *proc_target)
resumed. With the remote target (in all-stop), it's even resumed. With the remote target (in all-stop), it's even
impossible to issue another resumption if the target is already impossible to issue another resumption if the target is already
resumed, until the target reports a stop. */ resumed, until the target reports a stop. */
for (thread_info *thr : all_threads (proc_target)) for (thread_info &thr : all_threads (proc_target))
{ {
if (thr->state != THREAD_RUNNING) if (thr.state != THREAD_RUNNING)
continue; continue;
/* If we have any thread that is already executing, then we /* If we have any thread that is already executing, then we
don't need to resume the target -- it is already been don't need to resume the target -- it is already been
resumed. */ resumed. */
if (thr->executing ()) if (thr.executing ())
return; return;
/* If we have a pending event to process, skip resuming the /* If we have a pending event to process, skip resuming the
target and go straight to processing it. */ target and go straight to processing it. */
if (thr->resumed () && thr->has_pending_waitstatus ()) if (thr.resumed () && thr.has_pending_waitstatus ())
return; return;
} }
@@ -8539,13 +8539,13 @@ restart_after_all_stop_detach (process_stratum_target *proc_target)
/* Otherwise, find the first THREAD_RUNNING thread and resume /* Otherwise, find the first THREAD_RUNNING thread and resume
it. */ it. */
for (thread_info *thr : all_threads (proc_target)) for (thread_info &thr : all_threads (proc_target))
{ {
if (thr->state != THREAD_RUNNING) if (thr.state != THREAD_RUNNING)
continue; continue;
execution_control_state ecs (thr); execution_control_state ecs (&thr);
switch_to_thread (thr); switch_to_thread (&thr);
keep_going (&ecs); keep_going (&ecs);
return; return;
} }

View File

@@ -65,13 +65,13 @@ infrun_debug_show_threads (const char *title, ThreadRange threads)
INFRUN_SCOPED_DEBUG_ENTER_EXIT; INFRUN_SCOPED_DEBUG_ENTER_EXIT;
infrun_debug_printf ("%s:", title); infrun_debug_printf ("%s:", title);
for (thread_info *thread : threads) for (thread_info &thread : threads)
infrun_debug_printf (" thread %s, executing = %d, resumed = %d, " infrun_debug_printf (" thread %s, executing = %d, resumed = %d, "
"state = %s", "state = %s",
thread->ptid.to_string ().c_str (), thread.ptid.to_string ().c_str (),
thread->executing (), thread.executing (),
thread->resumed (), thread.resumed (),
thread_state_string (thread->state)); thread_state_string (thread.state));
} }
} }

View File

@@ -970,7 +970,7 @@ inf_has_multiple_threads ()
/* Return true as soon as we see the second thread of the current /* Return true as soon as we see the second thread of the current
inferior. */ inferior. */
for (thread_info *tp ATTRIBUTE_UNUSED : current_inferior ()->threads ()) for (thread_info &tp ATTRIBUTE_UNUSED : current_inferior ()->threads ())
if (++count > 1) if (++count > 1)
return true; return true;

View File

@@ -2377,9 +2377,9 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
target_thread_architecture (signalled_thr->ptid), target_thread_architecture (signalled_thr->ptid),
obfd, note_data, note_size, stop_signal); obfd, note_data, note_size, stop_signal);
} }
for (thread_info *thr : current_inferior ()->non_exited_threads ()) for (thread_info &thr : current_inferior ()->non_exited_threads ())
{ {
if (thr == signalled_thr) if (&thr == signalled_thr)
continue; continue;
/* On some architectures, like AArch64, each thread can have a distinct /* On some architectures, like AArch64, each thread can have a distinct
@@ -2388,7 +2388,7 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
Fetch each thread's gdbarch and pass it down to the lower layers so Fetch each thread's gdbarch and pass it down to the lower layers so
we can dump the right set of registers. */ we can dump the right set of registers. */
linux_corefile_thread (thr, target_thread_architecture (thr->ptid), linux_corefile_thread (&thr, target_thread_architecture (thr.ptid),
obfd, note_data, note_size, stop_signal); obfd, note_data, note_size, stop_signal);
} }

View File

@@ -1706,12 +1706,12 @@ thread_db_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
error (_("Thread handle size mismatch: %d vs %zu (from libthread_db)"), error (_("Thread handle size mismatch: %d vs %zu (from libthread_db)"),
handle_len, sizeof (handle_tid)); handle_len, sizeof (handle_tid));
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
thread_db_thread_info *priv = get_thread_db_thread_info (tp); thread_db_thread_info *priv = get_thread_db_thread_info (&tp);
if (priv != NULL && handle_tid == priv->tid) if (priv != NULL && handle_tid == priv->tid)
return tp; return &tp;
} }
return NULL; return NULL;

View File

@@ -682,8 +682,8 @@ mi_on_resume_1 (struct mi_interp *mi,
&& !multiple_inferiors_p ()) && !multiple_inferiors_p ())
gdb_printf (mi->raw_stdout, "*running,thread-id=\"all\"\n"); gdb_printf (mi->raw_stdout, "*running,thread-id=\"all\"\n");
else else
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
mi_output_running (tp); mi_output_running (&tp);
if (!mi->running_result_record_printed && mi->mi_proceeded) if (!mi->running_result_record_printed && mi->mi_proceeded)
{ {

View File

@@ -556,13 +556,13 @@ mi_cmd_thread_list_ids (const char *command, const char *const *argv, int argc)
{ {
ui_out_emit_tuple tuple_emitter (current_uiout, "thread-ids"); ui_out_emit_tuple tuple_emitter (current_uiout, "thread-ids");
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
{ {
if (tp->ptid == inferior_ptid) if (tp.ptid == inferior_ptid)
current_thread = tp->global_num; current_thread = tp.global_num;
num++; num++;
current_uiout->field_signed ("thread-id", tp->global_num); current_uiout->field_signed ("thread-id", tp.global_num);
} }
} }

View File

@@ -476,7 +476,7 @@ nbsd_resume(nbsd_nat_target *target, ptid_t ptid, int step,
/* If ptid is a specific LWP, suspend all other LWPs in the process. */ /* If ptid is a specific LWP, suspend all other LWPs in the process. */
inferior *inf = find_inferior_ptid (target, ptid); inferior *inf = find_inferior_ptid (target, ptid);
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
if (tp->ptid.lwp () == ptid.lwp ()) if (tp->ptid.lwp () == ptid.lwp ())
request = PT_RESUME; request = PT_RESUME;
@@ -491,20 +491,20 @@ nbsd_resume(nbsd_nat_target *target, ptid_t ptid, int step,
{ {
/* If ptid is a wildcard, resume all matching threads (they won't run /* If ptid is a wildcard, resume all matching threads (they won't run
until the process is continued however). */ until the process is continued however). */
for (thread_info *tp : all_non_exited_threads (target, ptid)) for (thread_info &tp : all_non_exited_threads (target, ptid))
if (ptrace (PT_RESUME, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1) if (ptrace (PT_RESUME, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
perror_with_name (("ptrace")); perror_with_name (("ptrace"));
} }
if (step) if (step)
{ {
for (thread_info *tp : all_non_exited_threads (target, ptid)) for (thread_info &tp : all_non_exited_threads (target, ptid))
if (ptrace (PT_SETSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1) if (ptrace (PT_SETSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
perror_with_name (("ptrace")); perror_with_name (("ptrace"));
} }
else else
{ {
for (thread_info *tp : all_non_exited_threads (target, ptid)) for (thread_info &tp : all_non_exited_threads (target, ptid))
if (ptrace (PT_CLEARSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1) if (ptrace (PT_CLEARSTEP, tp->ptid.pid (), NULL, tp->ptid.lwp ()) == -1)
perror_with_name (("ptrace")); perror_with_name (("ptrace"));
} }

View File

@@ -393,12 +393,12 @@ record_btrace_target_open (const char *args, int from_tty)
if (!target_has_execution ()) if (!target_has_execution ())
error (_("The program is not being run.")); error (_("The program is not being run."));
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
if (args == NULL || *args == 0 || number_is_in_list (args, tp->global_num)) if (args == NULL || *args == 0 || number_is_in_list (args, tp.global_num))
{ {
btrace_enable (tp, &record_btrace_conf); btrace_enable (&tp, &record_btrace_conf);
btrace_disable.add_thread (tp); btrace_disable.add_thread (&tp);
} }
record_btrace_push_target (); record_btrace_push_target ();
@@ -415,9 +415,9 @@ record_btrace_target::stop_recording ()
record_btrace_auto_disable (); record_btrace_auto_disable ();
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
if (tp->btrace.target != NULL) if (tp.btrace.target != NULL)
btrace_disable (tp); btrace_disable (&tp);
} }
/* The disconnect method of target record-btrace. */ /* The disconnect method of target record-btrace. */
@@ -449,8 +449,8 @@ record_btrace_target::close ()
/* We should have already stopped recording. /* We should have already stopped recording.
Tear down btrace in case we have not. */ Tear down btrace in case we have not. */
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
btrace_teardown (tp); btrace_teardown (&tp);
} }
/* The async method of target record-btrace. */ /* The async method of target record-btrace. */
@@ -1458,8 +1458,8 @@ bool
record_btrace_target::record_is_replaying (ptid_t ptid) record_btrace_target::record_is_replaying (ptid_t ptid)
{ {
process_stratum_target *proc_target = current_inferior ()->process_target (); process_stratum_target *proc_target = current_inferior ()->process_target ();
for (thread_info *tp : all_non_exited_threads (proc_target, ptid)) for (thread_info &tp : all_non_exited_threads (proc_target, ptid))
if (btrace_is_replaying (tp)) if (btrace_is_replaying (&tp))
return true; return true;
return false; return false;
@@ -2219,18 +2219,18 @@ record_btrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
{ {
gdb_assert (inferior_ptid.matches (ptid)); gdb_assert (inferior_ptid.matches (ptid));
for (thread_info *tp : all_non_exited_threads (proc_target, ptid)) for (thread_info &tp : all_non_exited_threads (proc_target, ptid))
{ {
if (tp->ptid.matches (inferior_ptid)) if (tp.ptid.matches (inferior_ptid))
record_btrace_resume_thread (tp, flag); record_btrace_resume_thread (&tp, flag);
else else
record_btrace_resume_thread (tp, cflag); record_btrace_resume_thread (&tp, cflag);
} }
} }
else else
{ {
for (thread_info *tp : all_non_exited_threads (proc_target, ptid)) for (thread_info &tp : all_non_exited_threads (proc_target, ptid))
record_btrace_resume_thread (tp, flag); record_btrace_resume_thread (&tp, flag);
} }
/* Async support. */ /* Async support. */
@@ -2616,9 +2616,9 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
/* Keep a work list of moving threads. */ /* Keep a work list of moving threads. */
process_stratum_target *proc_target = current_inferior ()->process_target (); process_stratum_target *proc_target = current_inferior ()->process_target ();
for (thread_info *tp : all_non_exited_threads (proc_target, ptid)) for (thread_info &tp : all_non_exited_threads (proc_target, ptid))
if ((tp->btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0) if ((tp.btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0)
moving.push_back (tp); moving.push_back (&tp);
if (moving.empty ()) if (moving.empty ())
{ {
@@ -2699,8 +2699,8 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
/* Stop all other threads. */ /* Stop all other threads. */
if (!target_is_non_stop_p ()) if (!target_is_non_stop_p ())
{ {
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
record_btrace_cancel_resume (tp); record_btrace_cancel_resume (&tp);
} }
/* In async mode, we need to announce further events. */ /* In async mode, we need to announce further events. */
@@ -2739,10 +2739,10 @@ record_btrace_target::stop (ptid_t ptid)
process_stratum_target *proc_target process_stratum_target *proc_target
= current_inferior ()->process_target (); = current_inferior ()->process_target ();
for (thread_info *tp : all_non_exited_threads (proc_target, ptid)) for (thread_info &tp : all_non_exited_threads (proc_target, ptid))
{ {
tp->btrace.flags &= ~BTHR_MOVE; tp.btrace.flags &= ~BTHR_MOVE;
tp->btrace.flags |= BTHR_STOP; tp.btrace.flags |= BTHR_STOP;
} }
} }
} }
@@ -2918,8 +2918,8 @@ record_btrace_target::goto_record (ULONGEST insn_number)
void void
record_btrace_target::record_stop_replaying () record_btrace_target::record_stop_replaying ()
{ {
for (thread_info *tp : current_inferior ()->non_exited_threads ()) for (thread_info &tp : current_inferior ()->non_exited_threads ())
record_btrace_stop_replaying (tp); record_btrace_stop_replaying (&tp);
} }
/* The execution_direction target method. */ /* The execution_direction target method. */

View File

@@ -1117,8 +1117,8 @@ record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
all executed instructions, so we can record them all. */ all executed instructions, so we can record them all. */
process_stratum_target *proc_target process_stratum_target *proc_target
= current_inferior ()->process_target (); = current_inferior ()->process_target ();
for (thread_info *thread : all_non_exited_threads (proc_target, ptid)) for (thread_info &thread : all_non_exited_threads (proc_target, ptid))
thread->control.may_range_step = 0; thread.control.may_range_step = 0;
this->beneath ()->resume (ptid, step, signal); this->beneath ()->resume (ptid, step, signal);
} }
@@ -1213,8 +1213,8 @@ record_full_wait_1 (struct target_ops *ops,
return ret; return ret;
} }
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
delete_single_step_breakpoints (tp); delete_single_step_breakpoints (&tp);
if (record_full_resume_step) if (record_full_resume_step)
return ret; return ret;

View File

@@ -4446,7 +4446,7 @@ static bool
has_single_non_exited_thread (inferior *inf) has_single_non_exited_thread (inferior *inf)
{ {
int count = 0; int count = 0;
for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ()) for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
if (++count > 1) if (++count > 1)
break; break;
return count == 1; return count == 1;
@@ -5214,26 +5214,26 @@ remote_target::process_initial_stop_replies (int from_tty)
/* Now go over all threads that are stopped, and print their current /* Now go over all threads that are stopped, and print their current
frame. If all-stop, then if there's a signalled thread, pick frame. If all-stop, then if there's a signalled thread, pick
that as current. */ that as current. */
for (thread_info *thread : all_non_exited_threads (this)) for (thread_info &thread : all_non_exited_threads (this))
{ {
if (first == NULL) if (first == NULL)
first = thread; first = &thread;
if (!non_stop) if (!non_stop)
thread->set_running (false); thread.set_running (false);
else if (thread->state != THREAD_STOPPED) else if (thread.state != THREAD_STOPPED)
continue; continue;
if (selected == nullptr && thread->has_pending_waitstatus ()) if (selected == nullptr && thread.has_pending_waitstatus ())
selected = thread; selected = &thread;
if (lowest_stopped == NULL if (lowest_stopped == NULL
|| thread->inf->num < lowest_stopped->inf->num || thread.inf->num < lowest_stopped->inf->num
|| thread->per_inf_num < lowest_stopped->per_inf_num) || thread.per_inf_num < lowest_stopped->per_inf_num)
lowest_stopped = thread; lowest_stopped = &thread;
if (non_stop) if (non_stop)
print_one_stopped_thread (thread); print_one_stopped_thread (&thread);
} }
/* In all-stop, we only print the status of one thread, and leave /* In all-stop, we only print the status of one thread, and leave
@@ -5623,10 +5623,10 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
remote_debug_printf ("warning: couldn't determine remote " remote_debug_printf ("warning: couldn't determine remote "
"current thread; picking first in list."); "current thread; picking first in list.");
for (thread_info *tp : all_non_exited_threads (this, for (thread_info &tp : all_non_exited_threads (this,
minus_one_ptid)) minus_one_ptid))
{ {
switch_to_thread (tp); switch_to_thread (&tp);
break; break;
} }
} }
@@ -6815,9 +6815,9 @@ remote_target::remote_detach_1 (inferior *inf, int from_tty)
/* See if any thread of the inferior we are detaching has a pending fork /* See if any thread of the inferior we are detaching has a pending fork
status. In that case, we must detach from the child resulting from status. In that case, we must detach from the child resulting from
that fork. */ that fork. */
for (thread_info *thread : inf->non_exited_threads ()) for (thread_info &thread : inf->non_exited_threads ())
{ {
const target_waitstatus *ws = thread_pending_fork_status (thread); const target_waitstatus *ws = thread_pending_fork_status (&thread);
if (ws == nullptr) if (ws == nullptr)
continue; continue;
@@ -7221,14 +7221,14 @@ char *
remote_target::append_pending_thread_resumptions (char *p, char *endp, remote_target::append_pending_thread_resumptions (char *p, char *endp,
ptid_t ptid) ptid_t ptid)
{ {
for (thread_info *thread : all_non_exited_threads (this, ptid)) for (thread_info &thread : all_non_exited_threads (this, ptid))
if (inferior_ptid != thread->ptid if (inferior_ptid != thread.ptid
&& thread->stop_signal () != GDB_SIGNAL_0) && thread.stop_signal () != GDB_SIGNAL_0)
{ {
p = append_resumption (p, endp, thread->ptid, p = append_resumption (p, endp, thread.ptid,
0, thread->stop_signal ()); 0, thread.stop_signal ());
thread->set_stop_signal (GDB_SIGNAL_0); thread.set_stop_signal (GDB_SIGNAL_0);
resume_clear_thread_private_info (thread); resume_clear_thread_private_info (&thread);
} }
return p; return p;
@@ -7254,8 +7254,8 @@ remote_target::remote_resume_with_hc (ptid_t ptid, int step,
else else
set_continue_thread (ptid); set_continue_thread (ptid);
for (thread_info *thread : all_non_exited_threads (this)) for (thread_info &thread : all_non_exited_threads (this))
resume_clear_thread_private_info (thread); resume_clear_thread_private_info (&thread);
buf = rs->buf.data (); buf = rs->buf.data ();
if (::execution_direction == EXEC_REVERSE) if (::execution_direction == EXEC_REVERSE)
@@ -7417,8 +7417,8 @@ remote_target::resume (ptid_t scope_ptid, int step, enum gdb_signal siggnal)
remote_resume_with_hc (scope_ptid, step, siggnal); remote_resume_with_hc (scope_ptid, step, siggnal);
/* Update resumed state tracked by the remote target. */ /* Update resumed state tracked by the remote target. */
for (thread_info *tp : all_non_exited_threads (this, scope_ptid)) for (thread_info &tp : all_non_exited_threads (this, scope_ptid))
get_remote_thread_info (tp)->set_resumed (); get_remote_thread_info (&tp)->set_resumed ();
/* We've just told the target to resume. The remote server will /* We've just told the target to resume. The remote server will
wait for the inferior to stop, and then send a stop reply. In wait for the inferior to stop, and then send a stop reply. In
@@ -7630,15 +7630,15 @@ remote_target::commit_resumed ()
bool any_pending_vcont_resume = false; bool any_pending_vcont_resume = false;
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
{ {
remote_thread_info *priv = get_remote_thread_info (tp); remote_thread_info *priv = get_remote_thread_info (&tp);
/* If a thread of a process is not meant to be resumed, then we /* If a thread of a process is not meant to be resumed, then we
can't wildcard that process. */ can't wildcard that process. */
if (priv->get_resume_state () == resume_state::NOT_RESUMED) if (priv->get_resume_state () == resume_state::NOT_RESUMED)
{ {
get_remote_inferior (tp->inf)->may_wildcard_vcont = false; get_remote_inferior (tp.inf)->may_wildcard_vcont = false;
/* And if we can't wildcard a process, we can't wildcard /* And if we can't wildcard a process, we can't wildcard
everything either. */ everything either. */
@@ -7652,7 +7652,7 @@ remote_target::commit_resumed ()
/* If a thread is the parent of an unfollowed fork/vfork/clone, /* If a thread is the parent of an unfollowed fork/vfork/clone,
then we can't do a global wildcard, as that would resume the then we can't do a global wildcard, as that would resume the
pending child. */ pending child. */
if (thread_pending_child_status (tp) != nullptr) if (thread_pending_child_status (&tp) != nullptr)
may_global_wildcard_vcont = false; may_global_wildcard_vcont = false;
} }
@@ -7669,9 +7669,9 @@ remote_target::commit_resumed ()
struct vcont_builder vcont_builder (this); struct vcont_builder vcont_builder (this);
/* Threads first. */ /* Threads first. */
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
{ {
remote_thread_info *remote_thr = get_remote_thread_info (tp); remote_thread_info *remote_thr = get_remote_thread_info (&tp);
/* If the thread was previously vCont-resumed, no need to send a specific /* If the thread was previously vCont-resumed, no need to send a specific
action for it. If we didn't receive a resume request for it, don't action for it. If we didn't receive a resume request for it, don't
@@ -7679,14 +7679,14 @@ remote_target::commit_resumed ()
if (remote_thr->get_resume_state () != resume_state::RESUMED_PENDING_VCONT) if (remote_thr->get_resume_state () != resume_state::RESUMED_PENDING_VCONT)
continue; continue;
gdb_assert (!thread_is_in_step_over_chain (tp)); gdb_assert (!thread_is_in_step_over_chain (&tp));
/* We should never be commit-resuming a thread that has a stop reply. /* We should never be commit-resuming a thread that has a stop reply.
Otherwise, we would end up reporting a stop event for a thread while Otherwise, we would end up reporting a stop event for a thread while
it is running on the remote target. */ it is running on the remote target. */
remote_state *rs = get_remote_state (); remote_state *rs = get_remote_state ();
for (const auto &stop_reply : rs->stop_reply_queue) for (const auto &stop_reply : rs->stop_reply_queue)
gdb_assert (stop_reply->ptid != tp->ptid); gdb_assert (stop_reply->ptid != tp.ptid);
const resumed_pending_vcont_info &info const resumed_pending_vcont_info &info
= remote_thr->resumed_pending_vcont_info (); = remote_thr->resumed_pending_vcont_info ();
@@ -7694,8 +7694,8 @@ remote_target::commit_resumed ()
/* Check if we need to send a specific action for this thread. If not, /* Check if we need to send a specific action for this thread. If not,
it will be included in a wildcard resume instead. */ it will be included in a wildcard resume instead. */
if (info.step || info.sig != GDB_SIGNAL_0 if (info.step || info.sig != GDB_SIGNAL_0
|| !get_remote_inferior (tp->inf)->may_wildcard_vcont) || !get_remote_inferior (tp.inf)->may_wildcard_vcont)
vcont_builder.push_action (tp->ptid, info.step, info.sig); vcont_builder.push_action (tp.ptid, info.step, info.sig);
remote_thr->set_resumed (); remote_thr->set_resumed ();
} }
@@ -7778,9 +7778,9 @@ remote_target::remote_stop_ns (ptid_t ptid)
whether the thread wasn't resumed with a signal. Generating a whether the thread wasn't resumed with a signal. Generating a
phony stop in that case would result in losing the signal. */ phony stop in that case would result in losing the signal. */
bool needs_commit = false; bool needs_commit = false;
for (thread_info *tp : all_non_exited_threads (this, ptid)) for (thread_info &tp : all_non_exited_threads (this, ptid))
{ {
remote_thread_info *remote_thr = get_remote_thread_info (tp); remote_thread_info *remote_thr = get_remote_thread_info (&tp);
if (remote_thr->get_resume_state () if (remote_thr->get_resume_state ()
== resume_state::RESUMED_PENDING_VCONT) == resume_state::RESUMED_PENDING_VCONT)
@@ -7801,17 +7801,17 @@ remote_target::remote_stop_ns (ptid_t ptid)
if (needs_commit) if (needs_commit)
commit_resumed (); commit_resumed ();
else else
for (thread_info *tp : all_non_exited_threads (this, ptid)) for (thread_info &tp : all_non_exited_threads (this, ptid))
{ {
remote_thread_info *remote_thr = get_remote_thread_info (tp); remote_thread_info *remote_thr = get_remote_thread_info (&tp);
if (remote_thr->get_resume_state () if (remote_thr->get_resume_state ()
== resume_state::RESUMED_PENDING_VCONT) == resume_state::RESUMED_PENDING_VCONT)
{ {
remote_debug_printf ("Enqueueing phony stop reply for thread pending " remote_debug_printf ("Enqueueing phony stop reply for thread pending "
"vCont-resume (%d, %ld, %s)", tp->ptid.pid(), "vCont-resume (%d, %ld, %s)", tp.ptid.pid(),
tp->ptid.lwp (), tp.ptid.lwp (),
pulongest (tp->ptid.tid ())); pulongest (tp.ptid.tid ()));
/* Check that the thread wasn't resumed with a signal. /* Check that the thread wasn't resumed with a signal.
Generating a phony stop would result in losing the Generating a phony stop would result in losing the
@@ -7821,10 +7821,10 @@ remote_target::remote_stop_ns (ptid_t ptid)
gdb_assert (info.sig == GDB_SIGNAL_0); gdb_assert (info.sig == GDB_SIGNAL_0);
stop_reply_up sr = std::make_unique<stop_reply> (); stop_reply_up sr = std::make_unique<stop_reply> ();
sr->ptid = tp->ptid; sr->ptid = tp.ptid;
sr->rs = rs; sr->rs = rs;
sr->ws.set_stopped (GDB_SIGNAL_0); sr->ws.set_stopped (GDB_SIGNAL_0);
sr->arch = tp->inf->arch (); sr->arch = tp.inf->arch ();
sr->stop_reason = TARGET_STOPPED_BY_NO_REASON; sr->stop_reason = TARGET_STOPPED_BY_NO_REASON;
sr->watch_data_address = 0; sr->watch_data_address = 0;
sr->core = 0; sr->core = 0;
@@ -8120,9 +8120,9 @@ remote_target::remove_new_children (threads_listing_context *context)
/* For any threads stopped at a (v)fork/clone event, remove the /* For any threads stopped at a (v)fork/clone event, remove the
corresponding child threads from the CONTEXT list. */ corresponding child threads from the CONTEXT list. */
for (thread_info *thread : all_non_exited_threads (this)) for (thread_info &thread : all_non_exited_threads (this))
{ {
const target_waitstatus *ws = thread_pending_child_status (thread); const target_waitstatus *ws = thread_pending_child_status (&thread);
if (ws == nullptr) if (ws == nullptr)
continue; continue;
@@ -8817,17 +8817,17 @@ remote_target::select_thread_for_ambiguous_stop_reply
/* Consider all non-exited threads of the target, find the first resumed /* Consider all non-exited threads of the target, find the first resumed
one. */ one. */
for (thread_info *thr : all_non_exited_threads (this)) for (thread_info &thr : all_non_exited_threads (this))
{ {
remote_thread_info *remote_thr = get_remote_thread_info (thr); remote_thread_info *remote_thr = get_remote_thread_info (&thr);
if (remote_thr->get_resume_state () != resume_state::RESUMED) if (remote_thr->get_resume_state () != resume_state::RESUMED)
continue; continue;
if (first_resumed_thread == nullptr) if (first_resumed_thread == nullptr)
first_resumed_thread = thr; first_resumed_thread = &thr;
else if (!process_wide_stop else if (!process_wide_stop
|| first_resumed_thread->ptid.pid () != thr->ptid.pid ()) || first_resumed_thread->ptid.pid () != thr.ptid.pid ())
ambiguous = true; ambiguous = true;
} }
@@ -8937,8 +8937,8 @@ remote_target::process_stop_reply (stop_reply_up stop_reply,
{ {
/* If the target works in all-stop mode, a stop-reply indicates that /* If the target works in all-stop mode, a stop-reply indicates that
all the target's threads stopped. */ all the target's threads stopped. */
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
get_remote_thread_info (tp)->set_not_resumed (); get_remote_thread_info (&tp)->set_not_resumed ();
} }
} }
@@ -9006,9 +9006,9 @@ remote_target::wait_ns (ptid_t ptid, struct target_waitstatus *status,
static ptid_t static ptid_t
first_remote_resumed_thread (remote_target *target) first_remote_resumed_thread (remote_target *target)
{ {
for (thread_info *tp : all_non_exited_threads (target, minus_one_ptid)) for (thread_info &tp : all_non_exited_threads (target, minus_one_ptid))
if (tp->resumed ()) if (tp.resumed ())
return tp->ptid; return tp.ptid;
return null_ptid; return null_ptid;
} }
@@ -10933,9 +10933,9 @@ remote_target::kill_new_fork_children (inferior *inf)
/* Kill the fork child threads of any threads in inferior INF that are stopped /* Kill the fork child threads of any threads in inferior INF that are stopped
at a fork event. */ at a fork event. */
for (thread_info *thread : inf->non_exited_threads ()) for (thread_info &thread : inf->non_exited_threads ())
{ {
const target_waitstatus *ws = thread_pending_fork_status (thread); const target_waitstatus *ws = thread_pending_fork_status (&thread);
if (ws == nullptr) if (ws == nullptr)
continue; continue;
@@ -15463,10 +15463,10 @@ remote_target::remote_btrace_maybe_reopen ()
if (m_features.packet_support (PACKET_qXfer_btrace_conf) != PACKET_ENABLE) if (m_features.packet_support (PACKET_qXfer_btrace_conf) != PACKET_ENABLE)
return; return;
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
{ {
memset (&rs->btrace_config, 0x00, sizeof (struct btrace_config)); memset (&rs->btrace_config, 0x00, sizeof (struct btrace_config));
btrace_read_config (tp, &rs->btrace_config); btrace_read_config (&tp, &rs->btrace_config);
if (rs->btrace_config.format == BTRACE_FORMAT_NONE) if (rs->btrace_config.format == BTRACE_FORMAT_NONE)
continue; continue;
@@ -15496,8 +15496,7 @@ remote_target::remote_btrace_maybe_reopen ()
btrace_format_string (rs->btrace_config.format)); btrace_format_string (rs->btrace_config.format));
} }
tp->btrace.target tp.btrace.target = new btrace_target_info { tp.ptid, rs->btrace_config };
= new btrace_target_info { tp->ptid, rs->btrace_config };
} }
} }
@@ -15733,18 +15732,18 @@ remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
int handle_len, int handle_len,
inferior *inf) inferior *inf)
{ {
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
{ {
remote_thread_info *priv = get_remote_thread_info (tp); remote_thread_info *priv = get_remote_thread_info (&tp);
if (tp->inf == inf && priv != NULL) if (tp.inf == inf && priv != NULL)
{ {
if (handle_len != priv->thread_handle.size ()) if (handle_len != priv->thread_handle.size ())
error (_("Thread handle size mismatch: %d vs %zu (from remote)"), error (_("Thread handle size mismatch: %d vs %zu (from remote)"),
handle_len, priv->thread_handle.size ()); handle_len, priv->thread_handle.size ());
if (memcmp (thread_handle, priv->thread_handle.data (), if (memcmp (thread_handle, priv->thread_handle.data (),
handle_len) == 0) handle_len) == 0)
return tp; return &tp;
} }
} }
@@ -15931,9 +15930,9 @@ remote_target::commit_requested_thread_options ()
/* Now set non-zero options for threads that need them. We don't /* Now set non-zero options for threads that need them. We don't
bother with the case of all threads of a process wanting the same bother with the case of all threads of a process wanting the same
non-zero options as that's not an expected scenario. */ non-zero options as that's not an expected scenario. */
for (thread_info *tp : all_non_exited_threads (this)) for (thread_info &tp : all_non_exited_threads (this))
{ {
gdb_thread_options options = tp->thread_options (); gdb_thread_options options = tp.thread_options ();
if (options == 0) if (options == 0)
continue; continue;
@@ -15950,10 +15949,10 @@ remote_target::commit_requested_thread_options ()
*obuf_p++ = ';'; *obuf_p++ = ';';
obuf_p += xsnprintf (obuf_p, obuf_endp - obuf_p, "%s", obuf_p += xsnprintf (obuf_p, obuf_endp - obuf_p, "%s",
phex_nz (options)); phex_nz (options));
if (tp->ptid != magic_null_ptid) if (tp.ptid != magic_null_ptid)
{ {
*obuf_p++ = ':'; *obuf_p++ = ':';
obuf_p = write_ptid (obuf_p, obuf_endp, tp->ptid); obuf_p = write_ptid (obuf_p, obuf_endp, tp.ptid);
} }
size_t osize = obuf_p - obuf; size_t osize = obuf_p - obuf;

View File

@@ -3812,11 +3812,11 @@ target_pass_ctrlc (void)
if (proc_target == NULL) if (proc_target == NULL)
continue; continue;
for (thread_info *thr : inf->non_exited_threads ()) for (thread_info &thr : inf->non_exited_threads ())
{ {
/* A thread can be THREAD_STOPPED and executing, while /* A thread can be THREAD_STOPPED and executing, while
running an infcall. */ running an infcall. */
if (thr->state == THREAD_RUNNING || thr->executing ()) if (thr.state == THREAD_RUNNING || thr.executing ())
{ {
/* We can get here quite deep in target layers. Avoid /* We can get here quite deep in target layers. Avoid
switching thread context or anything that would switching thread context or anything that would

View File

@@ -21,15 +21,12 @@
#include "gdbsupport/filtered-iterator.h" #include "gdbsupport/filtered-iterator.h"
#include "gdbsupport/iterator-range.h" #include "gdbsupport/iterator-range.h"
#include "gdbsupport/next-iterator.h"
#include "gdbsupport/reference-to-pointer-iterator.h"
#include "gdbsupport/safe-iterator.h" #include "gdbsupport/safe-iterator.h"
/* A forward iterator that iterates over a given inferior's /* A forward iterator that iterates over a given inferior's
threads. */ threads. */
using inf_threads_iterator using inf_threads_iterator = intrusive_list<thread_info>::iterator;
= reference_to_pointer_iterator<intrusive_list<thread_info>::iterator>;
/* A forward iterator that iterates over all threads of all /* A forward iterator that iterates over all threads of all
inferiors. */ inferiors. */
@@ -87,9 +84,9 @@ class all_matching_threads_iterator
{ {
public: public:
typedef all_matching_threads_iterator self_type; typedef all_matching_threads_iterator self_type;
typedef struct thread_info *value_type; typedef struct thread_info value_type;
typedef struct thread_info *&reference; typedef struct thread_info &reference;
typedef struct thread_info **pointer; typedef struct thread_info *pointer;
typedef std::forward_iterator_tag iterator_category; typedef std::forward_iterator_tag iterator_category;
typedef int difference_type; typedef int difference_type;
@@ -101,7 +98,7 @@ public:
/* Create a one-past-end iterator. */ /* Create a one-past-end iterator. */
all_matching_threads_iterator () = default; all_matching_threads_iterator () = default;
thread_info *operator* () const { return m_thr; } reference operator* () const { return *m_thr; }
all_matching_threads_iterator &operator++ () all_matching_threads_iterator &operator++ ()
{ {
@@ -149,9 +146,9 @@ private:
struct non_exited_thread_filter struct non_exited_thread_filter
{ {
bool operator() (struct thread_info *thr) const bool operator() (struct thread_info &thr) const
{ {
return thr->state != THREAD_EXITED; return thr.state != THREAD_EXITED;
} }
}; };

View File

@@ -558,9 +558,9 @@ delete_thread_silent (thread_info *thread)
struct thread_info * struct thread_info *
find_thread_global_id (int global_id) find_thread_global_id (int global_id)
{ {
for (thread_info *tp : all_threads ()) for (thread_info &tp : all_threads ())
if (tp->global_num == global_id) if (tp.global_num == global_id)
return tp; return &tp;
return NULL; return NULL;
} }
@@ -568,9 +568,9 @@ find_thread_global_id (int global_id)
static struct thread_info * static struct thread_info *
find_thread_id (struct inferior *inf, int thr_num) find_thread_id (struct inferior *inf, int thr_num)
{ {
for (thread_info *tp : inf->threads ()) for (thread_info &tp : inf->threads ())
if (tp->per_inf_num == thr_num) if (tp.per_inf_num == thr_num)
return tp; return &tp;
return NULL; return NULL;
} }
@@ -615,7 +615,7 @@ iterate_over_threads (gdb::function_view<bool (struct thread_info *)> callback)
bool bool
any_thread_p () any_thread_p ()
{ {
for (thread_info *tp ATTRIBUTE_UNUSED : all_threads ()) for (thread_info &tp ATTRIBUTE_UNUSED : all_threads ())
return true; return true;
return false; return false;
} }
@@ -639,8 +639,8 @@ live_threads_count (void)
int int
valid_global_thread_id (int global_id) valid_global_thread_id (int global_id)
{ {
for (thread_info *tp : all_threads ()) for (thread_info &tp : all_threads ())
if (tp->global_num == global_id) if (tp.global_num == global_id)
return 1; return 1;
return 0; return 0;
@@ -672,8 +672,8 @@ any_thread_of_inferior (inferior *inf)
if (inf == current_inferior () && inferior_ptid != null_ptid) if (inf == current_inferior () && inferior_ptid != null_ptid)
return inferior_thread (); return inferior_thread ();
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
return tp; return &tp;
return NULL; return NULL;
} }
@@ -699,12 +699,12 @@ any_live_thread_of_inferior (inferior *inf)
return curr_tp; return curr_tp;
} }
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
if (!tp->executing ()) if (!tp.executing ())
return tp; return &tp;
tp_executing = tp; tp_executing = &tp;
} }
/* If both the current thread and all live threads are executing, /* If both the current thread and all live threads are executing,
@@ -856,8 +856,8 @@ thread_change_ptid (process_stratum_target *targ,
void void
set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed) set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed)
{ {
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
tp->set_resumed (resumed); tp.set_resumed (resumed);
} }
/* Helper for set_running, that marks one thread either running or /* Helper for set_running, that marks one thread either running or
@@ -920,8 +920,8 @@ set_running (process_stratum_target *targ, ptid_t ptid, bool running)
multiple *running notifications just fine. */ multiple *running notifications just fine. */
bool any_started = false; bool any_started = false;
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
if (set_running_thread (tp, running)) if (set_running_thread (&tp, running))
any_started = true; any_started = true;
if (any_started) if (any_started)
@@ -931,8 +931,8 @@ set_running (process_stratum_target *targ, ptid_t ptid, bool running)
void void
set_executing (process_stratum_target *targ, ptid_t ptid, bool executing) set_executing (process_stratum_target *targ, ptid_t ptid, bool executing)
{ {
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
tp->set_executing (executing); tp.set_executing (executing);
/* It only takes one running thread to spawn more threads. */ /* It only takes one running thread to spawn more threads. */
if (executing) if (executing)
@@ -954,8 +954,8 @@ threads_are_executing (process_stratum_target *target)
void void
set_stop_requested (process_stratum_target *targ, ptid_t ptid, bool stop) set_stop_requested (process_stratum_target *targ, ptid_t ptid, bool stop)
{ {
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
tp->stop_requested = stop; tp.stop_requested = stop;
/* Call the stop requested observer so other components of GDB can /* Call the stop requested observer so other components of GDB can
react to this request. */ react to this request. */
@@ -968,8 +968,8 @@ finish_thread_state (process_stratum_target *targ, ptid_t ptid)
{ {
bool any_started = false; bool any_started = false;
for (thread_info *tp : all_non_exited_threads (targ, ptid)) for (thread_info &tp : all_non_exited_threads (targ, ptid))
if (set_running_thread (tp, tp->executing ())) if (set_running_thread (&tp, tp.executing ()))
any_started = true; any_started = true;
if (any_started) if (any_started)
@@ -1281,7 +1281,7 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
accommodate the largest entry. */ accommodate the largest entry. */
size_t target_id_col_width = 17; size_t target_id_col_width = 17;
for (thread_info *tp : all_threads ()) for (thread_info &tp : all_threads ())
{ {
any_thread = true; any_thread = true;
@@ -1290,16 +1290,16 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
switch_to_thread (current_thread); switch_to_thread (current_thread);
if (!should_print_thread (requested_threads, opts, if (!should_print_thread (requested_threads, opts,
default_inf_num, global_ids, pid, tp)) default_inf_num, global_ids, pid, &tp))
continue; continue;
/* Switch inferiors so we're looking at the right /* Switch inferiors so we're looking at the right
target stack. */ target stack. */
switch_to_inferior_no_thread (tp->inf); switch_to_inferior_no_thread (tp.inf);
target_id_col_width target_id_col_width
= std::max (target_id_col_width, = std::max (target_id_col_width,
thread_target_id_str (tp).size ()); thread_target_id_str (&tp).size ());
++n_matching_threads; ++n_matching_threads;
} }
@@ -1327,13 +1327,13 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
} }
for (inferior *inf : all_inferiors ()) for (inferior *inf : all_inferiors ())
for (thread_info *tp : inf->threads ()) for (thread_info &tp : inf->threads ())
{ {
if (tp == current_thread && tp->state == THREAD_EXITED) if (&tp == current_thread && tp.state == THREAD_EXITED)
current_exited = true; current_exited = true;
print_thread (uiout, requested_threads, opts, global_ids, pid, print_thread (uiout, requested_threads, opts, global_ids, pid,
default_inf_num, tp, current_thread); default_inf_num, &tp, current_thread);
} }
/* This end scope restores the current thread and the frame /* This end scope restores the current thread and the frame
@@ -1746,8 +1746,8 @@ thread_apply_all_command (const char *cmd, int from_tty)
std::vector<thread_info_ref> thr_list_cpy; std::vector<thread_info_ref> thr_list_cpy;
thr_list_cpy.reserve (tc); thr_list_cpy.reserve (tc);
for (thread_info *tp : all_non_exited_threads ()) for (thread_info &tp : all_non_exited_threads ())
thr_list_cpy.push_back (thread_info_ref::new_reference (tp)); thr_list_cpy.push_back (thread_info_ref::new_reference (&tp));
gdb_assert (thr_list_cpy.size () == tc); gdb_assert (thr_list_cpy.size () == tc);
auto *sorter = (ascending auto *sorter = (ascending
@@ -2031,38 +2031,38 @@ thread_find_command (const char *arg, int from_tty)
update_thread_list (); update_thread_list ();
for (thread_info *tp : all_threads ()) for (thread_info &tp : all_threads ())
{ {
switch_to_inferior_no_thread (tp->inf); switch_to_inferior_no_thread (tp.inf);
if (tp->name () != nullptr && re_exec (tp->name ())) if (tp.name () != nullptr && re_exec (tp.name ()))
{ {
gdb_printf (_("Thread %s has name '%s'\n"), gdb_printf (_("Thread %s has name '%s'\n"),
print_thread_id (tp), tp->name ()); print_thread_id (&tp), tp.name ());
match++; match++;
} }
tmp = target_thread_name (tp); tmp = target_thread_name (&tp);
if (tmp != NULL && re_exec (tmp)) if (tmp != NULL && re_exec (tmp))
{ {
gdb_printf (_("Thread %s has target name '%s'\n"), gdb_printf (_("Thread %s has target name '%s'\n"),
print_thread_id (tp), tmp); print_thread_id (&tp), tmp);
match++; match++;
} }
std::string name = target_pid_to_str (tp->ptid); std::string name = target_pid_to_str (tp.ptid);
if (!name.empty () && re_exec (name.c_str ())) if (!name.empty () && re_exec (name.c_str ()))
{ {
gdb_printf (_("Thread %s has target id '%s'\n"), gdb_printf (_("Thread %s has target id '%s'\n"),
print_thread_id (tp), name.c_str ()); print_thread_id (&tp), name.c_str ());
match++; match++;
} }
tmp = target_extra_thread_info (tp); tmp = target_extra_thread_info (&tp);
if (tmp != NULL && re_exec (tmp)) if (tmp != NULL && re_exec (tmp))
{ {
gdb_printf (_("Thread %s has extra info '%s'\n"), gdb_printf (_("Thread %s has extra info '%s'\n"),
print_thread_id (tp), tmp); print_thread_id (&tp), tmp);
match++; match++;
} }
} }
@@ -2164,9 +2164,9 @@ update_threads_executing (void)
return; return;
} }
for (thread_info *tp : inf->non_exited_threads ()) for (thread_info &tp : inf->non_exited_threads ())
{ {
if (tp->executing ()) if (tp.executing ())
{ {
targ->threads_executing = true; targ->threads_executing = true;
return; return;

View File

@@ -117,10 +117,10 @@ parse_thread_id (const char *tidstr, const char **end)
inf = current_inferior (); inf = current_inferior ();
thread_info *tp = nullptr; thread_info *tp = nullptr;
for (thread_info *it : inf->threads ()) for (thread_info &it : inf->threads ())
if (it->per_inf_num == thr_num) if (it.per_inf_num == thr_num)
{ {
tp = it; tp = &it;
break; break;
} }

View File

@@ -86,9 +86,9 @@ x86bsd_dr_set (ptid_t ptid, int regnum, unsigned long value)
DBREG_DRX ((&dbregs), regnum) = value; DBREG_DRX ((&dbregs), regnum) = value;
for (thread_info *thread : current_inferior ()->non_exited_threads ()) for (thread_info &thread : current_inferior ()->non_exited_threads ())
{ {
if (gdb_ptrace (PT_SETDBREGS, thread->ptid, if (gdb_ptrace (PT_SETDBREGS, thread.ptid,
(PTRACE_TYPE_ARG3) &dbregs) == -1) (PTRACE_TYPE_ARG3) &dbregs) == -1)
perror_with_name (_("Couldn't write debug registers")); perror_with_name (_("Couldn't write debug registers"));
} }