From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19869 invoked by alias); 6 Apr 2006 22:06:08 -0000 Received: (qmail 19861 invoked by uid 22791); 6 Apr 2006 22:06:07 -0000 X-Spam-Check-By: sourceware.org Received: from dsl027-180-168.sfo1.dsl.speakeasy.net (HELO sunset.davemloft.net) (216.27.180.168) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 06 Apr 2006 22:06:05 +0000 Received: from localhost ([127.0.0.1] ident=davem) by sunset.davemloft.net with esmtp (Exim 4.60) (envelope-from ) id 1FRcZr-0007AG-Cv; Thu, 06 Apr 2006 15:03:43 -0700 Date: Thu, 06 Apr 2006 22:06:00 -0000 Message-Id: <20060406.150330.76592441.davem@davemloft.net> To: gdb-patches@sources.redhat.com CC: drow@false.org, mark.kettenis@xs4all.nl Subject: [PATCH]: Use core regset when possible in linux-nat.c From: "David S. Miller" Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00083.txt.bz2 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 * 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 /* 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) \