public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: mark.kettenis@xs4all.nl (Mark Kettenis)
Cc: jan.kratochvil@redhat.com, Jon.Zhou@jdsu.com, gdb@sourceware.org
Subject: Re: support biarch gcore?
Date: Tue, 06 Jul 2010 20:48:00 -0000	[thread overview]
Message-ID: <201007062048.o66Kmixd002309@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <201007051154.o65BskRG028816@glazunov.sibelius.xs4all.nl> from "Mark Kettenis" at Jul 05, 2010 01:54:46 PM

Mark Kettenis wrote:

> Fixing the code in linux-nat.c is a bit nasty:
> 
> * The definition of the 32-bit version of gdb_gregset_t isn't readily
>   available on 64-bit systems.
> 
> * The code is used on all Linux platforms and only a few of them are
>   bi-arch.

This was really supposed to be fixed by the gdbarch_core_regset_sections
mechanism, which provides the names and sizes of all register sets
expected in a core file for the current architecture.

However, it seems that this mechanism isn't currently used for .reg
itself, only for the other sections.  While it is true that .reg needs
to be handled somewhat specially, it should still be possible to get
its size from gdbarch_core_regset_sections, and thus avoid the need
to use the gdb_gregset_t type.

Unfortunately, it also turned out that the section sizes provided for
.reg in those targets that have gdbarch_core_regset_sections, while
currently unused, were also nearly all wrong ...

The following patch fixes those sizes, and changes linux-nat.c to
use them.

Tested on powerpc64-linux (-m64 / -m32), amd64-linux (-m64 / -m32),
and i386-linux with no regressions.  In fact, it appears to fix all
pre-existing gcore-related failures on amd64 -m32 ...

Thoughts?

Bye,
Ulrich


ChangeLog:

	* linux-nat.c (linux_nat_do_thread_registers): Use section size
	from gdbarch_core_regset_sections also for .reg if present.

	* amd64-linux-tdep.c (amd64_linux_regset_sections): Fix incorrect
	section size for .reg.
	* ppc-linux-tdep.c (ppc_linux_vsx_regset_sections): Likewise.
	(ppc_linux_vmx_regset_sections): Likewise.
	(ppc_linux_fp_regset_sections): Likewise.
	(ppc64_linux_vsx_regset_sections): New variable.
	(ppc64_linux_vmx_regset_sections): Likewise.
	(ppc64_linux_fp_regset_sections): Likewise.
	(ppc_linux_init_abi): Install core_regset_section lists appropriate
	for current word size.


Index: gdb/amd64-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/amd64-linux-tdep.c,v
retrieving revision 1.37
diff -u -p -r1.37 amd64-linux-tdep.c
--- gdb/amd64-linux-tdep.c	22 Apr 2010 20:02:55 -0000	1.37
+++ gdb/amd64-linux-tdep.c	6 Jul 2010 20:24:45 -0000
@@ -52,7 +52,7 @@
 /* Supported register note sections.  */
 static struct core_regset_section amd64_linux_regset_sections[] =
 {
-  { ".reg", 144, "general-purpose" },
+  { ".reg", 27 * 8, "general-purpose" },
   { ".reg2", 512, "floating-point" },
   { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
   { NULL, 0 }
Index: gdb/linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-nat.c,v
retrieving revision 1.172
diff -u -p -r1.172 linux-nat.c
--- gdb/linux-nat.c	1 Jul 2010 15:36:16 -0000	1.172
+++ gdb/linux-nat.c	6 Jul 2010 20:24:46 -0000
@@ -4134,8 +4134,6 @@ linux_nat_do_thread_registers (bfd *obfd
 			       char *note_data, int *note_size,
 			       enum target_signal stop_signal)
 {
-  gdb_gregset_t gregs;
-  gdb_fpregset_t fpregs;
   unsigned long lwp = ptid_get_lwp (ptid);
   struct gdbarch *gdbarch = target_gdbarch;
   struct regcache *regcache = get_thread_arch_regcache (ptid, gdbarch);
@@ -4153,21 +4151,6 @@ linux_nat_do_thread_registers (bfd *obfd
   core_regset_p = gdbarch_regset_from_core_section_p (gdbarch);
   sect_list = gdbarch_core_regset_sections (gdbarch);
 
-  if (core_regset_p
-      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg",
-						     sizeof (gregs))) != NULL
-      && regset->collect_regset != NULL)
-    regset->collect_regset (regset, regcache, -1,
-			    &gregs, sizeof (gregs));
-  else
-    fill_gregset (regcache, &gregs, -1);
-
-  note_data = (char *) elfcore_write_prstatus (obfd,
-					       note_data,
-					       note_size,
-					       lwp,
-					       stop_signal, &gregs);
-
   /* The loop below uses the new struct core_regset_section, which stores
      the supported section names and sizes for the core file.  Note that
      note PRSTATUS needs to be treated specially.  But the other notes are
@@ -4175,12 +4158,6 @@ linux_nat_do_thread_registers (bfd *obfd
   if (core_regset_p && sect_list != NULL)
     while (sect_list->sect_name != NULL)
       {
-	/* .reg was already handled above.  */
-	if (strcmp (sect_list->sect_name, ".reg") == 0)
-	  {
-	    sect_list++;
-	    continue;
-	  }
 	regset = gdbarch_regset_from_core_section (gdbarch,
 						   sect_list->sect_name,
 						   sect_list->size);
@@ -4188,12 +4165,16 @@ linux_nat_do_thread_registers (bfd *obfd
 	gdb_regset = xmalloc (sect_list->size);
 	regset->collect_regset (regset, regcache, -1,
 				gdb_regset, sect_list->size);
-	note_data = (char *) elfcore_write_register_note (obfd,
-							  note_data,
-							  note_size,
-							  sect_list->sect_name,
-							  gdb_regset,
-							  sect_list->size);
+
+	if (strcmp (sect_list->sect_name, ".reg") == 0)
+	  note_data = (char *) elfcore_write_prstatus
+				(obfd, note_data, note_size,
+				 lwp, stop_signal, gdb_regset);
+	else
+	  note_data = (char *) elfcore_write_register_note
+				(obfd, note_data, note_size,
+				 sect_list->sect_name, gdb_regset,
+				 sect_list->size);
 	xfree (gdb_regset);
 	sect_list++;
       }
@@ -4203,6 +4184,24 @@ linux_nat_do_thread_registers (bfd *obfd
      the new support, the code below should be deleted.  */
   else
     {
+      gdb_gregset_t gregs;
+      gdb_fpregset_t fpregs;
+
+      if (core_regset_p
+	  && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg",
+							 sizeof (gregs))) != NULL
+	  && regset->collect_regset != NULL)
+	regset->collect_regset (regset, regcache, -1,
+				&gregs, sizeof (gregs));
+      else
+	fill_gregset (regcache, &gregs, -1);
+
+      note_data = (char *) elfcore_write_prstatus (obfd,
+						   note_data,
+						   note_size,
+						   lwp,
+						   stop_signal, &gregs);
+
       if (core_regset_p
           && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
 							 sizeof (fpregs))) != NULL
Index: gdb/ppc-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ppc-linux-tdep.c,v
retrieving revision 1.121
diff -u -p -r1.121 ppc-linux-tdep.c
--- gdb/ppc-linux-tdep.c	15 Apr 2010 20:19:24 -0000	1.121
+++ gdb/ppc-linux-tdep.c	6 Jul 2010 20:24:46 -0000
@@ -516,7 +516,7 @@ ppc64_standard_linkage1_target (struct f
 
 static struct core_regset_section ppc_linux_vsx_regset_sections[] =
 {
-  { ".reg", 268, "general-purpose" },
+  { ".reg", 48 * 4, "general-purpose" },
   { ".reg2", 264, "floating-point" },
   { ".reg-ppc-vmx", 544, "ppc Altivec" },
   { ".reg-ppc-vsx", 256, "POWER7 VSX" },
@@ -525,7 +525,7 @@ static struct core_regset_section ppc_li
 
 static struct core_regset_section ppc_linux_vmx_regset_sections[] =
 {
-  { ".reg", 268, "general-purpose" },
+  { ".reg", 48 * 4, "general-purpose" },
   { ".reg2", 264, "floating-point" },
   { ".reg-ppc-vmx", 544, "ppc Altivec" },
   { NULL, 0}
@@ -533,7 +533,31 @@ static struct core_regset_section ppc_li
 
 static struct core_regset_section ppc_linux_fp_regset_sections[] =
 {
-  { ".reg", 268, "general-purpose" },
+  { ".reg", 48 * 4, "general-purpose" },
+  { ".reg2", 264, "floating-point" },
+  { NULL, 0}
+};
+
+static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
+{
+  { ".reg", 48 * 8, "general-purpose" },
+  { ".reg2", 264, "floating-point" },
+  { ".reg-ppc-vmx", 544, "ppc Altivec" },
+  { ".reg-ppc-vsx", 256, "POWER7 VSX" },
+  { NULL, 0}
+};
+
+static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
+{
+  { ".reg", 48 * 8, "general-purpose" },
+  { ".reg2", 264, "floating-point" },
+  { ".reg-ppc-vmx", 544, "ppc Altivec" },
+  { NULL, 0}
+};
+
+static struct core_regset_section ppc64_linux_fp_regset_sections[] =
+{
+  { ".reg", 48 * 8, "general-purpose" },
   { ".reg2", 264, "floating-point" },
   { NULL, 0}
 };
@@ -1507,6 +1531,19 @@ ppc_linux_init_abi (struct gdbarch_info 
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
       else
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
+
+      /* Supported register sections.  */
+      if (tdesc_find_feature (info.target_desc,
+			      "org.gnu.gdb.power.vsx"))
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc_linux_vsx_regset_sections);
+      else if (tdesc_find_feature (info.target_desc,
+			       "org.gnu.gdb.power.altivec"))
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc_linux_vmx_regset_sections);
+      else
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc_linux_fp_regset_sections);
     }
   
   if (tdep->wordsize == 8)
@@ -1533,20 +1570,23 @@ ppc_linux_init_abi (struct gdbarch_info 
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
       else
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
+
+      /* Supported register sections.  */
+      if (tdesc_find_feature (info.target_desc,
+			      "org.gnu.gdb.power.vsx"))
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc64_linux_vsx_regset_sections);
+      else if (tdesc_find_feature (info.target_desc,
+			       "org.gnu.gdb.power.altivec"))
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc64_linux_vmx_regset_sections);
+      else
+	set_gdbarch_core_regset_sections (gdbarch,
+					  ppc64_linux_fp_regset_sections);
     }
   set_gdbarch_regset_from_core_section (gdbarch, ppc_linux_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
 
-  /* Supported register sections.  */
-  if (tdesc_find_feature (info.target_desc,
-			  "org.gnu.gdb.power.vsx"))
-    set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vsx_regset_sections);
-  else if (tdesc_find_feature (info.target_desc,
-			       "org.gnu.gdb.power.altivec"))
-    set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vmx_regset_sections);
-  else
-    set_gdbarch_core_regset_sections (gdbarch, ppc_linux_fp_regset_sections);
-
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
                                              svr4_fetch_objfile_link_map);


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

  reply	other threads:[~2010-07-06 20:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-03 10:48 Examining copied stack contents Martin Schröder
2010-07-05  4:54 ` support biarch gcore? Jon Zhou
2010-07-05  7:12   ` Jan Kratochvil
2010-07-05 11:55     ` Mark Kettenis
2010-07-06 20:48       ` Ulrich Weigand [this message]
2010-07-06 21:29         ` Mark Kettenis
2010-07-07 12:30           ` Ulrich Weigand
2010-07-08  2:35             ` Jon Zhou
2010-07-08 11:17               ` Ulrich Weigand
2010-07-08  4:47             ` H.J. Lu
2010-07-08  5:05               ` H.J. Lu
2010-07-08 11:15                 ` Ulrich Weigand
2010-07-08 13:52                   ` H.J. Lu
2010-07-21 22:45                     ` Joseph S. Myers
2010-07-05 18:50 ` Examining copied stack contents Petr Hluzín
2010-07-05 20:18   ` Martin Schröder
2010-07-05 20:27     ` Joel Brobecker
2010-07-07 17:29   ` Martin Schröder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201007062048.o66Kmixd002309@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=Jon.Zhou@jdsu.com \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=mark.kettenis@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).