aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2025-09-03 10:50:00 -0400
committerSimon Marchi <simon.marchi@efficios.com>2025-10-07 16:22:15 -0400
commite92df1d0eb6c81bf11a93e5df0319c56d25bbed2 (patch)
treee268ce5e124c02e8a4e95ea456a9bf834f70898a
parentf25e28c3fe3f9e2293875012b36b2644179ac06b (diff)
downloadbinutils-e92df1d0eb6c81bf11a93e5df0319c56d25bbed2.zip
binutils-e92df1d0eb6c81bf11a93e5df0319c56d25bbed2.tar.gz
binutils-e92df1d0eb6c81bf11a93e5df0319c56d25bbed2.tar.bz2
gdb: make lwp_info_iterator yield references
Same rational as the previous patches. Change-Id: I36852ec0c94dc3a87e3af033ca5e55c6b0f708b1 Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/linux-nat.c44
-rw-r--r--gdb/linux-nat.h3
-rw-r--r--gdb/linux-thread-db.c6
3 files changed, 26 insertions, 27 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 87fb800..8ca6d78 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -481,8 +481,8 @@ num_lwps (int pid)
{
int count = 0;
- for (const lwp_info *lp ATTRIBUTE_UNUSED : all_lwps ())
- if (lp->ptid.pid () == pid)
+ for (const lwp_info &lp : all_lwps ())
+ if (lp.ptid.pid () == pid)
count++;
return count;
@@ -930,12 +930,12 @@ struct lwp_info *
iterate_over_lwps (ptid_t filter,
gdb::function_view<iterate_over_lwps_ftype> callback)
{
- for (lwp_info *lp : all_lwps_safe ())
+ for (lwp_info &lp : all_lwps_safe ())
{
- if (lp->ptid.matches (filter))
+ if (lp.ptid.matches (filter))
{
- if (callback (lp) != 0)
- return lp;
+ if (callback (&lp) != 0)
+ return &lp;
}
}
@@ -2141,9 +2141,9 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
PTRACE_GETEVENTMSG, we'd still need to lookup the
corresponding LWP object, and it would be an extra ptrace
syscall, so this way may even be more efficient. */
- for (lwp_info *other_lp : all_lwps_safe ())
- if (other_lp != lp && other_lp->ptid.pid () == lp->ptid.pid ())
- exit_lwp (other_lp);
+ for (lwp_info &other_lp : all_lwps_safe ())
+ if (&other_lp != lp && other_lp.ptid.pid () == lp->ptid.pid ())
+ exit_lwp (&other_lp);
return 0;
}
@@ -3856,11 +3856,11 @@ linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
static lwp_info *
find_stopped_lwp (int pid)
{
- for (lwp_info *lp : all_lwps ())
- if (lp->ptid.pid () == pid
- && lp->stopped
- && !is_lwp_marked_dead (lp))
- return lp;
+ for (lwp_info &lp : all_lwps ())
+ if (lp.ptid.pid () == pid
+ && lp.stopped
+ && !is_lwp_marked_dead (&lp))
+ return &lp;
return nullptr;
}
@@ -3962,13 +3962,13 @@ linux_nat_target::update_thread_list ()
/* Update the processor core that each lwp/thread was last seen
running on. */
- for (lwp_info *lwp : all_lwps ())
+ for (lwp_info &lwp : all_lwps ())
{
/* Avoid accessing /proc if the thread hasn't run since we last
time we fetched the thread's core. Accessing /proc becomes
noticeably expensive when we have thousands of LWPs. */
- if (lwp->core == -1)
- lwp->core = linux_common_core_of_thread (lwp->ptid);
+ if (lwp.core == -1)
+ lwp.core = linux_common_core_of_thread (lwp.ptid);
}
}
@@ -4696,8 +4696,8 @@ maintenance_info_lwps (const char *arg, int from_tty)
figure out the widest ptid string. We'll use this to build our
output table below. */
size_t ptid_width = 8;
- for (lwp_info *lp : all_lwps ())
- ptid_width = std::max (ptid_width, lp->ptid.to_string ().size ());
+ for (lwp_info &lp : all_lwps ())
+ ptid_width = std::max (ptid_width, lp.ptid.to_string ().size ());
/* Setup the table headers. */
struct ui_out *uiout = current_uiout;
@@ -4707,13 +4707,13 @@ maintenance_info_lwps (const char *arg, int from_tty)
uiout->table_body ();
/* Display one table row for each lwp_info. */
- for (lwp_info *lp : all_lwps ())
+ for (lwp_info &lp : all_lwps ())
{
ui_out_emit_tuple tuple_emitter (uiout, "lwp-entry");
- thread_info *th = linux_target->find_thread (lp->ptid);
+ thread_info *th = linux_target->find_thread (lp.ptid);
- uiout->field_string ("lwp-ptid", lp->ptid.to_string ().c_str ());
+ uiout->field_string ("lwp-ptid", lp.ptid.to_string ().c_str ());
if (th == nullptr)
uiout->field_string ("thread-info", "None");
else
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index ed128c0..70d1241 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -299,8 +299,7 @@ struct lwp_info : intrusive_list_node<lwp_info>
/* lwp_info iterator and range types. */
-using lwp_info_iterator
- = reference_to_pointer_iterator<intrusive_list<lwp_info>::iterator>;
+using lwp_info_iterator = intrusive_list<lwp_info>::iterator;
using lwp_info_range = iterator_range<lwp_info_iterator>;
using lwp_info_safe_range = basic_safe_range<lwp_info_range>;
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 50df327..d30b25f 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -918,9 +918,9 @@ try_thread_db_load_1 (struct thread_db_info *info)
linux_stop_and_wait_all_lwps ();
- for (const lwp_info *lp : all_lwps ())
- if (lp->ptid.pid () == pid)
- thread_from_lwp (curr_thread, lp->ptid);
+ for (const lwp_info &lp : all_lwps ())
+ if (lp.ptid.pid () == pid)
+ thread_from_lwp (curr_thread, lp.ptid);
linux_unstop_all_lwps ();
}