gdb: move Tom de Vries to Global Maintainers
[deliverable/binutils-gdb.git] / gdb / i386-bsd-nat.c
index 492bd775737f5cc8a4718af2ba58c89782294990..4e8693246c87088881afd5a361c5803d2743116d 100644 (file)
@@ -1,6 +1,6 @@
 /* Native-dependent code for modern i386 BSD's.
 
-   Copyright (C) 2000-2016 Free Software Foundation, Inc.
+   Copyright (C) 2000-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "inf-ptrace.h"
 \f
 
+static PTRACE_TYPE_RET
+gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr,
+           PTRACE_TYPE_ARG4 data)
+{
+#ifdef __NetBSD__
+  gdb_assert (data == 0);
+  /* 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, data);
+#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
@@ -97,7 +112,7 @@ i386bsd_supply_gregset (struct regcache *regcache, const void *gregs)
       int offset = i386bsd_r_reg_offset[regnum];
 
       if (offset != -1)
-       regcache_raw_supply (regcache, regnum, regs + offset);
+       regcache->raw_supply (regnum, regs + offset);
     }
 }
 
@@ -119,7 +134,7 @@ i386bsd_collect_gregset (const struct regcache *regcache,
          int offset = i386bsd_r_reg_offset[i];
 
          if (offset != -1)
-           regcache_raw_collect (regcache, i, regs + offset);
+           regcache->raw_collect (i, regs + offset);
        }
     }
 }
@@ -127,16 +142,16 @@ i386bsd_collect_gregset (const struct regcache *regcache,
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
    for all registers (including the floating point registers).  */
 
-static void
-i386bsd_fetch_inferior_registers (struct target_ops *ops,
-                                 struct regcache *regcache, int regnum)
+void
+i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 {
+  ptid_t ptid = regcache->ptid ();
+
   if (regnum == -1 || GETREGS_SUPPLIES (regnum))
     {
       struct reg regs;
 
-      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
-                 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PT_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
        perror_with_name (_("Couldn't get registers"));
 
       i386bsd_supply_gregset (regcache, &regs);
@@ -144,6 +159,33 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
        return;
     }
 
+#ifdef PT_GETFSBASE
+  if (regnum == -1 || regnum == I386_FSBASE_REGNUM)
+    {
+      register_t base;
+
+      if (gdb_ptrace (PT_GETFSBASE, ptid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+       perror_with_name (_("Couldn't get segment register fs_base"));
+
+      regcache->raw_supply (I386_FSBASE_REGNUM, &base);
+      if (regnum != -1)
+       return;
+    }
+#endif
+#ifdef PT_GETGSBASE
+  if (regnum == -1 || regnum == I386_GSBASE_REGNUM)
+    {
+      register_t base;
+
+      if (gdb_ptrace (PT_GETGSBASE, ptid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+       perror_with_name (_("Couldn't get segment register gs_base"));
+
+      regcache->raw_supply (I386_GSBASE_REGNUM, &base);
+      if (regnum != -1)
+       return;
+    }
+#endif
+
   if (regnum == -1 || regnum >= I386_ST0_REGNUM)
     {
       struct fpreg fpregs;
@@ -157,8 +199,8 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
          void *xstateregs;
 
          xstateregs = alloca (x86bsd_xsave_len);
-         if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
+         if (gdb_ptrace (PT_GETXSTATE, ptid,
+                         (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
            perror_with_name (_("Couldn't get extended state status"));
 
          i387_supply_xsave (regcache, -1, xstateregs);
@@ -168,8 +210,8 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
       
 #ifdef HAVE_PT_GETXMMREGS
       if (have_ptrace_xmmregs != 0
-         && ptrace(PT_GETXMMREGS, get_ptrace_pid (inferior_ptid),
-                   (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
+         && gdb_ptrace(PT_GETXMMREGS, ptid,
+                       (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
        {
          have_ptrace_xmmregs = 1;
          i387_supply_fxsave (regcache, -1, xmmregs);
@@ -178,8 +220,8 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
        {
          have_ptrace_xmmregs = 0;
 #endif
-          if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_GETFPREGS, ptid,
+                         (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
            perror_with_name (_("Couldn't get floating point status"));
 
          i387_supply_fsave (regcache, -1, &fpregs);
@@ -192,28 +234,54 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
    this for all registers (including the floating point registers).  */
 
-static void
-i386bsd_store_inferior_registers (struct target_ops *ops,
-                                 struct regcache *regcache, int regnum)
+void
+i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)
 {
+  ptid_t ptid = regcache->ptid ();
+
   if (regnum == -1 || GETREGS_SUPPLIES (regnum))
     {
       struct reg regs;
 
-      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
-                  (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PT_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
         perror_with_name (_("Couldn't get registers"));
 
       i386bsd_collect_gregset (regcache, &regs, regnum);
 
-      if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
-                 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+      if (gdb_ptrace (PT_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
         perror_with_name (_("Couldn't write registers"));
 
       if (regnum != -1)
        return;
     }
 
+#ifdef PT_SETFSBASE
+  if (regnum == -1 || regnum == I386_FSBASE_REGNUM)
+    {
+      register_t base;
+
+      regcache->raw_collect (I386_FSBASE_REGNUM, &base);
+
+      if (gdb_ptrace (PT_SETFSBASE, ptid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+       perror_with_name (_("Couldn't write segment register fs_base"));
+      if (regnum != -1)
+       return;
+    }
+#endif
+#ifdef PT_SETGSBASE
+  if (regnum == -1 || regnum == I386_GSBASE_REGNUM)
+    {
+      register_t base;
+
+      regcache->raw_collect (I386_GSBASE_REGNUM, &base);
+
+      if (gdb_ptrace (PT_SETGSBASE, ptid, (PTRACE_TYPE_ARG3) &base, 0) == -1)
+       perror_with_name (_("Couldn't write segment register gs_base"));
+      if (regnum != -1)
+       return;
+    }
+#endif
+
   if (regnum == -1 || regnum >= I386_ST0_REGNUM)
     {
       struct fpreg fpregs;
@@ -227,14 +295,14 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
          void *xstateregs;
 
          xstateregs = alloca (x86bsd_xsave_len);
-         if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
+         if (gdb_ptrace (PT_GETXSTATE, ptid,
+                         (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
            perror_with_name (_("Couldn't get extended state status"));
 
          i387_collect_xsave (regcache, -1, xstateregs, 0);
 
-         if (ptrace (PT_SETXSTATE, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) xstateregs, x86bsd_xsave_len) == -1)
+         if (gdb_ptrace (PT_SETXSTATE, ptid, (PTRACE_TYPE_ARG3) xstateregs,
+                         x86bsd_xsave_len) == -1)
            perror_with_name (_("Couldn't write extended state status"));
          return;
        }
@@ -242,29 +310,29 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
 
 #ifdef HAVE_PT_GETXMMREGS
       if (have_ptrace_xmmregs != 0
-         && ptrace(PT_GETXMMREGS, get_ptrace_pid (inferior_ptid),
-                   (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
+         && gdb_ptrace(PT_GETXMMREGS, ptid,
+                       (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
        {
          have_ptrace_xmmregs = 1;
 
          i387_collect_fxsave (regcache, regnum, xmmregs);
 
-         if (ptrace (PT_SETXMMREGS, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
+         if (gdb_ptrace (PT_SETXMMREGS, ptid,
+                         (PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
             perror_with_name (_("Couldn't write XMM registers"));
        }
       else
        {
          have_ptrace_xmmregs = 0;
 #endif
-          if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_GETFPREGS, ptid,
+                         (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
            perror_with_name (_("Couldn't get floating point status"));
 
           i387_collect_fsave (regcache, regnum, &fpregs);
 
-          if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
-                     (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+          if (gdb_ptrace (PT_SETFPREGS, ptid,
+                         (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
            perror_with_name (_("Couldn't write floating point status"));
 #ifdef HAVE_PT_GETXMMREGS
         }
@@ -272,26 +340,9 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
     }
 }
 
-/* Create a prototype *BSD/i386 target.  The client can override it
-   with local methods.  */
-
-struct target_ops *
-i386bsd_target (void)
-{
-  struct target_ops *t;
-
-  t = x86bsd_target ();
-  t->to_fetch_registers = i386bsd_fetch_inferior_registers;
-  t->to_store_registers = i386bsd_store_inferior_registers;
-  return t;
-}
-\f
-
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_i386bsd_nat (void);
-
+void _initialize_i386bsd_nat ();
 void
-_initialize_i386bsd_nat (void)
+_initialize_i386bsd_nat ()
 {
   int offset;
 
This page took 0.02745 seconds and 4 git commands to generate.