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

Kamil Rytarowski n54@gmx.com
Tue Mar 17 11:58:26 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/amd64-bsd-nat.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/gdb/amd64-bsd-nat.c b/gdb/amd64-bsd-nat.c
index 9a3c9c22c05..fe122ce740b 100644
--- a/gdb/amd64-bsd-nat.c
+++ b/gdb/amd64-bsd-nat.c
@@ -36,6 +36,14 @@
 #include "amd64-bsd-nat.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
+
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
    for all registers (including the floating-point registers).  */

@@ -52,7 +60,7 @@ amd64bsd_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"));

       amd64_supply_native_gregset (regcache, &regs, -1);
@@ -65,7 +73,7 @@ amd64bsd_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 (tdep->fsbase_regnum, &base);
@@ -78,7 +86,7 @@ amd64bsd_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 (tdep->fsbase_regnum + 1, &base);
@@ -96,7 +104,7 @@ amd64bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
       if (x86bsd_xsave_len != 0)
 	{
 	  xstateregs = alloca (x86bsd_xsave_len);
-	  if (ptrace (PT_GETXSTATE, pid, (PTRACE_TYPE_ARG3) xstateregs, 0)
+	  if (gdb_ptrace (PT_GETXSTATE, pid, (PTRACE_TYPE_ARG3) xstateregs)
 	      == -1)
 	    perror_with_name (_("Couldn't get extended state status"));

@@ -105,7 +113,7 @@ amd64bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 	}
 #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"));

       amd64_supply_fxsave (regcache, -1, &fpregs);
@@ -128,12 +136,12 @@ amd64bsd_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"));

       amd64_collect_native_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)
@@ -149,7 +157,7 @@ amd64bsd_store_inferior_registers (struct regcache *regcache, int regnum)
       base = 0;
       regcache->raw_collect (tdep->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;
@@ -164,7 +172,7 @@ amd64bsd_store_inferior_registers (struct regcache *regcache, int regnum)
       base = 0;
       regcache->raw_collect (tdep->fsbase_regnum + 1, &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;
@@ -193,12 +201,12 @@ amd64bsd_store_inferior_registers (struct regcache *regcache, int regnum)
 	}
 #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"));

       amd64_collect_fxsave (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"));
     }
 }
--
2.25.0



More information about the Gdb-patches mailing list