Make linux_nat_detach/thread_db_detach use the inferior parameter

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.
This commit is contained in:
Simon Marchi 2018-01-19 11:48:11 -05:00
parent 6e1e1966ba
commit bc09b0c14f
7 changed files with 39 additions and 14 deletions

View 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);
}
}