Introduce utility function find_inferior_ptid

This patch introduces find_inferior_ptid to replace the common idiom

  find_inferior_pid (ptid_get_pid (...));

It replaces all the instances of that idiom that I found with the new
function.

No significant changes before/after the patch in the regression suite
on amd64 linux.

gdb/ChangeLog:

	* inferior.c (find_inferior_ptid): New function.
	* inferior.h (find_inferior_ptid): New declaration.
	* ada-tasks.c (ada_get_task_number): Use find_inferior_ptid.
	* corelow.c (core_pid_to_str): Same.
	* darwin-nat.c (darwin_resume): Same.
	* infrun.c (fetch_inferior_event): Same.
	(get_inferior_stop_soon): Same.
	(handle_inferior_event): Same.
	(handle_signal_stop): Same.
	* linux-nat.c (resume_lwp): Same.
	(stop_wait_callback): Same.
	* mi/mi-interp.c (mi_new_thread): Same.
	(mi_thread_exit): Same.
	* proc-service.c (ps_pglobal_lookup): Same.
	* record-btrace.c (record_btrace_step_thread): Same.
	* remote-sim.c (gdbsim_close_inferior): Same.
	(gdbsim_resume): Same.
	(gdbsim_stop): Same.
	* sol2-tdep.c (sol2_core_pid_to_str): Same.
	* target.c (memory_xfer_partial_1): Same.
	(default_thread_address_space): Same.
	* thread.c (thread_change_ptid): Same.
	(switch_to_thread): Same.
	(do_restore_current_thread_cleanup): Same.
This commit is contained in:
Simon Marchi 2014-12-15 12:00:55 -05:00
parent e882ef3cfc
commit c9657e708a
15 changed files with 62 additions and 25 deletions

View File

@ -1,3 +1,30 @@
2014-12-15 Simon Marchi <simon.marchi@ericsson.com>
* inferior.c (find_inferior_ptid): New function.
* inferior.h (find_inferior_ptid): New declaration.
* ada-tasks.c (ada_get_task_number): Use find_inferior_ptid.
* corelow.c (core_pid_to_str): Same.
* darwin-nat.c (darwin_resume): Same.
* infrun.c (fetch_inferior_event): Same.
(get_inferior_stop_soon): Same.
(handle_inferior_event): Same.
(handle_signal_stop): Same.
* linux-nat.c (resume_lwp): Same.
(stop_wait_callback): Same.
* mi/mi-interp.c (mi_new_thread): Same.
(mi_thread_exit): Same.
* proc-service.c (ps_pglobal_lookup): Same.
* record-btrace.c (record_btrace_step_thread): Same.
* remote-sim.c (gdbsim_close_inferior): Same.
(gdbsim_resume): Same.
(gdbsim_stop): Same.
* sol2-tdep.c (sol2_core_pid_to_str): Same.
* target.c (memory_xfer_partial_1): Same.
(default_thread_address_space): Same.
* thread.c (thread_change_ptid): Same.
(switch_to_thread): Same.
(do_restore_current_thread_cleanup): Same.
2014-12-15 Simon Marchi <simon.marchi@ericsson.com>
* defs.h (gdb_readline): Constify argument.

View File

@ -292,7 +292,7 @@ int
ada_get_task_number (ptid_t ptid)
{
int i;
struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
struct inferior *inf = find_inferior_ptid (ptid);
struct ada_tasks_inferior_data *data;
gdb_assert (inf != NULL);
@ -1449,4 +1449,3 @@ _initialize_tasks (void)
Without argument, this command simply prints the current task ID"),
&cmdlist);
}

View File

@ -954,7 +954,7 @@ core_pid_to_str (struct target_ops *ops, ptid_t ptid)
/* Otherwise, this isn't a "threaded" core -- use the PID field, but
only if it isn't a fake PID. */
inf = find_inferior_pid (ptid_get_pid (ptid));
inf = find_inferior_ptid (ptid);
if (inf != NULL && !inf->fake_pid_p)
return normal_pid_to_str (ptid);

View File

@ -859,7 +859,7 @@ darwin_resume (ptid_t ptid, int step, enum gdb_signal signal)
}
else
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
struct inferior *inf = find_inferior_ptid (ptid);
long tid = ptid_get_tid (ptid);
/* Stop the inferior (should be useless). */

View File

@ -367,6 +367,14 @@ find_inferior_pid (int pid)
return NULL;
}
/* See inferior.h */
struct inferior *
find_inferior_ptid (ptid_t ptid)
{
return find_inferior_pid (ptid_get_pid (ptid));
}
/* See inferior.h. */
struct inferior *

View File

@ -465,6 +465,9 @@ extern int valid_gdb_inferior_id (int num);
/* Search function to lookup an inferior by target 'pid'. */
extern struct inferior *find_inferior_pid (int pid);
/* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
extern struct inferior *find_inferior_ptid (ptid_t ptid);
/* Search function to lookup an inferior by GDB 'num'. */
extern struct inferior *find_inferior_id (int num);

View File

@ -3262,7 +3262,7 @@ fetch_inferior_event (void *client_data)
if (!ecs->wait_some_more)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
struct inferior *inf = find_inferior_ptid (ecs->ptid);
delete_just_stopped_threads_infrun_breakpoints ();
@ -3581,7 +3581,7 @@ fill_in_stop_func (struct gdbarch *gdbarch,
static enum stop_kind
get_inferior_stop_soon (ptid_t ptid)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
struct inferior *inf = find_inferior_ptid (ptid);
gdb_assert (inf != NULL);
return inf->control.stop_soon;
@ -3815,7 +3815,7 @@ handle_inferior_event (struct execution_control_state *ecs)
}
inferior_ptid = ecs->ptid;
set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
set_current_inferior (find_inferior_ptid (ecs->ptid));
set_current_program_space (current_inferior ()->pspace);
handle_vfork_child_exec_or_exit (0);
target_terminal_ours (); /* Must do this before mourn anyway. */
@ -3899,7 +3899,7 @@ Cannot fill $_exitsignal with the correct signal number.\n"));
if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
{
struct inferior *parent_inf
= find_inferior_pid (ptid_get_pid (ecs->ptid));
= find_inferior_ptid (ecs->ptid);
struct regcache *child_regcache;
CORE_ADDR parent_pc;
@ -4495,7 +4495,7 @@ handle_signal_stop (struct execution_control_state *ecs)
if (random_signal)
{
/* Signal not for debugging purposes. */
struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
struct inferior *inf = find_inferior_ptid (ecs->ptid);
enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
if (debug_infrun)

View File

@ -1435,7 +1435,7 @@ resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
{
if (lp->stopped)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid));
struct inferior *inf = find_inferior_ptid (lp->ptid);
if (inf->vfork_child != NULL)
{
@ -2388,7 +2388,7 @@ linux_nat_set_status_is_event (struct target_ops *t,
static int
stop_wait_callback (struct lwp_info *lp, void *data)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid));
struct inferior *inf = find_inferior_ptid (lp->ptid);
/* If this is a vfork parent, bail out, it is not going to report
any SIGSTOP until the vfork is done with. */

View File

@ -371,7 +371,7 @@ static void
mi_new_thread (struct thread_info *t)
{
struct mi_interp *mi = top_level_interpreter_data ();
struct inferior *inf = find_inferior_pid (ptid_get_pid (t->ptid));
struct inferior *inf = find_inferior_ptid (t->ptid);
gdb_assert (inf);
@ -391,7 +391,7 @@ mi_thread_exit (struct thread_info *t, int silent)
if (silent)
return;
inf = find_inferior_pid (ptid_get_pid (t->ptid));
inf = find_inferior_ptid (t->ptid);
mi = top_level_interpreter_data ();
old_chain = make_cleanup_restore_target_terminal ();

View File

@ -114,7 +114,7 @@ ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
{
struct bound_minimal_symbol ms;
struct cleanup *old_chain = save_current_program_space ();
struct inferior *inf = find_inferior_pid (ptid_get_pid (ph->ptid));
struct inferior *inf = find_inferior_ptid (ph->ptid);
ps_err_e result;
set_current_program_space (inf->pspace);

View File

@ -1662,7 +1662,7 @@ record_btrace_step_thread (struct thread_info *tp)
if (replay == NULL)
return btrace_step_no_history ();
inf = find_inferior_pid (ptid_get_pid (tp->ptid));
inf = find_inferior_ptid (tp->ptid);
aspace = inf->aspace;
/* Determine the end of the instruction trace. */
@ -1699,7 +1699,7 @@ record_btrace_step_thread (struct thread_info *tp)
if (replay == NULL)
replay = record_btrace_start_replaying (tp);
inf = find_inferior_pid (ptid_get_pid (tp->ptid));
inf = find_inferior_ptid (tp->ptid);
aspace = inf->aspace;
for (;;)

View File

@ -774,7 +774,7 @@ gdbsim_close_inferior (struct inferior *inf, void *arg)
Thus we need to verify the existence of an inferior using the
pid in question before setting inferior_ptid via
switch_to_thread() or mourning the inferior. */
if (find_inferior_pid (ptid_get_pid (ptid)) != NULL)
if (find_inferior_ptid (ptid) != NULL)
{
switch_to_thread (ptid);
generic_mourn_inferior ();
@ -881,7 +881,7 @@ gdbsim_resume (struct target_ops *ops,
either have multiple inferiors to resume or an error condition. */
if (sim_data)
gdbsim_resume_inferior (find_inferior_pid (ptid_get_pid (ptid)), &rd);
gdbsim_resume_inferior (find_inferior_ptid (ptid), &rd);
else if (ptid_equal (ptid, minus_one_ptid))
iterate_over_inferiors (gdbsim_resume_inferior, &rd);
else
@ -928,7 +928,7 @@ gdbsim_stop (struct target_ops *self, ptid_t ptid)
}
else
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
struct inferior *inf = find_inferior_ptid (ptid);
if (inf == NULL)
error (_("Can't stop pid %d. No inferior found."),

View File

@ -60,7 +60,7 @@ sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
/* GDB didn't use to put a NT_PSTATUS note in Solaris cores. If
that's missing, then we're dealing with a fake PID corelow.c made
up. */
inf = find_inferior_pid (ptid_get_pid (ptid));
inf = find_inferior_ptid (ptid);
if (inf == NULL || inf->fake_pid_p)
{
xsnprintf (buf, sizeof buf, "<core>");

View File

@ -1173,7 +1173,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
return TARGET_XFER_E_IO;
if (!ptid_equal (inferior_ptid, null_ptid))
inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
inf = find_inferior_ptid (inferior_ptid);
else
inf = NULL;
@ -2649,7 +2649,7 @@ default_thread_address_space (struct target_ops *self, ptid_t ptid)
struct inferior *inf;
/* Fall-back to the "main" address space of the inferior. */
inf = find_inferior_pid (ptid_get_pid (ptid));
inf = find_inferior_ptid (ptid);
if (inf == NULL || inf->aspace == NULL)
internal_error (__FILE__, __LINE__,

View File

@ -747,7 +747,7 @@ thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid)
/* It can happen that what we knew as the target inferior id
changes. E.g, target remote may only discover the remote process
pid after adding the inferior to GDB's list. */
inf = find_inferior_pid (ptid_get_pid (old_ptid));
inf = find_inferior_ptid (old_ptid);
inf->pid = ptid_get_pid (new_ptid);
tp = find_thread_ptid (old_ptid);
@ -1179,7 +1179,7 @@ switch_to_thread (ptid_t ptid)
{
struct inferior *inf;
inf = find_inferior_pid (ptid_get_pid (ptid));
inf = find_inferior_ptid (ptid);
gdb_assert (inf != NULL);
set_current_program_space (inf->pspace);
set_current_inferior (inf);
@ -1290,7 +1290,7 @@ do_restore_current_thread_cleanup (void *arg)
then don't revert back to it, but instead simply drop back to no
thread selected. */
if (tp
&& find_inferior_pid (ptid_get_pid (tp->ptid)) != NULL)
&& find_inferior_ptid (tp->ptid) != NULL)
restore_current_thread (old->inferior_ptid);
else
{