[PATCH]: Use core regset when possible in linux-nat.c

David S. Miller davem@davemloft.net
Thu Apr 6 22:06:00 GMT 2006


As discussed in:

  http://sources.redhat.com/ml/gdb/2006-04/msg00030.html

Some Linux platforms have different ptrace vs. core file
register layouts.

The suggested way to handle this is to use the core regset
interfaces.  Not all Linux target support that yet, so we
have to check and use the old code if the target does not
have core regset support.

Tested on sparc*-*-linux* Both gdb.base/corefile.exp and
gdb.base/gcore.exp pass (*1), which is what I was originally trying to
achieve :-)

Ok to apply?

*1: The test in corefile.exp to look at the mmap() area pointed
    to by buf2 fails due to a Linux kernel bug, it doesn't dump
    mmap() areas which have not been written to into the core
    file so gdb can't look at it.  I've posted a patch to linux-kernel
    already suggesting to take away that check in the ELF core dumper.

2006-04-06  David S. Miller  <davem@sunset.davemloft.net>

	* linux-nat.c (linux_nat_do_thread_registers): Use the
	regset_from_core_section infrastructure if the target
	supports it.
	* Makefile.in: Update dependencies.
	
--- ./linux-nat.c.~1~	2006-04-05 18:08:11.000000000 -0700
+++ ./linux-nat.c	2006-04-06 14:56:06.000000000 -0700
@@ -36,6 +36,7 @@
 #include "gdbthread.h"
 #include "gdbcmd.h"
 #include "regcache.h"
+#include "regset.h"
 #include "inf-ptrace.h"
 #include "auxv.h"
 #include <sys/param.h>		/* for MAXPATHLEN */
@@ -2529,21 +2530,49 @@ linux_nat_do_thread_registers (bfd *obfd
   gdb_fpxregset_t fpxregs;
 #endif
   unsigned long lwp = ptid_get_lwp (ptid);
-
-  fill_gregset (&gregs, -1);
+  struct gdbarch *gdbarch = current_gdbarch;
+  const struct regset *regset;
+  int core_regset_p;
+
+  core_regset_p = gdbarch_regset_from_core_section_p (gdbarch);
+  if (core_regset_p)
+    {
+      regset = gdbarch_regset_from_core_section (gdbarch, ".reg",
+						 sizeof (gregs));
+      regset->collect_regset (regset, current_regcache, -1,
+			      &gregs, sizeof (gregs));
+    }
+  else
+    fill_gregset (&gregs, -1);
   note_data = (char *) elfcore_write_prstatus (obfd,
 					       note_data,
 					       note_size,
 					       lwp,
 					       stop_signal, &gregs);
 
-  fill_fpregset (&fpregs, -1);
+  if (core_regset_p)
+    {
+      regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
+						 sizeof (fpregs));
+      regset->collect_regset (regset, current_regcache, -1,
+			      &fpregs, sizeof (fpregs));
+    }
+  else
+    fill_fpregset (&fpregs, -1);
   note_data = (char *) elfcore_write_prfpreg (obfd,
 					      note_data,
 					      note_size,
 					      &fpregs, sizeof (fpregs));
 #ifdef FILL_FPXREGSET
-  fill_fpxregset (&fpxregs, -1);
+  if (core_regset_p)
+    {
+      regset = gdbarch_regset_from_core_section (gdbarch, ".reg-xfp",
+						 sizeof (fpxregs));
+      regset->collect_regset (regset, current_regcache, -1,
+			      &fpxregs, sizeof (fpxregs));
+    }
+  else
+    fill_fpxregset (&fpxregs, -1);
   note_data = (char *) elfcore_write_prxfpreg (obfd,
 					       note_data,
 					       note_size,
--- ./Makefile.in.~1~	2006-04-05 15:55:07.000000000 -0700
+++ ./Makefile.in	2006-04-06 14:56:33.000000000 -0700
@@ -2195,8 +2195,8 @@ linux-fork.o: linux-fork.c $(defs_h) $(i
 	$(linux_nat_h)
 linux-nat.o: linux-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdb_string_h) \
 	$(gdb_wait_h) $(gdb_assert_h) $(linux_nat_h) $(gdbthread_h) \
-	$(gdbcmd_h) $(regcache_h) $(inf_ptrace_h) $(auxv_h) $(elf_bfd_h) \
-	$(gregset_h) $(gdbcore_h) $(gdbthread_h) $(gdb_stat_h) \
+	$(gdbcmd_h) $(regcache_h) $(regset_h) $(inf_ptrace_h) $(auxv_h) \
+	$(elf_bfd_h) $(gregset_h) $(gdbcore_h) $(gdbthread_h) $(gdb_stat_h) \
 	$(linux_fork_h)
 linux-thread-db.o: linux-thread-db.c $(defs_h) $(gdb_assert_h) \
 	$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(exceptions_h) \



More information about the Gdb-patches mailing list