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>
This commit is contained in:
Simon Marchi 2023-03-27 12:53:54 -04:00 committed by Simon Marchi
parent 91385d13a8
commit 3c8af02fa0
12 changed files with 34 additions and 37 deletions

View File

@ -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."),

View File

@ -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;

View File

@ -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."));

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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;

View File

@ -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)
{

View File

@ -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");

View File

@ -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;

View File

@ -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

View File

@ -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);