From 901b98215e767bbffb1bfa869e02d7dc5ea786ec Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 28 Aug 2021 10:58:45 -0400 Subject: gdb: use intrusive_list for linux-nat lwp_list Replace the manually maintained linked list of lwp_info objects with intrusive_list. Replace the ALL_LWPS macro with all_lwps, which returns a range. Add all_lwps_safe as well, for use in iterate_over_lwps, which currently iterates in a safe manner. Change-Id: I355313502510acc0103f5eaf2fbde80897d6376c --- gdb/linux-nat.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'gdb/linux-nat.c') diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index a297d3b..bac383d 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -421,9 +421,8 @@ static int num_lwps (int pid) { int count = 0; - struct lwp_info *lp; - for (lp = lwp_list; lp; lp = lp->next) + for (const lwp_info *lp ATTRIBUTE_UNUSED : all_lwps ()) if (lp->ptid.pid () == pid) count++; @@ -700,17 +699,31 @@ lwp_lwpid_htab_add_lwp (struct lwp_info *lp) creation order. This order is assumed in some cases. E.g., reaping status after killing alls lwps of a process: the leader LWP must be reaped last. */ -struct lwp_info *lwp_list; + +static intrusive_list lwp_list; + +/* See linux-nat.h. */ + +lwp_info_range +all_lwps () +{ + return lwp_info_range (lwp_list.begin ()); +} + +/* See linux-nat.h. */ + +lwp_info_safe_range +all_lwps_safe () +{ + return lwp_info_safe_range (lwp_list.begin ()); +} /* Add LP to sorted-by-reverse-creation-order doubly-linked list. */ static void lwp_list_add (struct lwp_info *lp) { - lp->next = lwp_list; - if (lwp_list != NULL) - lwp_list->prev = lp; - lwp_list = lp; + lwp_list.push_front (*lp); } /* Remove LP from sorted-by-reverse-creation-order doubly-linked @@ -720,12 +733,7 @@ static void lwp_list_remove (struct lwp_info *lp) { /* Remove from sorted-by-creation-order list. */ - if (lp->next != NULL) - lp->next->prev = lp->prev; - if (lp->prev != NULL) - lp->prev->next = lp->next; - if (lp == lwp_list) - lwp_list = lp->next; + lwp_list.erase (lwp_list.iterator_to (*lp)); } @@ -922,12 +930,8 @@ struct lwp_info * iterate_over_lwps (ptid_t filter, gdb::function_view callback) { - struct lwp_info *lp, *lpnext; - - for (lp = lwp_list; lp; lp = lpnext) + for (lwp_info *lp : all_lwps_safe ()) { - lpnext = lp->next; - if (lp->ptid.matches (filter)) { if (callback (lp) != 0) @@ -3715,8 +3719,6 @@ linux_nat_target::thread_alive (ptid_t ptid) void linux_nat_target::update_thread_list () { - struct lwp_info *lwp; - /* We add/delete threads from the list as clone/exit events are processed, so just try deleting exited threads still in the thread list. */ @@ -3724,7 +3726,7 @@ linux_nat_target::update_thread_list () /* Update the processor core that each lwp/thread was last seen running on. */ - ALL_LWPS (lwp) + 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 @@ -3948,7 +3950,7 @@ linux_proc_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, /* Iterate over LWPs of the current inferior, trying to access memory through one of them. */ - for (lwp_info *lp = lwp_list; lp != nullptr; lp = lp->next) + for (lwp_info *lp : all_lwps ()) { if (lp->ptid.pid () != cur_pid) continue; -- cgit v1.1