2004-07-28 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / i386-linux-nat.c
index 4549b37ad1d676bfe4828735614d0d25713809c9..38bfef65dc20b39424573f12eb4509dd00994ace 100644 (file)
@@ -1,6 +1,6 @@
-/* Native-dependent code for GNU/Linux x86.
+/* Native-dependent code for GNU/Linux i386.
 
-   Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -179,7 +179,7 @@ fetch_register (int regno)
   gdb_assert (!have_ptrace_getregs);
   if (cannot_fetch_register (regno))
     {
-      supply_register (regno, NULL);
+      regcache_raw_supply (current_regcache, regno, NULL);
       return;
     }
 
@@ -194,7 +194,7 @@ fetch_register (int regno)
     error ("Couldn't read register %s (#%d): %s.", REGISTER_NAME (regno),
           regno, safe_strerror (errno));
 
-  supply_register (regno, &val);
+  regcache_raw_supply (current_regcache, regno, &val);
 }
 
 /* Store one register. */
@@ -215,7 +215,7 @@ store_register (int regno)
     tid = PIDGET (inferior_ptid); /* Not a threaded program.  */
 
   errno = 0;
-  regcache_collect (regno, &val);
+  regcache_raw_collect (current_regcache, regno, &val);
   ptrace (PTRACE_POKEUSER, tid, register_addr (regno, 0), val);
   if (errno != 0)
     error ("Couldn't write register %s (#%d): %s.", REGISTER_NAME (regno),
@@ -236,10 +236,11 @@ supply_gregset (elf_gregset_t *gregsetp)
   int i;
 
   for (i = 0; i < I386_NUM_GREGS; i++)
-    supply_register (i, regp + regmap[i]);
+    regcache_raw_supply (current_regcache, i, regp + regmap[i]);
 
   if (I386_LINUX_ORIG_EAX_REGNUM < NUM_REGS)
-    supply_register (I386_LINUX_ORIG_EAX_REGNUM, regp + ORIG_EAX);
+    regcache_raw_supply (current_regcache, I386_LINUX_ORIG_EAX_REGNUM,
+                        regp + ORIG_EAX);
 }
 
 /* Fill register REGNO (if it is a general-purpose register) in
@@ -254,11 +255,12 @@ fill_gregset (elf_gregset_t *gregsetp, int regno)
 
   for (i = 0; i < I386_NUM_GREGS; i++)
     if (regno == -1 || regno == i)
-      regcache_collect (i, regp + regmap[i]);
+      regcache_raw_collect (current_regcache, i, regp + regmap[i]);
 
   if ((regno == -1 || regno == I386_LINUX_ORIG_EAX_REGNUM)
       && I386_LINUX_ORIG_EAX_REGNUM < NUM_REGS)
-    regcache_collect (I386_LINUX_ORIG_EAX_REGNUM, regp + ORIG_EAX);
+    regcache_raw_collect (current_regcache, I386_LINUX_ORIG_EAX_REGNUM,
+                         regp + ORIG_EAX);
 }
 
 #ifdef HAVE_PTRACE_GETREGS
@@ -320,7 +322,7 @@ static void store_regs (int tid, int regno) {}
 void 
 supply_fpregset (elf_fpregset_t *fpregsetp)
 {
-  i387_supply_fsave ((char *) fpregsetp);
+  i387_supply_fsave (current_regcache, -1, fpregsetp);
   dummy_sse_values ();
 }
 
@@ -385,7 +387,7 @@ static void store_fpregs (int tid, int regno) {}
 void
 supply_fpxregset (elf_fpxregset_t *fpxregsetp)
 {
-  i387_supply_fxsave ((char *) fpxregsetp);
+  i387_supply_fxsave (current_regcache, -1, fpxregsetp);
 }
 
 /* Fill register REGNO (if it is a floating-point or SSE register) in
@@ -472,9 +474,9 @@ dummy_sse_values (void)
   int reg;
 
   for (reg = 0; reg < tdep->num_xmm_regs; reg++)
-    supply_register (XMM0_REGNUM + reg, (char *) dummy);
+    regcache_raw_supply (current_regcache, XMM0_REGNUM + reg, (char *) dummy);
   if (tdep->num_xmm_regs > 0)
-    supply_register (MXCSR_REGNUM, (char *) &mxcsr);
+    regcache_raw_supply (current_regcache, MXCSR_REGNUM, (char *) &mxcsr);
 }
 
 #else
@@ -641,6 +643,8 @@ store_inferior_registers (int regno)
 }
 \f
 
+/* Support for debug registers.  */
+
 static unsigned long
 i386_linux_dr_get (int regnum)
 {
@@ -687,21 +691,6 @@ i386_linux_dr_set (int regnum, unsigned long value)
     perror_with_name ("Couldn't write debug register");
 }
 
-extern ps_err_e
-ps_get_thread_area(const struct ps_prochandle *ph, 
-                  lwpid_t lwpid, int idx, void **base)
-{
-  unsigned long int desc[3];
-#define PTRACE_GET_THREAD_AREA 25
-
-  if  (ptrace (PTRACE_GET_THREAD_AREA, 
-              lwpid, (void *) idx, (unsigned long) &desc) < 0)
-    return PS_ERR;
-
-  *(int *)base = desc[1];
-  return PS_OK;
-}
-
 void
 i386_linux_dr_set_control (unsigned long control)
 {
@@ -731,77 +720,43 @@ i386_linux_dr_get_status (void)
 }
 \f
 
-/* Interpreting register set info found in core files.  */
-
-/* Provide registers to GDB from a core file.
-
-   (We can't use the generic version of this function in
-   core-regset.c, because GNU/Linux has *three* different kinds of
-   register set notes.  core-regset.c would have to call
-   supply_fpxregset, which most platforms don't have.)
-
-   CORE_REG_SECT points to an array of bytes, which are the contents
-   of a `note' from a core file which BFD thinks might contain
-   register contents.  CORE_REG_SIZE is its size.
-
-   WHICH says which register set corelow suspects this is:
-     0 --- the general-purpose register set, in elf_gregset_t format
-     2 --- the floating-point register set, in elf_fpregset_t format
-     3 --- the extended floating-point register set, in elf_fpxregset_t format
-
-   REG_ADDR isn't used on GNU/Linux.  */
-
-static void
-fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
-                     int which, CORE_ADDR reg_addr)
-{
-  elf_gregset_t gregset;
-  elf_fpregset_t fpregset;
-
-  switch (which)
-    {
-    case 0:
-      if (core_reg_size != sizeof (gregset))
-       warning ("Wrong size gregset in core file.");
-      else
-       {
-         memcpy (&gregset, core_reg_sect, sizeof (gregset));
-         supply_gregset (&gregset);
-       }
-      break;
-
-    case 2:
-      if (core_reg_size != sizeof (fpregset))
-       warning ("Wrong size fpregset in core file.");
-      else
-       {
-         memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
-         supply_fpregset (&fpregset);
-       }
-      break;
-
-#ifdef HAVE_PTRACE_GETFPXREGS
-      {
-       elf_fpxregset_t fpxregset;
-
-      case 3:
-       if (core_reg_size != sizeof (fpxregset))
-         warning ("Wrong size fpxregset in core file.");
-       else
-         {
-           memcpy (&fpxregset, core_reg_sect, sizeof (fpxregset));
-           supply_fpxregset (&fpxregset);
-         }
-       break;
-      }
+/* Called by libthread_db.  Returns a pointer to the thread local
+   storage (or its descriptor).  */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph, 
+                   lwpid_t lwpid, int idx, void **base)
+{
+  /* NOTE: cagney/2003-08-26: The definition of this buffer is found
+     in the kernel header <asm-i386/ldt.h>.  It, after padding, is 4 x
+     4 byte integers in size: `entry_number', `base_addr', `limit',
+     and a bunch of status bits.
+
+     The values returned by this ptrace call should be part of the
+     regcache buffer, and ps_get_thread_area should channel its
+     request through the regcache.  That way remote targets could
+     provide the value using the remote protocol and not this direct
+     call.
+
+     Is this function needed?  I'm guessing that the `base' is the
+     address of a a descriptor that libthread_db uses to find the
+     thread local address base that GDB needs.  Perhaps that
+     descriptor is defined by the ABI.  Anyway, given that
+     libthread_db calls this function without prompting (gdb
+     requesting tls base) I guess it needs info in there anyway.  */
+  unsigned int desc[4];
+  gdb_assert (sizeof (int) == 4);
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
 #endif
 
-    default:
-      /* We've covered all the kinds of registers we know about here,
-         so this must be something we wouldn't know what to do with
-         anyway.  Just ignore it.  */
-      break;
-    }
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
+             (void *) idx, (unsigned long) &desc) < 0)
+    return PS_ERR;
+
+  *(int *)base = desc[1];
+  return PS_OK;
 }
 \f
 
@@ -862,7 +817,7 @@ child_resume (ptid_t ptid, int step, enum target_signal signal)
          that's about to be restored, and set the trace flag there.  */
 
       /* First check if PC is at a system call.  */
-      if (read_memory_nobpt (pc, (char *) buf, LINUX_SYSCALL_LEN) == 0
+      if (deprecated_read_memory_nobpt (pc, (char *) buf, LINUX_SYSCALL_LEN) == 0
          && memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
        {
          int syscall = read_register_pid (LINUX_SYSCALL_REGNUM,
@@ -898,22 +853,3 @@ child_post_startup_inferior (ptid_t ptid)
   i386_cleanup_dregs ();
   linux_child_post_startup_inferior (ptid);
 }
-\f
-
-/* Register that we are able to handle GNU/Linux ELF core file
-   formats.  */
-
-static struct core_fns linux_elf_core_fns =
-{
-  bfd_target_elf_flavour,              /* core_flavour */
-  default_check_format,                        /* check_format */
-  default_core_sniffer,                        /* core_sniffer */
-  fetch_core_registers,                        /* core_read_registers */
-  NULL                                 /* next */
-};
-
-void
-_initialize_i386_linux_nat (void)
-{
-  add_core_fns (&linux_elf_core_fns);
-}
This page took 0.027269 seconds and 4 git commands to generate.