Introduce utility function find_inferior_ptid
authorSimon Marchi <simon.marchi@ericsson.com>
Mon, 15 Dec 2014 17:00:55 +0000 (12:00 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Mon, 15 Dec 2014 17:00:55 +0000 (12:00 -0500)
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.

15 files changed:
gdb/ChangeLog
gdb/ada-tasks.c
gdb/corelow.c
gdb/darwin-nat.c
gdb/inferior.c
gdb/inferior.h
gdb/infrun.c
gdb/linux-nat.c
gdb/mi/mi-interp.c
gdb/proc-service.c
gdb/record-btrace.c
gdb/remote-sim.c
gdb/sol2-tdep.c
gdb/target.c
gdb/thread.c

index 2e13df58786e72d9827af90ff83550049dc8ce96..b92cfa2718617483228341cd55e74ff30e632c7d 100644 (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.
index 2d5a19db177b9193ed996f829d19d9aef7ed5b31..17d03385526af5a630eb78a012f4ac23a93bc2d8 100644 (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);
 }
-
index b91ad22f88b60a7da2cc35e2be3514a486f8d568..154b2c48ea151c572e8b9b3af5b5df30a75f2da1 100644 (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);
 
index 511f37046d9e89f1e46399c23d9dcc814dc541ac..36b6021dc53fd2843bc10d8883e23d7988da005f 100644 (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).  */
index 44f456001d52714a0d2ca8d03c63618f08c276b1..49c479dee728407c85a5d1e56d07f2dde5a8f0d1 100644 (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 *
index 0129549c9222ccc1f9995737322d1349ff3ca620..eebc034d4425922bc7f8f65b27153253ace40f73 100644 (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);
 
index 74f9e12a4ef953d4d00f7dd75379000698bc67d5..413b052f436b65a90bc5030f932b693d9884620f 100644 (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)
index 21797c119a2ca022c46a90c3f2d92f2d81fc38ba..29133f9465f8880804e0de3d56418c4bf9ddffc0 100644 (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.  */
index 60f066660a026944367a58d35204847ae34c3279..09ff7bfec69b689628b8c3371e5039c90dd4c006 100644 (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 ();
index 581948938742b73f07d97ba68ef7c6dd72a330a8..1dc98d8eedb852dbb817fdf2183c1182cc6b6849 100644 (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);
index 65d28e39c9bff0eb2d38b182aa423712b481c544..8b98a916bedb2f078ec2bcb2f2b42a9297247525 100644 (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 (;;)
index 890154836dbee224545607919e623eedd2d7b678..92c41ad11c645a9126c4c186fa21253e5b4fa5fc 100644 (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."),
index bf7d6a128f13c3088de2715632710d34e97404a9..a5089787d86bcc73047ad125223b85d4bb1a9187 100644 (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>");
index 7161e62acc3a8feff6f3c952e31c7c5ba0a6d75c..38c6c1631998b9627894e00ffca73c8a11ab434c 100644 (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__,
index a3040a77fd747e1415f172333bf631db3598ceb6..782fc702f479378767416c101f22fba9f9097d96 100644 (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
     {
This page took 0.03863 seconds and 4 git commands to generate.