From patchwork Mon Oct 28 08:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rohr, Stephan" X-Patchwork-Id: 99694 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 945273858CDA for ; Mon, 28 Oct 2024 08:21:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by sourceware.org (Postfix) with ESMTPS id 122B93858D26 for ; Mon, 28 Oct 2024 08:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 122B93858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 122B93858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730103644; cv=none; b=R+T+wdjPVZlOnHuFSsFI16TsVt47JOg4E8Dqoel60EWAFrnY57I3eQgNW4M2nBZCmHCOal6f9wx50BgKa8EBwmgRiEB1D3O++SaMCvqkEG66fDY+HGMkfObnUT5uMEkDyXEmUKKZI1jEkrBCczD378d76ofoeo0HKKPh6D+17eE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730103644; c=relaxed/simple; bh=vujdH3eJboRmqNrhvTnq/tUv86agmu4ZXllwMbbf730=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ZUoD3KXy3+KaYxschIwhQEw54jy4qFAVVmpz3ImIwiTn7LQ/RATPhNY23LSGQUmwguKV+YmiZWdcrqYvwEF0UyemFNYl5WKWX7rjFVqjklPJhpZfWq+kNDltjcHfgTvj8/ICYSH9KnANj4PNnGGheLC4GB21+gBAooJcZ6Qrkks= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730103637; x=1761639637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vujdH3eJboRmqNrhvTnq/tUv86agmu4ZXllwMbbf730=; b=SycVAHWEzd6iLVT4fLrdVnX0XUh31rL4Y3puKbZ6SjHxpfY4jhX8Mbfm ZOrOIYA+VulI+JHP05F2JtaT57zCMOgqcjF52i1hh6QC0am9Nj8BNOiKH aHyE+nZywJaeRztAu25igRIn6pE5YwGXBlbeZHUIvLh6XKkMOduv7AHaB 18UwVaJV/blJ0IX0n2fxy0WQvjrjSweq6w2luC0Eugam7HRVN745+dI3V eV0mnvILfXZoExjsWT6XM5BNI8X/TyafEoIh+w8QPGv1JOpHzjkZT8x5E xYfNjpg7vD6VLLUgray0jJ4DcbzO6uG5VUd6kjvYw1s8FH85dDX3TSqqi g==; X-CSE-ConnectionGUID: CBgg5z3PT/29fcxuARaLAg== X-CSE-MsgGUID: fXm8dPC2RJuhGX4Bw+cEbw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="33386736" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="33386736" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 01:20:34 -0700 X-CSE-ConnectionGUID: jJtv0P8pQaWgD1I4Nt/g+Q== X-CSE-MsgGUID: uqAHBpdQTTeXrjCpaaaWeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,238,1725346800"; d="scan'208";a="81133613" Received: from 984fee0031af.jf.intel.com (HELO localhost) ([10.165.54.65]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 01:20:31 -0700 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, simark@simark.ca, tom@tromey.com Subject: [PATCH v5 1/2] gdbserver: change 'all_processes' and 'all_threads' list type Date: Mon, 28 Oct 2024 01:20:17 -0700 Message-Id: <20241028082018.2564511-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028082018.2564511-1-stephan.rohr@intel.com> References: <20241028082018.2564511-1-stephan.rohr@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This patch replaces the 'std::list' type of 'all_processes' and 'all_threads' with the more lightweight 'owning_intrusive_list' type. --- gdbserver/gdbthread.h | 8 ++--- gdbserver/inferiors.cc | 75 +++++++++++++----------------------------- gdbserver/inferiors.h | 7 ++-- gdbserver/server.cc | 16 ++++----- 4 files changed, 37 insertions(+), 69 deletions(-) diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h index adc5857abfd..1c380d5ff22 100644 --- a/gdbserver/gdbthread.h +++ b/gdbserver/gdbthread.h @@ -21,14 +21,12 @@ #include "gdbsupport/common-gdbthread.h" #include "gdbsupport/function-view.h" -#include "inferiors.h" - -#include +#include "gdbsupport/owning_intrusive_list.h" struct btrace_target_info; struct regcache; -struct thread_info +struct thread_info : public intrusive_list_node { thread_info (ptid_t id, void *target_data) : id (id), target_data (target_data) @@ -86,7 +84,7 @@ struct thread_info gdb_thread_options thread_options = 0; }; -extern std::list all_threads; +extern owning_intrusive_list all_threads; void remove_thread (struct thread_info *thread); struct thread_info *add_thread (ptid_t ptid, void *target_data); diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index 5621db377fb..1d39a8d1a86 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -19,11 +19,12 @@ along with this program. If not, see . */ #include "gdbsupport/common-inferior.h" +#include "gdbsupport/owning_intrusive_list.h" #include "gdbthread.h" #include "dll.h" -std::list all_processes; -std::list all_threads; +owning_intrusive_list all_processes; +owning_intrusive_list all_threads; /* The current process. */ static process_info *current_process_; @@ -40,14 +41,12 @@ static std::string current_inferior_cwd; struct thread_info * add_thread (ptid_t thread_id, void *target_data) { - thread_info *new_thread = new thread_info (thread_id, target_data); - - all_threads.push_back (new_thread); + auto &new_thread = all_threads.emplace_back (thread_id, target_data); if (current_thread == NULL) - switch_to_thread (new_thread); + switch_to_thread (&new_thread); - return new_thread; + return &new_thread; } /* See gdbthread.h. */ @@ -56,7 +55,7 @@ struct thread_info * get_first_thread (void) { if (!all_threads.empty ()) - return all_threads.front (); + return &(all_threads.front ()); else return NULL; } @@ -88,12 +87,6 @@ find_any_thread_of_pid (int pid) }); } -static void -free_one_thread (thread_info *thread) -{ - delete thread; -} - void remove_thread (struct thread_info *thread) { @@ -101,10 +94,9 @@ remove_thread (struct thread_info *thread) target_disable_btrace (thread->btrace); discard_queued_stop_replies (ptid_of (thread)); - all_threads.remove (thread); + all_threads.erase (all_threads.iterator_to (*thread)); if (current_thread == thread) switch_to_thread (nullptr); - free_one_thread (thread); } void * @@ -128,7 +120,6 @@ set_thread_regcache_data (struct thread_info *thread, struct regcache *data) void clear_inferiors (void) { - for_each_thread (free_one_thread); all_threads.clear (); clear_dlls (); @@ -140,11 +131,8 @@ clear_inferiors (void) struct process_info * add_process (int pid, int attached) { - process_info *process = new process_info (pid, attached); - - all_processes.push_back (process); - - return process; + auto &process = all_processes.emplace_back (pid, attached); + return &process; } /* Remove a process from the common process list and free the memory @@ -157,10 +145,9 @@ remove_process (struct process_info *process) clear_symbol_cache (&process->symbol_cache); free_all_breakpoints (process); gdb_assert (find_thread_process (process) == NULL); - all_processes.remove (process); + all_processes.erase (all_processes.iterator_to (*process)); if (current_process () == process) switch_to_process (nullptr); - delete process; } process_info * @@ -177,7 +164,7 @@ process_info * get_first_process (void) { if (!all_processes.empty ()) - return all_processes.front (); + return &(all_processes.front ()); else return NULL; } @@ -220,13 +207,13 @@ current_process (void) void for_each_process (gdb::function_view func) { - std::list::iterator next, cur = all_processes.begin (); + owning_intrusive_list::iterator next, cur = all_processes.begin (); while (cur != all_processes.end ()) { next = cur; next++; - func (*cur); + func (&*cur); cur = next; } } @@ -236,18 +223,9 @@ for_each_process (gdb::function_view func) process_info * find_process (gdb::function_view func) { - std::list::iterator next, cur = all_processes.begin (); - - while (cur != all_processes.end ()) - { - next = cur; - next++; - - if (func (*cur)) - return *cur; - - cur = next; - } + for (process_info &process : all_processes) + if (func (&process)) + return &process; return NULL; } @@ -257,18 +235,9 @@ find_process (gdb::function_view func) thread_info * find_thread (gdb::function_view func) { - std::list::iterator next, cur = all_threads.begin (); - - while (cur != all_threads.end ()) - { - next = cur; - next++; - - if (func (*cur)) - return *cur; - - cur = next; - } + for (thread_info &thread : all_threads) + if (func (&thread)) + return &thread; return NULL; } @@ -299,13 +268,13 @@ find_thread (ptid_t filter, gdb::function_view func) void for_each_thread (gdb::function_view func) { - std::list::iterator next, cur = all_threads.begin (); + owning_intrusive_list::iterator next, cur = all_threads.begin (); while (cur != all_threads.end ()) { next = cur; next++; - func (*cur); + func (&*cur); cur = next; } } diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h index 7d453260270..3f2c5c70a39 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -20,8 +20,9 @@ #define GDBSERVER_INFERIORS_H #include "gdbsupport/gdb_vecs.h" +#include "gdbsupport/owning_intrusive_list.h" + #include "dll.h" -#include struct thread_info; struct regcache; @@ -32,7 +33,7 @@ struct raw_breakpoint; struct fast_tracepoint_jump; struct process_info_private; -struct process_info +struct process_info : public intrusive_list_node { process_info (int pid_, int attached_) : pid (pid_), attached (attached_) @@ -99,7 +100,7 @@ pid_of (const process_info *proc) struct process_info *current_process (void); struct process_info *get_thread_process (const struct thread_info *); -extern std::list all_processes; +extern owning_intrusive_list all_processes; /* Invoke FUNC for each process. */ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 5190df4aed5..5058428f58b 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1355,15 +1355,15 @@ handle_detach (char *own_buf) another process might delete the next thread in the iteration, which is the one saved by the safe iterator. We will never delete the currently iterated on thread, so standard iteration should be safe. */ - for (thread_info *thread : all_threads) + for (thread_info &thread : all_threads) { /* Only threads that are of the process we are detaching. */ - if (thread->id.pid () != pid) + if (thread.id.pid () != pid) continue; /* Only threads that have a pending fork event. */ target_waitkind kind; - thread_info *child = target_thread_pending_child (thread, &kind); + thread_info *child = target_thread_pending_child (&thread, &kind); if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED) continue; @@ -1375,7 +1375,7 @@ handle_detach (char *own_buf) if (detach_inferior (fork_child_process) != 0) warning (_("Failed to detach fork child %s, child of %s"), target_pid_to_str (ptid_t (fork_child_pid)).c_str (), - target_pid_to_str (thread->id).c_str ()); + target_pid_to_str (thread.id).c_str ()); } if (detach_inferior (process) != 0) @@ -2523,7 +2523,7 @@ static void handle_query (char *own_buf, int packet_len, int *new_packet_len_p) { client_state &cs = get_client_state (); - static std::list::const_iterator thread_iter; + static owning_intrusive_list::iterator thread_iter; /* Reply the current thread id. */ if (strcmp ("qC", own_buf) == 0 && !disable_packet_qC) @@ -2536,7 +2536,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) else { thread_iter = all_threads.begin (); - ptid = (*thread_iter)->id; + ptid = thread_iter->id; } sprintf (own_buf, "QC"); @@ -2599,7 +2599,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) thread_iter = all_threads.begin (); *own_buf++ = 'm'; - ptid_t ptid = (*thread_iter)->id; + ptid_t ptid = thread_iter->id; write_ptid (own_buf, ptid); thread_iter++; return; @@ -2611,7 +2611,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (thread_iter != all_threads.end ()) { *own_buf++ = 'm'; - ptid_t ptid = (*thread_iter)->id; + ptid_t ptid = thread_iter->id; write_ptid (own_buf, ptid); thread_iter++; return;