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.h | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'gdb/linux-nat.h') diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index b1b168d..74b5edd 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -196,11 +196,9 @@ extern linux_nat_target *linux_target; struct arch_lwp_info; -/* Structure describing an LWP. This is public only for the purposes - of ALL_LWPS; target-specific code should generally not access it - directly. */ +/* Structure describing an LWP. */ -struct lwp_info +struct lwp_info : intrusive_list_node { lwp_info (ptid_t ptid) : ptid (ptid) @@ -283,27 +281,26 @@ struct lwp_info /* Arch-specific additions. */ struct arch_lwp_info *arch_private = nullptr; - - /* Previous and next pointers in doubly-linked list of known LWPs, - sorted by reverse creation order. */ - struct lwp_info *prev = nullptr; - struct lwp_info *next = nullptr; }; -/* The global list of LWPs, for ALL_LWPS. Unlike the threads list, - there is always at least one LWP on the list while the GNU/Linux - native target is active. */ -extern struct lwp_info *lwp_list; +/* lwp_info iterator and range types. */ + +using lwp_info_iterator + = reference_to_pointer_iterator::iterator>; +using lwp_info_range = iterator_range; +using lwp_info_safe_range = basic_safe_range; + +/* Get an iterable range over all lwps. */ + +lwp_info_range all_lwps (); + +/* Same as the above, but safe against deletion while iterating. */ + +lwp_info_safe_range all_lwps_safe (); /* Does the current host support PTRACE_GETREGSET? */ extern enum tribool have_ptrace_getregset; -/* Iterate over each active thread (light-weight process). */ -#define ALL_LWPS(LP) \ - for ((LP) = lwp_list; \ - (LP) != NULL; \ - (LP) = (LP)->next) - /* Called from the LWP layer to inform the thread_db layer that PARENT spawned CHILD. Both LWPs are currently stopped. This function does whatever is required to have the child LWP under the -- cgit v1.1