]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make linux_nat_detach/thread_db_detach use the inferior parameter
authorSimon Marchi <simon.marchi@ericsson.com>
Fri, 19 Jan 2018 16:48:11 +0000 (11:48 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 19 Jan 2018 16:48:11 +0000 (11:48 -0500)
This patch makes these two functions actually use the inferior parameter
added by the previous patch, instead of reading inferior_ptid.  I chose
these two, because they are the one actually used when I detach on my
GNU/Linux system, so they were easy to test.

I took the opportunity to pass the inferior being detached to
inf_ptrace_detach_success, so it could use it too.  From there, it made
sense to add an overload of detach_inferior that takes the inferior
directly rather than the pid, to avoid having to pass inf->pid only for
the callee to look up the inferior structure by pid.

gdb/ChangeLog:

* inf-ptrace.c (inf_ptrace_detach): Adjust call to
inf_ptrace_detach_success.
(inf_ptrace_detach_success): Add inferior parameter, use it
instead of inferior_ptid, pass it to detach_inferior.
* inf-ptrace.h (inf_ptrace_detach_success): Add inferior
parameter.
* inferior.c (detach_inferior): Add overload that takes an
inferior object.
* inferior.h (detach_inferior): Likewise.
* linux-nat.c (linux_nat_detach): Use the inf parameter, don't
use inferior_ptid, adjust call to inf_ptrace_detach_success.
* linux-thread-db.c (thread_db_detach): Use inf parameter.

gdb/ChangeLog
gdb/inf-ptrace.c
gdb/inf-ptrace.h
gdb/inferior.c
gdb/inferior.h
gdb/linux-nat.c
gdb/linux-thread-db.c

index 4a994b411c7530642c78b1906fb352c537fc9991..5467e89c60436c9e99dad0e3b4f533944fc1b857 100644 (file)
@@ -1,3 +1,18 @@
+2018-01-19  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * inf-ptrace.c (inf_ptrace_detach): Adjust call to
+       inf_ptrace_detach_success.
+       (inf_ptrace_detach_success): Add inferior parameter, use it
+       instead of inferior_ptid, pass it to detach_inferior.
+       * inf-ptrace.h (inf_ptrace_detach_success): Add inferior
+       parameter.
+       * inferior.c (detach_inferior): Add overload that takes an
+       inferior object.
+       * inferior.h (detach_inferior): Likewise.
+       * linux-nat.c (linux_nat_detach): Use the inf parameter, don't
+       use inferior_ptid, adjust call to inf_ptrace_detach_success.
+       * linux-thread-db.c (thread_db_detach): Use inf parameter.
+
 2018-01-19  Simon Marchi  <simon.marchi@ericsson.com>
 
        * target.h (struct target_ops) <to_detach>: Add inferior
index aa8b17f41a52802058cd89ac57cdcc1b5e2db9af..72aa33480f4253eda9b0a3c4e8b92cae70f31a8c 100644 (file)
@@ -263,18 +263,16 @@ inf_ptrace_detach (struct target_ops *ops, inferior *inf, int from_tty)
   error (_("This system does not support detaching from a process"));
 #endif
 
-  inf_ptrace_detach_success (ops);
+  inf_ptrace_detach_success (ops, inf);
 }
 
 /* See inf-ptrace.h.  */
 
 void
-inf_ptrace_detach_success (struct target_ops *ops)
+inf_ptrace_detach_success (struct target_ops *ops, inferior *inf)
 {
-  pid_t pid = ptid_get_pid (inferior_ptid);
-
   inferior_ptid = null_ptid;
-  detach_inferior (pid);
+  detach_inferior (inf);
 
   inf_child_maybe_unpush_target (ops);
 }
index c5bd7573603e7a5322f0674e6e450f07c9113605..d10f64ae56c01819e99fdc17f83673b23a626240 100644 (file)
@@ -40,6 +40,6 @@ extern pid_t get_ptrace_pid (ptid_t);
 
 
 /* Cleanup the inferior after a successful ptrace detach.  */
-extern void inf_ptrace_detach_success (struct target_ops *ops);
+extern void inf_ptrace_detach_success (struct target_ops *ops, inferior *inf);
 
 #endif
index 0b8f340b63a1a1d021f37356c66133fd3d9767b4..38b7369275ba6bb6415323ccbf158d1438e5cba6 100644 (file)
@@ -253,10 +253,13 @@ exit_inferior_num_silent (int num)
   exit_inferior_1 (inf, 1);
 }
 
+/* See inferior.h.  */
+
 void
-detach_inferior (int pid)
+detach_inferior (inferior *inf)
 {
-  struct inferior *inf = find_inferior_pid (pid);
+  /* Save the pid, since exit_inferior_1 will reset it.  */
+  int pid = inf->pid;
 
   exit_inferior_1 (inf, 0);
 
@@ -264,6 +267,14 @@ detach_inferior (int pid)
     printf_unfiltered (_("[Inferior %d detached]\n"), pid);
 }
 
+/* See inferior.h.  */
+
+void
+detach_inferior (int pid)
+{
+  detach_inferior (find_inferior_pid (pid));
+}
+
 void
 inferior_appeared (struct inferior *inf, int pid)
 {
index 01a12f2290b654107fb988cf59eba8569b0528a2..a87ffe00546bb175e0b1be7d3cb7d6690223cab7 100644 (file)
@@ -458,6 +458,9 @@ extern struct inferior *add_inferior_silent (int pid);
 extern void delete_inferior (struct inferior *todel);
 
 /* Delete an existing inferior list entry, due to inferior detaching.  */
+extern void detach_inferior (inferior *inf);
+
+/* Same as the above, but with the inferior specified by PID.  */
 extern void detach_inferior (int pid);
 
 extern void exit_inferior (int pid);
index 70f4c084dc6e0428f7a032b40d6d6a547da9fcb0..b83066cb0407d59a6e2579332848589543edbb84 100644 (file)
@@ -1499,10 +1499,8 @@ detach_callback (struct lwp_info *lp, void *data)
 static void
 linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty)
 {
-  int pid;
   struct lwp_info *main_lwp;
-
-  pid = ptid_get_pid (inferior_ptid);
+  int pid = inf->pid;
 
   /* Don't unregister from the event loop, as there may be other
      inferiors running. */
@@ -1517,7 +1515,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty)
   iterate_over_lwps (pid_to_ptid (pid), detach_callback, NULL);
 
   /* Only the initial process should be left right now.  */
-  gdb_assert (num_lwps (ptid_get_pid (inferior_ptid)) == 1);
+  gdb_assert (num_lwps (pid) == 1);
 
   main_lwp = find_lwp_pid (pid_to_ptid (pid));
 
@@ -1538,7 +1536,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty)
 
       detach_one_lwp (main_lwp, &signo);
 
-      inf_ptrace_detach_success (ops);
+      inf_ptrace_detach_success (ops, inf);
     }
 }
 
index 873f929144b9b4477937915f28b3b6fe46b9bb99..794c97b48ac2d52ecba020ddc0dcea2b4a6816b7 100644 (file)
@@ -1094,7 +1094,7 @@ thread_db_detach (struct target_ops *ops, inferior *inf, int from_tty)
 {
   struct target_ops *target_beneath = find_target_beneath (ops);
 
-  delete_thread_db_info (ptid_get_pid (inferior_ptid));
+  delete_thread_db_info (inf->pid);
 
   target_beneath->to_detach (target_beneath, inf, from_tty);