* i386nbsd-nat.c (i386nbsd_supply_pcb): Cast to 'gdb_byte *' in
[deliverable/binutils-gdb.git] / gdb / amd64-linux-nat.c
index 1b6d0c57e76c6e52275463e05d58caae6c2e6468..023d161a90a31d840533a0ee82a9dbd0d538eb37 100644 (file)
@@ -48,7 +48,6 @@
 #include "gregset.h"
 
 #include "amd64-tdep.h"
-#include "amd64-linux-tdep.h"
 #include "i386-linux-tdep.h"
 #include "amd64-nat.h"
 
@@ -96,12 +95,6 @@ static int amd64_linux_gregset32_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1, -1,
   ORIG_RAX * 8                 /* "orig_eax" */
 };
-
-/* Which ptrace request retrieves which registers?
-   These apply to the corresponding SET requests as well.  */
-
-#define GETFPREGS_SUPPLIES(regno) \
-  (FP0_REGNUM <= (regno) && (regno) <= MXCSR_REGNUM)
 \f
 
 /* Transfering the general-purpose registers between GDB, inferiors
@@ -126,38 +119,6 @@ fill_gregset (elf_gregset_t *gregsetp, int regnum)
   amd64_collect_native_gregset (current_regcache, gregsetp, regnum);
 }
 
-/* Fetch all general-purpose registers from process/thread TID and
-   store their values in GDB's register cache.  */
-
-static void
-fetch_regs (int tid)
-{
-  elf_gregset_t regs;
-
-  if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
-    perror_with_name ("Couldn't get registers");
-
-  supply_gregset (&regs);
-}
-
-/* Store all valid general-purpose registers in GDB's register cache
-   into the process/thread specified by TID.  */
-
-static void
-store_regs (int tid, int regnum)
-{
-  elf_gregset_t regs;
-
-  if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
-    perror_with_name ("Couldn't get registers");
-
-  fill_gregset (&regs, regnum);
-
-  if (ptrace (PTRACE_SETREGS, tid, 0, (long) &regs) < 0)
-    perror_with_name ("Couldn't write registers");
-}
-\f
-
 /* Transfering floating-point registers between GDB, inferiors and cores.  */
 
 /* Fill GDB's register cache with the floating-point and SSE register
@@ -176,38 +137,7 @@ supply_fpregset (elf_fpregset_t *fpregsetp)
 void
 fill_fpregset (elf_fpregset_t *fpregsetp, int regnum)
 {
-  amd64_fill_fxsave ((char *) fpregsetp, regnum);
-}
-
-/* Fetch all floating-point registers from process/thread TID and store
-   thier values in GDB's register cache.  */
-
-static void
-fetch_fpregs (int tid)
-{
-  elf_fpregset_t fpregs;
-
-  if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
-    perror_with_name ("Couldn't get floating point status");
-
-  supply_fpregset (&fpregs);
-}
-
-/* Store all valid floating-point registers in GDB's register cache
-   into the process/thread specified by TID.  */
-
-static void
-store_fpregs (int tid, int regnum)
-{
-  elf_fpregset_t fpregs;
-
-  if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
-    perror_with_name ("Couldn't get floating point status");
-
-  fill_fpregset (&fpregs, regnum);
-
-  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
-    perror_with_name ("Couldn't write floating point status");
+  amd64_collect_fxsave (current_regcache, regnum, fpregsetp);
 }
 \f
 
@@ -229,19 +159,25 @@ fetch_inferior_registers (int regnum)
 
   if (regnum == -1 || amd64_native_gregset_supplies_p (regnum))
     {
-      fetch_regs (tid);
+      elf_gregset_t regs;
+
+      if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
+       perror_with_name (_("Couldn't get registers"));
+
+      amd64_supply_native_gregset (current_regcache, &regs, -1);
       if (regnum != -1)
        return;
     }
 
-  if (regnum == -1 || GETFPREGS_SUPPLIES (regnum))
+  if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
     {
-      fetch_fpregs (tid);
-      return;
-    }
+      elf_fpregset_t fpregs;
 
-  internal_error (__FILE__, __LINE__,
-                 "Got request for bad register number %d.", regnum);
+      if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
+       perror_with_name (_("Couldn't get floating point status"));
+
+      amd64_supply_fxsave (current_regcache, -1, &fpregs);
+    }
 }
 
 /* Store register REGNUM back into the child process.  If REGNUM is
@@ -260,19 +196,34 @@ store_inferior_registers (int regnum)
 
   if (regnum == -1 || amd64_native_gregset_supplies_p (regnum))
     {
-      store_regs (tid, regnum);
+      elf_gregset_t regs;
+
+      if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
+       perror_with_name (_("Couldn't get registers"));
+
+      amd64_collect_native_gregset (current_regcache, &regs, regnum);
+
+      if (ptrace (PTRACE_SETREGS, tid, 0, (long) &regs) < 0)
+       perror_with_name (_("Couldn't write registers"));
+
       if (regnum != -1)
        return;
     }
 
-  if (regnum == -1 || GETFPREGS_SUPPLIES (regnum))
+  if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
     {
-      store_fpregs (tid, regnum);
+      elf_fpregset_t fpregs;
+
+      if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
+       perror_with_name (_("Couldn't get floating point status"));
+
+      amd64_collect_fxsave (current_regcache, regnum, &fpregs);
+
+      if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
+       perror_with_name (_("Couldn't write floating point status"));
+
       return;
     }
-
-  internal_error (__FILE__, __LINE__,
-                 "Got request to store bad register number %d.", regnum);
 }
 \f
 
@@ -297,7 +248,7 @@ amd64_linux_dr_get (int regnum)
                  offsetof (struct user, u_debugreg[regnum]), 0);
   if (errno != 0)
 #if 0
-    perror_with_name ("Couldn't read debug register");
+    perror_with_name (_("Couldn't read debug register"));
 #else
     return 0;
 #endif
@@ -318,7 +269,7 @@ amd64_linux_dr_set (int regnum, unsigned long value)
   errno = 0;
   ptrace (PT_WRITE_U, tid, offsetof (struct user, u_debugreg[regnum]), value);
   if (errno != 0)
-    perror_with_name ("Couldn't write debug register");
+    perror_with_name (_("Couldn't write debug register"));
 }
 
 void
@@ -350,31 +301,60 @@ amd64_linux_dr_get_status (void)
 }
 \f
 
+/* This function is called by libthread_db as part of its handling of
+   a request for a thread's local storage address.  */
+
 ps_err_e
 ps_get_thread_area (const struct ps_prochandle *ph,
                     lwpid_t lwpid, int idx, void **base)
 {
-/* This definition comes from prctl.h, but some kernels may not have it.  */
+  if (gdbarch_ptr_bit (current_gdbarch) == 32)
+    {
+      /* The full structure is found in <asm-i386/ldt.h>.  The second
+        integer is the LDT's base_address and that is used to locate
+        the thread's local storage.  See i386-linux-nat.c more
+        info.  */
+      unsigned int desc[4];
+
+      /* This code assumes that "int" is 32 bits and that
+        GET_THREAD_AREA returns no more than 4 int values.  */
+      gdb_assert (sizeof (int) == 4);  
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+      if  (ptrace (PTRACE_GET_THREAD_AREA, 
+                  lwpid, (void *) (long) idx, (unsigned long) &desc) < 0)
+       return PS_ERR;
+      
+      /* Extend the value to 64 bits.  Here it's assumed that a "long"
+        and a "void *" are the same.  */
+      (*base) = (void *) (long) desc[1];
+      return PS_OK;
+    }
+  else
+    {
+      /* This definition comes from prctl.h, but some kernels may not
+         have it.  */
 #ifndef PTRACE_ARCH_PRCTL
 #define PTRACE_ARCH_PRCTL      30
 #endif
-
-  /* FIXME: ezannoni-2003-07-09 see comment above about include file order.
-     We could be getting bogus values for these two.  */
-  gdb_assert (FS < ELF_NGREG);
-  gdb_assert (GS < ELF_NGREG);
-  switch (idx)
-    {
-    case FS:
-      if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
-       return PS_OK;
-      break;
-    case GS:
-      if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
-       return PS_OK;
-      break;
-    default:                   /* Should not happen.  */
-      return PS_BADADDR;
+      /* FIXME: ezannoni-2003-07-09 see comment above about include
+        file order.  We could be getting bogus values for these two.  */
+      gdb_assert (FS < ELF_NGREG);
+      gdb_assert (GS < ELF_NGREG);
+      switch (idx)
+       {
+       case FS:
+         if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
+           return PS_OK;
+         break;
+       case GS:
+         if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
+           return PS_OK;
+         break;
+       default:                   /* Should not happen.  */
+         return PS_BADADDR;
+       }
     }
   return PS_ERR;               /* ptrace failed.  */
 }
This page took 0.026362 seconds and 4 git commands to generate.