[PATCH v3] Add support for NetBSD threads in sparc-nat.c

Kamil Rytarowski n54@gmx.com
Tue Mar 17 15:10:48 GMT 2020


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



More information about the Gdb-patches mailing list