This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Cross target core debugging: host=i386, Target=PPC


On Mon, Jul 29, 2002 at 07:44:39PM -0400, Daniel Jacobowitz wrote:
> On Mon, Jul 29, 2002 at 04:40:57PM -0700, Jason R Thorpe wrote:
> > On Mon, Jul 29, 2002 at 02:53:59PM -0700, Kevin Buettner wrote:
> > 
> >  > This part will need some work.  (The other parts might too; I haven't
> >  > looked closely at them yet.)  Anyway, there are several problems here...
> >  > 
> >  > 1) The constants ELF_NGREG, ELF_NFPREG, ELF_NVRREG will almost certainly
> >  >    be incorrect for other targets.
> >  > 
> >  > 2) Defining elf_greg_t in terms of a long isn't portable.
> >  > 
> >  > 3) Likewise, for elf_fpreg_t being defined in terms of a double.
> > 
> > Take a look at the way the e.g. mips-netbsd or the sh-netbsdelf targets
> > do this.
> 
> I'll dust off my patches for cross cores tonight.  I've just been
> sitting on them out of sheer laziness.

PowerPC was the easiest of the bunch to clean up.  Here it is.  The
wrappers in ppc-linux-nat.c are just there for type correctness at the
moment; I believe that eventually changing them to take char * (or some
target-independent wrapper struct as I believe Kevin proposed some time
ago) is the right thing to do.

The astute observer will also notice that this patch will segue into
multi-arching supply_gregset in the near future.

OK?

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

2002-07-30  Daniel Jacobowitz  <drow@mvista.com>

	* ppc-linux-tdep.c (ELF_NGREG, ELF_NFPREG, ELF_NVRREG)
	(ELF_FPREGSET_SIZE, ELF_GREGSET_SIZE): New macros.
	(fetch_core_registers, ppc_linux_supply_gregset)
	(ppc_linux_supply_fpregset): New functions.
	(ppc_linux_regset_core_fns): New.
	(_initialize_ppc_linux_tdep): Call add_core_fns.
	* ppc-tdep.h: Add prototypes for ppc_linux_supply_fpregset
	and ppc_linux_supply_gregset.
	* ppc-linux-nat.c (supply_gregset): Call ppc_linux_supply_gregset.
	(supply_fpregset): Call ppc_linux_supply_fpregset.
	* config/powerpc/linux.mh (NATDEPFILES): Remove core-regset.o and
	corelow.o.
	* config/powerpc/linux.mt (TDEPFILES): Add corelow.o.

Index: ppc-linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/ppc-linux-nat.c,v
retrieving revision 1.17
diff -u -p -r1.17 ppc-linux-nat.c
--- ppc-linux-nat.c	11 Apr 2002 19:08:56 -0000	1.17
+++ ppc-linux-nat.c	30 Jul 2002 15:23:15 -0000
@@ -475,21 +475,7 @@ store_inferior_registers (int regno)
 void
 supply_gregset (gdb_gregset_t *gregsetp)
 {
-  int regi;
-  register elf_greg_t *regp = (elf_greg_t *) gregsetp;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
-
-  for (regi = 0; regi < 32; regi++)
-    supply_register (regi, (char *) (regp + regi));
-
-  supply_register (PC_REGNUM, (char *) (regp + PT_NIP));
-  supply_register (tdep->ppc_lr_regnum, (char *) (regp + PT_LNK));
-  supply_register (tdep->ppc_cr_regnum, (char *) (regp + PT_CCR));
-  supply_register (tdep->ppc_xer_regnum, (char *) (regp + PT_XER));
-  supply_register (tdep->ppc_ctr_regnum, (char *) (regp + PT_CTR));
-  if (tdep->ppc_mq_regnum != -1)
-    supply_register (tdep->ppc_mq_regnum, (char *) (regp + PT_MQ));
-  supply_register (tdep->ppc_ps_regnum, (char *) (regp + PT_MSR));
+  ppc_linux_supply_gregset ((char *) gregsetp);
 }
 
 void
@@ -525,12 +511,7 @@ fill_gregset (gdb_gregset_t *gregsetp, i
 void
 supply_fpregset (gdb_fpregset_t * fpregsetp)
 {
-  int regi;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
-
-  for (regi = 0; regi < 32; regi++)
-    supply_register (FP0_REGNUM + regi, (char *) (*fpregsetp + regi));
-  supply_register (tdep->ppc_fpscr_regnum, (char *) (*fpregsetp + 32));
+  ppc_linux_supply_fpregset ((char *) fpregsetp);
 }
 
 /* Given a pointer to a floating point register set in /proc format
Index: ppc-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ppc-linux-tdep.c,v
retrieving revision 1.18
diff -u -p -r1.18 ppc-linux-tdep.c
--- ppc-linux-tdep.c	30 May 2002 01:21:51 -0000	1.18
+++ ppc-linux-tdep.c	30 Jul 2002 15:23:16 -0000
@@ -600,6 +600,84 @@ ppc_linux_svr4_fetch_link_map_offsets (v
   return lmp;
 }
 
+#define ELF_NGREG       48      /* includes nip, msr, lr, etc. */
+#define ELF_NFPREG      33      /* includes fpscr */
+#define ELF_NVRREG      33      /* includes vscr */
+
+#define ELF_GREGSET_SIZE (48 * 4)
+#define ELF_FPREGSET_SIZE (33 * 8)
+
+void
+ppc_linux_supply_gregset (char *buf)
+{
+  int regi;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
+
+  for (regi = 0; regi < 32; regi++)
+    supply_register (regi, buf + 4 * regi);
+
+  supply_register (PC_REGNUM, buf + 4 * PPC_LINUX_PT_NIP);
+  supply_register (tdep->ppc_lr_regnum, buf + 4 * PPC_LINUX_PT_LNK);
+  supply_register (tdep->ppc_cr_regnum, buf + 4 * PPC_LINUX_PT_CCR);
+  supply_register (tdep->ppc_xer_regnum, buf + 4 * PPC_LINUX_PT_XER);
+  supply_register (tdep->ppc_ctr_regnum, buf + 4 * PPC_LINUX_PT_CTR);
+  if (tdep->ppc_mq_regnum != -1)
+    supply_register (tdep->ppc_mq_regnum, buf + 4 * PPC_LINUX_PT_MQ);
+  supply_register (tdep->ppc_ps_regnum, buf + 4 * PPC_LINUX_PT_MSR);
+}
+
+void
+ppc_linux_supply_fpregset (char *buf)
+{
+  int regi;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
+
+  for (regi = 0; regi < 32; regi++)
+    supply_register (FP0_REGNUM + regi, buf + 8 * regi);
+
+  /* The FPSCR is stored in the low order word of the last doubleword in the
+     fpregset.  */
+  supply_register (tdep->ppc_fpscr_regnum, buf + 8 * 32 + 4);
+}
+
+/*
+  Use a local version of this function to get the correct types for regsets.
+*/
+
+static void
+fetch_core_registers (char *core_reg_sect,
+		      unsigned core_reg_size,
+		      int which,
+		      CORE_ADDR reg_addr)
+{
+  if (which == 0)
+    {
+      if (core_reg_size == ELF_GREGSET_SIZE)
+	ppc_linux_supply_gregset (core_reg_sect);
+      else
+	warning ("wrong size gregset struct in core file");
+    }
+  else if (which == 2)
+    {
+      if (core_reg_size == ELF_FPREGSET_SIZE)
+	ppc_linux_supply_fpregset (core_reg_sect);
+      else
+	warning ("wrong size fpregset struct in core file");
+    }
+}
+
+/* Register that we are able to handle ELF file formats using standard
+   procfs "regset" structures.  */
+
+static struct core_fns ppc_linux_regset_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 */
+};
+
 static void
 ppc_linux_init_abi (struct gdbarch_info info,
                     struct gdbarch *gdbarch)
@@ -639,4 +717,5 @@ _initialize_ppc_linux_tdep (void)
 {
   gdbarch_register_osabi (bfd_arch_powerpc, GDB_OSABI_LINUX,
 			  ppc_linux_init_abi);
+  add_core_fns (&ppc_linux_regset_core_fns);
 }
Index: ppc-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/ppc-tdep.h,v
retrieving revision 1.11
diff -u -p -r1.11 ppc-tdep.h
--- ppc-tdep.h	30 May 2002 01:21:51 -0000	1.11
+++ ppc-tdep.h	30 Jul 2002 15:23:16 -0000
@@ -39,6 +39,8 @@ CORE_ADDR ppc_sysv_abi_push_arguments (i
 				       CORE_ADDR);
 int ppc_linux_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache);
 struct link_map_offsets *ppc_linux_svr4_fetch_link_map_offsets (void);
+void ppc_linux_supply_gregset (char *buf);
+void ppc_linux_supply_fpregset (char *buf);
 
 
 /* From rs6000-tdep.c... */
Index: config/powerpc/linux.mh
===================================================================
RCS file: /cvs/src/src/gdb/config/powerpc/linux.mh,v
retrieving revision 1.11
diff -u -p -r1.11 linux.mh
--- config/powerpc/linux.mh	14 Feb 2002 05:48:38 -0000	1.11
+++ config/powerpc/linux.mh	30 Jul 2002 15:23:16 -0000
@@ -4,8 +4,8 @@ XM_FILE= xm-linux.h
 XM_CLIBS=
 
 NAT_FILE= nm-linux.h
-NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o linux-proc.o \
-	core-regset.o ppc-linux-nat.o proc-service.o thread-db.o lin-lwp.o \
+NATDEPFILES= infptrace.o inftarg.o fork-child.o linux-proc.o \
+	ppc-linux-nat.o proc-service.o thread-db.o lin-lwp.o \
 	gcore.o
 
 LOADLIBES = -ldl -rdynamic
Index: config/powerpc/linux.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/powerpc/linux.mt,v
retrieving revision 1.5
diff -u -p -r1.5 linux.mt
--- config/powerpc/linux.mt	30 May 2002 01:21:52 -0000	1.5
+++ config/powerpc/linux.mt	30 Jul 2002 15:23:16 -0000
@@ -1,6 +1,6 @@
 # Target: Motorola PPC on Linux
 TDEPFILES= rs6000-tdep.o ppc-linux-tdep.o ppc-sysv-tdep.o solib.o \
-	solib-svr4.o solib-legacy.o
+	solib-svr4.o solib-legacy.o corelow.o
 TM_FILE= tm-linux.h
 
 SIM_OBS = remote-sim.o


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]