Use htab_t in sim-options.c
[deliverable/binutils-gdb.git] / gdb / i386-bsd-nat.c
index cca46298435111407445cd380fc21142e3254239..a7c55284e08569af5108ba8440147c6d8ef1efcd 100644 (file)
@@ -1,6 +1,6 @@
 /* Native-dependent code for modern i386 BSD's.
 
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
+   Copyright (C) 2000-2021 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);
        }
     }
 }
@@ -130,13 +145,13 @@ i386bsd_collect_gregset (const struct regcache *regcache,
 void
 i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 {
-  pid_t pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();
 
   if (regnum == -1 || GETREGS_SUPPLIES (regnum))
     {
       struct reg regs;
 
-      if (ptrace (PT_GETREGS, pid, (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 regcache *regcache, int regnum)
        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 regcache *regcache, int regnum)
          void *xstateregs;
 
          xstateregs = alloca (x86bsd_xsave_len);
-         if (ptrace (PT_GETXSTATE, pid,
-                     (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,7 +210,8 @@ 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)
+         && gdb_ptrace(PT_GETXMMREGS, ptid,
+                       (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
        {
          have_ptrace_xmmregs = 1;
          i387_supply_fxsave (regcache, -1, xmmregs);
@@ -177,7 +220,8 @@ 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, ptid,
+                         (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
            perror_with_name (_("Couldn't get floating point status"));
 
          i387_supply_fsave (regcache, -1, &fpregs);
@@ -193,24 +237,51 @@ i386bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 void
 i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)
 {
-  pid_t pid = get_ptrace_pid (regcache->ptid ());
+  ptid_t ptid = regcache->ptid ();
 
   if (regnum == -1 || GETREGS_SUPPLIES (regnum))
     {
       struct reg regs;
 
-      if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
-        perror_with_name (_("Couldn't get registers"));
+      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, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
-        perror_with_name (_("Couldn't write registers"));
+      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;
@@ -224,14 +295,14 @@ i386bsd_store_inferior_registers (struct regcache *regcache, int regnum)
          void *xstateregs;
 
          xstateregs = alloca (x86bsd_xsave_len);
-         if (ptrace (PT_GETXSTATE, pid,
-                     (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, pid,
-                     (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;
        }
@@ -239,37 +310,40 @@ 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)
+         && 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, pid, (PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
-            perror_with_name (_("Couldn't write XMM registers"));
+         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, pid, (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);
+         i387_collect_fsave (regcache, regnum, &fpregs);
 
-          if (ptrace (PT_SETFPREGS, pid, (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
-        }
+       }
 #endif
     }
 }
 
+void _initialize_i386bsd_nat ();
 void
-_initialize_i386bsd_nat (void)
+_initialize_i386bsd_nat ()
 {
-  int offset;
-
   /* To support the recognition of signal handlers, i386-bsd-tdep.c
      hardcodes some constants.  Inclusion of this file means that we
      are compiling a native debugger, which means that we can use the
@@ -280,8 +354,6 @@ _initialize_i386bsd_nat (void)
 #define SC_REG_OFFSET i386fbsd4_sc_reg_offset
 #elif defined (__FreeBSD_version) && __FreeBSD_version >= 300005
 #define SC_REG_OFFSET i386fbsd_sc_reg_offset
-#elif defined (NetBSD) || defined (__NetBSD_Version__)
-#define SC_REG_OFFSET i386nbsd_sc_reg_offset
 #elif defined (OpenBSD)
 #define SC_REG_OFFSET i386obsd_sc_reg_offset
 #endif
@@ -300,7 +372,7 @@ _initialize_i386bsd_nat (void)
 
   /* Override the default value for the offset of the program counter
      in the sigcontext structure.  */
-  offset = offsetof (struct sigcontext, sc_pc);
+  int offset = offsetof (struct sigcontext, sc_pc);
 
   if (SC_PC_OFFSET != offset)
     {
This page took 0.031762 seconds and 4 git commands to generate.