public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add support for NetBSD threads in sparc-nat.c
@ 2020-03-17  9:40 Kamil Rytarowski
  2020-03-17 15:10 ` [PATCH v3] " Kamil Rytarowski
  0 siblings, 1 reply; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17  9:40 UTC (permalink / raw)
  To: gdb-patches

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

This file is still shared with other targets that use different 4th argument
type, that is always unused.
---
 gdb/sparc-nat.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index dff0f521565..9743bc3f3a0 100644
--- a/gdb/sparc-nat.c
+++ b/gdb/sparc-nat.c
@@ -78,6 +78,14 @@ typedef struct fp_status fpregset_t;
 #define PTRACE_SETFPREGS PT_SETFPREGS
 #endif

+/* Support for NetBSD threads.  */
+#ifdef __NetBSD__
+# define gdb_ptrace(request, pid, addr) \
+  ptrace (request, pid, addr, regcache->ptid ().lwp ())
+#else
+# define gdb_ptrace(request, pid, addr) ptrace (request, pid, addr, 0)
+#endif
+
 /* Register set description.  */
 const struct sparc_gregmap *sparc_gregmap;
 const struct sparc_fpregmap *sparc_fpregmap;
@@ -166,7 +174,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
@@ -178,7 +186,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating point status"));

       sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
@@ -199,12 +207,12 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);

-      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't write registers"));

       /* Deal with the stack regs.  */
@@ -225,7 +233,7 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs, saved_fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating-point registers"));

       memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
@@ -237,8 +245,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 	 to write the registers if nothing changed.  */
       if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
 	{
-	  if (ptrace (PTRACE_SETFPREGS, pid,
-		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+	  if (gdb_ptrace (PTRACE_SETFPREGS, pid,
+		      (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't write floating-point registers"));
 	}

--
2.25.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3] Add support for NetBSD threads in sparc-nat.c
  2020-03-17  9:40 [PATCH] Add support for NetBSD threads in sparc-nat.c Kamil Rytarowski
@ 2020-03-17 15:10 ` Kamil Rytarowski
  2020-03-17 16:03   ` Simon Marchi
  0 siblings, 1 reply; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17 15:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: cbiesinger, simark, Kamil Rytarowski

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

This file is still shared with other targets that use different 4th argument
type, that is always unused.
---
 gdb/sparc-nat.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index dff0f521565..be99ebb6789 100644
--- a/gdb/sparc-nat.c
+++ b/gdb/sparc-nat.c
@@ -78,6 +78,17 @@ typedef struct fp_status fpregset_t;
 #define PTRACE_SETFPREGS PT_SETFPREGS
 #endif

+static inline int
+gdb_ptrace(int request, pid_t pid, void *addr, struct regcache *regcache)
+{
+#ifdef __NetBSD__
+  /* Support for NetBSD threads.  */
+  return ptrace (request, pid, addr, regcache->ptid ().lwp ());
+#else
+  return ptrace (request, pid, addr, 0);
+#endif
+}
+
 /* Register set description.  */
 const struct sparc_gregmap *sparc_gregmap;
 const struct sparc_fpregmap *sparc_fpregmap;
@@ -166,7 +177,8 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, pid,
+		      (PTRACE_TYPE_ARG3) &regs, regcache) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
@@ -178,7 +190,8 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, pid,
+		      (PTRACE_TYPE_ARG3) &fpregs, regcache) == -1)
 	perror_with_name (_("Couldn't get floating point status"));

       sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
@@ -199,12 +212,14 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, pid,
+		      (PTRACE_TYPE_ARG3) &regs, regcache) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);

-      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_SETREGS, pid,
+		      (PTRACE_TYPE_ARG3) &regs, regcache) == -1)
 	perror_with_name (_("Couldn't write registers"));

       /* Deal with the stack regs.  */
@@ -225,7 +240,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs, saved_fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, pid,
+		      (PTRACE_TYPE_ARG3) &fpregs, regcache) == -1)
 	perror_with_name (_("Couldn't get floating-point registers"));

       memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
@@ -237,8 +253,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 	 to write the registers if nothing changed.  */
       if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
 	{
-	  if (ptrace (PTRACE_SETFPREGS, pid,
-		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+	  if (gdb_ptrace (PTRACE_SETFPREGS, pid,
+		      (PTRACE_TYPE_ARG3) &fpregs, regcache) == -1)
 	    perror_with_name (_("Couldn't write floating-point registers"));
 	}

--
2.25.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 15:10 ` [PATCH v3] " Kamil Rytarowski
@ 2020-03-17 16:03   ` Simon Marchi
  2020-03-17 16:46     ` [PATCH v4] " Kamil Rytarowski
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 16:03 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 11:10 a.m., Kamil Rytarowski wrote:
> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
> 
> This file is still shared with other targets that use different 4th argument
> type, that is always unused.
> ---
>  gdb/sparc-nat.c | 30 +++++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
> index dff0f521565..be99ebb6789 100644
> --- a/gdb/sparc-nat.c
> +++ b/gdb/sparc-nat.c
> @@ -78,6 +78,17 @@ typedef struct fp_status fpregset_t;
>  #define PTRACE_SETFPREGS PT_SETFPREGS
>  #endif
> 
> +static inline int

Remove the `inline`.

> +gdb_ptrace(int request, pid_t pid, void *addr, struct regcache *regcache)

Space before parenthesis.

> +{
> +#ifdef __NetBSD__
> +  /* Support for NetBSD threads.  */

Could you add a bit more to this comment, for example:

  /* Support for NetBSD threads: unlike most other ptrace implementations, NetBSD
     requires that we pass both the pid and lwp.  */

> +  return ptrace (request, pid, addr, regcache->ptid ().lwp ());
> +#else
> +  return ptrace (request, pid, addr, 0);
> +#endif
> +}

I think it would make more sense to just pass the whole ptid, rather than passing the regcache:

static int
gdb_ptrace (int request, ptid_t ptid, void *addr)
{
#ifdef __NetBSD__
  /* Support for NetBSD threads: unlike most other ptrace implementations, NetBSD
     requires that we pass both the pid and lwp.  */
  return ptrace (request, ptid.pid (), addr, ptid.lwp ());
#else
  int pid = get_ptrace_pid (ptid);
  return ptrace (request, pid, addr, 0);
#endif
}

Simon

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 16:03   ` Simon Marchi
@ 2020-03-17 16:46     ` Kamil Rytarowski
  2020-03-17 16:51       ` Simon Marchi
  2020-03-17 18:18       ` [PATCH v5] " Kamil Rytarowski
  0 siblings, 2 replies; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17 16:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: simark, cbiesinger, Kamil Rytarowski

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

This file is still shared with other targets that use different 4th argument
type, that is always unused.
---
 gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index dff0f521565..10cc01375ed 100644
--- a/gdb/sparc-nat.c
+++ b/gdb/sparc-nat.c
@@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
 #define PTRACE_SETFPREGS PT_SETFPREGS
 #endif

+static int
+gdb_ptrace (int request, ptid_t pid, void *addr)
+{
+#ifdef __NetBSD__
+  /* Support for NetBSD threads: unlike other ptrace implementations in this
+     file, NetBSD requires that we pass both the pid and lwp.  */
+  return ptrace (request, ptid (). pid (), addr, ptid ().lwp ());
+#else
+  pid_t pid = get_ptrace_pid (ptid);
+  return ptrace (request, pid, addr, 0);
+#endif
+}
+
 /* Register set description.  */
 const struct sparc_gregmap *sparc_gregmap;
 const struct sparc_fpregmap *sparc_fpregmap;
@@ -137,22 +150,7 @@ void
 sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  pid_t pid;
-
-  /* NOTE: cagney/2002-12-03: This code assumes that the currently
-     selected light weight processes' registers can be written
-     directly into the selected thread's register cache.  This works
-     fine when given an 1:1 LWP:thread model (such as found on
-     GNU/Linux) but will, likely, have problems when used on an N:1
-     (userland threads) or N:M (userland multiple LWP) model.  In the
-     case of the latter two, the LWP's registers do not necessarily
-     belong to the selected thread (the LWP could be in the middle of
-     executing the thread switch code).
-
-     These functions should instead be parameterized with an explicit
-     object (struct regcache, struct thread_info?) into which the LWPs
-     registers can be written.  */
-  pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();

   if (regnum == SPARC_G0_REGNUM)
     {
@@ -166,7 +164,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
@@ -178,7 +176,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating point status"));

       sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
@@ -189,22 +187,18 @@ void
 sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  pid_t pid;
-
-  /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
-     about threaded assumptions.  */
-  pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();

   if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum))
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);

-      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't write registers"));

       /* Deal with the stack regs.  */
@@ -225,7 +219,7 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs, saved_fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating-point registers"));

       memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
@@ -237,8 +231,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 	 to write the registers if nothing changed.  */
       if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
 	{
-	  if (ptrace (PTRACE_SETFPREGS, pid,
-		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+	  if (gdb_ptrace (PTRACE_SETFPREGS, ptid,
+			  (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't write floating-point registers"));
 	}

--
2.25.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 16:46     ` [PATCH v4] " Kamil Rytarowski
@ 2020-03-17 16:51       ` Simon Marchi
  2020-03-17 16:59         ` Simon Marchi
  2020-03-17 18:18       ` [PATCH v5] " Kamil Rytarowski
  1 sibling, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 16:51 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 12:46 p.m., Kamil Rytarowski wrote:
> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
> 
> This file is still shared with other targets that use different 4th argument
> type, that is always unused.
> ---
>  gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
>  1 file changed, 22 insertions(+), 28 deletions(-)
> 
> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
> index dff0f521565..10cc01375ed 100644
> --- a/gdb/sparc-nat.c
> +++ b/gdb/sparc-nat.c
> @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
>  #define PTRACE_SETFPREGS PT_SETFPREGS
>  #endif
> 
> +static int
> +gdb_ptrace (int request, ptid_t pid, void *addr)
> +{
> +#ifdef __NetBSD__
> +  /* Support for NetBSD threads: unlike other ptrace implementations in this
> +     file, NetBSD requires that we pass both the pid and lwp.  */
> +  return ptrace (request, ptid (). pid (), addr, ptid ().lwp ());

Does that even build?  ptid isn't the name of a parameter, and the parenthesis after
"ptid" should not be there.  Rename the pid parameter to ptid, and replace the above
with "ptid.pid ()" and "ptid.lwp ()".

Simon

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 16:51       ` Simon Marchi
@ 2020-03-17 16:59         ` Simon Marchi
  2020-03-17 17:07           ` Kamil Rytarowski
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 16:59 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 12:51 p.m., Simon Marchi wrote:
> On 2020-03-17 12:46 p.m., Kamil Rytarowski wrote:
>> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
>>
>> This file is still shared with other targets that use different 4th argument
>> type, that is always unused.
>> ---
>>  gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
>>  1 file changed, 22 insertions(+), 28 deletions(-)
>>
>> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
>> index dff0f521565..10cc01375ed 100644
>> --- a/gdb/sparc-nat.c
>> +++ b/gdb/sparc-nat.c
>> @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
>>  #define PTRACE_SETFPREGS PT_SETFPREGS
>>  #endif
>>
>> +static int
>> +gdb_ptrace (int request, ptid_t pid, void *addr)
>> +{
>> +#ifdef __NetBSD__
>> +  /* Support for NetBSD threads: unlike other ptrace implementations in this
>> +     file, NetBSD requires that we pass both the pid and lwp.  */
>> +  return ptrace (request, ptid (). pid (), addr, ptid ().lwp ());
> 
> Does that even build?  ptid isn't the name of a parameter, and the parenthesis after
> "ptid" should not be there.  Rename the pid parameter to ptid, and replace the above
> with "ptid.pid ()" and "ptid.lwp ()".
> 
> Simon
> 

I tried to build this using a sparc-linux cross-compiler, and I think we need
to adjust gdb_ptrace to account for the various possible arguments types.  The
following version of the function builds fine with sparc64-linux-gnu-gcc, can you
try it with NetBSD?

static PTRACE_TYPE_RET
gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG4 addr)
{
#ifdef __NetBSD__
  /* Support for NetBSD threads: unlike other ptrace implementations in this
     file, NetBSD requires that we pass both the pid and lwp.  */
  return ptrace (request, ptid.pid (), addr, ptid.lwp ());
#else
  pid_t pid = get_ptrace_pid (ptid);
  return ptrace (request, pid, addr, 0);
#endif
}

Alternatively, we could keep address as a "void *", and cast the value inside gdb_ptrace:

  return ptrace (request, ptid.pid (), (PTRACE_TYPE_ARG4) addr, ptid.lwp ());

All the callers of gdb_ptrace wouldn't have to cast that themselves, which is perhaps
a bit nicer.

Simon

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 16:59         ` Simon Marchi
@ 2020-03-17 17:07           ` Kamil Rytarowski
  2020-03-17 17:10             ` Simon Marchi
  0 siblings, 1 reply; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17 17:07 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 2493 bytes --]

On 17.03.2020 17:59, Simon Marchi wrote:
> On 2020-03-17 12:51 p.m., Simon Marchi wrote:
>> On 2020-03-17 12:46 p.m., Kamil Rytarowski wrote:
>>> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
>>>
>>> This file is still shared with other targets that use different 4th argument
>>> type, that is always unused.
>>> ---
>>>  gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
>>>  1 file changed, 22 insertions(+), 28 deletions(-)
>>>
>>> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
>>> index dff0f521565..10cc01375ed 100644
>>> --- a/gdb/sparc-nat.c
>>> +++ b/gdb/sparc-nat.c
>>> @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
>>>  #define PTRACE_SETFPREGS PT_SETFPREGS
>>>  #endif
>>>
>>> +static int
>>> +gdb_ptrace (int request, ptid_t pid, void *addr)
>>> +{
>>> +#ifdef __NetBSD__
>>> +  /* Support for NetBSD threads: unlike other ptrace implementations in this
>>> +     file, NetBSD requires that we pass both the pid and lwp.  */
>>> +  return ptrace (request, ptid (). pid (), addr, ptid ().lwp ());
>>
>> Does that even build?  ptid isn't the name of a parameter, and the parenthesis after
>> "ptid" should not be there.  Rename the pid parameter to ptid, and replace the above
>> with "ptid.pid ()" and "ptid.lwp ()".
>>
>> Simon
>>
> 
> I tried to build this using a sparc-linux cross-compiler, and I think we need
> to adjust gdb_ptrace to account for the various possible arguments types.  The
> following version of the function builds fine with sparc64-linux-gnu-gcc, can you
> try it with NetBSD?
> 
> static PTRACE_TYPE_RET
> gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG4 addr)

Does it work for you if you use PTRACE_TYPE_ARG3? addr is the 3rd argument.

PTRACE_TYPE_ARG4 is int on BSDs.

> {
> #ifdef __NetBSD__
>   /* Support for NetBSD threads: unlike other ptrace implementations in this
>      file, NetBSD requires that we pass both the pid and lwp.  */
>   return ptrace (request, ptid.pid (), addr, ptid.lwp ());
> #else
>   pid_t pid = get_ptrace_pid (ptid);
>   return ptrace (request, pid, addr, 0);
> #endif
> }
> 
> Alternatively, we could keep address as a "void *", and cast the value inside gdb_ptrace:
> 
>   return ptrace (request, ptid.pid (), (PTRACE_TYPE_ARG4) addr, ptid.lwp ());
> 
> All the callers of gdb_ptrace wouldn't have to cast that themselves, which is perhaps
> a bit nicer.
> 
> Simon
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 17:07           ` Kamil Rytarowski
@ 2020-03-17 17:10             ` Simon Marchi
  2020-03-17 18:14               ` Kamil Rytarowski
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 17:10 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 1:07 p.m., Kamil Rytarowski wrote:
> On 17.03.2020 17:59, Simon Marchi wrote:
>> I tried to build this using a sparc-linux cross-compiler, and I think we need
>> to adjust gdb_ptrace to account for the various possible arguments types.  The
>> following version of the function builds fine with sparc64-linux-gnu-gcc, can you
>> try it with NetBSD?
>>
>> static PTRACE_TYPE_RET
>> gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG4 addr)
> 
> Does it work for you if you use PTRACE_TYPE_ARG3? addr is the 3rd argument.
> 
> PTRACE_TYPE_ARG4 is int on BSDs.

Err yes sorry, it should be PTRACE_TYPE_ARG3, my bad.

Simon


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 17:10             ` Simon Marchi
@ 2020-03-17 18:14               ` Kamil Rytarowski
  0 siblings, 0 replies; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17 18:14 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 791 bytes --]

On 17.03.2020 18:10, Simon Marchi wrote:
> On 2020-03-17 1:07 p.m., Kamil Rytarowski wrote:
>> On 17.03.2020 17:59, Simon Marchi wrote:
>>> I tried to build this using a sparc-linux cross-compiler, and I think we need
>>> to adjust gdb_ptrace to account for the various possible arguments types.  The
>>> following version of the function builds fine with sparc64-linux-gnu-gcc, can you
>>> try it with NetBSD?
>>>
>>> static PTRACE_TYPE_RET
>>> gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG4 addr)
>>
>> Does it work for you if you use PTRACE_TYPE_ARG3? addr is the 3rd argument.
>>
>> PTRACE_TYPE_ARG4 is int on BSDs.
> 
> Err yes sorry, it should be PTRACE_TYPE_ARG3, my bad.
> 
> Simon
> 

I've tested v5 with the NetBSD/sparc build (32-bit).


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 16:46     ` [PATCH v4] " Kamil Rytarowski
  2020-03-17 16:51       ` Simon Marchi
@ 2020-03-17 18:18       ` Kamil Rytarowski
  2020-03-17 19:07         ` Simon Marchi
  1 sibling, 1 reply; 12+ messages in thread
From: Kamil Rytarowski @ 2020-03-17 18:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: simark, cbiesinger, Kamil Rytarowski

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.
---
 gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index dff0f521565..fadcfd34474 100644
--- a/gdb/sparc-nat.c
+++ b/gdb/sparc-nat.c
@@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
 #define PTRACE_SETFPREGS PT_SETFPREGS
 #endif

+static int
+gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr)
+{
+#ifdef __NetBSD__
+  /* Support for NetBSD threads: unlike other ptrace implementations in this
+     file, NetBSD requires that we pass both the pid and lwp.  */
+  return ptrace (request, ptid.pid (), addr, ptid.lwp ());
+#else
+  pid_t pid = get_ptrace_pid (ptid);
+  return ptrace (request, pid, addr, 0);
+#endif
+}
+
 /* Register set description.  */
 const struct sparc_gregmap *sparc_gregmap;
 const struct sparc_fpregmap *sparc_fpregmap;
@@ -137,22 +150,7 @@ void
 sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  pid_t pid;
-
-  /* NOTE: cagney/2002-12-03: This code assumes that the currently
-     selected light weight processes' registers can be written
-     directly into the selected thread's register cache.  This works
-     fine when given an 1:1 LWP:thread model (such as found on
-     GNU/Linux) but will, likely, have problems when used on an N:1
-     (userland threads) or N:M (userland multiple LWP) model.  In the
-     case of the latter two, the LWP's registers do not necessarily
-     belong to the selected thread (the LWP could be in the middle of
-     executing the thread switch code).
-
-     These functions should instead be parameterized with an explicit
-     object (struct regcache, struct thread_info?) into which the LWPs
-     registers can be written.  */
-  pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();

   if (regnum == SPARC_G0_REGNUM)
     {
@@ -166,7 +164,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
@@ -178,7 +176,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating point status"));

       sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
@@ -189,22 +187,18 @@ void
 sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  pid_t pid;
-
-  /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
-     about threaded assumptions.  */
-  pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();

   if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum))
     {
       gregset_t regs;

-      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't get registers"));

       sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);

-      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PTRACE_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
 	perror_with_name (_("Couldn't write registers"));

       /* Deal with the stack regs.  */
@@ -225,7 +219,7 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       fpregset_t fpregs, saved_fpregs;

-      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	perror_with_name (_("Couldn't get floating-point registers"));

       memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
@@ -237,8 +231,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
 	 to write the registers if nothing changed.  */
       if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
 	{
-	  if (ptrace (PTRACE_SETFPREGS, pid,
-		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+	  if (gdb_ptrace (PTRACE_SETFPREGS, ptid,
+			  (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't write floating-point registers"));
 	}

--
2.25.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 18:18       ` [PATCH v5] " Kamil Rytarowski
@ 2020-03-17 19:07         ` Simon Marchi
  2020-03-17 19:09           ` Simon Marchi
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 19:07 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 2:18 p.m., Kamil Rytarowski wrote:
> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
> 
> Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
> the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.
> ---
>  gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
>  1 file changed, 22 insertions(+), 28 deletions(-)
> 
> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
> index dff0f521565..fadcfd34474 100644
> --- a/gdb/sparc-nat.c
> +++ b/gdb/sparc-nat.c
> @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
>  #define PTRACE_SETFPREGS PT_SETFPREGS
>  #endif
> 
> +static int
> +gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr)
> +{
> +#ifdef __NetBSD__
> +  /* Support for NetBSD threads: unlike other ptrace implementations in this
> +     file, NetBSD requires that we pass both the pid and lwp.  */
> +  return ptrace (request, ptid.pid (), addr, ptid.lwp ());
> +#else
> +  pid_t pid = get_ptrace_pid (ptid);
> +  return ptrace (request, pid, addr, 0);
> +#endif
> +}
> +
>  /* Register set description.  */
>  const struct sparc_gregmap *sparc_gregmap;
>  const struct sparc_fpregmap *sparc_fpregmap;
> @@ -137,22 +150,7 @@ void
>  sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>  {
>    struct gdbarch *gdbarch = regcache->arch ();
> -  pid_t pid;
> -
> -  /* NOTE: cagney/2002-12-03: This code assumes that the currently
> -     selected light weight processes' registers can be written
> -     directly into the selected thread's register cache.  This works
> -     fine when given an 1:1 LWP:thread model (such as found on
> -     GNU/Linux) but will, likely, have problems when used on an N:1
> -     (userland threads) or N:M (userland multiple LWP) model.  In the
> -     case of the latter two, the LWP's registers do not necessarily
> -     belong to the selected thread (the LWP could be in the middle of
> -     executing the thread switch code).
> -
> -     These functions should instead be parameterized with an explicit
> -     object (struct regcache, struct thread_info?) into which the LWPs
> -     registers can be written.  */
> -  pid = get_ptrace_pid (regcache->ptid ());
> +  ptid_t ptid = regcache->ptid ();
> 
>    if (regnum == SPARC_G0_REGNUM)
>      {
> @@ -166,7 +164,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>      {
>        gregset_t regs;
> 
> -      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
> +      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>  	perror_with_name (_("Couldn't get registers"));
> 
>        sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
> @@ -178,7 +176,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>      {
>        fpregset_t fpregs;
> 
> -      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
> +      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
>  	perror_with_name (_("Couldn't get floating point status"));
> 
>        sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
> @@ -189,22 +187,18 @@ void
>  sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>  {
>    struct gdbarch *gdbarch = regcache->arch ();
> -  pid_t pid;
> -
> -  /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
> -     about threaded assumptions.  */
> -  pid = get_ptrace_pid (regcache->ptid ());
> +  ptid_t ptid = regcache->ptid ();
> 
>    if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum))
>      {
>        gregset_t regs;
> 
> -      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
> +      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>  	perror_with_name (_("Couldn't get registers"));
> 
>        sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);
> 
> -      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
> +      if (gdb_ptrace (PTRACE_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>  	perror_with_name (_("Couldn't write registers"));
> 
>        /* Deal with the stack regs.  */
> @@ -225,7 +219,7 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>      {
>        fpregset_t fpregs, saved_fpregs;
> 
> -      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
> +      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
>  	perror_with_name (_("Couldn't get floating-point registers"));
> 
>        memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
> @@ -237,8 +231,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>  	 to write the registers if nothing changed.  */
>        if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
>  	{
> -	  if (ptrace (PTRACE_SETFPREGS, pid,
> -		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
> +	  if (gdb_ptrace (PTRACE_SETFPREGS, ptid,
> +			  (PTRACE_TYPE_ARG3) &fpregs) == -1)
>  	    perror_with_name (_("Couldn't write floating-point registers"));
>  	}
> 
> --
> 2.25.0
> 

Thanks, this version LGTM.

Simon

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5] Add support for NetBSD threads in sparc-nat.c
  2020-03-17 19:07         ` Simon Marchi
@ 2020-03-17 19:09           ` Simon Marchi
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Marchi @ 2020-03-17 19:09 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-17 3:07 p.m., Simon Marchi wrote:
> On 2020-03-17 2:18 p.m., Kamil Rytarowski wrote:
>> NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.
>>
>> Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
>> the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.
>> ---
>>  gdb/sparc-nat.c | 50 ++++++++++++++++++++++---------------------------
>>  1 file changed, 22 insertions(+), 28 deletions(-)
>>
>> diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
>> index dff0f521565..fadcfd34474 100644
>> --- a/gdb/sparc-nat.c
>> +++ b/gdb/sparc-nat.c
>> @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t;
>>  #define PTRACE_SETFPREGS PT_SETFPREGS
>>  #endif
>>
>> +static int
>> +gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr)
>> +{
>> +#ifdef __NetBSD__
>> +  /* Support for NetBSD threads: unlike other ptrace implementations in this
>> +     file, NetBSD requires that we pass both the pid and lwp.  */
>> +  return ptrace (request, ptid.pid (), addr, ptid.lwp ());
>> +#else
>> +  pid_t pid = get_ptrace_pid (ptid);
>> +  return ptrace (request, pid, addr, 0);
>> +#endif
>> +}
>> +
>>  /* Register set description.  */
>>  const struct sparc_gregmap *sparc_gregmap;
>>  const struct sparc_fpregmap *sparc_fpregmap;
>> @@ -137,22 +150,7 @@ void
>>  sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>>  {
>>    struct gdbarch *gdbarch = regcache->arch ();
>> -  pid_t pid;
>> -
>> -  /* NOTE: cagney/2002-12-03: This code assumes that the currently
>> -     selected light weight processes' registers can be written
>> -     directly into the selected thread's register cache.  This works
>> -     fine when given an 1:1 LWP:thread model (such as found on
>> -     GNU/Linux) but will, likely, have problems when used on an N:1
>> -     (userland threads) or N:M (userland multiple LWP) model.  In the
>> -     case of the latter two, the LWP's registers do not necessarily
>> -     belong to the selected thread (the LWP could be in the middle of
>> -     executing the thread switch code).
>> -
>> -     These functions should instead be parameterized with an explicit
>> -     object (struct regcache, struct thread_info?) into which the LWPs
>> -     registers can be written.  */
>> -  pid = get_ptrace_pid (regcache->ptid ());
>> +  ptid_t ptid = regcache->ptid ();
>>
>>    if (regnum == SPARC_G0_REGNUM)
>>      {
>> @@ -166,7 +164,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>>      {
>>        gregset_t regs;
>>
>> -      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
>> +      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>>  	perror_with_name (_("Couldn't get registers"));
>>
>>        sparc_supply_gregset (sparc_gregmap, regcache, -1, &regs);
>> @@ -178,7 +176,7 @@ sparc_fetch_inferior_registers (struct regcache *regcache, int regnum)
>>      {
>>        fpregset_t fpregs;
>>
>> -      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
>> +      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
>>  	perror_with_name (_("Couldn't get floating point status"));
>>
>>        sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs);
>> @@ -189,22 +187,18 @@ void
>>  sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>>  {
>>    struct gdbarch *gdbarch = regcache->arch ();
>> -  pid_t pid;
>> -
>> -  /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
>> -     about threaded assumptions.  */
>> -  pid = get_ptrace_pid (regcache->ptid ());
>> +  ptid_t ptid = regcache->ptid ();
>>
>>    if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum))
>>      {
>>        gregset_t regs;
>>
>> -      if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
>> +      if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>>  	perror_with_name (_("Couldn't get registers"));
>>
>>        sparc_collect_gregset (sparc_gregmap, regcache, regnum, &regs);
>>
>> -      if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
>> +      if (gdb_ptrace (PTRACE_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs) == -1)
>>  	perror_with_name (_("Couldn't write registers"));
>>
>>        /* Deal with the stack regs.  */
>> @@ -225,7 +219,7 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>>      {
>>        fpregset_t fpregs, saved_fpregs;
>>
>> -      if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
>> +      if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
>>  	perror_with_name (_("Couldn't get floating-point registers"));
>>
>>        memcpy (&saved_fpregs, &fpregs, sizeof (fpregs));
>> @@ -237,8 +231,8 @@ sparc_store_inferior_registers (struct regcache *regcache, int regnum)
>>  	 to write the registers if nothing changed.  */
>>        if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0)
>>  	{
>> -	  if (ptrace (PTRACE_SETFPREGS, pid,
>> -		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
>> +	  if (gdb_ptrace (PTRACE_SETFPREGS, ptid,
>> +			  (PTRACE_TYPE_ARG3) &fpregs) == -1)
>>  	    perror_with_name (_("Couldn't write floating-point registers"));
>>  	}
>>
>> --
>> 2.25.0
>>
> 
> Thanks, this version LGTM.
> 
> Simon

Don't forget the ChangeLog entry though.

Simon


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-03-17 19:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17  9:40 [PATCH] Add support for NetBSD threads in sparc-nat.c Kamil Rytarowski
2020-03-17 15:10 ` [PATCH v3] " Kamil Rytarowski
2020-03-17 16:03   ` Simon Marchi
2020-03-17 16:46     ` [PATCH v4] " Kamil Rytarowski
2020-03-17 16:51       ` Simon Marchi
2020-03-17 16:59         ` Simon Marchi
2020-03-17 17:07           ` Kamil Rytarowski
2020-03-17 17:10             ` Simon Marchi
2020-03-17 18:14               ` Kamil Rytarowski
2020-03-17 18:18       ` [PATCH v5] " Kamil Rytarowski
2020-03-17 19:07         ` Simon Marchi
2020-03-17 19:09           ` Simon Marchi

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).