[MIPS] Use lwpid from lwp_info instead of inferior_ptid

Message ID 1493303002-8056-1-git-send-email-yao.qi@linaro.org
State New, archived
Headers

Commit Message

Yao Qi April 27, 2017, 2:23 p.m. UTC
  RAJESH reported that GDB gets "Couldn't write debug register: No such
process." on mips64 when GDB attaches to a multi threaded application.

Looks GDB nows PTRACE_GET_WATCH_REGS for inferior_ptid but
PTRACE_SET_WATCH_REGS for lwp->ptid, they may be different.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>

	* mips-linux-nat.c (mips_linux_new_thread): Get lwpid from
	lwp_info instead of getting from inferior_ptid.
---
 gdb/mips-linux-nat.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Simon Marchi April 27, 2017, 2:26 p.m. UTC | #1
On 2017-04-27 10:23, Yao Qi wrote:
> RAJESH reported that GDB gets "Couldn't write debug register: No such
> process." on mips64 when GDB attaches to a multi threaded application.
> 
> Looks GDB nows PTRACE_GET_WATCH_REGS for inferior_ptid but
> PTRACE_SET_WATCH_REGS for lwp->ptid, they may be different.
> 
> gdb:
> 
> 2017-04-27  Yao Qi  <yao.qi@linaro.org>
> 
> 	* mips-linux-nat.c (mips_linux_new_thread): Get lwpid from
> 	lwp_info instead of getting from inferior_ptid.
> ---
>  gdb/mips-linux-nat.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
> index 9596b49..c5c18fd 100644
> --- a/gdb/mips-linux-nat.c
> +++ b/gdb/mips-linux-nat.c
> @@ -624,14 +624,13 @@ write_watchpoint_regs (void)
>  static void
>  mips_linux_new_thread (struct lwp_info *lp)
>  {
> -  int tid;
> +  long tid = ptid_get_lwp (lp->ptid);

You can replace this with "lp->ptid.lwp ()".

Otherwise, LGTM.

> 
> -  if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid),
> +  if (!mips_linux_read_watch_registers (tid,
>  					&watch_readback,
>  					&watch_readback_valid, 0))
>      return;
> 
> -  tid = ptid_get_lwp (lp->ptid);
>    if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1)
>      perror_with_name (_("Couldn't write debug register"));
>  }
  
Yao Qi April 28, 2017, 8:55 a.m. UTC | #2
On Thu, Apr 27, 2017 at 3:26 PM, Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
> You can replace this with "lp->ptid.lwp ()".
>
> Otherwise, LGTM.
>

Done, and patch is pushed to master and 8.0 branch.
  

Patch

diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
index 9596b49..c5c18fd 100644
--- a/gdb/mips-linux-nat.c
+++ b/gdb/mips-linux-nat.c
@@ -624,14 +624,13 @@  write_watchpoint_regs (void)
 static void
 mips_linux_new_thread (struct lwp_info *lp)
 {
-  int tid;
+  long tid = ptid_get_lwp (lp->ptid);
 
-  if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid),
+  if (!mips_linux_read_watch_registers (tid,
 					&watch_readback,
 					&watch_readback_valid, 0))
     return;
 
-  tid = ptid_get_lwp (lp->ptid);
   if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1)
     perror_with_name (_("Couldn't write debug register"));
 }