From patchwork Mon Mar 27 16:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 66966 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 4C3803858C66 for ; Mon, 27 Mar 2023 16:54:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C3803858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679936072; bh=t8VTzvE6tEQXjuYySLtoKlxL18+LC1ReQp92Xdc3iAc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=A8eEn9IfpPFQbS0FP17xc26cFOW3yyQW3/KzLZISiqCgKzMFbbPwSVKwtQfGKUKIX asxYpDFP4cK7sUm/E/zdgNNcnmprIcN5fDP4E0Fc85y9opSPMatjx4WB9VLf7QtYQB zwjKRyhlkzp0cmVozM+mxw8OOz5GbWviIoj2STbs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9360B3858C54 for ; Mon, 27 Mar 2023 16:53:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9360B3858C54 Received: from localhost.localdomain (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 498C01E15D; Mon, 27 Mar 2023 12:53:56 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/2] gdb: make find_thread_ptid an inferior method Date: Mon, 27 Mar 2023 12:53:54 -0400 Message-Id: <20230327165355.89228-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230327165355.89228-1-simon.marchi@efficios.com> References: <20230327165355.89228-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1173.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Make find_thread_ptid (the overload that takes an inferior) a method of struct inferior. Change-Id: Ie5b9fa623ff35aa7ddb45e2805254fc8e83c9cd4 --- gdb/ada-tasks.c | 8 ++++---- gdb/aix-thread.c | 6 +++--- gdb/btrace.c | 2 +- gdb/gdbthread.h | 3 --- gdb/inferior.c | 12 ++++++++++++ gdb/inferior.h | 3 +++ gdb/infrun.c | 4 ++-- gdb/linux-thread-db.c | 2 +- gdb/python/py-threadevent.c | 3 +-- gdb/ravenscar-thread.c | 2 +- gdb/sol-thread.c | 4 ++-- gdb/thread.c | 22 ++++------------------ 12 files changed, 34 insertions(+), 37 deletions(-) diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index b14d159df149..f107d4e4c286 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -1177,7 +1177,7 @@ print_ada_task_info (struct ui_out *uiout, if (uiout->is_mi_like_p ()) { thread_info *thread = (ada_task_is_alive (task_info) - ? find_thread_ptid (inf, task_info->ptid) + ? inf->find_thread (task_info->ptid) : nullptr); if (thread != NULL) @@ -1393,7 +1393,7 @@ task_command_1 (const char *taskno_str, int from_tty, struct inferior *inf) computed if target_get_ada_task_ptid has not been implemented for our target (yet). Rather than cause an assertion error in that case, it's nicer for the user to just refuse to perform the task switch. */ - thread_info *tp = find_thread_ptid (inf, task_info->ptid); + thread_info *tp = inf->find_thread (task_info->ptid); if (tp == NULL) error (_("Unable to compute thread ID for task %s.\n" "Cannot switch to this task."), @@ -1577,7 +1577,7 @@ task_apply_all_command (const char *cmd, int from_tty) if (!ada_task_is_alive (&task)) continue; - thread_info *tp = find_thread_ptid (inf, task.ptid); + thread_info *tp = inf->find_thread (task.ptid); if (tp == nullptr) warning (_("Unable to compute thread ID for task %s.\n" "Cannot switch to this task."), @@ -1627,7 +1627,7 @@ task_apply_command (const char *tidlist, int from_tty) if (!ada_task_is_alive (&task)) continue; - thread_info *tp = find_thread_ptid (inf, task.ptid); + thread_info *tp = inf->find_thread (task.ptid); if (tp == nullptr) warning (_("Unable to compute thread ID for task %s.\n" "Cannot switch to this task."), diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index df843d3c4873..f4ccfb2b364d 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -1172,7 +1172,7 @@ aix_thread_target::resume (ptid_t ptid, int step, enum gdb_signal sig) } else { - thread = find_thread_ptid (current_inferior (), ptid); + thread = current_inferior ()->find_thread (ptid); if (!thread) error (_("aix-thread resume: unknown pthread %ld"), ptid.lwp ()); @@ -1566,7 +1566,7 @@ aix_thread_target::fetch_registers (struct regcache *regcache, int regno) beneath ()->fetch_registers (regcache, regno); else { - thread = find_thread_ptid (current_inferior (), regcache->ptid ()); + thread = current_inferior ()->find_thread (regcache->ptid ()); aix_thread_info *priv = get_aix_thread_info (thread); tid = priv->tid; @@ -2032,7 +2032,7 @@ aix_thread_target::store_registers (struct regcache *regcache, int regno) beneath ()->store_registers (regcache, regno); else { - thread = find_thread_ptid (current_inferior (), regcache->ptid ()); + thread = current_inferior ()->find_thread (regcache->ptid ()); aix_thread_info *priv = get_aix_thread_info (thread); tid = priv->tid; diff --git a/gdb/btrace.c b/gdb/btrace.c index 38d3882c1540..dbdcea0a8eaf 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -3246,7 +3246,7 @@ maint_btrace_packet_history_cmd (const char *arg, int from_tty) struct btrace_thread_info *btinfo; unsigned int size, begin, end, from, to; - thread_info *tp = find_thread_ptid (current_inferior (), inferior_ptid); + thread_info *tp = current_inferior ()->find_thread (inferior_ptid); if (tp == NULL) error (_("No thread.")); diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 848daa94410a..81e4afd24c25 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -672,9 +672,6 @@ extern bool in_thread_list (process_stratum_target *targ, ptid_t ptid); global id, not the system's). */ extern int valid_global_thread_id (int global_id); -/* Find (non-exited) thread PTID of inferior INF. */ -extern thread_info *find_thread_ptid (inferior *inf, ptid_t ptid); - /* Search function to lookup a (non-exited) thread by 'ptid'. */ extern struct thread_info *find_thread_ptid (process_stratum_target *targ, ptid_t ptid); diff --git a/gdb/inferior.c b/gdb/inferior.c index a1e3c79d8a20..6eb9f3ff23b9 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -216,6 +216,18 @@ add_inferior (int pid) /* See inferior.h. */ +thread_info * +inferior::find_thread (ptid_t ptid) +{ + auto it = this->ptid_thread_map.find (ptid); + if (it != this->ptid_thread_map.end ()) + return it->second; + else + return nullptr; +} + +/* See inferior.h. */ + void inferior::clear_thread_list (bool silent) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 72034cc4ffbc..633916eb7c1f 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -490,6 +490,9 @@ class inferior : public refcounted_object, inline safe_inf_threads_range threads_safe () { return safe_inf_threads_range (this->thread_list.begin ()); } + /* Find (non-exited) thread PTID of this inferior. */ + thread_info *find_thread (ptid_t ptid); + /* Delete all threads in the thread list. If SILENT, exit threads silently. */ void clear_thread_list (bool silent); diff --git a/gdb/infrun.c b/gdb/infrun.c index ee812baf8dac..334080142f15 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -645,7 +645,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ The former case will have pending_follow cleared, the later will have pending_follow set. */ - thread_info *parent_thread = find_thread_ptid (parent_inf, parent_ptid); + thread_info *parent_thread = parent_inf->find_thread (parent_ptid); gdb_assert (parent_thread != nullptr); parent_thread->pending_follow.set_spurious (); @@ -3730,7 +3730,7 @@ do_target_wait_1 (inferior *inf, ptid_t ptid, ptid.to_string ().c_str ()); /* We have a specific thread to check. */ - tp = find_thread_ptid (inf, ptid); + tp = inf->find_thread (ptid); gdb_assert (tp != nullptr); if (!tp->has_pending_waitstatus ()) tp = nullptr; diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 5f2f167dbce7..ef1c2819229d 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1655,7 +1655,7 @@ thread_db_target::update_thread_list () std::string thread_db_target::pid_to_str (ptid_t ptid) { - thread_info *thread_info = find_thread_ptid (current_inferior (), ptid); + thread_info *thread_info = current_inferior ()->find_thread (ptid); if (thread_info != NULL && thread_info->priv != NULL) { diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index b29f69a3855f..05a833def259 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -28,8 +28,7 @@ py_get_event_thread (ptid_t ptid) if (non_stop) { thread_info *thread - = find_thread_ptid (current_inferior ()->process_target (), - ptid); + = current_inferior ()->find_thread (ptid); if (thread != nullptr) return thread_to_thread_object (thread); PyErr_SetString (PyExc_RuntimeError, "Could not find event thread"); diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 22fbdbe9662e..ad357352eca8 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -452,7 +452,7 @@ ravenscar_thread_target::wait (ptid_t ptid, void ravenscar_thread_target::add_thread (struct ada_task_info *task) { - if (find_thread_ptid (current_inferior (), task->ptid) == NULL) + if (current_inferior ()->find_thread (task->ptid) == NULL) { ::add_thread (current_inferior ()->process_target (), task->ptid); m_cpu_map[task->ptid.tid ()] = task->base_cpu; diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 8945c2041db8..ed1a803fbdb0 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -451,7 +451,7 @@ sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, /* See if we have a new thread. */ if (rtnval.tid_p ()) { - thread_info *thr = find_thread_ptid (current_inferior (), rtnval); + thread_info *thr = current_inferior ()->find_thread (rtnval); if (thr == NULL || thr->state == THREAD_EXITED) { process_stratum_target *proc_target @@ -1003,7 +1003,7 @@ sol_update_thread_list_callback (const td_thrhandle_t *th, void *ignored) return -1; ptid_t ptid = ptid_t (current_inferior ()->pid, 0, ti.ti_tid); - thread_info *thr = find_thread_ptid (current_inferior (), ptid); + thread_info *thr = current_inferior ()->find_thread (ptid); if (thr == NULL || thr->state == THREAD_EXITED) { process_stratum_target *proc_target diff --git a/gdb/thread.c b/gdb/thread.c index 3d4cba32303d..9bca4784f900 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -221,7 +221,7 @@ set_thread_exited (thread_info *tp, bool silent) clear_thread_inferior_resources (tp); /* Remove from the ptid_t map. We don't want for - find_thread_ptid to find exited threads. Also, the target + inferior::find_thread to find exited threads. Also, the target may reuse the ptid for a new thread, and there can only be one value per key; adding a new thread with the same ptid_t would overwrite the exited thread's ptid entry. */ @@ -275,7 +275,7 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid) If we do, it must be dead, otherwise we wouldn't be adding a new thread with the same id. The OS is reusing this id --- delete the old thread, and create a new one. */ - thread_info *tp = find_thread_ptid (inf, ptid); + thread_info *tp = inf->find_thread (ptid); if (tp != nullptr) delete_thread (tp); @@ -520,21 +520,7 @@ find_thread_ptid (process_stratum_target *targ, ptid_t ptid) inferior *inf = find_inferior_ptid (targ, ptid); if (inf == NULL) return NULL; - return find_thread_ptid (inf, ptid); -} - -/* See gdbthread.h. */ - -struct thread_info * -find_thread_ptid (inferior *inf, ptid_t ptid) -{ - gdb_assert (inf != nullptr); - - auto it = inf->ptid_thread_map.find (ptid); - if (it != inf->ptid_thread_map.end ()) - return it->second; - else - return nullptr; + return inf->find_thread (ptid); } /* See gdbthread.h. */ @@ -802,7 +788,7 @@ thread_change_ptid (process_stratum_target *targ, inf = find_inferior_ptid (targ, old_ptid); inf->pid = new_ptid.pid (); - tp = find_thread_ptid (inf, old_ptid); + tp = inf->find_thread (old_ptid); gdb_assert (tp != nullptr); int num_erased = inf->ptid_thread_map.erase (old_ptid);