* Re: Reg : gdb crash is seen while attaching a process to gdb.
[not found] ` <CAPXMrf_+cHn9sjFY-yXy==cNoGS98cSmcV+R9TVLbeExru+NWQ@mail.gmail.com>
@ 2017-04-27 9:02 ` Yao Qi
2017-04-27 10:12 ` RAJESH DASARI
0 siblings, 1 reply; 5+ messages in thread
From: Yao Qi @ 2017-04-27 9:02 UTC (permalink / raw)
To: RAJESH DASARI; +Cc: gdb-patches
RAJESH DASARI <raajeshdasari@gmail.com> writes:
[Move it to gdb-patches@sourceware.org]
> Could someone please provide comments.
>
> diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
> index 9d22773..68641f8 100644
> --- a/gdb/mips-linux-nat.c
> +++ b/gdb/mips-linux-nat.c
> @@ -634,9 +634,20 @@ mips_linux_new_thread (struct lwp_info *lp)
> &watch_readback_valid, 0))
> return;
>
> + long r;
> + r= ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL);
> 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"));
> + if ( r == -1L && errno == ESRCH )
> + {
> + /* sleep for a while to eliminate race condition on update to kernel
> + * task structure with the process state (STOP state of thread).
> + */
> + usleep(10000);
> + if ( ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1 )
> + {
> + perror_with_name (_("Couldn't write debug register"));
> + }
> + }
> }
I am wondering why mips_linux_read_watch_registers
(ptrace (PTRACE_GET_WATCH_REGS) is successful but
ptrace (PTRACE_SET_WATCH_REGS) fails here. Looks they may use different
lwpids. Does the patch work for you?
--
Yao (齐尧)
From dc9b626b826b26431772271c9d9a3ee343d8a1e8 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Thu, 27 Apr 2017 09:59:40 +0100
Subject: [PATCH] Use lwpid from lwp_info instead of inferior_ptid
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.
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"));
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Reg : gdb crash is seen while attaching a process to gdb.
2017-04-27 9:02 ` Reg : gdb crash is seen while attaching a process to gdb Yao Qi
@ 2017-04-27 10:12 ` RAJESH DASARI
2017-04-27 14:23 ` [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid Yao Qi
0 siblings, 1 reply; 5+ messages in thread
From: RAJESH DASARI @ 2017-04-27 10:12 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
Hi ,
Yes it worked for me.
Thanks,
Rajesh Dasari.
On Thu, Apr 27, 2017 at 2:32 PM, Yao Qi <qiyaoltc@gmail.com> wrote:
> RAJESH DASARI <raajeshdasari@gmail.com> writes:
>
> [Move it to gdb-patches@sourceware.org]
>
>> Could someone please provide comments.
>>
>> diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
>> index 9d22773..68641f8 100644
>> --- a/gdb/mips-linux-nat.c
>> +++ b/gdb/mips-linux-nat.c
>> @@ -634,9 +634,20 @@ mips_linux_new_thread (struct lwp_info *lp)
>> &watch_readback_valid, 0))
>> return;
>>
>> + long r;
>> + r= ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL);
>> 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"));
>> + if ( r == -1L && errno == ESRCH )
>> + {
>> + /* sleep for a while to eliminate race condition on update to kernel
>> + * task structure with the process state (STOP state of thread).
>> + */
>> + usleep(10000);
>> + if ( ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1 )
>> + {
>> + perror_with_name (_("Couldn't write debug register"));
>> + }
>> + }
>> }
>
> I am wondering why mips_linux_read_watch_registers
> (ptrace (PTRACE_GET_WATCH_REGS) is successful but
> ptrace (PTRACE_SET_WATCH_REGS) fails here. Looks they may use different
> lwpids. Does the patch work for you?
>
> --
> Yao (齐尧)
>
> From dc9b626b826b26431772271c9d9a3ee343d8a1e8 Mon Sep 17 00:00:00 2001
> From: Yao Qi <yao.qi@linaro.org>
> Date: Thu, 27 Apr 2017 09:59:40 +0100
> Subject: [PATCH] Use lwpid from lwp_info instead of inferior_ptid
>
> 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.
>
> 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"));
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid
2017-04-27 10:12 ` RAJESH DASARI
@ 2017-04-27 14:23 ` Yao Qi
2017-04-27 14:26 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Yao Qi @ 2017-04-27 14:23 UTC (permalink / raw)
To: gdb-patches; +Cc: raajeshdasari, macro
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);
- 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"));
}
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid
2017-04-27 14:23 ` [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid Yao Qi
@ 2017-04-27 14:26 ` Simon Marchi
2017-04-28 8:55 ` Yao Qi
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2017-04-27 14:26 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches, raajeshdasari, macro
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"));
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid
2017-04-27 14:26 ` Simon Marchi
@ 2017-04-28 8:55 ` Yao Qi
0 siblings, 0 replies; 5+ messages in thread
From: Yao Qi @ 2017-04-28 8:55 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches, RAJESH DASARI, Maciej W. Rozycki
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.
--
Yao (齐尧)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-04-28 8:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAPXMrf8TH66vZtp+9riDpDR4fBizip5-LQtZ9+1nSfVaywTLxg@mail.gmail.com>
[not found] ` <CAH=s-PPcmOkY-yPuGsDbE0L=Q=SC9qjw9afTZnHfRE_oMPTzVA@mail.gmail.com>
[not found] ` <728178DD-B9FD-4695-A7FF-F13B829DFD2E@gmail.com>
[not found] ` <864lyfp0b7.fsf@gmail.com>
[not found] ` <CAPXMrf9sjaQ4DUF+2guOYNE2FGRsM7RCcnRxZZ6VT28xLu40ZA@mail.gmail.com>
[not found] ` <CAPXMrf_+cHn9sjFY-yXy==cNoGS98cSmcV+R9TVLbeExru+NWQ@mail.gmail.com>
2017-04-27 9:02 ` Reg : gdb crash is seen while attaching a process to gdb Yao Qi
2017-04-27 10:12 ` RAJESH DASARI
2017-04-27 14:23 ` [PATCH] [MIPS] Use lwpid from lwp_info instead of inferior_ptid Yao Qi
2017-04-27 14:26 ` Simon Marchi
2017-04-28 8:55 ` Yao Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).