01917d
commit 5aa82d050d61784823767fe3c982b6862fa47391
01917d
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
01917d
Date:   Thu Sep 4 15:26:43 2014 +0000
01917d
01917d
    Replace 'core_regset_sections' by iterator method
01917d
    
01917d
    The core_regset_sections list in gdbarch (needed for multi-arch
01917d
    capable core file generation support) is replaced by an iterator
01917d
    method.  Overall, this reduces the code a bit, and it allows for more
01917d
    flexibility.
01917d
    
01917d
    gdb/ChangeLog:
01917d
    
01917d
    	* amd64-linux-tdep.c (amd64_linux_regset_sections): Remove.
01917d
    	(amd64_linux_iterate_over_regset_sections): New.
01917d
    	(amd64_linux_init_abi_common): Don't install the regset section
01917d
    	list, but the new iterator in gdbarch.
01917d
    	* arm-linux-tdep.c (arm_linux_fpa_regset_sections)
01917d
    	(arm_linux_vfp_regset_sections): Remove.  Move combined logic...
01917d
    	(arm_linux_iterate_over_regset_sections): ...here.  New function.
01917d
    	(arm_linux_init_abi): Set iterator instead of section list.
01917d
    	* corelow.c (get_core_registers_cb): New function, logic moved
01917d
    	from...
01917d
    	(get_core_registers): ...loop body here.  Use new iterator method
01917d
    	instead of walking through the regset section list.
01917d
    	* gdbarch.sh: Remove 'core_regset_sections'.  New method
01917d
    	'iterate_over_regset_sections'.  New typedef
01917d
    	'iterate_over_regset_sections_cb'.
01917d
    	* gdbarch.c: Regenerate.
01917d
    	* gdbarch.h: Likewise.
01917d
    	* i386-linux-tdep.c (i386_linux_regset_sections)
01917d
    	(i386_linux_sse_regset_sections, i386_linux_avx_regset_sections):
01917d
    	Remove.
01917d
    	(i386_linux_iterate_over_regset_sections): New.
01917d
    	(i386_linux_init_abi): Don't choose a regset section list, but
01917d
    	install new iterator in gdbarch.
01917d
    	* linux-tdep.c (struct linux_collect_regset_section_cb_data): New.
01917d
    	(linux_collect_regset_section_cb): New function, logic moved
01917d
    	from...
01917d
    	(linux_collect_thread_registers): ...loop body here.  Use iterator
01917d
    	method instead of walking through list.
01917d
    	(linux_make_corefile_notes_1): Check for presence of iterator
01917d
    	method instead of regset section list.
01917d
    	* ppc-linux-tdep.c (ppc_linux_vsx_regset_sections)
01917d
    	(ppc_linux_vmx_regset_sections, ppc_linux_fp_regset_sections)
01917d
    	(ppc64_linux_vsx_regset_sections, ppc64_linux_vmx_regset_sections)
01917d
    	(ppc64_linux_fp_regset_sections): Remove.  Move combined logic...
01917d
    	(ppc_linux_iterate_over_regset_sections): ...here.  New function.
01917d
    	(ppc_linux_init_abi): Don't choose from above regset section
01917d
    	lists, but install new iterator in gdbarch.
01917d
    	* regset.h (struct core_regset_section): Remove.
01917d
    	* s390-linux-tdep.c (struct gdbarch_tdep): Add new fields
01917d
    	have_linux_v1, have_linux_v2, and have_tdb.
01917d
    	(s390_linux32_regset_sections, s390_linux32v1_regset_sections)
01917d
    	(s390_linux32v2_regset_sections, s390_linux64_regset_sections)
01917d
    	(s390_linux64v1_regset_sections, s390_linux64v2_regset_sections)
01917d
    	(s390x_linux64_regset_sections, s390x_linux64v1_regset_sections)
01917d
    	(s390x_linux64v2_regset_sections): Remove.  Move combined logic...
01917d
    	(s390_iterate_over_regset_sections): ...here.  New function.  Use
01917d
    	new tdep fields.
01917d
    	(s390_gdbarch_init): Set new tdep fields.  Don't choose from above
01917d
    	regset section lists, but install new iterator.
01917d
01917d
### a/gdb/ChangeLog
01917d
### b/gdb/ChangeLog
01917d
## -1,3 +1,55 @@
01917d
+2014-09-30  Andreas Arnez  <arnez@linux.vnet.ibm.com>
01917d
+
01917d
+	* amd64-linux-tdep.c (amd64_linux_regset_sections): Remove.
01917d
+	(amd64_linux_iterate_over_regset_sections): New.
01917d
+	(amd64_linux_init_abi_common): Don't install the regset section
01917d
+	list, but the new iterator in gdbarch.
01917d
+	* arm-linux-tdep.c (arm_linux_fpa_regset_sections)
01917d
+	(arm_linux_vfp_regset_sections): Remove.  Move combined logic...
01917d
+	(arm_linux_iterate_over_regset_sections): ...here.  New function.
01917d
+	(arm_linux_init_abi): Set iterator instead of section list.
01917d
+	* corelow.c (get_core_registers_cb): New function, logic moved
01917d
+	from...
01917d
+	(get_core_registers): ...loop body here.  Use new iterator method
01917d
+	instead of walking through the regset section list.
01917d
+	* gdbarch.sh: Remove 'core_regset_sections'.  New method
01917d
+	'iterate_over_regset_sections'.  New typedef
01917d
+	'iterate_over_regset_sections_cb'.
01917d
+	* gdbarch.c: Regenerate.
01917d
+	* gdbarch.h: Likewise.
01917d
+	* i386-linux-tdep.c (i386_linux_regset_sections)
01917d
+	(i386_linux_sse_regset_sections, i386_linux_avx_regset_sections):
01917d
+	Remove.
01917d
+	(i386_linux_iterate_over_regset_sections): New.
01917d
+	(i386_linux_init_abi): Don't choose a regset section list, but
01917d
+	install new iterator in gdbarch.
01917d
+	* linux-tdep.c (struct linux_collect_regset_section_cb_data): New.
01917d
+	(linux_collect_regset_section_cb): New function, logic moved
01917d
+	from...
01917d
+	(linux_collect_thread_registers): ...loop body here.  Use iterator
01917d
+	method instead of walking through list.
01917d
+	(linux_make_corefile_notes_1): Check for presence of iterator
01917d
+	method instead of regset section list.
01917d
+	* ppc-linux-tdep.c (ppc_linux_vsx_regset_sections)
01917d
+	(ppc_linux_vmx_regset_sections, ppc_linux_fp_regset_sections)
01917d
+	(ppc64_linux_vsx_regset_sections, ppc64_linux_vmx_regset_sections)
01917d
+	(ppc64_linux_fp_regset_sections): Remove.  Move combined logic...
01917d
+	(ppc_linux_iterate_over_regset_sections): ...here.  New function.
01917d
+	(ppc_linux_init_abi): Don't choose from above regset section
01917d
+	lists, but install new iterator in gdbarch.
01917d
+	* regset.h (struct core_regset_section): Remove.
01917d
+	* s390-linux-tdep.c (struct gdbarch_tdep): Add new fields
01917d
+	have_linux_v1, have_linux_v2, and have_tdb.
01917d
+	(s390_linux32_regset_sections, s390_linux32v1_regset_sections)
01917d
+	(s390_linux32v2_regset_sections, s390_linux64_regset_sections)
01917d
+	(s390_linux64v1_regset_sections, s390_linux64v2_regset_sections)
01917d
+	(s390x_linux64_regset_sections, s390x_linux64v1_regset_sections)
01917d
+	(s390x_linux64v2_regset_sections): Remove.  Move combined logic...
01917d
+	(s390_iterate_over_regset_sections): ...here.  New function.  Use
01917d
+	new tdep fields.
01917d
+	(s390_gdbarch_init): Set new tdep fields.  Don't choose from above
01917d
+	regset section lists, but install new iterator.
01917d
+
01917d
 2014-09-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
01917d
 
01917d
 	* solib-svr4.c (svr4_parse_libraries): Use "library-list-svr4.dtd".
01917d
Index: gdb-7.6.1/gdb/arm-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/arm-linux-tdep.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/arm-linux-tdep.c	2016-02-21 21:24:21.585851082 +0100
01917d
@@ -724,21 +724,24 @@
01917d
   return NULL;
01917d
 }
01917d
 
01917d
-/* Core file register set sections.  */
01917d
+/* Iterate over core file register note sections.  */
01917d
 
01917d
-static struct core_regset_section arm_linux_fpa_regset_sections[] =
01917d
+static void
01917d
+arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+					iterate_over_regset_sections_cb *cb,
01917d
+					void *cb_data,
01917d
+					const struct regcache *regcache)
01917d
 {
01917d
-  { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" },
01917d
-  { ".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01917d
 
01917d
-static struct core_regset_section arm_linux_vfp_regset_sections[] =
01917d
-{
01917d
-  { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" },
01917d
-  { ".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
+  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose", cb_data);
01917d
+
01917d
+  if (tdep->have_vfp_registers)
01917d
+    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point",
01917d
+	cb_data);
01917d
+  else if (tdep->have_fpa_registers)
01917d
+    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point", cb_data);
01917d
+}
01917d
 
01917d
 /* Determine target description from core file.  */
01917d
 
01917d
@@ -1266,13 +1269,10 @@
01917d
   /* Core file support.  */
01917d
   set_gdbarch_regset_from_core_section (gdbarch,
01917d
 					arm_linux_regset_from_core_section);
01917d
+  set_gdbarch_iterate_over_regset_sections
01917d
+    (gdbarch, arm_linux_iterate_over_regset_sections);
01917d
   set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description);
01917d
 
01917d
-  if (tdep->have_vfp_registers)
01917d
-    set_gdbarch_core_regset_sections (gdbarch, arm_linux_vfp_regset_sections);
01917d
-  else if (tdep->have_fpa_registers)
01917d
-    set_gdbarch_core_regset_sections (gdbarch, arm_linux_fpa_regset_sections);
01917d
-
01917d
   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
01917d
 
01917d
   /* Displaced stepping.  */
01917d
Index: gdb-7.6.1/gdb/corelow.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/corelow.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/corelow.c	2016-02-21 21:24:21.586851089 +0100
01917d
@@ -621,6 +621,22 @@
01917d
 				  bfd_section_vma (core_bfd, section)));
01917d
 }
01917d
 
01917d
+/* Callback for get_core_registers that handles a single core file
01917d
+   register note section. */
01917d
+
01917d
+static void
01917d
+get_core_registers_cb (const char *sect_name, int size,
01917d
+		       const char *human_name, void *cb_data)
01917d
+{
01917d
+  struct regcache *regcache = (struct regcache *) cb_data;
01917d
+
01917d
+  if (strcmp (sect_name, ".reg") == 0)
01917d
+    get_core_register_section (regcache, sect_name, 0, human_name, 1);
01917d
+  else if (strcmp (sect_name, ".reg2") == 0)
01917d
+    get_core_register_section (regcache, sect_name, 2, human_name, 0);
01917d
+  else
01917d
+    get_core_register_section (regcache, sect_name, 3, human_name, 0);
01917d
+}
01917d
 
01917d
 /* Get the registers out of a core file.  This is the machine-
01917d
    independent part.  Fetch_core_registers is the machine-dependent
01917d
@@ -633,8 +649,8 @@
01917d
 get_core_registers (struct target_ops *ops,
01917d
 		    struct regcache *regcache, int regno)
01917d
 {
01917d
-  struct core_regset_section *sect_list;
01917d
   int i;
01917d
+  struct gdbarch *gdbarch;
01917d
 
01917d
   if (!(core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
01917d
       && (core_vec == NULL || core_vec->core_read_registers == NULL))
01917d
@@ -644,23 +660,11 @@
01917d
       return;
01917d
     }
01917d
 
01917d
-  sect_list = gdbarch_core_regset_sections (get_regcache_arch (regcache));
01917d
-  if (sect_list)
01917d
-    while (sect_list->sect_name != NULL)
01917d
-      {
01917d
-        if (strcmp (sect_list->sect_name, ".reg") == 0)
01917d
-	  get_core_register_section (regcache, sect_list->sect_name,
01917d
-				     0, sect_list->human_name, 1);
01917d
-        else if (strcmp (sect_list->sect_name, ".reg2") == 0)
01917d
-	  get_core_register_section (regcache, sect_list->sect_name,
01917d
-				     2, sect_list->human_name, 0);
01917d
-	else
01917d
-	  get_core_register_section (regcache, sect_list->sect_name,
01917d
-				     3, sect_list->human_name, 0);
01917d
-
01917d
-	sect_list++;
01917d
-      }
01917d
-
01917d
+  gdbarch = get_regcache_arch (regcache);
01917d
+  if (gdbarch_iterate_over_regset_sections_p (gdbarch))
01917d
+    gdbarch_iterate_over_regset_sections (gdbarch,
01917d
+					  get_core_registers_cb,
01917d
+					  (void *) regcache, NULL);
01917d
   else
01917d
     {
01917d
       get_core_register_section (regcache,
01917d
Index: gdb-7.6.1/gdb/gdbarch.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/gdbarch.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/gdbarch.c	2016-02-21 21:24:21.587851096 +0100
01917d
@@ -266,7 +266,7 @@
01917d
   gdbarch_register_reggroup_p_ftype *register_reggroup_p;
01917d
   gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument;
01917d
   gdbarch_regset_from_core_section_ftype *regset_from_core_section;
01917d
-  struct core_regset_section * core_regset_sections;
01917d
+  gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections;
01917d
   gdbarch_make_corefile_notes_ftype *make_corefile_notes;
01917d
   gdbarch_elfcore_write_linux_prpsinfo_ftype *elfcore_write_linux_prpsinfo;
01917d
   gdbarch_find_memory_regions_ftype *find_memory_regions;
01917d
@@ -742,6 +742,7 @@
01917d
   /* Skip verify of register_reggroup_p, invalid_p == 0 */
01917d
   /* Skip verify of fetch_pointer_argument, has predicate.  */
01917d
   /* Skip verify of regset_from_core_section, has predicate.  */
01917d
+  /* Skip verify of iterate_over_regset_sections, has predicate.  */
01917d
   /* Skip verify of make_corefile_notes, has predicate.  */
01917d
   /* Skip verify of elfcore_write_linux_prpsinfo, has predicate.  */
01917d
   /* Skip verify of find_memory_regions, has predicate.  */
01917d
@@ -927,9 +928,6 @@
01917d
                       "gdbarch_dump: core_read_description = <%s>\n",
01917d
                       host_address_to_string (gdbarch->core_read_description));
01917d
   fprintf_unfiltered (file,
01917d
-                      "gdbarch_dump: core_regset_sections = %s\n",
01917d
-                      host_address_to_string (gdbarch->core_regset_sections));
01917d
-  fprintf_unfiltered (file,
01917d
                       "gdbarch_dump: gdbarch_core_xfer_shared_libraries_p() = %d\n",
01917d
                       gdbarch_core_xfer_shared_libraries_p (gdbarch));
01917d
   fprintf_unfiltered (file,
01917d
@@ -1125,6 +1123,12 @@
01917d
                       "gdbarch_dump: iterate_over_objfiles_in_search_order = <%s>\n",
01917d
                       host_address_to_string (gdbarch->iterate_over_objfiles_in_search_order));
01917d
   fprintf_unfiltered (file,
01917d
+                      "gdbarch_dump: gdbarch_iterate_over_regset_sections_p() = %d\n",
01917d
+                      gdbarch_iterate_over_regset_sections_p (gdbarch));
01917d
+  fprintf_unfiltered (file,
01917d
+                      "gdbarch_dump: iterate_over_regset_sections = <%s>\n",
01917d
+                      host_address_to_string (gdbarch->iterate_over_regset_sections));
01917d
+  fprintf_unfiltered (file,
01917d
                       "gdbarch_dump: long_bit = %s\n",
01917d
                       plongest (gdbarch->long_bit));
01917d
   fprintf_unfiltered (file,
01917d
@@ -3398,20 +3402,28 @@
01917d
   gdbarch->regset_from_core_section = regset_from_core_section;
01917d
 }
01917d
 
01917d
-struct core_regset_section *
01917d
-gdbarch_core_regset_sections (struct gdbarch *gdbarch)
01917d
+int
01917d
+gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch)
01917d
+{
01917d
+  gdb_assert (gdbarch != NULL);
01917d
+  return gdbarch->iterate_over_regset_sections != NULL;
01917d
+}
01917d
+
01917d
+void
01917d
+gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
01917d
 {
01917d
   gdb_assert (gdbarch != NULL);
01917d
+  gdb_assert (gdbarch->iterate_over_regset_sections != NULL);
01917d
   if (gdbarch_debug >= 2)
01917d
-    fprintf_unfiltered (gdb_stdlog, "gdbarch_core_regset_sections called\n");
01917d
-  return gdbarch->core_regset_sections;
01917d
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_iterate_over_regset_sections called\n");
01917d
+  gdbarch->iterate_over_regset_sections (gdbarch, cb, cb_data, regcache);
01917d
 }
01917d
 
01917d
 void
01917d
-set_gdbarch_core_regset_sections (struct gdbarch *gdbarch,
01917d
-                                  struct core_regset_section * core_regset_sections)
01917d
+set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+                                          gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
01917d
 {
01917d
-  gdbarch->core_regset_sections = core_regset_sections;
01917d
+  gdbarch->iterate_over_regset_sections = iterate_over_regset_sections;
01917d
 }
01917d
 
01917d
 int
01917d
Index: gdb-7.6.1/gdb/gdbarch.h
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/gdbarch.h	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/gdbarch.h	2016-02-21 21:24:21.588851102 +0100
01917d
@@ -85,6 +85,9 @@
01917d
 typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
01917d
   (struct objfile *objfile, void *cb_data);
01917d
 
01917d
+typedef void (iterate_over_regset_sections_cb)
01917d
+  (const char *sect_name, int size, const char *human_name, void *cb_data);
01917d
+
01917d
 
01917d
 /* The following are pre-initialized by GDBARCH.  */
01917d
 
01917d
@@ -742,10 +745,18 @@
01917d
 extern const struct regset * gdbarch_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name, size_t sect_size);
01917d
 extern void set_gdbarch_regset_from_core_section (struct gdbarch *gdbarch, gdbarch_regset_from_core_section_ftype *regset_from_core_section);
01917d
 
01917d
-/* Supported register notes in a core file. */
01917d
-
01917d
-extern struct core_regset_section * gdbarch_core_regset_sections (struct gdbarch *gdbarch);
01917d
-extern void set_gdbarch_core_regset_sections (struct gdbarch *gdbarch, struct core_regset_section * core_regset_sections);
01917d
+/* Iterate over all supported register notes in a core file.  For each
01917d
+   supported register note section, the iterator must call CB and pass
01917d
+   CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
01917d
+   the supported register note sections based on the current register
01917d
+   values.  Otherwise it should enumerate all supported register note
01917d
+   sections. */
01917d
+
01917d
+extern int gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch);
01917d
+
01917d
+typedef void (gdbarch_iterate_over_regset_sections_ftype) (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
01917d
+extern void gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
01917d
+extern void set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections);
01917d
 
01917d
 /* Create core file notes */
01917d
 
01917d
Index: gdb-7.6.1/gdb/gdbarch.sh
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/gdbarch.sh	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/gdbarch.sh	2016-02-21 21:24:21.588851102 +0100
01917d
@@ -648,8 +648,13 @@
01917d
 # name SECT_NAME and size SECT_SIZE.
01917d
 M:const struct regset *:regset_from_core_section:const char *sect_name, size_t sect_size:sect_name, sect_size
01917d
 
01917d
-# Supported register notes in a core file.
01917d
-v:struct core_regset_section *:core_regset_sections:const char *name, int len::::::host_address_to_string (gdbarch->core_regset_sections)
01917d
+# Iterate over all supported register notes in a core file.  For each
01917d
+# supported register note section, the iterator must call CB and pass
01917d
+# CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
01917d
+# the supported register note sections based on the current register
01917d
+# values.  Otherwise it should enumerate all supported register note
01917d
+# sections.
01917d
+M:void:iterate_over_regset_sections:iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache:cb, cb_data, regcache
01917d
 
01917d
 # Create core file notes
01917d
 M:char *:make_corefile_notes:bfd *obfd, int *note_size:obfd, note_size
01917d
@@ -1135,6 +1140,9 @@
01917d
 
01917d
 typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
01917d
   (struct objfile *objfile, void *cb_data);
01917d
+
01917d
+typedef void (iterate_over_regset_sections_cb)
01917d
+  (const char *sect_name, int size, const char *human_name, void *cb_data);
01917d
 EOF
01917d
 
01917d
 # function typedef's
01917d
Index: gdb-7.6.1/gdb/linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/linux-tdep.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/linux-tdep.c	2016-02-21 21:24:21.589851109 +0100
01917d
@@ -1409,6 +1409,57 @@
01917d
   return note_data;
01917d
 }
01917d
 
01917d
+/* Structure for passing information from
01917d
+   linux_collect_thread_registers via an iterator to
01917d
+   linux_collect_regset_section_cb. */
01917d
+
01917d
+struct linux_collect_regset_section_cb_data
01917d
+{
01917d
+  struct gdbarch *gdbarch;
01917d
+  const struct regcache *regcache;
01917d
+  bfd *obfd;
01917d
+  char *note_data;
01917d
+  int *note_size;
01917d
+  unsigned long lwp;
01917d
+  enum gdb_signal stop_signal;
01917d
+  int abort_iteration;
01917d
+};
01917d
+
01917d
+/* Callback for iterate_over_regset_sections that records a single
01917d
+   regset in the corefile note section.  */
01917d
+
01917d
+static void
01917d
+linux_collect_regset_section_cb (const char *sect_name, int size,
01917d
+				 const char *human_name, void *cb_data)
01917d
+{
01917d
+  const struct regset *regset;
01917d
+  char *buf;
01917d
+  struct linux_collect_regset_section_cb_data *data = cb_data;
01917d
+
01917d
+  if (data->abort_iteration)
01917d
+    return;
01917d
+
01917d
+  regset = gdbarch_regset_from_core_section (data->gdbarch, sect_name, size);
01917d
+  gdb_assert (regset && regset->collect_regset);
01917d
+
01917d
+  buf = xmalloc (size);
01917d
+  regset->collect_regset (regset, data->regcache, -1, buf, size);
01917d
+
01917d
+  /* PRSTATUS still needs to be treated specially.  */
01917d
+  if (strcmp (sect_name, ".reg") == 0)
01917d
+    data->note_data = (char *) elfcore_write_prstatus
01917d
+      (data->obfd, data->note_data, data->note_size, data->lwp,
01917d
+       gdb_signal_to_host (data->stop_signal), buf);
01917d
+  else
01917d
+    data->note_data = (char *) elfcore_write_register_note
01917d
+      (data->obfd, data->note_data, data->note_size,
01917d
+       sect_name, buf, size);
01917d
+  xfree (buf);
01917d
+
01917d
+  if (data->note_data == NULL)
01917d
+    data->abort_iteration = 1;
01917d
+}
01917d
+
01917d
 /* Records the thread's register state for the corefile note
01917d
    section.  */
01917d
 
01917d
@@ -1419,47 +1470,25 @@
01917d
 				enum gdb_signal stop_signal)
01917d
 {
01917d
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01917d
-  struct core_regset_section *sect_list;
01917d
-  unsigned long lwp;
01917d
+  struct linux_collect_regset_section_cb_data data;
01917d
 
01917d
-  sect_list = gdbarch_core_regset_sections (gdbarch);
01917d
-  gdb_assert (sect_list);
01917d
+  data.gdbarch = gdbarch;
01917d
+  data.regcache = regcache;
01917d
+  data.obfd = obfd;
01917d
+  data.note_data = note_data;
01917d
+  data.note_size = note_size;
01917d
+  data.stop_signal = stop_signal;
01917d
+  data.abort_iteration = 0;
01917d
 
01917d
   /* For remote targets the LWP may not be available, so use the TID.  */
01917d
-  lwp = ptid_get_lwp (ptid);
01917d
-  if (!lwp)
01917d
-    lwp = ptid_get_tid (ptid);
01917d
-
01917d
-  while (sect_list->sect_name != NULL)
01917d
-    {
01917d
-      const struct regset *regset;
01917d
-      char *buf;
01917d
-
01917d
-      regset = gdbarch_regset_from_core_section (gdbarch,
01917d
-						 sect_list->sect_name,
01917d
-						 sect_list->size);
01917d
-      gdb_assert (regset && regset->collect_regset);
01917d
-
01917d
-      buf = xmalloc (sect_list->size);
01917d
-      regset->collect_regset (regset, regcache, -1, buf, sect_list->size);
01917d
-
01917d
-      /* PRSTATUS still needs to be treated specially.  */
01917d
-      if (strcmp (sect_list->sect_name, ".reg") == 0)
01917d
-	note_data = (char *) elfcore_write_prstatus
01917d
-			       (obfd, note_data, note_size, lwp,
01917d
-				gdb_signal_to_host (stop_signal), buf);
01917d
-      else
01917d
-	note_data = (char *) elfcore_write_register_note
01917d
-			       (obfd, note_data, note_size,
01917d
-				sect_list->sect_name, buf, sect_list->size);
01917d
-      xfree (buf);
01917d
-      sect_list++;
01917d
-
01917d
-      if (!note_data)
01917d
-	return NULL;
01917d
-    }
01917d
-
01917d
-  return note_data;
01917d
+  data.lwp = ptid_get_lwp (ptid);
01917d
+  if (!data.lwp)
01917d
+    data.lwp = ptid_get_tid (ptid);
01917d
+
01917d
+  gdbarch_iterate_over_regset_sections (gdbarch,
01917d
+					linux_collect_regset_section_cb,
01917d
+					&data, regcache);
01917d
+  return data.note_data;
01917d
 }
01917d
 
01917d
 /* Fetch the siginfo data for the current thread, if it exists.  If
01917d
@@ -1839,7 +1868,7 @@
01917d
      converted to gdbarch_core_regset_sections, we no longer need to fall back
01917d
      to the target method at this point.  */
01917d
 
01917d
-  if (!gdbarch_core_regset_sections (gdbarch))
01917d
+  if (!gdbarch_iterate_over_regset_sections_p (gdbarch))
01917d
     return target_make_corefile_notes (obfd, note_size);
01917d
   else
01917d
     return linux_make_corefile_notes (gdbarch, obfd, note_size,
01917d
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c	2016-02-21 21:24:21.590851115 +0100
01917d
@@ -260,54 +260,6 @@
01917d
 				      readbuf, writebuf);
01917d
 }
01917d
 
01917d
-static struct core_regset_section ppc_linux_vsx_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 4, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { ".reg-ppc-vmx", 544, "ppc Altivec" },
01917d
-  { ".reg-ppc-vsx", 256, "POWER7 VSX" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section ppc_linux_vmx_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 4, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { ".reg-ppc-vmx", 544, "ppc Altivec" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section ppc_linux_fp_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 4, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 8, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { ".reg-ppc-vmx", 544, "ppc Altivec" },
01917d
-  { ".reg-ppc-vsx", 256, "POWER7 VSX" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 8, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { ".reg-ppc-vmx", 544, "ppc Altivec" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section ppc64_linux_fp_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 48 * 8, "general-purpose" },
01917d
-  { ".reg2", 264, "floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
 /* PLT stub in executable.  */
01917d
 static struct ppc_insn_pattern powerpc32_plt_stub[] =
01917d
   {
01917d
@@ -589,6 +541,28 @@
01917d
   return NULL;
01917d
 }
01917d
 
01917d
+/* Iterate over supported core file register note sections. */
01917d
+
01917d
+static void
01917d
+ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+					iterate_over_regset_sections_cb *cb,
01917d
+					void *cb_data,
01917d
+					const struct regcache *regcache)
01917d
+{
01917d
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01917d
+  int have_altivec = tdep->ppc_vr0_regnum != -1;
01917d
+  int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
01917d
+
01917d
+  cb (".reg", 48 * tdep->wordsize, "general-purpose", cb_data);
01917d
+  cb (".reg2", 264, "floating-point", cb_data);
01917d
+
01917d
+  if (have_altivec)
01917d
+    cb (".reg-ppc-vmx", 544, "ppc Altivec", cb_data);
01917d
+
01917d
+  if (have_vsx)
01917d
+    cb (".reg-ppc-vsx", 256, "POWER7 VSX", cb_data);
01917d
+}
01917d
+
01917d
 static void
01917d
 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
01917d
 			  struct trad_frame_cache *this_cache,
01917d
@@ -1790,19 +1764,6 @@
01917d
       else
01917d
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
01917d
 
01917d
-      /* Supported register sections.  */
01917d
-      if (tdesc_find_feature (info.target_desc,
01917d
-			      "org.gnu.gdb.power.vsx"))
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc_linux_vsx_regset_sections);
01917d
-      else if (tdesc_find_feature (info.target_desc,
01917d
-			       "org.gnu.gdb.power.altivec"))
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc_linux_vmx_regset_sections);
01917d
-      else
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc_linux_fp_regset_sections);
01917d
-
01917d
       if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
01917d
 	{
01917d
 	  powerpc_so_ops = svr4_so_ops;
01917d
@@ -1854,19 +1815,6 @@
01917d
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
01917d
       else
01917d
 	set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
01917d
-
01917d
-      /* Supported register sections.  */
01917d
-      if (tdesc_find_feature (info.target_desc,
01917d
-			      "org.gnu.gdb.power.vsx"))
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc64_linux_vsx_regset_sections);
01917d
-      else if (tdesc_find_feature (info.target_desc,
01917d
-			       "org.gnu.gdb.power.altivec"))
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc64_linux_vmx_regset_sections);
01917d
-      else
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  ppc64_linux_fp_regset_sections);
01917d
     }
01917d
 
01917d
   /* PPC32 uses a different prpsinfo32 compared to most other Linux
01917d
@@ -1878,6 +1826,8 @@
01917d
   set_gdbarch_regset_from_core_section (gdbarch,
01917d
 					ppc_linux_regset_from_core_section);
01917d
   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
01917d
+  set_gdbarch_iterate_over_regset_sections (gdbarch,
01917d
+					    ppc_linux_iterate_over_regset_sections);
01917d
 
01917d
   /* Enable TLS support.  */
01917d
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
01917d
Index: gdb-7.6.1/gdb/regset.h
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/regset.h	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/regset.h	2016-02-21 21:24:21.590851115 +0100
01917d
@@ -23,14 +23,6 @@
01917d
 struct gdbarch;
01917d
 struct regcache;
01917d
 
01917d
-/* Data structure for the supported register notes in a core file.  */
01917d
-struct core_regset_section
01917d
-{
01917d
-  const char *sect_name;
01917d
-  int size;
01917d
-  const char *human_name;
01917d
-};
01917d
-
01917d
 /* Data structure describing a register set.  */
01917d
 
01917d
 typedef void (supply_regset_ftype) (const struct regset *, struct regcache *,
01917d
Index: gdb-7.6.1/gdb/s390-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/s390-tdep.c	2016-02-21 21:24:15.859813662 +0100
01917d
+++ gdb-7.6.1/gdb/s390-tdep.c	2016-02-21 21:24:21.591851122 +0100
01917d
@@ -84,6 +84,10 @@
01917d
 
01917d
   const struct regset *fpregset;
01917d
   int sizeof_fpregset;
01917d
+
01917d
+  int have_linux_v1;
01917d
+  int have_linux_v2;
01917d
+  int have_tdb;
01917d
 };
01917d
 
01917d
 
01917d
@@ -691,84 +695,6 @@
01917d
   s390_collect_regset
01917d
 };
01917d
 
01917d
-static struct core_regset_section s390_linux32_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390_linux32v1_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-last-break", 8, "s390 last-break address" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390_linux32v2_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-last-break", 8, "s390 last-break address" },
01917d
-  { ".reg-s390-system-call", 4, "s390 system-call" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390_linux64_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390_linux64v1_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
01917d
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390_linux64v2_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
01917d
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
01917d
-  { ".reg-s390-system-call", 4, "s390 system-call" },
01917d
-  { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390x_linux64_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390x_linux64v1_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-static struct core_regset_section s390x_linux64v2_regset_sections[] =
01917d
-{
01917d
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
01917d
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
01917d
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
01917d
-  { ".reg-s390-system-call", 4, "s390 system-call" },
01917d
-  { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" },
01917d
-  { NULL, 0}
01917d
-};
01917d
-
01917d
-
01917d
 /* Return the appropriate register set for the core section identified
01917d
    by SECT_NAME and SECT_SIZE.  */
01917d
 static const struct regset *
01917d
@@ -799,6 +725,38 @@
01917d
   return NULL;
01917d
 }
01917d
 
01917d
+/* Iterate over supported core file register note sections. */
01917d
+
01917d
+static void
01917d
+s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+				   iterate_over_regset_sections_cb *cb,
01917d
+				   void *cb_data,
01917d
+				   const struct regcache *regcache)
01917d
+{
01917d
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01917d
+
01917d
+  cb (".reg", tdep->sizeof_gregset, "general-purpose", cb_data);
01917d
+  cb (".reg2", s390_sizeof_fpregset, "floating-point", cb_data);
01917d
+
01917d
+  if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1)
01917d
+    cb (".reg-s390-high-gprs", 16 * 4, "s390 GPR upper halves", cb_data);
01917d
+
01917d
+  if (tdep->have_linux_v1)
01917d
+    cb (".reg-s390-last-break", 8, "s930 last-break address", cb_data);
01917d
+
01917d
+  if (tdep->have_linux_v2)
01917d
+    cb (".reg-s390-system-call", 4, "s390 system-call", cb_data);
01917d
+
01917d
+  /* If regcache is set, we are in "write" (gcore) mode.  In this
01917d
+     case, don't iterate over the TDB unless its registers are
01917d
+     available.  */
01917d
+  if (tdep->have_tdb
01917d
+      && (regcache == NULL
01917d
+	  || REG_VALID == regcache_register_status (regcache,
01917d
+						    S390_TDB_DWORD0_REGNUM)))
01917d
+    cb (".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB", cb_data);
01917d
+}
01917d
+
01917d
 static const struct target_desc *
01917d
 s390_core_read_description (struct gdbarch *gdbarch,
01917d
 			    struct target_ops *target, bfd *abfd)
01917d
@@ -3031,6 +2989,7 @@
01917d
   int have_upper = 0;
01917d
   int have_linux_v1 = 0;
01917d
   int have_linux_v2 = 0;
01917d
+  int have_tdb = 0;
01917d
   int first_pseudo_reg, last_pseudo_reg;
01917d
   static const char *const stap_register_prefixes[] = { "%", NULL };
01917d
   static const char *const stap_register_indirection_prefixes[] = { "(",
01917d
@@ -3175,6 +3134,7 @@
01917d
 	    valid_p &= tdesc_numbered_register (feature, tdesc_data,
01917d
 						S390_TDB_DWORD0_REGNUM + i,
01917d
 						tdb_regs[i]);
01917d
+	  have_tdb = 1;
01917d
 	}
01917d
 
01917d
       if (!valid_p)
01917d
@@ -3204,6 +3164,9 @@
01917d
   /* Otherwise create a new gdbarch for the specified machine type.  */
01917d
   tdep = XCALLOC (1, struct gdbarch_tdep);
01917d
   tdep->abi = tdep_abi;
01917d
+  tdep->have_linux_v1 = have_linux_v1;
01917d
+  tdep->have_linux_v2 = have_linux_v2;
01917d
+  tdep->have_tdb = have_tdb;
01917d
   gdbarch = gdbarch_alloc (&info, tdep);
01917d
 
01917d
   set_gdbarch_believe_pcc_promotion (gdbarch, 0);
01917d
@@ -3234,6 +3197,8 @@
01917d
   set_gdbarch_regset_from_core_section (gdbarch,
01917d
                                         s390_regset_from_core_section);
01917d
   set_gdbarch_core_read_description (gdbarch, s390_core_read_description);
01917d
+  set_gdbarch_iterate_over_regset_sections (gdbarch,
01917d
+					    s390_iterate_over_regset_sections);
01917d
   set_gdbarch_cannot_store_register (gdbarch, s390_cannot_store_register);
01917d
   set_gdbarch_write_pc (gdbarch, s390_write_pc);
01917d
   set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
01917d
@@ -3301,31 +3266,6 @@
01917d
       set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
01917d
       set_solib_svr4_fetch_link_map_offsets
01917d
 	(gdbarch, svr4_ilp32_fetch_link_map_offsets);
01917d
-
01917d
-      if (have_upper)
01917d
-	{
01917d
-	  if (have_linux_v2)
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux64v2_regset_sections);
01917d
-	  else if (have_linux_v1)
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux64v1_regset_sections);
01917d
-	  else
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux64_regset_sections);
01917d
-	}
01917d
-      else
01917d
-	{
01917d
-	  if (have_linux_v2)
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux32v2_regset_sections);
01917d
-	  else if (have_linux_v1)
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux32v1_regset_sections);
01917d
-	  else
01917d
-	    set_gdbarch_core_regset_sections (gdbarch,
01917d
-					      s390_linux32_regset_sections);
01917d
-	}
01917d
       break;
01917d
 
01917d
     case ABI_LINUX_ZSERIES:
01917d
@@ -3345,16 +3285,6 @@
01917d
                                                     s390_address_class_type_flags_to_name);
01917d
       set_gdbarch_address_class_name_to_type_flags (gdbarch,
01917d
                                                     s390_address_class_name_to_type_flags);
01917d
-
01917d
-      if (have_linux_v2)
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  s390x_linux64v2_regset_sections);
01917d
-      else if (have_linux_v1)
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  s390x_linux64v1_regset_sections);
01917d
-      else
01917d
-	set_gdbarch_core_regset_sections (gdbarch,
01917d
-					  s390x_linux64_regset_sections);
01917d
       break;
01917d
     }
01917d
 
01917d
Index: gdb-7.6.1/gdb/amd64-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/amd64-linux-tdep.c	2016-02-21 21:41:37.020617839 +0100
01917d
+++ gdb-7.6.1/gdb/amd64-linux-tdep.c	2016-02-21 21:41:44.948669651 +0100
01917d
@@ -51,15 +51,6 @@
01917d
 #include "record-full.h"
01917d
 #include "linux-record.h"
01917d
 
01917d
-/* Supported register note sections.  */
01917d
-static struct core_regset_section amd64_linux_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 27 * 8, "general-purpose" },
01917d
-  { ".reg2", 512, "floating-point" },
01917d
-  { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
01917d
-  { NULL, 0 }
01917d
-};
01917d
-
01917d
 /* Mapping between the general-purpose registers in `struct user'
01917d
    format and GDB's register cache layout.  */
01917d
 
01917d
@@ -1376,6 +1367,19 @@
01917d
     }
01917d
 }
01917d
 
01917d
+/* Iterate over core file register note sections.  */
01917d
+
01917d
+static void
01917d
+amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+					  iterate_over_regset_sections_cb *cb,
01917d
+					  void *cb_data,
01917d
+					  const struct regcache *regcache)
01917d
+{
01917d
+  cb (".reg", 27 * 8, "general-purpose", cb_data);
01917d
+  cb (".reg2", 512, "floating-point", cb_data);
01917d
+  cb (".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
01917d
+}
01917d
+
01917d
 static void
01917d
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch)
01917d
 {
01917d
@@ -1410,8 +1414,9 @@
01917d
   /* GNU/Linux uses the dynamic linker included in the GNU C Library.  */
01917d
   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
01917d
 
01917d
-  /* Install supported register note sections.  */
01917d
-  set_gdbarch_core_regset_sections (gdbarch, amd64_linux_regset_sections);
01917d
+  /* Iterate over core file register note sections.  */
01917d
+  set_gdbarch_iterate_over_regset_sections
01917d
+    (gdbarch, amd64_linux_iterate_over_regset_sections);
01917d
 
01917d
   set_gdbarch_core_read_description (gdbarch,
01917d
 				     amd64_linux_core_read_description);
01917d
Index: gdb-7.6.1/gdb/i386-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/i386-linux-tdep.c	2016-02-21 21:41:37.020617839 +0100
01917d
+++ gdb-7.6.1/gdb/i386-linux-tdep.c	2016-02-21 21:41:44.948669651 +0100
01917d
@@ -52,28 +52,6 @@
01917d
 #include "features/i386/i386-mmx-linux.c"
01917d
 #include "features/i386/i386-avx-linux.c"
01917d
 
01917d
-/* Supported register note sections.  */
01917d
-static struct core_regset_section i386_linux_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 68, "general-purpose" },
01917d
-  { ".reg2", 108, "floating-point" },
01917d
-  { NULL, 0 }
01917d
-};
01917d
-
01917d
-static struct core_regset_section i386_linux_sse_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 68, "general-purpose" },
01917d
-  { ".reg-xfp", 512, "extended floating-point" },
01917d
-  { NULL, 0 }
01917d
-};
01917d
-
01917d
-static struct core_regset_section i386_linux_avx_regset_sections[] =
01917d
-{
01917d
-  { ".reg", 68, "general-purpose" },
01917d
-  { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
01917d
-  { NULL, 0 }
01917d
-};
01917d
-
01917d
 /* Return non-zero, when the register is in the corresponding register
01917d
    group.  Put the LINUX_ORIG_EAX register in the system group.  */
01917d
 static int
01917d
@@ -661,6 +639,26 @@
01917d
     return tdesc_i386_mmx_linux;
01917d
 }
01917d
 
01917d
+/* Iterate over core file register note sections.  */
01917d
+
01917d
+static void
01917d
+i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
01917d
+					 iterate_over_regset_sections_cb *cb,
01917d
+					 void *cb_data,
01917d
+					 const struct regcache *regcache)
01917d
+{
01917d
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01917d
+
01917d
+  cb (".reg", 68, "general-purpose", cb_data);
01917d
+
01917d
+  if (tdep->xcr0 & I386_XSTATE_AVX)
01917d
+    cb (".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
01917d
+  else if (tdep->xcr0 & I386_XSTATE_SSE)
01917d
+    cb (".reg-xfp", 512, "extended floating-point", cb_data);
01917d
+  else
01917d
+    cb (".reg2", 108, "floating-point", cb_data);
01917d
+}
01917d
+
01917d
 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
01917d
    inferior is still inside the syscall.  On next PTRACE_SINGLESTEP it will
01917d
    finish the syscall but PC will not change.
01917d
@@ -939,14 +937,9 @@
01917d
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
01917d
                                              svr4_fetch_objfile_link_map);
01917d
 
01917d
-  /* Install supported register note sections.  */
01917d
-  if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx"))
01917d
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_avx_regset_sections);
01917d
-  else if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse"))
01917d
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_sse_regset_sections);
01917d
-  else
01917d
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_regset_sections);
01917d
-
01917d
+  /* Core file support.  */
01917d
+  set_gdbarch_iterate_over_regset_sections
01917d
+    (gdbarch, i386_linux_iterate_over_regset_sections);
01917d
   set_gdbarch_core_read_description (gdbarch,
01917d
 				     i386_linux_core_read_description);
01917d