[PATCH] Add support for NetBSD threads in i386-bsd-nat.c

Kamil Rytarowski n54@gmx.com
Tue Mar 17 12:12:57 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/i386-bsd-nat.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/gdb/i386-bsd-nat.c b/gdb/i386-bsd-nat.c
index 4e22013a7a8..fb04b68aa90 100644
--- a/gdb/i386-bsd-nat.c
+++ b/gdb/i386-bsd-nat.c
@@ -34,6 +34,14 @@
 #include "inf-ptrace.h"
 

+/* 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
+
 /* In older BSD versions we cannot get at some of the segment
    registers.  FreeBSD for example didn't support the %fs and %gs
    registers until the 3.0 release.  We have autoconf checks for their
@@ -136,7 +144,7 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       struct reg regs;

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

       i386bsd_supply_gregset (regcache, &regs);
@@ -149,7 +157,7 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       register_t base;

-      if (ptrace (PT_GETFSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+      if (gdb_ptrace (PT_GETFSBASE, pid, (PTRACE_TYPE_ARG3) &base) == -1)
 	perror_with_name (_("Couldn't get segment register fs_base"));

       regcache->raw_supply (I386_FSBASE_REGNUM, &base);
@@ -162,7 +170,7 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
     {
       register_t base;

-      if (ptrace (PT_GETGSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+      if (gdb_ptrace (PT_GETGSBASE, pid, (PTRACE_TYPE_ARG3) &base) == -1)
 	perror_with_name (_("Couldn't get segment register gs_base"));

       regcache->raw_supply (I386_GSBASE_REGNUM, &base);
@@ -195,7 +203,7 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)

 #ifdef HAVE_PT_GETXMMREGS
       if (have_ptrace_xmmregs != 0
-	  && ptrace(PT_GETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
+	  && ptrace(PT_GETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs) == 0)
 	{
 	  have_ptrace_xmmregs = 1;
 	  i387_supply_fxsave (regcache, -1, xmmregs);
@@ -204,7 +212,7 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 	{
 	  have_ptrace_xmmregs = 0;
 #endif
-          if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't get floating point status"));

 	  i387_supply_fsave (regcache, -1, &fpregs);
@@ -226,12 +234,12 @@ i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)
     {
       struct reg regs;

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

       i386bsd_collect_gregset (regcache, &regs, regnum);

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

       if (regnum != -1)
@@ -245,7 +253,7 @@ i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)

       regcache->raw_collect (I386_FSBASE_REGNUM, &base);

-      if (ptrace (PT_SETFSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+      if (gdb_ptrace (PT_SETFSBASE, pid, (PTRACE_TYPE_ARG3) &base) == -1)
 	perror_with_name (_("Couldn't write segment register fs_base"));
       if (regnum != -1)
 	return;
@@ -258,7 +266,7 @@ i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)

       regcache->raw_collect (I386_GSBASE_REGNUM, &base);

-      if (ptrace (PT_SETGSBASE, pid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+      if (gdb_ptrace (PT_SETGSBASE, pid, (PTRACE_TYPE_ARG3) &base) == -1)
 	perror_with_name (_("Couldn't write segment register gs_base"));
       if (regnum != -1)
 	return;
@@ -293,25 +301,25 @@ i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)

 #ifdef HAVE_PT_GETXMMREGS
       if (have_ptrace_xmmregs != 0
-	  && ptrace(PT_GETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
+	  && ptrace(PT_GETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs) == 0)
 	{
 	  have_ptrace_xmmregs = 1;

 	  i387_collect_fxsave (regcache, regnum, xmmregs);

-	  if (ptrace (PT_SETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
+	  if (gdb_ptrace (PT_SETXMMREGS, pid, (PTRACE_TYPE_ARG3) xmmregs) == -1)
             perror_with_name (_("Couldn't write XMM registers"));
 	}
       else
 	{
 	  have_ptrace_xmmregs = 0;
 #endif
-          if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't get floating point status"));

           i387_collect_fsave (regcache, regnum, &fpregs);

-          if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs) == -1)
 	    perror_with_name (_("Couldn't write floating point status"));
 #ifdef HAVE_PT_GETXMMREGS
         }
--
2.25.0



More information about the Gdb-patches mailing list