Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Updates for m68k-linux target
@ 2002-01-24  2:02 Andreas Schwab
  2002-01-24  9:52 ` Andrew Cagney
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2002-01-24  2:02 UTC (permalink / raw)
  To: gdb-patches

This patch updates the ptrace interface for the m68k-linux target.

Ok to check in?

Andreas.

2002-01-24  Andreas Schwab  <schwab@suse.de>

	* config/m68k/tm-m68k.h (LAST_FPU_CTRL_REGNUM): Define.
	* m68klinux-nat.c: Fix ptrace interface for fetching/storing
	registers and add support for PTRACE_GETREGS.

Index: src/gdb/config/m68k/tm-m68k.h
===================================================================
RCS file: /cvs/src/src/gdb/config/m68k/tm-m68k.h,v
retrieving revision 1.8
diff -u -a -u -r1.8 src/gdb/config/m68k/tm-m68k.h
--- src/gdb/config/m68k/tm-m68k.h	2002/01/05 04:30:34	1.8
+++ src/gdb/config/m68k/tm-m68k.h	2002/01/19 22:29:37
@@ -194,6 +194,7 @@
 #define FPC_REGNUM 26		/* 68881 control register */
 #define FPS_REGNUM 27		/* 68881 status register */
 #define FPI_REGNUM 28		/* 68881 iaddr register */
+#define LAST_FPU_CTRL_REGNUM 28
 
 /* Store the address of the place in which to copy the structure the
    subroutine will return.  This is called from call_function. */
Index: src/gdb/m68klinux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
retrieving revision 1.6
diff -u -a -u -r1.6 src/gdb/m68klinux-nat.c
--- src/gdb/m68klinux-nat.c	2001/07/11 18:39:11	1.6
+++ src/gdb/m68klinux-nat.c	2002/01/19 22:27:53
@@ -32,11 +32,16 @@
 #include <sys/param.h>
 #include <sys/dir.h>
 #include <signal.h>
+#include <sys/ptrace.h>
 #include <sys/user.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <sys/procfs.h>
 
+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
+
 #include <sys/file.h>
 #include "gdb_stat.h"
 
@@ -57,6 +62,26 @@
   45, 46, 47
 };
 
+/* Which ptrace request retrieves which registers?
+   These apply to the corresponding SET requests as well.  */
+#define NUM_GREGS (18)
+#define MAX_NUM_REGS (NUM_GREGS + 11)
+#define GETREGS_SUPPLIES(regno) \
+  (0 <= (regno) && (regno) < NUM_GREGS)
+#define GETFPREGS_SUPPLIES(regno) \
+  (FP0_REGNUM <= (regno) && (regno) <= LAST_FPU_CTRL_REGNUM)
+
+/* Does the current host support the GETREGS request?  */
+int have_ptrace_getregs =
+#ifdef HAVE_PTRACE_GETREGS
+  1
+#else
+  0
+#endif
+;
+
+\f
+
 /* BLOCKEND is the value of u.u_ar0, and points to the place where GS
    is stored.  */
 
@@ -87,32 +112,240 @@
 void
 supply_gregset (elf_gregset_t *gregsetp)
 {
+  elf_greg_t *regp = (elf_greg_t *) gregsetp;
   int regi;
 
   for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
-    supply_register (regi, (char *) (*gregsetp + regmap[regi]));
-  supply_register (PS_REGNUM, (char *) (*gregsetp + PT_SR));
-  supply_register (PC_REGNUM, (char *) (*gregsetp + PT_PC));
+    supply_register (regi, (char *) &regp[regmap[regi]]);
+  supply_register (PS_REGNUM, (char *) &regp[PT_SR]);
+  supply_register (PC_REGNUM, (char *) &regp[PT_PC]);
 }
+
+/* Convert the valid general-purpose register values in GDB's register
+   array to `struct user' format and store them in *GREGSETP.  The
+   array VALID indicates which register values are valid.  If VALID is
+   NULL, all registers are assumed to be valid.  */
 
-/*  Given a pointer to a floating point register set in /proc format
-   (fpregset_t *), unpack the register contents and supply them as gdb's
-   idea of the current floating point register values. */
+static void
+convert_to_gregset (elf_gregset_t *gregsetp, char *valid)
+{
+  elf_greg_t *regp = (elf_greg_t *) gregsetp;
+  int regi;
 
+  for (regi = 0; regi < NUM_GREGS; regi++)
+    if (! valid || valid[regi])
+      regp[regmap[regi]] = *(int *) &registers[REGISTER_BYTE (regi)];
+}
+
+/* Fill register REGNO (if it is a general-purpose register) in
+   *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
+   do this for all registers.  */
 void
+fill_gregset (elf_gregset_t *gregsetp, int regno)
+{
+  if (regno == -1)
+    {
+      convert_to_gregset (gregsetp, NULL);
+      return;
+    }
+
+  if (GETREGS_SUPPLIES (regno))
+    {
+      char valid[NUM_GREGS];
+
+      memset (valid, 0, sizeof (valid));
+      valid[regno] = 1;
+
+      convert_to_gregset (gregsetp, valid);
+    }
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Fetch all general-purpose registers from process/thread TID and
+   store their values in GDB's register array.  */
+
+static void
+fetch_regs (int tid)
+{
+  elf_gregset_t regs;
+  int ret;
+
+  ret = ptrace (PTRACE_GETREGS, tid, 0, (int) &regs);
+  if (ret < 0)
+    {
+      if (errno == EIO)
+	{
+	  /* The kernel we're running on doesn't support the GETREGS
+             request.  Reset `have_ptrace_getregs'.  */
+	  have_ptrace_getregs = 0;
+	  return;
+	}
+
+      warning ("Couldn't get registers.");
+      return;
+    }
+
+  supply_gregset (&regs);
+}
+
+/* Store all valid general-purpose registers in GDB's register array
+   into the process/thread specified by TID.  */
+
+static void
+store_regs (int tid)
+{
+  elf_gregset_t regs;
+  int ret;
+
+  ret = ptrace (PTRACE_GETREGS, tid, 0, (int) &regs);
+  if (ret < 0)
+    {
+      warning ("Couldn't get registers.");
+      return;
+    }
+
+  convert_to_gregset (&regs, register_valid);
+
+  ret = ptrace (PTRACE_SETREGS, tid, 0, (int) &regs);
+  if (ret < 0)
+    {
+      warning ("Couldn't write registers.");
+      return;
+    }
+}
+
+#else
+
+static void fetch_regs (int tid) {}
+static void store_regs (int tid) {}
+
+#endif
+
+\f
+/* Transfering floating-point registers between GDB, inferiors and cores.  */
+
+/* What is the address of fpN within the floating-point register set F?  */
+#define FPREG_ADDR(f, n) ((char *) &(f)->fpregs[(n) * 3])
+
+/* Fill GDB's register array with the floating-point register values in
+   *FPREGSETP.  */
+
+void
 supply_fpregset (elf_fpregset_t *fpregsetp)
 {
   int regi;
 
   for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
-    supply_register (regi, (char *) &fpregsetp->fpregs[(regi - FP0_REGNUM) * 3]);
+    supply_register (regi, FPREG_ADDR (fpregsetp, regi - FP0_REGNUM));
   supply_register (FPC_REGNUM, (char *) &fpregsetp->fpcntl[0]);
   supply_register (FPS_REGNUM, (char *) &fpregsetp->fpcntl[1]);
   supply_register (FPI_REGNUM, (char *) &fpregsetp->fpcntl[2]);
 }
 
+/* Convert the valid floating-point register values in GDB's register
+   array to `struct user' format and store them in *FPREGSETP.  The
+   array VALID indicates which register values are valid.  If VALID is
+   NULL, all registers are assumed to be valid.  */
+
+static void
+convert_to_fpregset (elf_fpregset_t *fpregsetp, char *valid)
+{
+  int reg;
+
+  /* Fill in the floating-point registers.  */
+  for (reg = 0; reg < 8; reg++)
+    if (!valid || valid[FP0_REGNUM + reg])
+      memcpy (FPREG_ADDR (fpregsetp, reg),
+	      &registers[REGISTER_BYTE (FP0_REGNUM + reg)],
+	      REGISTER_RAW_SIZE(FP0_REGNUM + reg));
+
+  /* Fill in the floating-point control registers.  */
+  for (reg = 0; reg < 3; reg++)
+    if (!valid || valid[FPC_REGNUM + reg])
+      fpregsetp->fpcntl[reg]
+	= *(int *) &registers[REGISTER_BYTE (FPC_REGNUM + reg)];
+}
+
+/* Fill register REGNO (if it is a floating-point register) in
+   *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
+   do this for all registers.  */
+
+void
+fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
+{
+  if (regno == -1)
+    {
+      convert_to_fpregset (fpregsetp, NULL);
+      return;
+    }
+
+  if (GETFPREGS_SUPPLIES (regno))
+    {
+      char valid[MAX_NUM_REGS];
+      
+      memset (valid, 0, sizeof (valid));
+      valid[regno] = 1;
+	      
+      convert_to_fpregset (fpregsetp, valid);
+    }
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Fetch all floating-point registers from process/thread TID and store
+   thier values in GDB's register array.  */
+
+static void
+fetch_fpregs (int tid)
+{
+  elf_fpregset_t fpregs;
+  int ret;
+
+  ret = ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs);
+  if (ret < 0)
+    {
+      warning ("Couldn't get floating point status.");
+      return;
+    }
+
+  supply_fpregset (&fpregs);
+}
+
+/* Store all valid floating-point registers in GDB's register array
+   into the process/thread specified by TID.  */
+
+static void
+store_fpregs (int tid)
+{
+  elf_fpregset_t fpregs;
+  int ret;
+
+  ret = ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs);
+  if (ret < 0)
+    {
+      warning ("Couldn't get floating point status.");
+      return;
+    }
+
+  convert_to_fpregset (&fpregs, register_valid);
+
+  ret = ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs);
+  if (ret < 0)
+    {
+      warning ("Couldn't write floating point status.");
+      return;
+    }
+}
+
+#else
+
+static void fetch_fpregs (int tid) {}
+static void store_fpregs (int tid) {}
+
 #endif
 
+#endif
 \f
 /* Interpreting register set info found in core files.  */
 

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Updates for m68k-linux target
  2002-01-24  2:02 Updates for m68k-linux target Andreas Schwab
@ 2002-01-24  9:52 ` Andrew Cagney
  2002-01-26 14:24   ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2002-01-24  9:52 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

> This patch updates the ptrace interface for the m68k-linux target.
> 
> Ok to check in?


Just a few tweeks, otherwize yes.


> 2002-01-24  Andreas Schwab  <schwab@suse.de>
> 
> * config/m68k/tm-m68k.h (LAST_FPU_CTRL_REGNUM): Define.
> 	* m68klinux-nat.c: Fix ptrace interface for fetching/storing
> 	registers and add support for PTRACE_GETREGS.
> 
> Index: src/gdb/config/m68k/tm-m68k.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/config/m68k/tm-m68k.h,v
> retrieving revision 1.8
> diff -u -a -u -r1.8 src/gdb/config/m68k/tm-m68k.h
> --- src/gdb/config/m68k/tm-m68k.h	2002/01/05 04:30:34	1.8
> +++ src/gdb/config/m68k/tm-m68k.h	2002/01/19 22:29:37
> @@ -194,6 +194,7 @@
>  #define FPC_REGNUM 26		/* 68881 control register */
>  #define FPS_REGNUM 27		/* 68881 status register */
>  #define FPI_REGNUM 28		/* 68881 iaddr register */
> +#define LAST_FPU_CTRL_REGNUM 28
>  
>  /* Store the address of the place in which to copy the structure the
>     subroutine will return.  This is called from call_function. */
> Index: src/gdb/m68klinux-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
> retrieving revision 1.6
> diff -u -a -u -r1.6 src/gdb/m68klinux-nat.c
> --- src/gdb/m68klinux-nat.c	2001/07/11 18:39:11	1.6
> +++ src/gdb/m68klinux-nat.c	2002/01/19 22:27:53
> @@ -32,11 +32,16 @@
>  #include <sys/param.h>
> #include <sys/dir.h>
> #include <signal.h>
> +#include <sys/ptrace.h>
> #include <sys/user.h>
> #include <sys/ioctl.h>
> #include <fcntl.h>
> #include <sys/procfs.h>
> +#ifdef HAVE_SYS_REG_H
> +#include <sys/reg.h>
> +#endif
> +
>  #include <sys/file.h>
> #include "gdb_stat.h"
>  
> @@ -57,6 +62,26 @@
>    45, 46, 47
>  };
>  
> +/* Which ptrace request retrieves which registers?
> +   These apply to the corresponding SET requests as well.  */
> +#define NUM_GREGS (18)
> +#define MAX_NUM_REGS (NUM_GREGS + 11)
> +#define GETREGS_SUPPLIES(regno) \
> +  (0 <= (regno) && (regno) < NUM_GREGS)


Function.

> +#define GETFPREGS_SUPPLIES(regno) \
> +  (FP0_REGNUM <= (regno) && (regno) <= LAST_FPU_CTRL_REGNUM)


Function.


> +/* Does the current host support the GETREGS request?  */
> +int have_ptrace_getregs =
> +#ifdef HAVE_PTRACE_GETREGS
> +  1
> +#else
> +  0
> +#endif
> +;


Dig dig, ah, i386-linux-nat.c.


> +  for (regi = 0; regi < NUM_GREGS; regi++)
> +    if (! valid || valid[regi])
> +      regp[regmap[regi]] = *(int *) &registers[REGISTER_BYTE (regi)];


Use regcache_collect().



> +/* Convert the valid floating-point register values in GDB's register
> +   array to `struct user' format and store them in *FPREGSETP.  The
> +   array VALID indicates which register values are valid.  If VALID is
> +   NULL, all registers are assumed to be valid.  */


Suggest changing ``Convert ...'' to ``Transfer ...'' or ``Copy ...''.
Within GDB the words ``convert'' and ``floating-point'' combine to 
suggest the old REGISTER_CONVERTIBLE et.al. macros which really did 
convert floating-point values as they were being copied to/from core GDB.


> +static void
> +convert_to_fpregset (elf_fpregset_t *fpregsetp, char *valid)
> +{
> +  int reg;
> +
> +  /* Fill in the floating-point registers.  */
> +  for (reg = 0; reg < 8; reg++)
> +    if (!valid || valid[FP0_REGNUM + reg])
> +      memcpy (FPREG_ADDR (fpregsetp, reg),
> +	      &registers[REGISTER_BYTE (FP0_REGNUM + reg)],
> +	      REGISTER_RAW_SIZE(FP0_REGNUM + reg));


regcache_collect ();


> +  /* Fill in the floating-point control registers.  */
> +  for (reg = 0; reg < 3; reg++)
> +    if (!valid || valid[FPC_REGNUM + reg])
> +      fpregsetp->fpcntl[reg]
> +	= *(int *) &registers[REGISTER_BYTE (FPC_REGNUM + reg)];


Ditto.


enjoy,

Andrew




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Updates for m68k-linux target
  2002-01-24  9:52 ` Andrew Cagney
@ 2002-01-26 14:24   ` Andreas Schwab
  2002-01-29 13:41     ` Andrew Cagney
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2002-01-26 14:24 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

Andrew Cagney <ac131313@cygnus.com> writes:

|> > This patch updates the ptrace interface for the m68k-linux target.
|> > Ok to check in?
|> 
|> 
|> Just a few tweeks, otherwize yes.

I wrote this stuff already long ago, but didn't find the time to submit,
so it suffered from bit rot.  While looking over it again, I noticed that
the support for PTRACE_GETREGS wasn't actually complete.  Here is a new
version that finishes it and addresses your remarks.  Committed.

Andreas.

2002-01-26  Andreas Schwab  <schwab@suse.de>

	* config/m68k/nm-linux.h (FETCH_INFERIOR_REGISTERS): Define.
	* m68klinux-nat.c: Update ptrace interface for fetching/storing
	registers and add support for PTRACE_GETREGS.

Index: gdb/m68klinux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
retrieving revision 1.6
diff -u -a -u -r1.6 gdb/m68klinux-nat.c
--- gdb/m68klinux-nat.c	2001/07/11 18:39:11	1.6
+++ gdb/m68klinux-nat.c	2002/01/26 22:20:25
@@ -32,11 +32,16 @@
 #include <sys/param.h>
 #include <sys/dir.h>
 #include <signal.h>
+#include <sys/ptrace.h>
 #include <sys/user.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <sys/procfs.h>
 
+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
+
 #include <sys/file.h>
 #include "gdb_stat.h"
 
@@ -57,6 +62,34 @@
   45, 46, 47
 };
 
+/* Which ptrace request retrieves which registers?
+   These apply to the corresponding SET requests as well.  */
+#define NUM_GREGS (18)
+#define MAX_NUM_REGS (NUM_GREGS + 11)
+
+int
+getregs_supplies (int regno)
+{
+  return 0 <= regno && regno < NUM_GREGS;
+}
+
+int
+getfpregs_supplies (int regno)
+{
+  return FP0_REGNUM <= regno && regno <= FPI_REGNUM;
+}
+
+/* Does the current host support the GETREGS request?  */
+int have_ptrace_getregs =
+#ifdef HAVE_PTRACE_GETREGS
+  1
+#else
+  0
+#endif
+;
+
+\f
+
 /* BLOCKEND is the value of u.u_ar0, and points to the place where GS
    is stored.  */
 
@@ -65,7 +98,151 @@
 {
   return (blockend + 4 * regmap[regnum]);
 }
+\f
+
+/* Fetching registers directly from the U area, one at a time.  */
+
+/* FIXME: This duplicates code from `inptrace.c'.  The problem is that we
+   define FETCH_INFERIOR_REGISTERS since we want to use our own versions
+   of {fetch,store}_inferior_registers that use the GETREGS request.  This
+   means that the code in `infptrace.c' is #ifdef'd out.  But we need to
+   fall back on that code when GDB is running on top of a kernel that
+   doesn't support the GETREGS request.  */
+
+#ifndef PT_READ_U
+#define PT_READ_U PTRACE_PEEKUSR
+#endif
+#ifndef PT_WRITE_U
+#define PT_WRITE_U PTRACE_POKEUSR
+#endif
+
+/* Default the type of the ptrace transfer to int.  */
+#ifndef PTRACE_XFER_TYPE
+#define PTRACE_XFER_TYPE int
+#endif
+
+/* Fetch one register.  */
+
+static void
+fetch_register (int regno)
+{
+  /* This isn't really an address.  But ptrace thinks of it as one.  */
+  CORE_ADDR regaddr;
+  char mess[128];		/* For messages */
+  register int i;
+  unsigned int offset;		/* Offset of registers within the u area.  */
+  char buf[MAX_REGISTER_RAW_SIZE];
+  int tid;
+
+  if (CANNOT_FETCH_REGISTER (regno))
+    {
+      memset (buf, '\0', REGISTER_RAW_SIZE (regno));	/* Supply zeroes */
+      supply_register (regno, buf);
+      return;
+    }
+
+  /* Overload thread id onto process id */
+  if ((tid = TIDGET (inferior_ptid)) == 0)
+    tid = PIDGET (inferior_ptid);	/* no thread id, just use process id */
+
+  offset = U_REGS_OFFSET;
+
+  regaddr = register_addr (regno, offset);
+  for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+    {
+      errno = 0;
+      *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid,
+					       (PTRACE_ARG3_TYPE) regaddr, 0);
+      regaddr += sizeof (PTRACE_XFER_TYPE);
+      if (errno != 0)
+	{
+	  sprintf (mess, "reading register %s (#%d)", 
+		   REGISTER_NAME (regno), regno);
+	  perror_with_name (mess);
+	}
+    }
+  supply_register (regno, buf);
+}
 
+/* Fetch register values from the inferior.
+   If REGNO is negative, do this for all registers.
+   Otherwise, REGNO specifies which register (so we can save time). */
+
+void
+old_fetch_inferior_registers (int regno)
+{
+  if (regno >= 0)
+    {
+      fetch_register (regno);
+    }
+  else
+    {
+      for (regno = 0; regno < NUM_REGS; regno++)
+	{
+	  fetch_register (regno);
+	}
+    }
+}
+
+/* Store one register. */
+
+static void
+store_register (int regno)
+{
+  /* This isn't really an address.  But ptrace thinks of it as one.  */
+  CORE_ADDR regaddr;
+  char mess[128];		/* For messages */
+  register int i;
+  unsigned int offset;		/* Offset of registers within the u area.  */
+  int tid;
+
+  if (CANNOT_STORE_REGISTER (regno))
+    {
+      return;
+    }
+
+  /* Overload thread id onto process id */
+  if ((tid = TIDGET (inferior_ptid)) == 0)
+    tid = PIDGET (inferior_ptid);	/* no thread id, just use process id */
+
+  offset = U_REGS_OFFSET;
+
+  regaddr = register_addr (regno, offset);
+  for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+    {
+      errno = 0;
+      ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
+	      *(PTRACE_XFER_TYPE *) & registers[REGISTER_BYTE (regno) + i]);
+      regaddr += sizeof (PTRACE_XFER_TYPE);
+      if (errno != 0)
+	{
+	  sprintf (mess, "writing register %s (#%d)", 
+		   REGISTER_NAME (regno), regno);
+	  perror_with_name (mess);
+	}
+    }
+}
+
+/* Store our register values back into the inferior.
+   If REGNO is negative, do this for all registers.
+   Otherwise, REGNO specifies which register (so we can save time).  */
+
+void
+old_store_inferior_registers (int regno)
+{
+  if (regno >= 0)
+    {
+      store_register (regno);
+    }
+  else
+    {
+      for (regno = 0; regno < NUM_REGS; regno++)
+	{
+	  store_register (regno);
+	}
+    }
+}
+\f
 /*  Given a pointer to a general register set in /proc format
    (elf_gregset_t *), unpack the register contents and supply
    them as gdb's idea of the current register values. */
@@ -87,32 +264,268 @@
 void
 supply_gregset (elf_gregset_t *gregsetp)
 {
+  elf_greg_t *regp = (elf_greg_t *) gregsetp;
   int regi;
 
   for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
-    supply_register (regi, (char *) (*gregsetp + regmap[regi]));
-  supply_register (PS_REGNUM, (char *) (*gregsetp + PT_SR));
-  supply_register (PC_REGNUM, (char *) (*gregsetp + PT_PC));
+    supply_register (regi, (char *) &regp[regmap[regi]]);
+  supply_register (PS_REGNUM, (char *) &regp[PT_SR]);
+  supply_register (PC_REGNUM, (char *) &regp[PT_PC]);
 }
+
+/* Fill register REGNO (if it is a general-purpose register) in
+   *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
+   do this for all registers.  */
+void
+fill_gregset (elf_gregset_t *gregsetp, int regno)
+{
+  elf_greg_t *regp = (elf_greg_t *) gregsetp;
+  int i;
+
+  for (i = 0; i < NUM_GREGS; i++)
+    if ((regno == -1 || regno == i))
+      regcache_collect (i, regp + regmap[i]);
+}
+
+#ifdef HAVE_PTRACE_GETREGS
 
-/*  Given a pointer to a floating point register set in /proc format
-   (fpregset_t *), unpack the register contents and supply them as gdb's
-   idea of the current floating point register values. */
+/* Fetch all general-purpose registers from process/thread TID and
+   store their values in GDB's register array.  */
+
+static void
+fetch_regs (int tid)
+{
+  elf_gregset_t regs;
+
+  if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
+    {
+      if (errno == EIO)
+	{
+	  /* The kernel we're running on doesn't support the GETREGS
+             request.  Reset `have_ptrace_getregs'.  */
+	  have_ptrace_getregs = 0;
+	  return;
+	}
+
+      perror_with_name ("Couldn't get registers");
+    }
+
+  supply_gregset (&regs);
+}
 
+/* Store all valid general-purpose registers in GDB's register array
+   into the process/thread specified by TID.  */
+
+static void
+store_regs (int tid, int regno)
+{
+  elf_gregset_t regs;
+
+  if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
+    perror_with_name ("Couldn't get registers");
+
+  fill_gregset (&regs, regno);
+
+  if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
+    perror_with_name ("Couldn't write registers");
+}
+
+#else
+
+static void fetch_regs (int tid) {}
+static void store_regs (int tid, int regno) {}
+
+#endif
+
+\f
+/* Transfering floating-point registers between GDB, inferiors and cores.  */
+
+/* What is the address of fpN within the floating-point register set F?  */
+#define FPREG_ADDR(f, n) ((char *) &(f)->fpregs[(n) * 3])
+
+/* Fill GDB's register array with the floating-point register values in
+   *FPREGSETP.  */
+
 void
 supply_fpregset (elf_fpregset_t *fpregsetp)
 {
   int regi;
 
   for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
-    supply_register (regi, (char *) &fpregsetp->fpregs[(regi - FP0_REGNUM) * 3]);
+    supply_register (regi, FPREG_ADDR (fpregsetp, regi - FP0_REGNUM));
   supply_register (FPC_REGNUM, (char *) &fpregsetp->fpcntl[0]);
   supply_register (FPS_REGNUM, (char *) &fpregsetp->fpcntl[1]);
   supply_register (FPI_REGNUM, (char *) &fpregsetp->fpcntl[2]);
 }
 
+/* Fill register REGNO (if it is a floating-point register) in
+   *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
+   do this for all registers.  */
+
+void
+fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
+{
+  int i;
+
+  /* Fill in the floating-point registers.  */
+  for (i = FP0_REGNUM; i < FP0_REGNUM + 8; i++)
+    if (regno == -1 || regno == i)
+      memcpy (FPREG_ADDR (fpregsetp, regno - FP0_REGNUM),
+	      &registers[REGISTER_BYTE (regno)],
+	      REGISTER_RAW_SIZE(regno));
+
+  /* Fill in the floating-point control registers.  */
+  for (i = FPC_REGNUM; i <= FPI_REGNUM; i++)
+    if (regno == -1 || regno == i)
+      fpregsetp->fpcntl[regno - FPC_REGNUM]
+	= *(int *) &registers[REGISTER_BYTE (regno)];
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Fetch all floating-point registers from process/thread TID and store
+   thier values in GDB's register array.  */
+
+static void
+fetch_fpregs (int tid)
+{
+  elf_fpregset_t fpregs;
+
+  if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
+    perror_with_name ("Couldn't get floating point status");
+
+  supply_fpregset (&fpregs);
+}
+
+/* Store all valid floating-point registers in GDB's register array
+   into the process/thread specified by TID.  */
+
+static void
+store_fpregs (int tid, int regno)
+{
+  elf_fpregset_t fpregs;
+
+  if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
+    perror_with_name ("Couldn't get floating point status");
+
+  fill_fpregset (&fpregs, regno);
+
+  if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
+    perror_with_name ("Couldn't write floating point status");
+}
+
+#else
+
+static void fetch_fpregs (int tid) {}
+static void store_fpregs (int tid, int regno) {}
+
+#endif
+
 #endif
+\f
+/* Transferring arbitrary registers between GDB and inferior.  */
+
+/* Fetch register REGNO from the child process.  If REGNO is -1, do
+   this for all registers (including the floating point and SSE
+   registers).  */
 
+void
+fetch_inferior_registers (int regno)
+{
+  int tid;
+
+  /* Use the old method of peeking around in `struct user' if the
+     GETREGS request isn't available.  */
+  if (! have_ptrace_getregs)
+    {
+      old_fetch_inferior_registers (regno);
+      return;
+    }
+
+  /* Linux LWP ID's are process ID's.  */
+  if ((tid = TIDGET (inferior_ptid)) == 0)
+    tid = PIDGET (inferior_ptid);		/* Not a threaded program.  */
+
+  /* Use the PTRACE_GETFPXREGS request whenever possible, since it
+     transfers more registers in one system call, and we'll cache the
+     results.  But remember that fetch_fpxregs can fail, and return
+     zero.  */
+  if (regno == -1)
+    {
+      fetch_regs (tid);
+
+      /* The call above might reset `have_ptrace_getregs'.  */
+      if (! have_ptrace_getregs)
+	{
+	  old_fetch_inferior_registers (-1);
+	  return;
+	}
+
+      fetch_fpregs (tid);
+      return;
+    }
+
+  if (getregs_supplies (regno))
+    {
+      fetch_regs (tid);
+      return;
+    }
+
+  if (getfpregs_supplies (regno))
+    {
+      fetch_fpregs (tid);
+      return;
+    }
+
+  internal_error (__FILE__, __LINE__,
+		  "Got request for bad register number %d.", regno);
+}
+
+/* Store register REGNO back into the child process.  If REGNO is -1,
+   do this for all registers (including the floating point and SSE
+   registers).  */
+void
+store_inferior_registers (int regno)
+{
+  int tid;
+
+  /* Use the old method of poking around in `struct user' if the
+     SETREGS request isn't available.  */
+  if (! have_ptrace_getregs)
+    {
+      old_store_inferior_registers (regno);
+      return;
+    }
+
+  /* Linux LWP ID's are process ID's.  */
+  if ((tid = TIDGET (inferior_ptid)) == 0)
+    tid = PIDGET (inferior_ptid);	/* Not a threaded program.  */
+
+  /* Use the PTRACE_SETFPREGS requests whenever possible, since it
+     transfers more registers in one system call.  But remember that
+     store_fpregs can fail, and return zero.  */
+  if (regno == -1)
+    {
+      store_regs (tid, regno);
+      store_fpregs (tid, regno);
+      return;
+    }
+
+  if (getregs_supplies (regno))
+    {
+      store_regs (tid, regno);
+      return;
+    }
+
+  if (getfpregs_supplies (regno))
+    {
+      store_fpregs (tid, regno);
+      return;
+    }
+
+  internal_error (__FILE__, __LINE__,
+		  "Got request to store bad register number %d.", regno);
+}
 \f
 /* Interpreting register set info found in core files.  */
 
Index: gdb/config/m68k/nm-linux.h
===================================================================
RCS file: /cvs/src/src/gdb/config/m68k/nm-linux.h,v
retrieving revision 1.3
diff -u -a -r1.3 gdb/config/m68k/nm-linux.h
--- gdb/config/m68k/nm-linux.h	2001/03/06 08:21:30	1.3
+++ gdb/config/m68k/nm-linux.h	2002/01/26 19:23:31
@@ -35,4 +35,7 @@
 
 extern int m68k_linux_register_u_addr (int, int);
 
+/* Override copies of {fetch,store}_inferior_registers in `infptrace.c'.  */
+#define FETCH_INFERIOR_REGISTERS
+
 #endif /* #ifndef NM_LINUX_H */

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Updates for m68k-linux target
  2002-01-26 14:24   ` Andreas Schwab
@ 2002-01-29 13:41     ` Andrew Cagney
  2002-01-30  5:57       ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2002-01-29 13:41 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

> +  for (i = FPC_REGNUM; i <= FPI_REGNUM; i++)
> +    if (regno == -1 || regno == i)
> +      fpregsetp->fpcntl[regno - FPC_REGNUM]
> +	= *(int *) &registers[REGISTER_BYTE (regno)];
> 
BTW, there were a few registers[] references still lurking in there.


enjoy,
Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Updates for m68k-linux target
  2002-01-29 13:41     ` Andrew Cagney
@ 2002-01-30  5:57       ` Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2002-01-30  5:57 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

Andrew Cagney <ac131313@cygnus.com> writes:

|> > +  for (i = FPC_REGNUM; i <= FPI_REGNUM; i++)
|> > +    if (regno == -1 || regno == i)
|> > +      fpregsetp->fpcntl[regno - FPC_REGNUM]
|> > +	= *(int *) &registers[REGISTER_BYTE (regno)];
|> > 
|> BTW, there were a few registers[] references still lurking in there.

Thanks for noticing, I have fixed it and installed the patch below for being
obvious.

Andreas.

2002-01-30  Andreas Schwab  <schwab@suse.de>

	* m68klinux-nat.c: Fix last change to use regcache_collect
	instead of referencing registers[] directly.


Index: m68klinux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
retrieving revision 1.7
diff -u -a -r1.7 m68klinux-nat.c
--- m68klinux-nat.c	2002/01/26 22:23:22	1.7
+++ m68klinux-nat.c	2002/01/30 13:55:22
@@ -195,6 +195,7 @@
   register int i;
   unsigned int offset;		/* Offset of registers within the u area.  */
   int tid;
+  char *buf = alloca (MAX_REGISTER_RAW_SIZE);
 
   if (CANNOT_STORE_REGISTER (regno))
     {
@@ -208,11 +209,16 @@
   offset = U_REGS_OFFSET;
 
   regaddr = register_addr (regno, offset);
+
+  /* Put the contents of regno into a local buffer */
+  regcache_collect (regno, buf);
+
+  /* Store the local buffer into the inferior a chunk at the time. */
   for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
       ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
-	      *(PTRACE_XFER_TYPE *) & registers[REGISTER_BYTE (regno) + i]);
+	      *(PTRACE_XFER_TYPE *) (buf + i));
       regaddr += sizeof (PTRACE_XFER_TYPE);
       if (errno != 0)
 	{
@@ -370,15 +376,12 @@
   /* Fill in the floating-point registers.  */
   for (i = FP0_REGNUM; i < FP0_REGNUM + 8; i++)
     if (regno == -1 || regno == i)
-      memcpy (FPREG_ADDR (fpregsetp, regno - FP0_REGNUM),
-	      &registers[REGISTER_BYTE (regno)],
-	      REGISTER_RAW_SIZE(regno));
+      regcache_collect (regno, FPREG_ADDR (fpregsetp, regno - FP0_REGNUM));
 
   /* Fill in the floating-point control registers.  */
   for (i = FPC_REGNUM; i <= FPI_REGNUM; i++)
     if (regno == -1 || regno == i)
-      fpregsetp->fpcntl[regno - FPC_REGNUM]
-	= *(int *) &registers[REGISTER_BYTE (regno)];
+      regcache_collect (regno, fpregsetp->fpcntl[regno - FPC_REGNUM]);
 }
 
 #ifdef HAVE_PTRACE_GETREGS

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-01-30 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-24  2:02 Updates for m68k-linux target Andreas Schwab
2002-01-24  9:52 ` Andrew Cagney
2002-01-26 14:24   ` Andreas Schwab
2002-01-29 13:41     ` Andrew Cagney
2002-01-30  5:57       ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox