diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1db98ff9f6..31a672eafa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2015-03-03 Pedro Alves + + * i386-linux-nat.c (i386_linux_resume): Get the ptrace PID out of + the lwp field of ptid. Pass the full ptid to get_thread_regcache. + * inf-ptrace.c (get_ptrace_pid): New function. + (inf_ptrace_resume): Use it. + * linux-nat.c (linux_resume_one_lwp): Pass the LWP's ptid ummodified + to the lower layer. + 2015-03-03 Markus Metzger * nat/linux-btrace.c: Include sys/utsname.h. diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c index b95b47e7bb..8cb8c66c30 100644 --- a/gdb/i386-linux-nat.c +++ b/gdb/i386-linux-nat.c @@ -648,8 +648,7 @@ static void i386_linux_resume (struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal signal) { - int pid = ptid_get_pid (ptid); - + int pid = ptid_get_lwp (ptid); int request; if (catch_syscall_enabled () > 0) @@ -659,7 +658,7 @@ i386_linux_resume (struct target_ops *ops, if (step) { - struct regcache *regcache = get_thread_regcache (pid_to_ptid (pid)); + struct regcache *regcache = get_thread_regcache (ptid); struct gdbarch *gdbarch = get_regcache_arch (regcache); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); ULONGEST pc; diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 4c22a84ba4..606bdb4289 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -289,6 +289,22 @@ inf_ptrace_stop (struct target_ops *self, ptid_t ptid) kill (-inferior_process_group (), SIGINT); } +/* Return which PID to pass to ptrace in order to observe/control the + tracee identified by PTID. */ + +static pid_t +get_ptrace_pid (ptid_t ptid) +{ + pid_t pid; + + /* If we have an LWPID to work with, use it. Otherwise, we're + dealing with a non-threaded program/target. */ + pid = ptid_get_lwp (ptid); + if (pid == 0) + pid = ptid_get_pid (ptid); + return pid; +} + /* Resume execution of thread PTID, or all threads if PTID is -1. If STEP is nonzero, single-step it. If SIGNAL is nonzero, give it that signal. */ @@ -297,13 +313,16 @@ static void inf_ptrace_resume (struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal signal) { - pid_t pid = ptid_get_pid (ptid); + pid_t pid; + int request; - if (pid == -1) + if (ptid_equal (minus_one_ptid, ptid)) /* Resume all threads. Traditionally ptrace() only supports single-threaded processes, so simply resume the inferior. */ - pid = ptid_get_pid (inferior_ptid); + pid = get_ptrace_pid (inferior_ptid); + else + pid = get_ptrace_pid (ptid); if (catch_syscall_enabled () > 0) request = PT_SYSCALL; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 2e1133d11d..cb10e2c655 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1506,8 +1506,6 @@ linux_nat_detach (struct target_ops *ops, const char *args, int from_tty) static void linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo) { - ptid_t ptid; - lp->step = step; /* stop_pc doubles as the PC the LWP had when it was last resumed. @@ -1524,9 +1522,7 @@ linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo) if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (lp); - /* Convert to something the lower layer understands. */ - ptid = pid_to_ptid (ptid_get_lwp (lp->ptid)); - linux_ops->to_resume (linux_ops, ptid, step, signo); + linux_ops->to_resume (linux_ops, lp->ptid, step, signo); lp->stop_reason = LWP_STOPPED_BY_NO_REASON; lp->stopped = 0; registers_changed_ptid (lp->ptid);