From e92df1d0eb6c81bf11a93e5df0319c56d25bbed2 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 3 Sep 2025 10:50:00 -0400 Subject: [PATCH] gdb: make lwp_info_iterator yield references Same rational as the previous patches. Change-Id: I36852ec0c94dc3a87e3af033ca5e55c6b0f708b1 Approved-By: Tom Tromey --- gdb/linux-nat.c | 44 +++++++++++++++++++++---------------------- gdb/linux-nat.h | 3 +-- gdb/linux-thread-db.c | 6 +++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 87fb800e544..8ca6d78bb7e 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 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 ed128c0ab7c..70d1241c549 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -299,8 +299,7 @@ struct lwp_info : intrusive_list_node /* lwp_info iterator and range types. */ -using lwp_info_iterator - = reference_to_pointer_iterator::iterator>; +using lwp_info_iterator = intrusive_list::iterator; using lwp_info_range = iterator_range; using lwp_info_safe_range = basic_safe_range; diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 50df32704e8..d30b25f4d19 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 (); } -- 2.47.3