aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2023-03-27 12:53:54 -0400
committerSimon Marchi <simon.marchi@efficios.com>2023-04-04 21:05:30 -0400
commit3c8af02fa0b140edcde2a65d016f565aad1a699b (patch)
tree7d738cf49a90ef27a9b700b5e914f6d91b765e73
parent91385d13a8820bf3e6274ec51d4da613bae67554 (diff)
downloadgdb-3c8af02fa0b140edcde2a65d016f565aad1a699b.zip
gdb-3c8af02fa0b140edcde2a65d016f565aad1a699b.tar.gz
gdb-3c8af02fa0b140edcde2a65d016f565aad1a699b.tar.bz2
gdb: make find_thread_ptid an inferior method
Make find_thread_ptid (the overload that takes an inferior) a method of struct inferior. Change-Id: Ie5b9fa623ff35aa7ddb45e2805254fc8e83c9cd4 Reviewed-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/ada-tasks.c8
-rw-r--r--gdb/aix-thread.c6
-rw-r--r--gdb/btrace.c2
-rw-r--r--gdb/gdbthread.h3
-rw-r--r--gdb/inferior.c12
-rw-r--r--gdb/inferior.h3
-rw-r--r--gdb/infrun.c4
-rw-r--r--gdb/linux-thread-db.c2
-rw-r--r--gdb/python/py-threadevent.c3
-rw-r--r--gdb/ravenscar-thread.c2
-rw-r--r--gdb/sol-thread.c4
-rw-r--r--gdb/thread.c22
12 files changed, 34 insertions, 37 deletions
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index b14d159..f107d4e 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 df843d3..f4ccfb2 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 38d3882..dbdcea0 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 848daa9..81e4afd 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 a1e3c79..6eb9f3f 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 72034cc..633916e 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -490,6 +490,9 @@ public:
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 8714111..461855b 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -646,7 +646,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 ();
@@ -3761,7 +3761,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 5f2f167..ef1c281 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 b29f69a..05a833d 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 22fbdbe..ad35735 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 8945c20..ed1a803 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 25d97cd6..38afdff 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);