public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 26/26] Drop 'regset_from_core_section' gdbarch method
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
  2014-09-12 15:40 ` [PATCH 01/26] Replace 'core_regset_sections' by iterator method Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 05/26] ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
                   ` (30 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches

Now that all instances of the regset_from_core_section gdbarch method
have been replaced by the new iterator method, delete the obsolete
method from the gdbarch interface.  Adjust all invocations and
references to it.

gdb/ChangeLog:

	* gdbarch.sh (regset_from_core_section): Remove gdbarch method.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Likewise.
	* corelow.c (sniff_core_bfd): Drop presence check for deleted
	gdbarch method 'regset_from_core_section'.
	(get_core_register_section): Remove handling for the case that
	regset == NULL and regset_from_core_section is defined.
	(get_core_registers): Drop check for deleted method.
	* procfs.c (procfs_do_thread_registers): Adjust comment.
---
 gdb/corelow.c  | 22 ++--------------------
 gdb/gdbarch.c  | 32 --------------------------------
 gdb/gdbarch.h  |  9 ---------
 gdb/gdbarch.sh |  4 ----
 gdb/procfs.c   |  2 +-
 5 files changed, 3 insertions(+), 66 deletions(-)

diff --git a/gdb/corelow.c b/gdb/corelow.c
index 42af7f4..30d3367 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -134,9 +134,7 @@ sniff_core_bfd (bfd *abfd)
 
   /* Don't sniff if we have support for register sets in
      CORE_GDBARCH.  */
-  if (core_gdbarch
-      && (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
-	  || gdbarch_regset_from_core_section_p (core_gdbarch)))
+  if (core_gdbarch && gdbarch_iterate_over_regset_sections_p (core_gdbarch))
     return NULL;
 
   for (cf = core_file_fns; cf != NULL; cf = cf->next)
@@ -536,20 +534,6 @@ get_core_register_section (struct regcache *regcache,
       return;
     }
 
-  if (regset == NULL
-      && core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
-    {
-      regset = gdbarch_regset_from_core_section (core_gdbarch,
-						 name, size);
-      if (regset == NULL)
-	{
-	  if (required)
-	    warning (_("Couldn't recognize %s registers in core file."),
-		     human_name);
-	  return;
-	}
-    }
-
   if (regset != NULL)
     {
       regset->supply_regset (regset, regcache, -1, contents, size);
@@ -605,9 +589,7 @@ get_core_registers (struct target_ops *ops,
   int i;
   struct gdbarch *gdbarch;
 
-  if (!(core_gdbarch
-	&& (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
-	    || gdbarch_regset_from_core_section_p (core_gdbarch)))
+  if (!(core_gdbarch && gdbarch_iterate_over_regset_sections_p (core_gdbarch))
       && (core_vec == NULL || core_vec->core_read_registers == NULL))
     {
       fprintf_filtered (gdb_stderr,
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index be4bb78..e96d651 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -259,7 +259,6 @@ struct gdbarch
   gdbarch_address_class_name_to_type_flags_ftype *address_class_name_to_type_flags;
   gdbarch_register_reggroup_p_ftype *register_reggroup_p;
   gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument;
-  gdbarch_regset_from_core_section_ftype *regset_from_core_section;
   gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections;
   gdbarch_make_corefile_notes_ftype *make_corefile_notes;
   gdbarch_elfcore_write_linux_prpsinfo_ftype *elfcore_write_linux_prpsinfo;
@@ -570,7 +569,6 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of address_class_name_to_type_flags, has predicate.  */
   /* Skip verify of register_reggroup_p, invalid_p == 0 */
   /* Skip verify of fetch_pointer_argument, has predicate.  */
-  /* Skip verify of regset_from_core_section, has predicate.  */
   /* Skip verify of iterate_over_regset_sections, has predicate.  */
   /* Skip verify of make_corefile_notes, has predicate.  */
   /* Skip verify of elfcore_write_linux_prpsinfo, has predicate.  */
@@ -1144,12 +1142,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: register_type = <%s>\n",
                       host_address_to_string (gdbarch->register_type));
   fprintf_unfiltered (file,
-                      "gdbarch_dump: gdbarch_regset_from_core_section_p() = %d\n",
-                      gdbarch_regset_from_core_section_p (gdbarch));
-  fprintf_unfiltered (file,
-                      "gdbarch_dump: regset_from_core_section = <%s>\n",
-                      host_address_to_string (gdbarch->regset_from_core_section));
-  fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_relocate_instruction_p() = %d\n",
                       gdbarch_relocate_instruction_p (gdbarch));
   fprintf_unfiltered (file,
@@ -3241,30 +3233,6 @@ set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_regset_from_core_section_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->regset_from_core_section != NULL;
-}
-
-const struct regset *
-gdbarch_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name, size_t sect_size)
-{
-  gdb_assert (gdbarch != NULL);
-  gdb_assert (gdbarch->regset_from_core_section != NULL);
-  if (gdbarch_debug >= 2)
-    fprintf_unfiltered (gdb_stdlog, "gdbarch_regset_from_core_section called\n");
-  return gdbarch->regset_from_core_section (gdbarch, sect_name, sect_size);
-}
-
-void
-set_gdbarch_regset_from_core_section (struct gdbarch *gdbarch,
-                                      gdbarch_regset_from_core_section_ftype regset_from_core_section)
-{
-  gdbarch->regset_from_core_section = regset_from_core_section;
-}
-
-int
 gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 90a63ca..6e84004 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -736,15 +736,6 @@ typedef CORE_ADDR (gdbarch_fetch_pointer_argument_ftype) (struct frame_info *fra
 extern CORE_ADDR gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, struct frame_info *frame, int argi, struct type *type);
 extern void set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument);
 
-/* Return the appropriate register set for a core file section with
-   name SECT_NAME and size SECT_SIZE. */
-
-extern int gdbarch_regset_from_core_section_p (struct gdbarch *gdbarch);
-
-typedef const struct regset * (gdbarch_regset_from_core_section_ftype) (struct gdbarch *gdbarch, const char *sect_name, size_t sect_size);
-extern const struct regset * gdbarch_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name, size_t sect_size);
-extern void set_gdbarch_regset_from_core_section (struct gdbarch *gdbarch, gdbarch_regset_from_core_section_ftype *regset_from_core_section);
-
 /* Iterate over all supported register notes in a core file.  For each
    supported register note section, the iterator must call CB and pass
    CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 293854f..c785887 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -651,10 +651,6 @@ m:int:register_reggroup_p:int regnum, struct reggroup *reggroup:regnum, reggroup
 # Fetch the pointer to the ith function argument.
 F:CORE_ADDR:fetch_pointer_argument:struct frame_info *frame, int argi, struct type *type:frame, argi, type
 
-# Return the appropriate register set for a core file section with
-# name SECT_NAME and size SECT_SIZE.
-M:const struct regset *:regset_from_core_section:const char *sect_name, size_t sect_size:sect_name, sect_size
-
 # Iterate over all supported register notes in a core file.  For each
 # supported register note section, the iterator must call CB and pass
 # CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 3465bc5..4607b8c 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -5371,7 +5371,7 @@ procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
   /* This part is the old method for fetching registers.
      It should be replaced by the newer one using regsets
      once it is implemented in this platform:
-     gdbarch_regset_from_core_section() and regset->collect_regset().  */
+     gdbarch_iterate_over_regset_sections().  */
 
   old_chain = save_inferior_ptid ();
   inferior_ptid = ptid;
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/26] Replace 'core_regset_sections' by iterator method
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 26/26] Drop 'regset_from_core_section' gdbarch method Andreas Arnez
                   ` (31 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches
  Cc: Ulrich Weigand, Kevin Buettner, Mark Kettenis, Richard Earnshaw

The core_regset_sections list in gdbarch (needed for multi-arch
capable core file generation support) is replaced by an iterator
method.  Overall, this reduces the code a bit, and it allows for more
flexibility.

gdb/ChangeLog:

	* amd64-linux-tdep.c (amd64_linux_regset_sections): Remove.
	(amd64_linux_iterate_over_regset_sections): New.
	(amd64_linux_init_abi_common): Don't install the regset section
	list, but the new iterator in gdbarch.
	* arm-linux-tdep.c (arm_linux_fpa_regset_sections)
	(arm_linux_vfp_regset_sections): Remove.  Move combined logic...
	(arm_linux_iterate_over_regset_sections): ...here.  New function.
	(arm_linux_init_abi): Set iterator instead of section list.
	* corelow.c (get_core_registers_cb): New function, logic moved
	from...
	(get_core_registers): ...loop body here.  Use new iterator method
	instead of walking through the regset section list.
	* gdbarch.sh: Remove 'core_regset_sections'.  New method
	'iterate_over_regset_sections'.  New typedef
	'iterate_over_regset_sections_cb'.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Likewise.
	* i386-linux-tdep.c (i386_linux_regset_sections)
	(i386_linux_sse_regset_sections, i386_linux_avx_regset_sections):
	Remove.
	(i386_linux_iterate_over_regset_sections): New.
	(i386_linux_init_abi): Don't choose a regset section list, but
	install new iterator in gdbarch.
	* linux-tdep.c (struct linux_collect_regset_section_cb_data): New.
	(linux_collect_regset_section_cb): New function, logic moved
	from...
	(linux_collect_thread_registers): ...loop body here.  Use iterator
	method instead of walking through list.
	(linux_make_corefile_notes_1): Check for presence of iterator
	method instead of regset section list.
	* ppc-linux-tdep.c (ppc_linux_vsx_regset_sections)
	(ppc_linux_vmx_regset_sections, ppc_linux_fp_regset_sections)
	(ppc64_linux_vsx_regset_sections, ppc64_linux_vmx_regset_sections)
	(ppc64_linux_fp_regset_sections): Remove.  Move combined logic...
	(ppc_linux_iterate_over_regset_sections): ...here.  New function.
	(ppc_linux_init_abi): Don't choose from above regset section
	lists, but install new iterator in gdbarch.
	* regset.h (struct core_regset_section): Remove.
	* s390-linux-tdep.c (struct gdbarch_tdep): Add new fields
	have_linux_v1, have_linux_v2, and have_tdb.
	(s390_linux32_regset_sections, s390_linux32v1_regset_sections)
	(s390_linux32v2_regset_sections, s390_linux64_regset_sections)
	(s390_linux64v1_regset_sections, s390_linux64v2_regset_sections)
	(s390x_linux64_regset_sections, s390x_linux64v1_regset_sections)
	(s390x_linux64v2_regset_sections): Remove.  Move combined logic...
	(s390_iterate_over_regset_sections): ...here.  New function.  Use
	new tdep fields.
	(s390_gdbarch_init): Set new tdep fields.  Don't choose from above
	regset section lists, but install new iterator.
---
 gdb/amd64-linux-tdep.c |  27 +++++----
 gdb/arm-linux-tdep.c   |  34 +++++------
 gdb/corelow.c          |  40 +++++++------
 gdb/gdbarch.c          |  34 +++++++----
 gdb/gdbarch.h          |  17 +++++-
 gdb/gdbarch.sh         |  12 +++-
 gdb/i386-linux-tdep.c  |  54 ++++++++---------
 gdb/linux-tdep.c       | 107 +++++++++++++++++++++------------
 gdb/ppc-linux-tdep.c   |  98 ++++++++----------------------
 gdb/regset.h           |   8 ---
 gdb/s390-linux-tdep.c  | 157 ++++++++++++++-----------------------------------
 11 files changed, 260 insertions(+), 328 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 850ca20..2432bae 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -53,15 +53,6 @@
 #include "record-full.h"
 #include "linux-record.h"
 
-/* Supported register note sections.  */
-static struct core_regset_section amd64_linux_regset_sections[] =
-{
-  { ".reg", 27 * 8, "general-purpose" },
-  { ".reg2", 512, "floating-point" },
-  { ".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state" },
-  { NULL, 0 }
-};
-
 /* Mapping between the general-purpose registers in `struct user'
    format and GDB's register cache layout.  */
 
@@ -1609,6 +1600,19 @@ amd64_linux_core_read_description (struct gdbarch *gdbarch,
     }
 }
 
+/* Iterate over core file register note sections.  */
+
+static void
+amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					  iterate_over_regset_sections_cb *cb,
+					  void *cb_data,
+					  const struct regcache *regcache)
+{
+  cb (".reg", 27 * 8, "general-purpose", cb_data);
+  cb (".reg2", 512, "floating-point", cb_data);
+  cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+}
+
 static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
@@ -1643,8 +1647,9 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch)
   /* GNU/Linux uses the dynamic linker included in the GNU C Library.  */
   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
 
-  /* Install supported register note sections.  */
-  set_gdbarch_core_regset_sections (gdbarch, amd64_linux_regset_sections);
+  /* Iterate over core file register note sections.  */
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, amd64_linux_iterate_over_regset_sections);
 
   set_gdbarch_core_read_description (gdbarch,
 				     amd64_linux_core_read_description);
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 3d524c9..22decd5 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -753,21 +753,24 @@ arm_linux_regset_from_core_section (struct gdbarch *gdbarch,
   return NULL;
 }
 
-/* Core file register set sections.  */
+/* Iterate over core file register note sections.  */
 
-static struct core_regset_section arm_linux_fpa_regset_sections[] =
+static void
+arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
 {
-  { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" },
-  { ".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point" },
-  { NULL, 0}
-};
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-static struct core_regset_section arm_linux_vfp_regset_sections[] =
-{
-  { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" },
-  { ".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point" },
-  { NULL, 0}
-};
+  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose", cb_data);
+
+  if (tdep->have_vfp_registers)
+    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point",
+	cb_data);
+  else if (tdep->have_fpa_registers)
+    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point", cb_data);
+}
 
 /* Determine target description from core file.  */
 
@@ -1456,13 +1459,10 @@ arm_linux_init_abi (struct gdbarch_info info,
   /* Core file support.  */
   set_gdbarch_regset_from_core_section (gdbarch,
 					arm_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, arm_linux_iterate_over_regset_sections);
   set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description);
 
-  if (tdep->have_vfp_registers)
-    set_gdbarch_core_regset_sections (gdbarch, arm_linux_vfp_regset_sections);
-  else if (tdep->have_fpa_registers)
-    set_gdbarch_core_regset_sections (gdbarch, arm_linux_fpa_regset_sections);
-
   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
 
   /* Displaced stepping.  */
diff --git a/gdb/corelow.c b/gdb/corelow.c
index ecd99f6..7e64e1d 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -550,6 +550,22 @@ get_core_register_section (struct regcache *regcache,
 				  bfd_section_vma (core_bfd, section)));
 }
 
+/* Callback for get_core_registers that handles a single core file
+   register note section. */
+
+static void
+get_core_registers_cb (const char *sect_name, int size,
+		       const char *human_name, void *cb_data)
+{
+  struct regcache *regcache = (struct regcache *) cb_data;
+
+  if (strcmp (sect_name, ".reg") == 0)
+    get_core_register_section (regcache, sect_name, 0, human_name, 1);
+  else if (strcmp (sect_name, ".reg2") == 0)
+    get_core_register_section (regcache, sect_name, 2, human_name, 0);
+  else
+    get_core_register_section (regcache, sect_name, 3, human_name, 0);
+}
 
 /* Get the registers out of a core file.  This is the machine-
    independent part.  Fetch_core_registers is the machine-dependent
@@ -562,8 +578,8 @@ static void
 get_core_registers (struct target_ops *ops,
 		    struct regcache *regcache, int regno)
 {
-  struct core_regset_section *sect_list;
   int i;
+  struct gdbarch *gdbarch;
 
   if (!(core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
       && (core_vec == NULL || core_vec->core_read_registers == NULL))
@@ -573,23 +589,11 @@ get_core_registers (struct target_ops *ops,
       return;
     }
 
-  sect_list = gdbarch_core_regset_sections (get_regcache_arch (regcache));
-  if (sect_list)
-    while (sect_list->sect_name != NULL)
-      {
-        if (strcmp (sect_list->sect_name, ".reg") == 0)
-	  get_core_register_section (regcache, sect_list->sect_name,
-				     0, sect_list->human_name, 1);
-        else if (strcmp (sect_list->sect_name, ".reg2") == 0)
-	  get_core_register_section (regcache, sect_list->sect_name,
-				     2, sect_list->human_name, 0);
-	else
-	  get_core_register_section (regcache, sect_list->sect_name,
-				     3, sect_list->human_name, 0);
-
-	sect_list++;
-      }
-
+  gdbarch = get_regcache_arch (regcache);
+  if (gdbarch_iterate_over_regset_sections_p (gdbarch))
+    gdbarch_iterate_over_regset_sections (gdbarch,
+					  get_core_registers_cb,
+					  (void *) regcache, NULL);
   else
     {
       get_core_register_section (regcache,
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index b0ee79d..be4bb78 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -260,7 +260,7 @@ struct gdbarch
   gdbarch_register_reggroup_p_ftype *register_reggroup_p;
   gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument;
   gdbarch_regset_from_core_section_ftype *regset_from_core_section;
-  struct core_regset_section * core_regset_sections;
+  gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections;
   gdbarch_make_corefile_notes_ftype *make_corefile_notes;
   gdbarch_elfcore_write_linux_prpsinfo_ftype *elfcore_write_linux_prpsinfo;
   gdbarch_find_memory_regions_ftype *find_memory_regions;
@@ -571,6 +571,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of register_reggroup_p, invalid_p == 0 */
   /* Skip verify of fetch_pointer_argument, has predicate.  */
   /* Skip verify of regset_from_core_section, has predicate.  */
+  /* Skip verify of iterate_over_regset_sections, has predicate.  */
   /* Skip verify of make_corefile_notes, has predicate.  */
   /* Skip verify of elfcore_write_linux_prpsinfo, has predicate.  */
   /* Skip verify of find_memory_regions, has predicate.  */
@@ -768,9 +769,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: core_read_description = <%s>\n",
                       host_address_to_string (gdbarch->core_read_description));
   fprintf_unfiltered (file,
-                      "gdbarch_dump: core_regset_sections = %s\n",
-                      host_address_to_string (gdbarch->core_regset_sections));
-  fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_core_xfer_shared_libraries_p() = %d\n",
                       gdbarch_core_xfer_shared_libraries_p (gdbarch));
   fprintf_unfiltered (file,
@@ -987,6 +985,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: iterate_over_objfiles_in_search_order = <%s>\n",
                       host_address_to_string (gdbarch->iterate_over_objfiles_in_search_order));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: gdbarch_iterate_over_regset_sections_p() = %d\n",
+                      gdbarch_iterate_over_regset_sections_p (gdbarch));
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: iterate_over_regset_sections = <%s>\n",
+                      host_address_to_string (gdbarch->iterate_over_regset_sections));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: long_bit = %s\n",
                       plongest (gdbarch->long_bit));
   fprintf_unfiltered (file,
@@ -3260,20 +3264,28 @@ set_gdbarch_regset_from_core_section (struct gdbarch *gdbarch,
   gdbarch->regset_from_core_section = regset_from_core_section;
 }
 
-struct core_regset_section *
-gdbarch_core_regset_sections (struct gdbarch *gdbarch)
+int
+gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  return gdbarch->iterate_over_regset_sections != NULL;
+}
+
+void
+gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
 {
   gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->iterate_over_regset_sections != NULL);
   if (gdbarch_debug >= 2)
-    fprintf_unfiltered (gdb_stdlog, "gdbarch_core_regset_sections called\n");
-  return gdbarch->core_regset_sections;
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_iterate_over_regset_sections called\n");
+  gdbarch->iterate_over_regset_sections (gdbarch, cb, cb_data, regcache);
 }
 
 void
-set_gdbarch_core_regset_sections (struct gdbarch *gdbarch,
-                                  struct core_regset_section * core_regset_sections)
+set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
+                                          gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
 {
-  gdbarch->core_regset_sections = core_regset_sections;
+  gdbarch->iterate_over_regset_sections = iterate_over_regset_sections;
 }
 
 int
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 0303b2e..bbda3da 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -81,6 +81,9 @@ extern struct gdbarch *target_gdbarch (void);
 typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
 
+typedef void (iterate_over_regset_sections_cb)
+  (const char *sect_name, int size, const char *human_name, void *cb_data);
+
 
 /* The following are pre-initialized by GDBARCH.  */
 
@@ -741,10 +744,18 @@ typedef const struct regset * (gdbarch_regset_from_core_section_ftype) (struct g
 extern const struct regset * gdbarch_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name, size_t sect_size);
 extern void set_gdbarch_regset_from_core_section (struct gdbarch *gdbarch, gdbarch_regset_from_core_section_ftype *regset_from_core_section);
 
-/* Supported register notes in a core file. */
+/* Iterate over all supported register notes in a core file.  For each
+   supported register note section, the iterator must call CB and pass
+   CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
+   the supported register note sections based on the current register
+   values.  Otherwise it should enumerate all supported register note
+   sections. */
+
+extern int gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch);
 
-extern struct core_regset_section * gdbarch_core_regset_sections (struct gdbarch *gdbarch);
-extern void set_gdbarch_core_regset_sections (struct gdbarch *gdbarch, struct core_regset_section * core_regset_sections);
+typedef void (gdbarch_iterate_over_regset_sections_ftype) (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
+extern void gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
+extern void set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections);
 
 /* Create core file notes */
 
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 2a8bca8..80d3eec 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -655,8 +655,13 @@ F:CORE_ADDR:fetch_pointer_argument:struct frame_info *frame, int argi, struct ty
 # name SECT_NAME and size SECT_SIZE.
 M:const struct regset *:regset_from_core_section:const char *sect_name, size_t sect_size:sect_name, sect_size
 
-# Supported register notes in a core file.
-v:struct core_regset_section *:core_regset_sections:const char *name, int len::::::host_address_to_string (gdbarch->core_regset_sections)
+# Iterate over all supported register notes in a core file.  For each
+# supported register note section, the iterator must call CB and pass
+# CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
+# the supported register note sections based on the current register
+# values.  Otherwise it should enumerate all supported register note
+# sections.
+M:void:iterate_over_regset_sections:iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache:cb, cb_data, regcache
 
 # Create core file notes
 M:char *:make_corefile_notes:bfd *obfd, int *note_size:obfd, note_size
@@ -1169,6 +1174,9 @@ extern struct gdbarch *target_gdbarch (void);
 
 typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
+
+typedef void (iterate_over_regset_sections_cb)
+  (const char *sect_name, int size, const char *human_name, void *cb_data);
 EOF
 
 # function typedef's
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index b3707f7..4ee6874 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -52,28 +52,6 @@
 #include "features/i386/i386-avx-linux.c"
 #include "features/i386/i386-avx512-linux.c"
 
-/* Supported register note sections.  */
-static struct core_regset_section i386_linux_regset_sections[] =
-{
-  { ".reg", 68, "general-purpose" },
-  { ".reg2", 108, "floating-point" },
-  { NULL, 0 }
-};
-
-static struct core_regset_section i386_linux_sse_regset_sections[] =
-{
-  { ".reg", 68, "general-purpose" },
-  { ".reg-xfp", 512, "extended floating-point" },
-  { NULL, 0 }
-};
-
-static struct core_regset_section i386_linux_avx_regset_sections[] =
-{
-  { ".reg", 68, "general-purpose" },
-  { ".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state" },
-  { NULL, 0 }
-};
-
 /* Return non-zero, when the register is in the corresponding register
    group.  Put the LINUX_ORIG_EAX register in the system group.  */
 static int
@@ -670,6 +648,26 @@ i386_linux_core_read_description (struct gdbarch *gdbarch,
     return tdesc_i386_mmx_linux;
 }
 
+/* Iterate over core file register note sections.  */
+
+static void
+i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  cb (".reg", 68, "general-purpose", cb_data);
+
+  if (tdep->xcr0 & X86_XSTATE_AVX)
+    cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+  else if (tdep->xcr0 & X86_XSTATE_SSE)
+    cb (".reg-xfp", 512, "extended floating-point", cb_data);
+  else
+    cb (".reg2", 108, "floating-point", cb_data);
+}
+
 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
    inferior is still inside the syscall.  On next PTRACE_SINGLESTEP it will
    finish the syscall but PC will not change.
@@ -948,15 +946,9 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
                                              svr4_fetch_objfile_link_map);
 
-  /* Install supported register note sections.  */
-  if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512")
-      || tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx"))
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_avx_regset_sections);
-  else if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse"))
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_sse_regset_sections);
-  else
-    set_gdbarch_core_regset_sections (gdbarch, i386_linux_regset_sections);
-
+  /* Core file support.  */
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, i386_linux_iterate_over_regset_sections);
   set_gdbarch_core_read_description (gdbarch,
 				     i386_linux_core_read_description);
 
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index dae59c5..3d8b1fc 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1084,6 +1084,57 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
   return note_data;
 }
 
+/* Structure for passing information from
+   linux_collect_thread_registers via an iterator to
+   linux_collect_regset_section_cb. */
+
+struct linux_collect_regset_section_cb_data
+{
+  struct gdbarch *gdbarch;
+  const struct regcache *regcache;
+  bfd *obfd;
+  char *note_data;
+  int *note_size;
+  unsigned long lwp;
+  enum gdb_signal stop_signal;
+  int abort_iteration;
+};
+
+/* Callback for iterate_over_regset_sections that records a single
+   regset in the corefile note section.  */
+
+static void
+linux_collect_regset_section_cb (const char *sect_name, int size,
+				 const char *human_name, void *cb_data)
+{
+  const struct regset *regset;
+  char *buf;
+  struct linux_collect_regset_section_cb_data *data = cb_data;
+
+  if (data->abort_iteration)
+    return;
+
+  regset = gdbarch_regset_from_core_section (data->gdbarch, sect_name, size);
+  gdb_assert (regset && regset->collect_regset);
+
+  buf = xmalloc (size);
+  regset->collect_regset (regset, data->regcache, -1, buf, size);
+
+  /* PRSTATUS still needs to be treated specially.  */
+  if (strcmp (sect_name, ".reg") == 0)
+    data->note_data = (char *) elfcore_write_prstatus
+      (data->obfd, data->note_data, data->note_size, data->lwp,
+       gdb_signal_to_host (data->stop_signal), buf);
+  else
+    data->note_data = (char *) elfcore_write_register_note
+      (data->obfd, data->note_data, data->note_size,
+       sect_name, buf, size);
+  xfree (buf);
+
+  if (data->note_data == NULL)
+    data->abort_iteration = 1;
+}
+
 /* Records the thread's register state for the corefile note
    section.  */
 
@@ -1094,47 +1145,25 @@ linux_collect_thread_registers (const struct regcache *regcache,
 				enum gdb_signal stop_signal)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  struct core_regset_section *sect_list;
-  unsigned long lwp;
+  struct linux_collect_regset_section_cb_data data;
 
-  sect_list = gdbarch_core_regset_sections (gdbarch);
-  gdb_assert (sect_list);
+  data.gdbarch = gdbarch;
+  data.regcache = regcache;
+  data.obfd = obfd;
+  data.note_data = note_data;
+  data.note_size = note_size;
+  data.stop_signal = stop_signal;
+  data.abort_iteration = 0;
 
   /* For remote targets the LWP may not be available, so use the TID.  */
-  lwp = ptid_get_lwp (ptid);
-  if (!lwp)
-    lwp = ptid_get_tid (ptid);
-
-  while (sect_list->sect_name != NULL)
-    {
-      const struct regset *regset;
-      char *buf;
-
-      regset = gdbarch_regset_from_core_section (gdbarch,
-						 sect_list->sect_name,
-						 sect_list->size);
-      gdb_assert (regset && regset->collect_regset);
-
-      buf = xmalloc (sect_list->size);
-      regset->collect_regset (regset, regcache, -1, buf, sect_list->size);
-
-      /* PRSTATUS still needs to be treated specially.  */
-      if (strcmp (sect_list->sect_name, ".reg") == 0)
-	note_data = (char *) elfcore_write_prstatus
-			       (obfd, note_data, note_size, lwp,
-				gdb_signal_to_host (stop_signal), buf);
-      else
-	note_data = (char *) elfcore_write_register_note
-			       (obfd, note_data, note_size,
-				sect_list->sect_name, buf, sect_list->size);
-      xfree (buf);
-      sect_list++;
-
-      if (!note_data)
-	return NULL;
-    }
-
-  return note_data;
+  data.lwp = ptid_get_lwp (ptid);
+  if (!data.lwp)
+    data.lwp = ptid_get_tid (ptid);
+
+  gdbarch_iterate_over_regset_sections (gdbarch,
+					linux_collect_regset_section_cb,
+					&data, regcache);
+  return data.note_data;
 }
 
 /* Fetch the siginfo data for the current thread, if it exists.  If
@@ -1524,7 +1553,7 @@ linux_make_corefile_notes_1 (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
      converted to gdbarch_core_regset_sections, we no longer need to fall back
      to the target method at this point.  */
 
-  if (!gdbarch_core_regset_sections (gdbarch))
+  if (!gdbarch_iterate_over_regset_sections_p (gdbarch))
     return target_make_corefile_notes (obfd, note_size);
   else
     return linux_make_corefile_notes (gdbarch, obfd, note_size,
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 316b254..7ab3255 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -257,54 +257,6 @@ ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
 				      readbuf, writebuf);
 }
 
-static struct core_regset_section ppc_linux_vsx_regset_sections[] =
-{
-  { ".reg", 48 * 4, "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 ppc_linux_vmx_regset_sections[] =
-{
-  { ".reg", 48 * 4, "general-purpose" },
-  { ".reg2", 264, "floating-point" },
-  { ".reg-ppc-vmx", 544, "ppc Altivec" },
-  { NULL, 0}
-};
-
-static struct core_regset_section ppc_linux_fp_regset_sections[] =
-{
-  { ".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}
-};
-
 /* PLT stub in executable.  */
 static struct ppc_insn_pattern powerpc32_plt_stub[] =
   {
@@ -558,6 +510,28 @@ ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
   return NULL;
 }
 
+/* Iterate over supported core file register note sections. */
+
+static void
+ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  int have_altivec = tdep->ppc_vr0_regnum != -1;
+  int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
+
+  cb (".reg", 48 * tdep->wordsize, "general-purpose", cb_data);
+  cb (".reg2", 264, "floating-point", cb_data);
+
+  if (have_altivec)
+    cb (".reg-ppc-vmx", 544, "ppc Altivec", cb_data);
+
+  if (have_vsx)
+    cb (".reg-ppc-vsx", 256, "POWER7 VSX", cb_data);
+}
+
 static void
 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
 			  struct trad_frame_cache *this_cache,
@@ -1352,19 +1326,6 @@ ppc_linux_init_abi (struct gdbarch_info info,
       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 (powerpc_so_ops.in_dynsym_resolve_code == NULL)
 	{
 	  powerpc_so_ops = svr4_so_ops;
@@ -1416,19 +1377,6 @@ ppc_linux_init_abi (struct gdbarch_info 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);
     }
 
   /* PPC32 uses a different prpsinfo32 compared to most other Linux
@@ -1440,6 +1388,8 @@ ppc_linux_init_abi (struct gdbarch_info info,
   set_gdbarch_regset_from_core_section (gdbarch,
 					ppc_linux_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
+  set_gdbarch_iterate_over_regset_sections (gdbarch,
+					    ppc_linux_iterate_over_regset_sections);
 
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
diff --git a/gdb/regset.h b/gdb/regset.h
index 37ed99a..68e19ee 100644
--- a/gdb/regset.h
+++ b/gdb/regset.h
@@ -23,14 +23,6 @@
 struct gdbarch;
 struct regcache;
 
-/* Data structure for the supported register notes in a core file.  */
-struct core_regset_section
-{
-  const char *sect_name;
-  int size;
-  const char *human_name;
-};
-
 /* Data structure describing a register set.  */
 
 typedef void (supply_regset_ftype) (const struct regset *, struct regcache *,
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index ac8118b..840431d 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -88,6 +88,10 @@ struct gdbarch_tdep
 
   const struct regset *fpregset;
   int sizeof_fpregset;
+
+  int have_linux_v1;
+  int have_linux_v2;
+  int have_tdb;
 };
 
 
@@ -532,84 +536,6 @@ const struct regset s390_tdb_regset = {
   regcache_collect_regset
 };
 
-static struct core_regset_section s390_linux32_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390_linux32v1_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-last-break", 8, "s390 last-break address" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390_linux32v2_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-last-break", 8, "s390 last-break address" },
-  { ".reg-s390-system-call", 4, "s390 system-call" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390_linux64_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390_linux64v1_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390_linux64v2_regset_sections[] =
-{
-  { ".reg", s390_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
-  { ".reg-s390-system-call", 4, "s390 system-call" },
-  { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390x_linux64_regset_sections[] =
-{
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390x_linux64v1_regset_sections[] =
-{
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
-  { NULL, 0}
-};
-
-static struct core_regset_section s390x_linux64v2_regset_sections[] =
-{
-  { ".reg", s390x_sizeof_gregset, "general-purpose" },
-  { ".reg2", s390_sizeof_fpregset, "floating-point" },
-  { ".reg-s390-last-break", 8, "s930 last-break address" },
-  { ".reg-s390-system-call", 4, "s390 system-call" },
-  { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" },
-  { NULL, 0}
-};
-
-
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 static const struct regset *
@@ -640,6 +566,38 @@ s390_regset_from_core_section (struct gdbarch *gdbarch,
   return NULL;
 }
 
+/* Iterate over supported core file register note sections. */
+
+static void
+s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				   iterate_over_regset_sections_cb *cb,
+				   void *cb_data,
+				   const struct regcache *regcache)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  cb (".reg", tdep->sizeof_gregset, "general-purpose", cb_data);
+  cb (".reg2", s390_sizeof_fpregset, "floating-point", cb_data);
+
+  if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1)
+    cb (".reg-s390-high-gprs", 16 * 4, "s390 GPR upper halves", cb_data);
+
+  if (tdep->have_linux_v1)
+    cb (".reg-s390-last-break", 8, "s930 last-break address", cb_data);
+
+  if (tdep->have_linux_v2)
+    cb (".reg-s390-system-call", 4, "s390 system-call", cb_data);
+
+  /* If regcache is set, we are in "write" (gcore) mode.  In this
+     case, don't iterate over the TDB unless its registers are
+     available.  */
+  if (tdep->have_tdb
+      && (regcache == NULL
+	  || REG_VALID == regcache_register_status (regcache,
+						    S390_TDB_DWORD0_REGNUM)))
+    cb (".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB", cb_data);
+}
+
 static const struct target_desc *
 s390_core_read_description (struct gdbarch *gdbarch,
 			    struct target_ops *target, bfd *abfd)
@@ -2904,6 +2862,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   int have_upper = 0;
   int have_linux_v1 = 0;
   int have_linux_v2 = 0;
+  int have_tdb = 0;
   int first_pseudo_reg, last_pseudo_reg;
   static const char *const stap_register_prefixes[] = { "%", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
@@ -3048,6 +3007,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	    valid_p &= tdesc_numbered_register (feature, tdesc_data,
 						S390_TDB_DWORD0_REGNUM + i,
 						tdb_regs[i]);
+	  have_tdb = 1;
 	}
 
       if (!valid_p)
@@ -3077,6 +3037,9 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Otherwise create a new gdbarch for the specified machine type.  */
   tdep = XCNEW (struct gdbarch_tdep);
   tdep->abi = tdep_abi;
+  tdep->have_linux_v1 = have_linux_v1;
+  tdep->have_linux_v2 = have_linux_v2;
+  tdep->have_tdb = have_tdb;
   gdbarch = gdbarch_alloc (&info, tdep);
 
   set_gdbarch_believe_pcc_promotion (gdbarch, 0);
@@ -3107,6 +3070,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_regset_from_core_section (gdbarch,
 					s390_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, s390_core_read_description);
+  set_gdbarch_iterate_over_regset_sections (gdbarch,
+					    s390_iterate_over_regset_sections);
   set_gdbarch_cannot_store_register (gdbarch, s390_cannot_store_register);
   set_gdbarch_write_pc (gdbarch, s390_write_pc);
   set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
@@ -3179,31 +3144,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	(gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
       set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390);
-
-      if (have_upper)
-	{
-	  if (have_linux_v2)
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux64v2_regset_sections);
-	  else if (have_linux_v1)
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux64v1_regset_sections);
-	  else
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux64_regset_sections);
-	}
-      else
-	{
-	  if (have_linux_v2)
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux32v2_regset_sections);
-	  else if (have_linux_v1)
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux32v1_regset_sections);
-	  else
-	    set_gdbarch_core_regset_sections (gdbarch,
-					      s390_linux32_regset_sections);
-	}
       break;
 
     case ABI_LINUX_ZSERIES:
@@ -3223,18 +3163,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 						    s390_address_class_type_flags_to_name);
       set_gdbarch_address_class_name_to_type_flags (gdbarch,
 						    s390_address_class_name_to_type_flags);
-
       set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390);
-
-      if (have_linux_v2)
-	set_gdbarch_core_regset_sections (gdbarch,
-					  s390x_linux64v2_regset_sections);
-      else if (have_linux_v1)
-	set_gdbarch_core_regset_sections (gdbarch,
-					  s390x_linux64v1_regset_sections);
-      else
-	set_gdbarch_core_regset_sections (gdbarch,
-					  s390x_linux64_regset_sections);
       break;
     }
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 12/26] IA64: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (7 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 21/26] TILEGX: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 16/26] NIOS2: " Andreas Arnez
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jeff Johnston

For IA-64 GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* ia64-linux-tdep.c (ia64_linux_regset_from_core_section): Remove.
	(ia64_linux_iterate_over_regset_sections): New.
	(ia64_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/ia64-linux-tdep.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 3bdf2a1..deedec6 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -201,20 +201,14 @@ static const struct regset ia64_linux_fpregset =
     ia64_linux_supply_fpregset, regcache_collect_regset
   };
 
-static const struct regset *
-ia64_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name,
-				     size_t sect_size)
+static void
+ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= IA64_LINUX_GREGS_SIZE)
-    return &ia64_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size >= IA64_LINUX_FPREGS_SIZE)
-    return &ia64_linux_fpregset;
-
-  return NULL;
+  cb (".reg", IA64_LINUX_GREGS_SIZE, &ia64_linux_gregset, NULL, cb_data);
+  cb (".reg2", IA64_LINUX_FPREGS_SIZE, &ia64_linux_fpregset, NULL, cb_data);
 }
 
 static void
@@ -248,8 +242,8 @@ ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
                                              svr4_fetch_objfile_link_map);
 
   /* Core file support. */
-  set_gdbarch_regset_from_core_section (gdbarch,
-					ia64_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, ia64_linux_iterate_over_regset_sections);
 
   /* SystemTap related.  */
   set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 20/26] SPARC: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (16 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 06/26] ARM: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 19/26] SH: " Andreas Arnez
                   ` (14 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis

For SPARC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* sparc-tdep.c (sparc_regset_from_core_section): Remove.
	(sparc_iterate_over_regset_sections): New.
	(sparc32_gdbarch_init): Adjust gdbarch initialization.
	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for SPARC FreeBSD
	targets.
	* sparc64fbsd-tdep.c (fbsd-tdep.h): Include.
	(sparc64fbsd_init_abi): Call fbsd_init_abi.
	* sparc64fbsd-nat.c (_initialize_sparc64fbsd_nat): Do not set
	target method 'make_corefile_notes'.
---
 gdb/configure.tgt      |  2 +-
 gdb/sparc-tdep.c       | 24 ++++++++++--------------
 gdb/sparc64fbsd-nat.c  |  1 -
 gdb/sparc64fbsd-tdep.c |  4 ++++
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 3111a2c..9aea728 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -543,7 +543,7 @@ sparc64-*-linux*)
 sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu)
 	# Target: FreeBSD/sparc64
 	gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64fbsd-tdep.o \
-			solib-svr4.o \
+			fbsd-tdep.o solib-svr4.o \
 			ravenscar-thread.o sparc-ravenscar-thread.o"
 	;;
 sparc-*-netbsd* | sparc-*-knetbsd*-gnu)
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index bcd4f6e..7eb3b18 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -1645,22 +1645,18 @@ sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 }
 \f
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-sparc_regset_from_core_section (struct gdbarch *gdbarch,
-				const char *sect_name, size_t sect_size)
+static void
+sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				    iterate_over_regset_sections_cb *cb,
+				    void *cb_data,
+				    const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset)
-    return tdep->gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset)
-    return tdep->fpregset;
-
-  return NULL;
+  cb (".reg", tdep->sizeof_gregset, tdep->gregset, NULL, cb_data);
+  cb (".reg2", tdep->sizeof_fpregset, tdep->fpregset, NULL, cb_data);
 }
 \f
 
@@ -1740,8 +1736,8 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* If we have register sets, enable the generic core file support.  */
   if (tdep->gregset)
-    set_gdbarch_regset_from_core_section (gdbarch,
-					  sparc_regset_from_core_section);
+    set_gdbarch_iterate_over_regset_sections
+      (gdbarch, sparc_iterate_over_regset_sections);
 
   register_sparc_ravenscar_ops (gdbarch);
 
diff --git a/gdb/sparc64fbsd-nat.c b/gdb/sparc64fbsd-nat.c
index 59a2004..67ed8f5 100644
--- a/gdb/sparc64fbsd-nat.c
+++ b/gdb/sparc64fbsd-nat.c
@@ -72,7 +72,6 @@ _initialize_sparc64fbsd_nat (void)
   t = sparc_target ();
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
-  t->to_make_corefile_notes = fbsd_make_corefile_notes;
   add_target (t);
 
   sparc_gregmap = &sparc64fbsd_gregmap;
diff --git a/gdb/sparc64fbsd-tdep.c b/gdb/sparc64fbsd-tdep.c
index 568db72..0ba6c6d 100644
--- a/gdb/sparc64fbsd-tdep.c
+++ b/gdb/sparc64fbsd-tdep.c
@@ -28,6 +28,7 @@
 #include "trad-frame.h"
 
 #include "sparc64-tdep.h"
+#include "fbsd-tdep.h"
 #include "solib-svr4.h"
 
 /* From <machine/reg.h>.  */
@@ -221,6 +222,9 @@ sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* Generic FreeBSD support. */
+  fbsd_init_abi (info, gdbarch);
+
   tdep->gregset = &sparc64fbsd_gregset;
   tdep->sizeof_gregset = 256;
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 11/26] M68K: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (11 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 17/26] PPC: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 13/26] M88K: " Andreas Arnez
                   ` (19 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andreas Schwab

For m68k BSD and GNU/Linux targets, no longer define the gdbarch
method 'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m68kbsd-tdep.c (m68kbsd_regset_from_core_section): Remove.
	(m68kbsd_iterate_over_regset_sections): New.
	(m68kbsd_init_abi): Adjust gdbarch initialization.
	* m68klinux-tdep.c (m68k_linux_regset_from_core_section): Remove.
	(m68k_linux_iterate_over_regset_sections): New.
	(m68k_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/m68kbsd-tdep.c   | 24 ++++++++++--------------
 gdb/m68klinux-tdep.c | 27 ++++++++++-----------------
 2 files changed, 20 insertions(+), 31 deletions(-)

diff --git a/gdb/m68kbsd-tdep.c b/gdb/m68kbsd-tdep.c
index 6ce12b8..a329eab 100644
--- a/gdb/m68kbsd-tdep.c
+++ b/gdb/m68kbsd-tdep.c
@@ -114,20 +114,16 @@ static const struct regset m68kbsd_fpregset =
   m68kbsd_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-m68kbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				      iterate_over_regset_sections_cb *cb,
+				      void *cb_data,
+				      const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= M68KBSD_SIZEOF_GREGS)
-    return &m68kbsd_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= M68KBSD_SIZEOF_FPREGS)
-    return &m68kbsd_fpregset;
-
-  return NULL;
+  cb (".reg", M68KBSD_SIZEOF_GREGS, &m68kbsd_gregset, NULL, cb_data);
+  cb (".reg2", M68KBSD_SIZEOF_FPREGS, &m68kbsd_fpregset, NULL, cb_data);
 }
 \f
 
@@ -195,8 +191,8 @@ m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   set_gdbarch_decr_pc_after_break (gdbarch, 2);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m68kbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m68kbsd_iterate_over_regset_sections);
 }
 
 /* OpenBSD and NetBSD a.out.  */
diff --git a/gdb/m68klinux-tdep.c b/gdb/m68klinux-tdep.c
index ae2da9a..61e3cda 100644
--- a/gdb/m68klinux-tdep.c
+++ b/gdb/m68klinux-tdep.c
@@ -369,23 +369,16 @@ static const struct regset m68k_linux_fpregset =
     regcache_supply_regset, regcache_collect_regset
   };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-m68k_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name,
-				     size_t sect_size)
+static void
+m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= M68K_LINUX_GREGS_SIZE)
-    return &m68k_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size >= M68K_LINUX_FPREGS_SIZE)
-    return &m68k_linux_fpregset;
-
-  return NULL;
+  cb (".reg", M68K_LINUX_GREGS_SIZE, &m68k_linux_gregset, NULL, cb_data);
+  cb (".reg2", M68K_LINUX_FPREGS_SIZE, &m68k_linux_fpregset, NULL, cb_data);
 }
 
 static void
@@ -423,8 +416,8 @@ m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
 
   /* Core file support. */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m68k_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m68k_linux_iterate_over_regset_sections);
 
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 09/26] X86: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (13 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 13/26] M88K: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 03/26] Add multi-arch capable 'fbsd_make_corefile_notes' variant Andreas Arnez
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis

For all I386 and AMD64 targets, replace all occurrences of
regset_from_core_section by the iterator method.

gdb/ChangeLog:

	* amd64obsd-tdep.c (amd64obsd_regset_from_core_section): Remove.
	(amd64obsd_iterate_over_regset_sections): New.
	(amd64obsd_core_init_abi): Adjust gdbarch initialization.
	* i386-cygwin-tdep.c (i386_windows_regset_from_core_section):
	Remove.
	(i386_cygwin_init_abi): Clear tdep->sizeof_fpregset.  Drop
	regset_from_core_section initialization.
	* i386-tdep.c (i386_regset_from_core_section): Remove.
	(i386_iterate_over_regset_sections): New.
	(i386_gdbarch_init): Adjust gdbarch initialization.
	* i386-tdep.h (i386_regset_from_core_section): Remove prototype.
	(i386_iterate_over_regset_sections): New prototype.
	* i386obsd-tdep.c (i386obsd_aout_regset_from_core_section):
	Remove.
	(i386obsd_aout_iterate_over_regset_sections): New.
	(i386obsd_aout_init_abi): Adjust gdbarch initialization.
	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for all x86 FreeBSD
	targets.
	* amd64fbsd-tdep.c (fbsd-tdep.h): Include.
	(amd64fbsd_init_abi): Call fbsd_init_abi.
	* i386fbsd-tdep.c (fbsd-tdep.h): Include.
	(i386fbsd4_init_abi): Call fbsd_init_abi.
	* amd64fbsd-nat.c (_initialize_amd64fbsd_nat): No longer set
	target method 'make_corefile_notes'.
	* i386fbsd-nat.c (_initialize_i386fbsd_nat): Likewise.
---
 gdb/amd64fbsd-nat.c    |  1 -
 gdb/amd64fbsd-tdep.c   |  4 ++++
 gdb/amd64obsd-tdep.c   | 19 +++++++++----------
 gdb/configure.tgt      |  4 ++--
 gdb/i386-cygwin-tdep.c | 18 ++----------------
 gdb/i386-tdep.c        | 26 +++++++++++---------------
 gdb/i386-tdep.h        | 12 ++++++------
 gdb/i386fbsd-nat.c     |  1 -
 gdb/i386fbsd-tdep.c    |  4 ++++
 gdb/i386obsd-tdep.c    | 20 +++++++++-----------
 10 files changed, 47 insertions(+), 62 deletions(-)

diff --git a/gdb/amd64fbsd-nat.c b/gdb/amd64fbsd-nat.c
index fe4e009..df101d0 100644
--- a/gdb/amd64fbsd-nat.c
+++ b/gdb/amd64fbsd-nat.c
@@ -183,7 +183,6 @@ _initialize_amd64fbsd_nat (void)
 
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
-  t->to_make_corefile_notes = fbsd_make_corefile_notes;
   add_target (t);
 
   /* Support debugging kernel virtual memory images.  */
diff --git a/gdb/amd64fbsd-tdep.c b/gdb/amd64fbsd-tdep.c
index 07b065a..13e14ad 100644
--- a/gdb/amd64fbsd-tdep.c
+++ b/gdb/amd64fbsd-tdep.c
@@ -26,6 +26,7 @@
 
 #include "amd64-tdep.h"
 #include "bsd-uthread.h"
+#include "fbsd-tdep.h"
 #include "solib-svr4.h"
 
 /* Support for signal handlers.  */
@@ -182,6 +183,9 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* Generic FreeBSD support. */
+  fbsd_init_abi (info, gdbarch);
+
   /* Obviously FreeBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
 
diff --git a/gdb/amd64obsd-tdep.c b/gdb/amd64obsd-tdep.c
index ef0c0c2..80300c8 100644
--- a/gdb/amd64obsd-tdep.c
+++ b/gdb/amd64obsd-tdep.c
@@ -57,20 +57,19 @@ static const struct regset amd64obsd_combined_regset =
     NULL, amd64obsd_supply_regset, NULL
   };
 
-static const struct regset *
-amd64obsd_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
+static void
+amd64obsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   /* OpenBSD core dumps don't use seperate register sets for the
      general-purpose and floating-point registers.  */
 
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE)
-    return &amd64obsd_combined_regset;
-
-  return NULL;
+  cb (".reg", tdep->sizeof_gregset + I387_SIZEOF_FXSAVE,
+      &amd64obsd_combined_regset, NULL, cb_data);
 }
 \f
 
@@ -492,8 +491,8 @@ amd64obsd_core_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   amd64obsd_init_abi (info, gdbarch);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, amd64obsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, amd64obsd_iterate_over_regset_sections);
 }
 \f
 
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 01311b2..4b09d3a 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -189,7 +189,7 @@ i[34567]86-*-dicos*)
 i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu)
 	# Target: FreeBSD/i386
 	gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
-			bsd-uthread.o solib-svr4.o"
+			bsd-uthread.o fbsd-tdep.o solib-svr4.o"
 	;;
 i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu)
 	# Target: NetBSD/i386
@@ -667,7 +667,7 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
 	# Target: FreeBSD/amd64
 	gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \
 			i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
-			bsd-uthread.o solib-svr4.o"
+			bsd-uthread.o fbsd-tdep.o solib-svr4.o"
 	;;
 x86_64-*-mingw* | x86_64-*-cygwin*)
         # Target: MingW/amd64
diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c
index 47c7bde..b8793c1 100644
--- a/gdb/i386-cygwin-tdep.c
+++ b/gdb/i386-cygwin-tdep.c
@@ -88,20 +88,6 @@ static int i386_windows_gregset_reg_offset[] =
 
 #define I386_WINDOWS_SIZEOF_GREGSET 716
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-
-static const struct regset *
-i386_windows_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name, size_t sect_size)
-{
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size == I386_WINDOWS_SIZEOF_GREGSET)
-    return &i386_gregset;
-
-  return NULL;
-}
-
 struct cpms_data
 {
   struct gdbarch *gdbarch;
@@ -235,9 +221,9 @@ i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->gregset_num_regs = ARRAY_SIZE (i386_windows_gregset_reg_offset);
   tdep->sizeof_gregset = I386_WINDOWS_SIZEOF_GREGSET;
 
+  tdep->sizeof_fpregset = 0;
+
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, i386_windows_regset_from_core_section);
   set_gdbarch_core_xfer_shared_libraries
     (gdbarch, windows_core_xfer_shared_libraries);
   set_gdbarch_core_pid_to_str (gdbarch, i386_windows_core_pid_to_str);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8f8cc99..f685a6a 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3818,22 +3818,19 @@ const struct regset i386_fpregset =
     NULL, i386_supply_fpregset, i386_collect_fpregset
   };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Default iterator over core file register note sections.  */
 
-const struct regset *
-i386_regset_from_core_section (struct gdbarch *gdbarch,
-			       const char *sect_name, size_t sect_size)
+void
+i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				   iterate_over_regset_sections_cb *cb,
+				   void *cb_data,
+				   const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
-    return &i386_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
-    return tdep->fpregset;
-
-  return NULL;
+  cb (".reg", tdep->sizeof_gregset, &i386_gregset, NULL, cb_data);
+  if (tdep->sizeof_fpregset)
+    cb (".reg2", tdep->sizeof_fpregset, tdep->fpregset, NULL, cb_data);
 }
 \f
 
@@ -8566,10 +8563,9 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* If we have a register mapping, enable the generic core file
      support, unless it has already been enabled.  */
   if (tdep->gregset_reg_offset
-      && !gdbarch_regset_from_core_section_p (gdbarch)
       && !gdbarch_iterate_over_regset_sections_p (gdbarch))
-    set_gdbarch_regset_from_core_section (gdbarch,
-					  i386_regset_from_core_section);
+    set_gdbarch_iterate_over_regset_sections
+      (gdbarch, i386_iterate_over_regset_sections);
 
   set_gdbarch_skip_permanent_breakpoint (gdbarch,
 					 i386_skip_permanent_breakpoint);
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index db8f4f7..90f4007 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -393,12 +393,12 @@ extern const struct regset i386_gregset;
 /* Floating-point register set. */
 extern const struct regset i386_fpregset;
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-extern const struct regset *
-  i386_regset_from_core_section (struct gdbarch *gdbarch,
-				 const char *sect_name, size_t sect_size);
-
+/* Default iterator over core file register note sections.  */
+extern void
+  i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				     iterate_over_regset_sections_cb *cb,
+				     void *cb_data,
+				     const struct regcache *regcache);
 
 extern struct displaced_step_closure *i386_displaced_step_copy_insn
   (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to,
diff --git a/gdb/i386fbsd-nat.c b/gdb/i386fbsd-nat.c
index 754677f..6fafbf0 100644
--- a/gdb/i386fbsd-nat.c
+++ b/gdb/i386fbsd-nat.c
@@ -143,7 +143,6 @@ _initialize_i386fbsd_nat (void)
   t->to_resume = i386fbsd_resume;
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
-  t->to_make_corefile_notes = fbsd_make_corefile_notes;
   add_target (t);
 
   /* Support debugging kernel virtual memory images.  */
diff --git a/gdb/i386fbsd-tdep.c b/gdb/i386fbsd-tdep.c
index 8942ad3..b37427f 100644
--- a/gdb/i386fbsd-tdep.c
+++ b/gdb/i386fbsd-tdep.c
@@ -26,6 +26,7 @@
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 #include "bsd-uthread.h"
+#include "fbsd-tdep.h"
 #include "solib-svr4.h"
 
 /* FreeBSD 3.0-RELEASE or later.  */
@@ -204,6 +205,9 @@ i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* Generic FreeBSD support. */
+  fbsd_init_abi (info, gdbarch);
+
   /* Inherit stuff from older releases.  We assume that FreeBSD
      4.0-RELEASE always uses ELF.  */
   i386fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386obsd-tdep.c b/gdb/i386obsd-tdep.c
index 2b7d48b..1fd414f 100644
--- a/gdb/i386obsd-tdep.c
+++ b/gdb/i386obsd-tdep.c
@@ -154,21 +154,19 @@ static const struct regset i386obsd_aout_gregset =
     NULL, i386obsd_aout_supply_regset, NULL
   };
 
-static const struct regset *
-i386obsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
-					const char *sect_name,
-					size_t sect_size)
+static void
+i386obsd_aout_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					    iterate_over_regset_sections_cb *cb,
+					    void *cb_data,
+					    const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   /* OpenBSD a.out core dumps don't use seperate register sets for the
      general-purpose and floating-point registers.  */
 
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
-    return &i386obsd_aout_gregset;
-
-  return NULL;
+  cb (".reg", tdep->sizeof_gregset + I387_SIZEOF_FSAVE,
+      &i386obsd_aout_gregset, NULL, cb_data);
 }
 \f
 
@@ -482,8 +480,8 @@ i386obsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   i386obsd_init_abi (info, gdbarch);
 
   /* OpenBSD a.out has a single register set.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, i386obsd_aout_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, i386obsd_aout_iterate_over_regset_sections);
 }
 
 /* OpenBSD ELF.  */
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 00/26] Regset rework
@ 2014-09-12 15:40 Andreas Arnez
  2014-09-12 15:40 ` [PATCH 01/26] Replace 'core_regset_sections' by iterator method Andreas Arnez
                   ` (32 more replies)
  0 siblings, 33 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches

Earlier this year I've posted a two-part patch series with "regset
rework preparations":

* https://sourceware.org/ml/gdb-patches/2014-05/msg00239.html
* https://sourceware.org/ml/gdb-patches/2014-07/msg00808.html

Now this patch series attempts the next major refactoring step in this
area.  It has two main goals:

* Unify GDB's capabilities with respect to core files across the
  various architectures.  In particular enable more targets for
  multi-arch capable core file generation support.

* Streamline the regset support: reduce the gdbarch interface and
  reduce overall complexity.

One important means to achieve these goals is by merging two existing
gdbarch interfaces into one.  Currently, the gdbarch variable
'core_regset_sections' enumerates the core file register notes to be
handled by GDB; it specifies each note section's BFD name, size, and
human-friendly name.  In addition, the gdbarch method
'regset_from_core_section' translates a BFD name to a register set
definition.  Both of these interfaces are merged into a single gdbarch
method 'iterate_over_regset_sections', which enumerates the core file
notes *and* provides the register set definition for each.

For illustration, a typical implementation of the gdbarch method
'regset_from_core_section' may look like this:

  static const struct regset *
  foo_regset_from_core_section (struct gdbarch *gdbarch,
                                const char *sect_name,
                                size_t sect_size)
  {
    if (strcmp (sect_name, ".reg") == 0
        && sect_size >= FOO_SIZEOF_GREGSET)
      return &foo_gregset;

    if (strcmp (sect_name, ".reg2") == 0
        && sect_size >= FOO_SIZEOF_FPREGSET)
      return &foo_fpregset;

    return NULL;
  }

The new iterator would then look like this:

  static void
  foo_iterate_over_regset_sections (struct gdbarch *gdbarch,
                                    iterate_over_regset_sections_cb *cb,
                                    void *cb_data,
                                    const struct regcache *regcache)
  {
    cb (".reg", FOO_SIZEOF_GREGSET, &foo_gregset, NULL, cb_data);
    cb (".reg2", FOO_SIZEOF_FPREGSET, &foo_fpregset, NULL, cb_data);
  }

Two kinds of targets particularly benefit from this change:

* Those which currently define the 'core_regset_sections' variable;
  they now have one less gdbarch interface to deal with.  In some
  cases this reduces the regset handling code quite substantially.

* Those which define collect_regset functions for all register sets,
  but do not define the 'core_regset_sections' variable.  They gain
  multi-arch capable core file generation support.

Since the regset rework preparations, all Linux targets fall into one
of these categories, except for CRIS -- which still uses the ancient
deprecated_add_core_fns.

Also, currently there is some fall-back handling for the case that
'regset_from_core_section' is defined and 'core_regset_sections' is
not.  This handling is removed.

The series has been compiled with --enable-targets=all on a 64-bit
platform.  It has been tested on GNU/Linux for s390x, i386, and amd64.

Any comments welcome.


Andreas Arnez (26):
  Replace 'core_regset_sections' by iterator method
  Add 'regset' parameter to 'iterate_over_regset_sections_cb'
  Add multi-arch capable 'fbsd_make_corefile_notes' variant
  AARCH64: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  ALPHA: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  ARM: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  FRV: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  HPPA: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  X86: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  M32R: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  M68K: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  IA64: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  M88K: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  MIPS: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  MN10300: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'.
  NIOS2: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  PPC: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  SCORE: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  SH: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  SPARC: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  TILEGX: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  VAX: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  XTENSA: Migrate from 'regset_from_core_section' to
    'iterate_over_regset_sections'
  Drop target method 'fbsd_make_corefile_notes'
  Linux targets: drop fall back to target method for
    'make_corefile_notes'
  Drop 'regset_from_core_section' gdbarch method

 gdb/Makefile.in          |   4 +-
 gdb/aarch64-linux-tdep.c |  26 +++----
 gdb/alpha-linux-tdep.c   |  24 +++---
 gdb/alphabsd-tdep.h      |  10 +--
 gdb/alphafbsd-tdep.c     |   5 ++
 gdb/alphanbsd-tdep.c     |  87 ++++++++++-----------
 gdb/alphaobsd-tdep.c     |   4 +-
 gdb/amd64-linux-tdep.c   |  57 +++++++++++---
 gdb/amd64-tdep.c         |  51 +------------
 gdb/amd64-tdep.h         |   2 +
 gdb/amd64fbsd-nat.c      |   1 -
 gdb/amd64fbsd-tdep.c     |   4 +
 gdb/amd64obsd-tdep.c     |  19 +++--
 gdb/arm-linux-tdep.c     |  55 ++++----------
 gdb/arm-tdep.h           |   8 +-
 gdb/armbsd-tdep.c        |  20 ++---
 gdb/armobsd-tdep.c       |   4 +-
 gdb/configure.tgt        |   8 +-
 gdb/corelow.c            |  86 ++++++++++++---------
 gdb/fbsd-nat.c           |  76 -------------------
 gdb/fbsd-nat.h           |   6 --
 gdb/fbsd-tdep.c          | 137 +++++++++++++++++++++++++++++++++
 gdb/fbsd-tdep.h          |  25 ++++++
 gdb/frv-linux-tdep.c     |  25 +++---
 gdb/gdbarch.c            |  54 +++++--------
 gdb/gdbarch.h            |  25 +++---
 gdb/gdbarch.sh           |  17 +++--
 gdb/hppa-hpux-tdep.c     |  19 +++--
 gdb/hppa-linux-tdep.c    |  22 +++---
 gdb/hppanbsd-tdep.c      |  20 +++--
 gdb/hppaobsd-tdep.c      |  24 +++---
 gdb/i386-cygwin-tdep.c   |  18 +----
 gdb/i386-linux-tdep.c    |  86 +++++++++++++--------
 gdb/i386-tdep.c          |  60 ++++-----------
 gdb/i386-tdep.h          |  16 ++--
 gdb/i386fbsd-nat.c       |   1 -
 gdb/i386fbsd-tdep.c      |   4 +
 gdb/i386obsd-tdep.c      |  20 +++--
 gdb/ia64-linux-tdep.c    |  24 +++---
 gdb/linux-nat.c          |  57 --------------
 gdb/linux-tdep.c         | 140 ++++++++++++++++++----------------
 gdb/linux-tdep.h         |   3 -
 gdb/m32r-linux-tdep.c    |  19 ++---
 gdb/m68kbsd-tdep.c       |  24 +++---
 gdb/m68klinux-tdep.c     |  27 +++----
 gdb/m88k-tdep.c          |  20 +++--
 gdb/mips-linux-tdep.c    |  47 +++++-------
 gdb/mips64obsd-tdep.c    |  20 +++--
 gdb/mipsnbsd-tdep.c      |  28 +++----
 gdb/mn10300-linux-tdep.c |  23 +++---
 gdb/nios2-linux-tdep.c   |  24 +++---
 gdb/ppc-linux-tdep.c     | 119 ++++++-----------------------
 gdb/ppcfbsd-nat.c        |   1 -
 gdb/ppcfbsd-tdep.c       |  35 ++++-----
 gdb/ppcnbsd-tdep.c       |  24 +++---
 gdb/ppcobsd-tdep.c       |  20 +++--
 gdb/procfs.c             |   2 +-
 gdb/regset.h             |   8 --
 gdb/rs6000-aix-tdep.c    |  27 +++----
 gdb/s390-linux-tdep.c    | 192 ++++++++++-------------------------------------
 gdb/score-tdep.c         |  25 +++---
 gdb/sh-linux-tdep.c      |   4 +
 gdb/sh-tdep.c            |  21 +++---
 gdb/sh-tdep.h            |   2 +
 gdb/shnbsd-tdep.c        |   1 +
 gdb/sparc-tdep.c         |  24 +++---
 gdb/sparc64fbsd-nat.c    |   1 -
 gdb/sparc64fbsd-tdep.c   |   4 +
 gdb/tilegx-linux-tdep.c  |  22 +++---
 gdb/vax-tdep.c           |  20 +++--
 gdb/xtensa-tdep.c        |  27 +++----
 71 files changed, 946 insertions(+), 1219 deletions(-)
 create mode 100644 gdb/fbsd-tdep.c
 create mode 100644 gdb/fbsd-tdep.h

-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 04/26] AARCH64: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (9 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 16/26] NIOS2: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 17/26] PPC: " Andreas Arnez
                   ` (21 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Richard Earnshaw

Don't define the 'regset_from_core_section' method, but the iterator
method instead.  This slightly reduces the code and enables non-native
use of the 'generate-core-file' command.

Also, when all instances of 'regset_from_core_section' are replaced,
it can be dropped from the gdbarch interface.

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_linux_regset_from_core_section):
	Remove.
	(aarch64_linux_iterate_over_regset_sections): New.
	(aarch64_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/aarch64-linux-tdep.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 6377977..804e767 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -215,20 +215,16 @@ const struct regset aarch64_linux_fpregset =
 
 /* Implement the "regset_from_core_section" gdbarch method.  */
 
-static const struct regset *
-aarch64_linux_regset_from_core_section (struct gdbarch *gdbarch,
-					const char *sect_name,
-					size_t sect_size)
+static void
+aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					    iterate_over_regset_sections_cb *cb,
+					    void *cb_data,
+					    const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size == AARCH64_LINUX_SIZEOF_GREGSET)
-    return &aarch64_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size == AARCH64_LINUX_SIZEOF_FPREGSET)
-    return &aarch64_linux_fpregset;
-
-  return NULL;
+  cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, &aarch64_linux_gregset,
+      NULL, cb_data);
+  cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, &aarch64_linux_fpregset,
+      NULL, cb_data);
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
@@ -376,8 +372,8 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Enable longjmp.  */
   tdep->jb_pc = 11;
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					aarch64_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, aarch64_linux_iterate_over_regset_sections);
 
   /* SystemTap related.  */
   set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 08/26] HPPA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (18 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 19/26] SH: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 16:14 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Randolph Chung

For HP PA-RISC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* hppa-hpux-tdep.c (hppa_hpux_regset_from_core_section): Remove.
	(hppa_hpux_iterate_over_regset_sections): New.
	(hppa_hpux_init_abi): Adjust gdbarch initialization.
	* hppa-linux-tdep.c (hppa_linux_regset_from_core_section): Remove.
	(hppa_linux_iterate_over_regset_sections): New.
	(hppa_linux_init_abi): Adjust.
	* hppanbsd-tdep.c (hppaobsd_regset_from_core_section): Remove.
	(hppanbsd_iterate_over_regset_sections): New.
	(hppanbsd_init_abi): Adjust.
	* hppaobsd-tdep.c (hppaobsd_regset_from_core_section): Remove.
	(hppaobsd_iterate_over_regset_sections): New.
	(hppaobsd_init_abi): Adjust.
---
 gdb/hppa-hpux-tdep.c  | 19 +++++++++----------
 gdb/hppa-linux-tdep.c | 22 +++++++++++-----------
 gdb/hppanbsd-tdep.c   | 20 +++++++++-----------
 gdb/hppaobsd-tdep.c   | 24 ++++++++++--------------
 4 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/gdb/hppa-hpux-tdep.c b/gdb/hppa-hpux-tdep.c
index 688ac9a..ee59811 100644
--- a/gdb/hppa-hpux-tdep.c
+++ b/gdb/hppa-hpux-tdep.c
@@ -1371,15 +1371,14 @@ static const struct regset hppa_hpux_regset =
   hppa_hpux_supply_save_state
 };
 
-static const struct regset *
-hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
+static void
+hppa_hpux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8)
-    return &hppa_hpux_regset;
-
-  return NULL;
+  cb (".reg", HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8, &hppa_hpux_regset,
+      NULL, cb_data);
 }
 \f
 
@@ -1495,8 +1494,8 @@ hppa_hpux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_skip_permanent_breakpoint
     (gdbarch, hppa_skip_permanent_breakpoint);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, hppa_hpux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, hppa_hpux_iterate_over_regset_sections);
 
   frame_unwind_append_unwinder (gdbarch, &hppa_hpux_sigtramp_frame_unwind);
 }
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 6bc604b..52837ee 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -472,17 +472,17 @@ static const struct regset hppa_linux_fpregset =
   regcache_supply_regset, regcache_collect_regset
 };
 
-static const struct regset *
-hppa_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name,
-				     size_t sect_size)
+static void
+hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0)
-    return &hppa_linux_regset;
-  else if (strcmp (sect_name, ".reg2") == 0)
-    return &hppa_linux_fpregset;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  return NULL;
+  cb (".reg", 80 * tdep->bytes_per_address, &hppa_linux_regset,
+      NULL, cb_data);
+  cb (".reg2", 64 * 4, &hppa_linux_fpregset, NULL, cb_data);
 }
 \f
 
@@ -520,8 +520,8 @@ hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
      more work in gcc and glibc first.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, hppa_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, hppa_linux_iterate_over_regset_sections);
 
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, hppa_dwarf_reg_to_regnum);
 
diff --git a/gdb/hppanbsd-tdep.c b/gdb/hppanbsd-tdep.c
index b3f04c7..4587466 100644
--- a/gdb/hppanbsd-tdep.c
+++ b/gdb/hppanbsd-tdep.c
@@ -184,17 +184,15 @@ static const struct regset hppanbsd_gregset =
   hppanbsd_supply_gregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-static const struct regset *
-hppanbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+hppanbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				       iterate_over_regset_sections_cb *cb,
+				       void *cb_data,
+				       const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPANBSD_SIZEOF_GREGS)
-    return &hppanbsd_gregset;
-
-  return NULL;
+  cb (".reg", HPPANBSD_SIZEOF_GREGS, &hppanbsd_gregset, NULL, cb_data);
 }
 \f
 static void
@@ -204,8 +202,8 @@ hppanbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   hppabsd_init_abi (info, gdbarch);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, hppanbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, hppanbsd_iterate_over_regset_sections);
 
   tramp_frame_prepend_unwinder (gdbarch, &hppanbsd_sigtramp_si4);
 }
diff --git a/gdb/hppaobsd-tdep.c b/gdb/hppaobsd-tdep.c
index c521359..3d2f217 100644
--- a/gdb/hppaobsd-tdep.c
+++ b/gdb/hppaobsd-tdep.c
@@ -140,20 +140,16 @@ static const struct regset hppaobsd_fpregset =
   hppaobsd_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-static const struct regset *
-hppaobsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+hppaobsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				       iterate_over_regset_sections_cb *cb,
+				       void *cb_data,
+				       const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPAOBSD_SIZEOF_GREGS)
-    return &hppaobsd_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPAOBSD_SIZEOF_FPREGS)
-    return &hppaobsd_fpregset;
-
-  return NULL;
+  cb (".reg", HPPAOBSD_SIZEOF_GREGS, &hppaobsd_gregset, NULL, cb_data);
+  cb (".reg2", HPPAOBSD_SIZEOF_FPREGS, &hppaobsd_fpregset, NULL, cb_data);
 }
 \f
 
@@ -164,8 +160,8 @@ hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   hppabsd_init_abi (info, gdbarch);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, hppaobsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, hppaobsd_iterate_over_regset_sections);
 }
 \f
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 23/26] XTENSA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (3 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 07/26] FRV: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 22/26] VAX: " Andreas Arnez
                   ` (27 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev

For Xtensa targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* xtensa-tdep.c (xtensa_regset_from_core_section): Remove.
	(xtensa_iterate_over_regset_sections): New.
	(xtensa_gdbarch_init): Adjust gdbarch initialization.
---
 gdb/xtensa-tdep.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 24ec5f0..dcdaa83 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -910,23 +910,18 @@ xtensa_gregset =
 };
 
 
-/* Return the appropriate register set for the core
-   section identified by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-static const struct regset *
-xtensa_regset_from_core_section (struct gdbarch *core_arch,
-				 const char *sect_name,
-				 size_t sect_size)
+static void
+xtensa_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				     iterate_over_regset_sections_cb *cb,
+				     void *cb_data,
+				     const struct regcache *regcache)
 {
-  DEBUGTRACE ("xtensa_regset_from_core_section "
-	      "(..., sect_name==\"%s\", sect_size==%x)\n",
-	      sect_name, (unsigned int) sect_size);
-
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= sizeof(xtensa_elf_gregset_t))
-    return &xtensa_gregset;
+  DEBUGTRACE ("xtensa_iterate_over_regset_sections\n");
 
-  return NULL;
+  cb (".reg", sizeof (xtensa_elf_gregset_t), &xtensa_gregset,
+      NULL, cb_data);
 }
 
 
@@ -3280,8 +3275,8 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   xtensa_add_reggroups (gdbarch);
   set_gdbarch_register_reggroup_p (gdbarch, xtensa_register_reggroup_p);
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					xtensa_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, xtensa_iterate_over_regset_sections);
 
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 13/26] M88K: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (12 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 11/26] M68K: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 09/26] X86: " Andreas Arnez
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis

For M88K targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m88k-tdep.c (m88k_regset_from_core_section): Remove.
	(m88k_iterate_over_regset_sections): New.
	(m88k_gdbarch_init): Adjust gdbarch initialization.
---
 gdb/m88k-tdep.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/gdb/m88k-tdep.c b/gdb/m88k-tdep.c
index 7c8506b..74d4b35 100644
--- a/gdb/m88k-tdep.c
+++ b/gdb/m88k-tdep.c
@@ -802,17 +802,15 @@ static const struct regset m88k_gregset =
   m88k_supply_gregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-static const struct regset *
-m88k_regset_from_core_section (struct gdbarch *gdbarch,
-			       const char *sect_name, size_t sect_size)
+static void
+m88k_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				   iterate_over_regset_sections_cb *cb,
+				   void *cb_data,
+				   const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= M88K_NUM_REGS * 4)
-    return &m88k_gregset;
-
-  return NULL;
+  cb (".reg", M88K_NUM_REGS * 4, &m88k_gregset, NULL, cb_data);
 }
 \f
 
@@ -842,8 +840,8 @@ m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pc_regnum (gdbarch, M88K_SXIP_REGNUM);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m88k_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m88k_iterate_over_regset_sections);
 
   set_gdbarch_print_insn (gdbarch, print_insn_m88k);
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 21/26] TILEGX: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (6 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 14/26] MIPS: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 12/26] IA64: " Andreas Arnez
                   ` (24 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jiong Wang

For TILE-Gx GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* tilegx-linux-tdep.c (TILEGX_LINUX_SIZEOF_GREGSET): New macro.
	(tilegx_regset_from_core_section): Remove.
	(tilegx_iterate_over_regset_sections): New.
	(tilegx_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/tilegx-linux-tdep.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/gdb/tilegx-linux-tdep.c b/gdb/tilegx-linux-tdep.c
index 184d00c..829a09b 100644
--- a/gdb/tilegx-linux-tdep.c
+++ b/gdb/tilegx-linux-tdep.c
@@ -83,6 +83,8 @@ static const struct regcache_map_entry tilegx_linux_regmap[] =
     { 0 }
   };
 
+#define TILEGX_LINUX_SIZEOF_GREGSET (64 * 8)
+
 /* TILE-Gx Linux kernel register set.  */
 
 static const struct regset tilegx_linux_regset =
@@ -91,15 +93,15 @@ static const struct regset tilegx_linux_regset =
   regcache_supply_regset, regcache_collect_regset
 };
 
-static const struct regset *
-tilegx_regset_from_core_section (struct gdbarch *gdbarch,
-				 const char *sect_name,
-				 size_t sect_size)
-{
-  if (strcmp (sect_name, ".reg") == 0)
-    return &tilegx_linux_regset;
 
-  return NULL;
+static void
+tilegx_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				     iterate_over_regset_sections_cb *cb,
+				     void *cb_data,
+				     const struct regcache *regcache)
+{
+  cb (".reg", TILEGX_LINUX_SIZEOF_GREGSET, &tilegx_linux_regset,
+      NULL, cb_data);
 }
 
 /* OS specific initialization of gdbarch.  */
@@ -113,8 +115,8 @@ tilegx_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   tramp_frame_prepend_unwinder (gdbarch, &tilegx_linux_rt_sigframe);
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					tilegx_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, tilegx_iterate_over_regset_sections);
 
   /* GNU/Linux uses SVR4-style shared libraries.  */
   if (arch_size == 32)
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 17/26] PPC: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (10 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 04/26] AARCH64: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 11/26] M68K: " Andreas Arnez
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kevin Buettner, Mark Kettenis

For PPC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for PowerPC
	FreeBSD targets.
	* ppcfbsd-nat.c (_initialize_ppcfbsd_nat): Do not set target
	method 'make_corefile_notes'.
	* ppcfbsd-tdep.c (fbsd-tdep.h): Include.
	(ppcfbsd_regset_from_core_section): Remove.
	(ppcfbsd_iterate_over_regset_sections): New.
	(ppcfbsd_init_abi): Call fbsd_init_abi.  Adjust gdbarch
	initialization.
	* ppcnbsd-tdep.c (ppcnbsd_regset_from_core_section): Remove.
	(ppcnbsd_iterate_over_regset_sections): New.
	(ppcnbsd_init_abi): Adjust.
	* ppcobsd-tdep.c (ppcobsd_regset_from_core_section): Remove.
	(ppcobsd_iterate_over_regset_sections): New.
	(ppcobsd_init_abi): Adjust.
	* rs6000-aix-tdep.c (rs6000_aix_regset_from_core_section): Remove.
	(rs6000_aix_iterate_over_regset_sections): New.
	(rs6000_aix_init_osabi): Adjust.
---
 gdb/configure.tgt     |  2 +-
 gdb/ppcfbsd-nat.c     |  1 -
 gdb/ppcfbsd-tdep.c    | 35 ++++++++++++++++++-----------------
 gdb/ppcnbsd-tdep.c    | 24 ++++++++++--------------
 gdb/ppcobsd-tdep.c    | 20 +++++++++-----------
 gdb/rs6000-aix-tdep.c | 27 ++++++++++-----------------
 6 files changed, 48 insertions(+), 61 deletions(-)

diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 4b09d3a..3111a2c 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -415,7 +415,7 @@ nios2*-*-*)
 powerpc*-*-freebsd*)
 	# Target: FreeBSD/powerpc
 	gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \
-		        ppcfbsd-tdep.o solib-svr4.o \
+		        ppcfbsd-tdep.o fbsd-tdep.o solib-svr4.o \
 			ravenscar-thread.o ppc-ravenscar-thread.o"
 	;;
 
diff --git a/gdb/ppcfbsd-nat.c b/gdb/ppcfbsd-nat.c
index 1b27c6b..1e33764 100644
--- a/gdb/ppcfbsd-nat.c
+++ b/gdb/ppcfbsd-nat.c
@@ -214,7 +214,6 @@ _initialize_ppcfbsd_nat (void)
   t->to_store_registers = ppcfbsd_store_inferior_registers;
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
-  t->to_make_corefile_notes = fbsd_make_corefile_notes;
   add_target (t);
 
   /* Support debugging kernel virtual memory images.  */
diff --git a/gdb/ppcfbsd-tdep.c b/gdb/ppcfbsd-tdep.c
index b78ccfc..d497c69 100644
--- a/gdb/ppcfbsd-tdep.c
+++ b/gdb/ppcfbsd-tdep.c
@@ -33,6 +33,7 @@
 #include "ppc-tdep.h"
 #include "ppc64-tdep.h"
 #include "ppcfbsd-tdep.h"
+#include "fbsd-tdep.h"
 #include "solib-svr4.h"
 
 
@@ -128,24 +129,21 @@ ppc_fbsd_fpregset (void)
   return &ppc32_fbsd_fpregset;
 }
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-ppcfbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				      iterate_over_regset_sections_cb *cb,
+				      void *cb_data,
+				      const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
-    {
-      if (tdep->wordsize == 4)
-	return &ppc32_fbsd_gregset;
-      else
-	return &ppc64_fbsd_gregset;
-    }
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
-    return &ppc32_fbsd_fpregset;
-  return NULL;
+
+  if (tdep->wordsize == 4)
+    cb (".reg", 148, &ppc32_fbsd_gregset, NULL, cb_data);
+  else
+    cb (".reg", 296, &ppc64_fbsd_gregset, NULL, cb_data);
+  cb (".reg2", 264, &ppc32_fbsd_fpregset, NULL, cb_data);
 }
 
 /* Default page size.  */
@@ -300,6 +298,9 @@ ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* Generic FreeBSD support. */
+  fbsd_init_abi (info, gdbarch);
+
   /* FreeBSD doesn't support the 128-bit `long double' from the psABI.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
@@ -329,8 +330,8 @@ ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
       set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
     }
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, ppcfbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, ppcfbsd_iterate_over_regset_sections);
 
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
diff --git a/gdb/ppcnbsd-tdep.c b/gdb/ppcnbsd-tdep.c
index a5c1e3d..0028e51 100644
--- a/gdb/ppcnbsd-tdep.c
+++ b/gdb/ppcnbsd-tdep.c
@@ -51,20 +51,16 @@ const struct regset ppcnbsd_fpregset =
   ppc_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-ppcnbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				      iterate_over_regset_sections_cb *cb,
+				      void *cb_data,
+				      const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
-    return &ppcnbsd_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
-    return &ppcnbsd_fpregset;
-
-  return NULL;
+  cb (".reg", 148, &ppcnbsd_gregset, NULL, cb_data);
+  cb (".reg2", 264, &ppcnbsd_fpregset, NULL, cb_data);
 }
 \f
 
@@ -185,8 +181,8 @@ ppcnbsd_init_abi (struct gdbarch_info info,
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, ppcnbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, ppcnbsd_iterate_over_regset_sections);
 
   tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
   tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
diff --git a/gdb/ppcobsd-tdep.c b/gdb/ppcobsd-tdep.c
index d745dd0..5e8fa43 100644
--- a/gdb/ppcobsd-tdep.c
+++ b/gdb/ppcobsd-tdep.c
@@ -80,17 +80,15 @@ const struct regset ppcobsd_fpregset =
   ppc_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-ppcobsd_regset_from_core_section (struct gdbarch *gdbarch,
-				  const char *sect_name, size_t sect_size)
+static void
+ppcobsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				      iterate_over_regset_sections_cb *cb,
+				      void *cb_data,
+				      const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= 412)
-    return &ppcobsd_gregset;
-
-  return NULL;
+  cb (".reg", 412, &ppcobsd_gregset, NULL, cb_data);
 }
 \f
 
@@ -257,8 +255,8 @@ ppcobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, ppcobsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, ppcobsd_iterate_over_regset_sections);
 
   frame_unwind_append_unwinder (gdbarch, &ppcobsd_sigtramp_frame_unwind);
 }
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 03dc8c0..0cea0b2 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -147,25 +147,18 @@ static const struct regset rs6000_aix64_regset =
   rs6000_aix_collect_regset,
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-rs6000_aix_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name, size_t sect_size)
+static void
+rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
   if (gdbarch_tdep (gdbarch)->wordsize == 4)
-    {
-      if (strcmp (sect_name, ".reg") == 0 && sect_size >= 592)
-        return &rs6000_aix32_regset;
-    }
+    cb (".reg", 592, &rs6000_aix32_regset, NULL, cb_data);
   else
-    {
-      if (strcmp (sect_name, ".reg") == 0 && sect_size >= 576)
-        return &rs6000_aix64_regset;
-    }
-
-  return NULL;
+    cb (".reg", 576, &rs6000_aix64_regset, NULL, cb_data);
 }
 
 
@@ -1065,8 +1058,8 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
     (gdbarch, rs6000_convert_from_func_ptr_addr);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, rs6000_aix_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, rs6000_aix_iterate_over_regset_sections);
   set_gdbarch_core_xfer_shared_libraries_aix
     (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 14/26] MIPS: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (5 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 22/26] VAX: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 21/26] TILEGX: " Andreas Arnez
                   ` (25 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maciej W . Rozycki, Daniel Jacobowitz

For MIPS targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* mips-linux-tdep.c (mips_linux_regset_from_core_section): Remove.
	(mips_linux_iterate_over_regset_sections): New.
	(mips_linux_init_abi): Adjust gdbarch initialization.
	* mips64obsd-tdep.c (mips64obsd_regset_from_core_section): Remove.
	(mips64obsd_iterate_over_regset_sections): New.
	(mips64obsd_init_abi): Adjust.
	* mipsnbsd-tdep.c (mipsnbsd_regset_from_core_section): Remove.
	(mipsnbsd_iterate_over_regset_sections): New.
	(mipsnbsd_init_abi): Adjust.
---
 gdb/mips-linux-tdep.c | 47 +++++++++++++++++------------------------------
 gdb/mips64obsd-tdep.c | 20 +++++++++-----------
 gdb/mipsnbsd-tdep.c   | 28 ++++++++++++----------------
 3 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index 5639870..c2cec3d 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -636,39 +636,26 @@ static const struct regset mips64_linux_fpregset =
     NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
   };
 
-static const struct regset *
-mips_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name, size_t sect_size)
+static void
+mips_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  mips_elf_gregset_t gregset;
-  mips_elf_fpregset_t fpregset;
-  mips64_elf_gregset_t gregset64;
-  mips64_elf_fpregset_t fpregset64;
-
-  if (strcmp (sect_name, ".reg") == 0)
+  if (register_size (gdbarch, MIPS_ZERO_REGNUM) == 4)
     {
-      if (sect_size == sizeof (gregset))
-	return &mips_linux_gregset;
-      else if (sect_size == sizeof (gregset64))
-	return &mips64_linux_gregset;
-      else
-	{
-	  warning (_("wrong size gregset struct in core file"));
-	}
+      cb (".reg", sizeof (mips_elf_gregset_t), &mips_linux_gregset,
+	  NULL, cb_data);
+      cb (".reg2", sizeof (mips_elf_fpregset_t), &mips_linux_fpregset,
+	  NULL, cb_data);
     }
-  else if (strcmp (sect_name, ".reg2") == 0)
+  else
     {
-      if (sect_size == sizeof (fpregset))
-	return &mips_linux_fpregset;
-      else if (sect_size == sizeof (fpregset64))
-	return &mips64_linux_fpregset;
-      else
-	{
-	  warning (_("wrong size fpregset struct in core file"));
-	}
+      cb (".reg", sizeof (mips64_elf_gregset_t), &mips64_linux_gregset,
+	  NULL, cb_data);
+      cb (".reg2", sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
+	  NULL, cb_data);
     }
-
-  return NULL;
 }
 
 static const struct target_desc *
@@ -1628,8 +1615,8 @@ mips_linux_init_abi (struct gdbarch_info info,
   set_gdbarch_core_read_description (gdbarch,
 				     mips_linux_core_read_description);
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					mips_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, mips_linux_iterate_over_regset_sections);
 
   set_gdbarch_gdb_signal_from_target (gdbarch,
 				      mips_gdb_signal_from_target);
diff --git a/gdb/mips64obsd-tdep.c b/gdb/mips64obsd-tdep.c
index e312e51..11ff357 100644
--- a/gdb/mips64obsd-tdep.c
+++ b/gdb/mips64obsd-tdep.c
@@ -64,17 +64,15 @@ static const struct regset mips64obsd_gregset =
   mips64obsd_supply_gregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-mips64obsd_regset_from_core_section (struct gdbarch *gdbarch,
-				     const char *sect_name, size_t sect_size)
+static void
+mips64obsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= MIPS64OBSD_NUM_REGS * 8)
-    return &mips64obsd_gregset;
-
-  return NULL;
+  cb (".reg", MIPS64OBSD_NUM_REGS * 8, &mips64obsd_gregset, NULL, cb_data);
 }
 \f
 
@@ -145,8 +143,8 @@ mips64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* OpenBSD/mips64 only supports the n64 ABI, but the braindamaged
      way GDB works, forces us to pretend we can handle them all.  */
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, mips64obsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, mips64obsd_iterate_over_regset_sections);
 
   tramp_frame_prepend_unwinder (gdbarch, &mips64obsd_sigframe);
 
diff --git a/gdb/mipsnbsd-tdep.c b/gdb/mipsnbsd-tdep.c
index f8aa210..926e7d9 100644
--- a/gdb/mipsnbsd-tdep.c
+++ b/gdb/mipsnbsd-tdep.c
@@ -112,24 +112,20 @@ static const struct regset mipsnbsd_fpregset =
   mipsnbsd_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-mipsnbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				   const char *sect_name, size_t sect_size)
+static void
+mipsnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				       iterate_over_regset_sections_cb *cb,
+				       void *cb_data,
+				       const struct regcache *regcache)
 {
   size_t regsize = mips_isa_regsize (gdbarch);
-  
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size >= MIPSNBSD_NUM_GREGS * regsize)
-    return &mipsnbsd_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size >= MIPSNBSD_NUM_FPREGS * regsize)
-    return &mipsnbsd_fpregset;
 
-  return NULL;
+  cb (".reg", MIPSNBSD_NUM_GREGS * regsize, &mipsnbsd_gregset,
+      NULL, cb_data);
+  cb (".reg2", MIPSNBSD_NUM_FPREGS * regsize, &mipsnbsd_fpregset,
+      NULL, cb_data);
 }
 \f
 
@@ -358,8 +354,8 @@ static void
 mipsnbsd_init_abi (struct gdbarch_info info,
                    struct gdbarch *gdbarch)
 {
-  set_gdbarch_regset_from_core_section
-    (gdbarch, mipsnbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, mipsnbsd_iterate_over_regset_sections);
 
   set_gdbarch_get_longjmp_target (gdbarch, mipsnbsd_get_longjmp_target);
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 06/26] ARM: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (15 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 03/26] Add multi-arch capable 'fbsd_make_corefile_notes' variant Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 20/26] SPARC: " Andreas Arnez
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Richard Earnshaw

For ARM BSD targets, don't define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* arm-tdep.h (armbsd_regset_from_core_section): Remove prototype.
	(armbsd_iterate_over_regset_sections): New prototype.
	* armbsd-tdep.c (armbsd_regset_from_core_section): Remove.
	(armbsd_iterate_over_regset_sections): New.
	* armobsd-tdep.c (armobsd_init_abi): Adjust gdbarch
	initialization.
---
 gdb/arm-tdep.h     |  8 +++++---
 gdb/armbsd-tdep.c  | 20 ++++++++------------
 gdb/armobsd-tdep.c |  4 ++--
 3 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
index 29669d0..1d55e78 100644
--- a/gdb/arm-tdep.h
+++ b/gdb/arm-tdep.h
@@ -341,9 +341,11 @@ extern int arm_process_record (struct gdbarch *gdbarch,
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 
-extern const struct regset *
-  armbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				   const char *sect_name, size_t sect_size);
+extern void
+  armbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				       iterate_over_regset_sections_cb *cb,
+				       void *cb_data,
+				       const struct regcache *regcache);
 
 /* Target descriptions.  */
 extern struct target_desc *tdesc_arm_with_m;
diff --git a/gdb/armbsd-tdep.c b/gdb/armbsd-tdep.c
index 62e82b8..c4c5fd0 100644
--- a/gdb/armbsd-tdep.c
+++ b/gdb/armbsd-tdep.c
@@ -107,18 +107,14 @@ static const struct regset armbsd_fpregset =
   armbsd_supply_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-const struct regset *
-armbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				 const char *sect_name, size_t sect_size)
+void
+armbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				     iterate_over_regset_sections_cb *cb,
+				     void *cb_data,
+				     const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= ARMBSD_SIZEOF_GREGS)
-    return &armbsd_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= ARMBSD_SIZEOF_FPREGS)
-    return &armbsd_fpregset;
-
-  return NULL;
+  cb (".reg", ARMBSD_SIZEOF_GREGS, &armbsd_gregset, NULL, cb_data);
+  cb (".reg2", ARMBSD_SIZEOF_FPREGS, &armbsd_fpregset, NULL, cb_data);
 }
diff --git a/gdb/armobsd-tdep.c b/gdb/armobsd-tdep.c
index f4904a3..d7bfddc 100644
--- a/gdb/armobsd-tdep.c
+++ b/gdb/armobsd-tdep.c
@@ -91,8 +91,8 @@ armobsd_init_abi (struct gdbarch_info info,
   tdep->jb_pc = 24;
   tdep->jb_elt_size = 4;
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, armbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, armbsd_iterate_over_regset_sections);
 
   /* OpenBSD/arm uses -fpcc-struct-return by default.  */
   tdep->struct_return = pcc_struct_return;
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 03/26] Add multi-arch capable 'fbsd_make_corefile_notes' variant
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (14 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 09/26] X86: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 06/26] ARM: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
                   ` (16 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis

This creates a new version of the FreeBSD core file note generation
logic in the new target-dependent file "fbsd-tdep.c".  The new version
is mostly copied from "fbsd-nat.c", but uses the iterator instead of
regset_from_core_section and defines fbsd_make_corefile_notes as a
gdbarch method instead of a target method.

Consecutive architecture-dependent changes exploit the new version,
migrating away from the target method.  When all FreeBSD targets are
changed, the target method can go away.

gdb/ChangeLog:

	* fbsd-tdep.c: New file.
	* fbsd-tdep.h: New file.
	* Makefile.in (ALL_TARGET_OBS): Add fbsd-tdep.o.
	(HFILES_NO_SRCDIR): Add fbsd-tdep.h.
	(ALLDEPFILES): Add fbsd-tdep.c.
---
 gdb/Makefile.in |   4 +-
 gdb/fbsd-tdep.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/fbsd-tdep.h |  25 +++++++++++
 3 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 gdb/fbsd-tdep.c
 create mode 100644 gdb/fbsd-tdep.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f6b9176..409f5fa 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -625,6 +625,7 @@ ALL_TARGET_OBS = \
 	bfin-linux-tdep.o bfin-tdep.o \
 	cris-linux-tdep.o cris-tdep.o \
 	dicos-tdep.o \
+	fbsd-tdep.o \
 	frv-linux-tdep.o frv-tdep.o \
 	h8300-tdep.o \
 	hppabsd-tdep.o hppanbsd-tdep.o hppaobsd-tdep.o \
@@ -938,7 +939,7 @@ target/wait.h target/waitstatus.h nat/linux-nat.h nat/linux-waitpid.h \
 common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \
 i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
-common/common-exceptions.h target/target.h common/symbol.h
+common/common-exceptions.h target/target.h common/symbol.h fbsd-tdep.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -1621,6 +1622,7 @@ ALLDEPFILES = \
 	dcache.c dicos-tdep.c darwin-nat.c \
 	exec.c \
 	fbsd-nat.c \
+	fbsd-tdep.c \
 	fork-child.c \
 	glibc-tdep.c \
 	go32-nat.c h8300-tdep.c \
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
new file mode 100644
index 0000000..a60fbc2
--- /dev/null
+++ b/gdb/fbsd-tdep.c
@@ -0,0 +1,137 @@
+/* Target-dependent code for FreeBSD, architecture-independent.
+
+   Copyright (C) 2002-2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "gdbcore.h"
+#include "inferior.h"
+#include "regcache.h"
+#include "regset.h"
+#include "gdbthread.h"
+
+#include "gdb_assert.h"
+#include <string.h>
+
+#include "elf-bfd.h"
+#include "fbsd-tdep.h"
+
+
+static int
+find_signalled_thread (struct thread_info *info, void *data)
+{
+  if (info->suspend.stop_signal != GDB_SIGNAL_0
+      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
+    return 1;
+
+  return 0;
+}
+
+static enum gdb_signal
+find_stop_signal (void)
+{
+  struct thread_info *info =
+    iterate_over_threads (find_signalled_thread, NULL);
+
+  if (info)
+    return info->suspend.stop_signal;
+  else
+    return GDB_SIGNAL_0;
+}
+
+struct fbsd_collect_regset_section_cb_data
+{
+  const struct regcache *regcache;
+  bfd *obfd;
+  char *note_data;
+  int *note_size;
+};
+
+static void
+fbsd_collect_regset_section_cb (const char *sect_name, int size,
+				const struct regset *regset,
+				const char *human_name, void *cb_data)
+{
+  char *buf;
+  struct fbsd_collect_regset_section_cb_data *data = cb_data;
+
+  gdb_assert (regset->collect_regset);
+
+  buf = xmalloc (size);
+  regset->collect_regset (regset, data->regcache, -1, buf, size);
+
+  /* PRSTATUS still needs to be treated specially.  */
+  if (strcmp (sect_name, ".reg") == 0)
+    data->note_data = (char *) elfcore_write_prstatus
+      (data->obfd, data->note_data, data->note_size,
+       ptid_get_pid (inferior_ptid), find_stop_signal (), buf);
+  else
+    data->note_data = (char *) elfcore_write_register_note
+      (data->obfd, data->note_data, data->note_size,
+       sect_name, buf, size);
+  xfree (buf);
+}
+
+/* Create appropriate note sections for a corefile, returning them in
+   allocated memory.  */
+
+static char *
+fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
+{
+  const struct regcache *regcache = get_current_regcache ();
+  char *note_data;
+  Elf_Internal_Ehdr *i_ehdrp;
+  struct fbsd_collect_regset_section_cb_data data;
+
+  /* Put a "FreeBSD" label in the ELF header.  */
+  i_ehdrp = elf_elfheader (obfd);
+  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+
+  gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
+
+  data.regcache = regcache;
+  data.obfd = obfd;
+  data.note_data = NULL;
+  data.note_size = note_size;
+  gdbarch_iterate_over_regset_sections (gdbarch,
+					fbsd_collect_regset_section_cb,
+					&data, regcache);
+  note_data = data.note_data;
+
+  if (get_exec_file (0))
+    {
+      const char *fname = lbasename (get_exec_file (0));
+      char *psargs = xstrdup (fname);
+
+      if (get_inferior_args ())
+	psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
+			   (char *) NULL);
+
+      note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
+					  fname, psargs);
+    }
+
+  return note_data;
+}
+
+/* To be called from GDB_OSABI_FREEBSD_ELF handlers. */
+
+void
+fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes);
+}
diff --git a/gdb/fbsd-tdep.h b/gdb/fbsd-tdep.h
new file mode 100644
index 0000000..0a592ae
--- /dev/null
+++ b/gdb/fbsd-tdep.h
@@ -0,0 +1,25 @@
+/* Target-dependent code for FreeBSD, architecture independent.
+
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef FBSD_TDEP_H
+#define FBSD_TDEP_H
+
+extern void fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
+
+#endif /* fbsd-tdep.h */
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 05/26] ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
  2014-09-12 15:40 ` [PATCH 01/26] Replace 'core_regset_sections' by iterator method Andreas Arnez
  2014-09-12 15:40 ` [PATCH 26/26] Drop 'regset_from_core_section' gdbarch method Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 07/26] FRV: " Andreas Arnez
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis, Richard Henderson

Don't define the 'regset_from_core_section' method, but the iterator
method instead.  Do this for GNU/Linux- as well as
Net/OpenBSD-targets.  In the case of GNU/Linux this should enable
non-native use of the 'generate-core-file' command.

gdb/ChangeLog:

	* alpha-linux-tdep.c (alpha_linux_regset_from_core_section): Remove.
	(alpha_linux_iterate_over_regset_sections): New.
	(alpha_linux_init_abi): Adjust gdbarch initialization.
	* alphabsd-tdep.h (alphanbsd_regset_from_core_section): Remove
	prototype.
	(alphanbsd_iterate_over_regset_sections): New prototype.
    	* alphafbsd-tdep.c (alphafbsd_init_abi): Add comment for missing
    	fbsd_init_abi invocation.
	* alphanbsd-tdep.c (alphanbsd_supply_gregset): Move below
	alphanbsd_aout_supply_gregset.  Invoke the latter for the
	appropriate size.
	(alphanbsd_aout_gregset): Remove.
	(alphanbsd_regset_from_core_section): Remove.
	(alphanbsd_iterate_over_regset_sections): New.
	(alphanbsd_init_abi): Adjust gdbarch initialization.
	* alphaobsd-tdep.c (alphaobsd_init_abi): Likewise.
---
 gdb/alpha-linux-tdep.c | 24 ++++++--------
 gdb/alphabsd-tdep.h    | 10 +++---
 gdb/alphafbsd-tdep.c   |  5 +++
 gdb/alphanbsd-tdep.c   | 87 ++++++++++++++++++++++----------------------------
 gdb/alphaobsd-tdep.c   |  4 +--
 5 files changed, 60 insertions(+), 70 deletions(-)

diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index 51ce1a7..e56be7e 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -230,20 +230,16 @@ static const struct regset alpha_linux_fpregset =
   alpha_linux_supply_fpregset, alpha_linux_collect_fpregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-alpha_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				      const char *sect_name, size_t sect_size)
+static void
+alpha_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					  iterate_over_regset_sections_cb *cb,
+					  void *cb_data,
+					  const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= 32 * 8)
-    return &alpha_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 32 * 8)
-    return &alpha_linux_fpregset;
-
-  return NULL;
+  cb (".reg", 32 * 8, &alpha_linux_gregset, NULL, cb_data);
+  cb (".reg2", 32 * 8, &alpha_linux_fpregset, NULL, cb_data);
 }
 
 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
@@ -383,8 +379,8 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
                                              svr4_fetch_objfile_link_map);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, alpha_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, alpha_linux_iterate_over_regset_sections);
 
   set_gdbarch_gdb_signal_from_target (gdbarch,
 				      alpha_linux_gdb_signal_from_target);
diff --git a/gdb/alphabsd-tdep.h b/gdb/alphabsd-tdep.h
index def7b04..a724ff7 100644
--- a/gdb/alphabsd-tdep.h
+++ b/gdb/alphabsd-tdep.h
@@ -31,10 +31,10 @@ void alphabsd_fill_fpreg (const struct regcache *, char *, int);
 
 /* Functions exported from alphanbsd-tdep.c.  */
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-extern const struct regset *
-  alphanbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				      const char *sect_name, size_t len);
+/* Iterate over supported core file register note sections. */
+void alphanbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					     iterate_over_regset_sections_cb *cb,
+					     void *cb_data,
+					     const struct regcache *regcache);
 
 #endif /* alphabsd-tdep.h */
diff --git a/gdb/alphafbsd-tdep.c b/gdb/alphafbsd-tdep.c
index 95b64a0..2b7e36e 100644
--- a/gdb/alphafbsd-tdep.c
+++ b/gdb/alphafbsd-tdep.c
@@ -93,6 +93,11 @@ alphafbsd_init_abi (struct gdbarch_info info,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* FIXME: Should activate generic FreeBSD support here with
+     fbsd_init_abi(), but this requires a valid
+     'iterate_over_regset_sections' gdbarch method and
+     'collect_regset' functions for each regset.  */
+
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
 
diff --git a/gdb/alphanbsd-tdep.c b/gdb/alphanbsd-tdep.c
index a4dd6e9..1c2e630 100644
--- a/gdb/alphanbsd-tdep.c
+++ b/gdb/alphanbsd-tdep.c
@@ -73,30 +73,6 @@ alphanbsd_supply_fpregset (const struct regset *regset,
    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
 
 static void
-alphanbsd_supply_gregset (const struct regset *regset,
-			  struct regcache *regcache,
-			  int regnum, const void *gregs, size_t len)
-{
-  const gdb_byte *regs = gregs;
-  int i;
-
-  gdb_assert (len >= ALPHANBSD_SIZEOF_GREGS);
-
-  for (i = 0; i < ALPHA_ZERO_REGNUM; i++)
-    {
-      if (regnum == i || regnum == -1)
-	regcache_raw_supply (regcache, i, regs + i * 8);
-    }
-
-  if (regnum == ALPHA_PC_REGNUM || regnum == -1)
-    regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
-}
-
-/* Supply register REGNUM from the buffer specified by GREGS and LEN
-   in the general-purpose register set REGSET to register cache
-   REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
-
-static void
 alphanbsd_aout_supply_gregset (const struct regset *regset,
 			       struct regcache *regcache,
 			       int regnum, const void *gregs, size_t len)
@@ -136,6 +112,34 @@ alphanbsd_aout_supply_gregset (const struct regset *regset,
     }
 }
 
+/* Supply register REGNUM from the buffer specified by GREGS and LEN
+   in the general-purpose register set REGSET to register cache
+   REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
+
+static void
+alphanbsd_supply_gregset (const struct regset *regset,
+			  struct regcache *regcache,
+			  int regnum, const void *gregs, size_t len)
+{
+  const gdb_byte *regs = gregs;
+  int i;
+
+  if (len >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
+    {
+      alphanbsd_aout_supply_gregset (regset, regcache, regnum, gregs, len);
+      return;
+    }
+
+  for (i = 0; i < ALPHA_ZERO_REGNUM; i++)
+    {
+      if (regnum == i || regnum == -1)
+	regcache_raw_supply (regcache, i, regs + i * 8);
+    }
+
+  if (regnum == ALPHA_PC_REGNUM || regnum == -1)
+    regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
+}
+
 /* NetBSD/alpha register sets.  */
 
 static const struct regset alphanbsd_gregset =
@@ -150,31 +154,16 @@ static const struct regset alphanbsd_fpregset =
   alphanbsd_supply_fpregset
 };
 
-static const struct regset alphanbsd_aout_gregset =
-{
-  NULL,
-  alphanbsd_aout_supply_gregset
-};
-
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-const struct regset *
-alphanbsd_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
+void
+alphanbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= ALPHANBSD_SIZEOF_GREGS)
-    {
-      if (sect_size >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
-	return &alphanbsd_aout_gregset;
-      else
-	return &alphanbsd_gregset;
-    }
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= ALPHANBSD_SIZEOF_FPREGS)
-    return &alphanbsd_fpregset;
-
-  return NULL;
+  cb (".reg", ALPHANBSD_SIZEOF_GREGS, &alphanbsd_gregset, NULL, cb_data);
+  cb (".reg2", ALPHANBSD_SIZEOF_FPREGS, &alphanbsd_fpregset, NULL, cb_data);
 }
 \f
 
@@ -283,8 +272,8 @@ alphanbsd_init_abi (struct gdbarch_info info,
   tdep->jb_pc = 2;
   tdep->jb_elt_size = 8;
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, alphanbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, alphanbsd_iterate_over_regset_sections);
 }
 \f
 
diff --git a/gdb/alphaobsd-tdep.c b/gdb/alphaobsd-tdep.c
index 5c2a8b0..fcddd3a 100644
--- a/gdb/alphaobsd-tdep.c
+++ b/gdb/alphaobsd-tdep.c
@@ -121,8 +121,8 @@ alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->jb_pc = 2;
   tdep->jb_elt_size = 8;
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, alphanbsd_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, alphanbsd_iterate_over_regset_sections);
 }
 \f
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 16/26] NIOS2: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (8 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 12/26] IA64: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 04/26] AARCH64: " Andreas Arnez
                   ` (22 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Yao Qi

For Nios II GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* nios2-linux-tdep.c (NIOS2_GREGS_SIZE): New macro.
	(nios2_regset_from_core_section): Remove.
	(nios2_iterate_over_regset_sections): New.
	(nios2_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/nios2-linux-tdep.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index b9ee922..95098ea 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -49,6 +49,11 @@ static const int reg_offsets[NIOS2_NUM_REGS] =
   -1, -1, -1, -1, -1, -1, -1, -1
 };
 
+/* General register set size.  Should match sizeof (struct pt_regs) +
+   sizeof (struct switch_stack) from the NIOS2 Linux kernel patch.  */
+
+#define NIOS2_GREGS_SIZE (4 * 34)
+
 /* Implement the supply_regset hook for core files.  */
 
 static void
@@ -97,16 +102,15 @@ static const struct regset nios2_core_regset =
   nios2_collect_gregset
 };
 
-/* Implement the regset_from_core_section gdbarch method.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-nios2_regset_from_core_section (struct gdbarch *gdbarch,
-                                const char *sect_name, size_t sect_size)
+static void
+nios2_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				    iterate_over_regset_sections_cb *cb,
+				    void *cb_data,
+				    const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0)
-    return &nios2_core_regset;
-
-  return NULL;
+  cb (".reg", NIOS2_GREGS_SIZE, &nios2_core_regset, NULL, cb_data);
 }
 
 /* Initialize a trad-frame cache corresponding to the tramp-frame.
@@ -181,8 +185,8 @@ nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
                                              svr4_fetch_objfile_link_map);
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section (gdbarch,
-                                        nios2_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, nios2_iterate_over_regset_sections);
   /* Linux signal frame unwinders.  */
   tramp_frame_prepend_unwinder (gdbarch,
                                 &nios2_linux_rt_sigreturn_tramp_frame);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 22/26] VAX: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (4 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 23/26] XTENSA: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 14/26] MIPS: " Andreas Arnez
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches

For VAX targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* vax-tdep.c (vax_regset_from_core_section): Remove.
	(vax_iterate_over_regset_sections): New.
	(vax_gdbarch_init): Adjust gdbarch initialization.
---
 gdb/vax-tdep.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c
index 0f47002..2793261b 100644
--- a/gdb/vax-tdep.c
+++ b/gdb/vax-tdep.c
@@ -89,17 +89,15 @@ static const struct regset vax_gregset =
   vax_supply_gregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-vax_regset_from_core_section (struct gdbarch *gdbarch,
-			      const char *sect_name, size_t sect_size)
+static void
+vax_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				  iterate_over_regset_sections_cb *cb,
+				  void *cb_data,
+				  const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= VAX_NUM_REGS * 4)
-    return &vax_gregset;
-
-  return NULL;
+  cb (".reg", VAX_NUM_REGS * 4, &vax_gregset, NULL, cb_data);
 }
 \f
 /* The VAX UNIX calling convention uses R1 to pass a structure return
@@ -483,8 +481,8 @@ vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM);
   set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM);
 
-  set_gdbarch_regset_from_core_section
-    (gdbarch, vax_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, vax_iterate_over_regset_sections);
 
   /* Frame and stack info */
   set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 07/26] FRV: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (2 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 05/26] ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 23/26] XTENSA: " Andreas Arnez
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches

For FR-V GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* frv-linux-tdep.c (frv_linux_regset_from_core_section): Remove.
	(frv_linux_iterate_over_regset_sections): New.
	(frv_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/frv-linux-tdep.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/gdb/frv-linux-tdep.c b/gdb/frv-linux-tdep.c
index d962845..824cf99 100644
--- a/gdb/frv-linux-tdep.c
+++ b/gdb/frv-linux-tdep.c
@@ -443,19 +443,16 @@ static const struct regset frv_linux_fpregset =
   regcache_supply_regset, regcache_collect_regset
 };
 
-static const struct regset *
-frv_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
+static void
+frv_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					iterate_over_regset_sections_cb *cb,
+					void *cb_data,
+					const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 
-      && sect_size >= sizeof (frv_elf_gregset_t))
-    return &frv_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 
-      && sect_size >= sizeof (frv_elf_fpregset_t))
-    return &frv_linux_fpregset;
-
-  return NULL;
+  cb (".reg", sizeof (frv_elf_gregset_t), &frv_linux_gregset,
+      NULL, cb_data);
+  cb (".reg2", sizeof (frv_elf_fpregset_t), &frv_linux_fpregset,
+      NULL, cb_data);
 }
 
 \f
@@ -467,8 +464,8 @@ frv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Set the sigtramp frame sniffer.  */
   frame_unwind_append_unwinder (gdbarch, &frv_linux_sigtramp_frame_unwind); 
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-                                        frv_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, frv_linux_iterate_over_regset_sections);
 }
 
 static enum gdb_osabi
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 19/26] SH: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (17 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 20/26] SPARC: " Andreas Arnez
@ 2014-09-12 15:40 ` Andreas Arnez
  2014-09-12 15:40 ` [PATCH 08/26] HPPA: " Andreas Arnez
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 15:40 UTC (permalink / raw)
  To: gdb-patches

For Super-H targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* sh-linux-tdep.c (sh_linux_init_abi): Set tdep fields
	'sizeof_gregset' and 'sizeof_fpregset'.
	* sh-tdep.c (sh_regset_from_core_section): Remove.
	(sh_iterate_over_regset_sections): New.
	(sh_gdbarch_init): Adjust gdbarch initialization.
	* sh-tdep.h (struct gdbarch_tdep): New fields sizeof_gregset and
	sizeof_fpregset.
	* shnbsd-tdep.c (shnbsd_init_abi): Set tdep field
	'sizeof_gregset'.
---
 gdb/sh-linux-tdep.c |  4 ++++
 gdb/sh-tdep.c       | 21 +++++++++++----------
 gdb/sh-tdep.h       |  2 ++
 gdb/shnbsd-tdep.c   |  1 +
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index 19cba41..2cc9fb8 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -200,8 +200,12 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
     {
       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+      /* Remember regset characteristics.  The sizes should match
+	 elf_gregset_t and elf_fpregset_t from Linux.  */
       tdep->core_gregmap = (struct sh_corefile_regmap *)gregs_table;
+      tdep->sizeof_gregset = 92;
       tdep->core_fpregmap = (struct sh_corefile_regmap *)fpregs_table;
+      tdep->sizeof_fpregset = 136;
 
       tramp_frame_prepend_unwinder (gdbarch, &sh_linux_sigreturn_tramp_frame);
       tramp_frame_prepend_unwinder (gdbarch, &sh_linux_rt_sigreturn_tramp_frame);
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index c8c36db..d91a292 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -2207,19 +2207,19 @@ static const struct regset sh_corefile_fpregset =
   sh_corefile_collect_regset
 };
 
-static const struct regset *
-sh_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name,
-			     size_t sect_size)
+static void
+sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				 iterate_over_regset_sections_cb *cb,
+				 void *cb_data,
+				 const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  if (tdep->core_gregmap && strcmp (sect_name, ".reg") == 0)
-    return &sh_corefile_gregset;
-
-  if (tdep->core_fpregmap && strcmp (sect_name, ".reg2") == 0)
-    return &sh_corefile_fpregset;
+  if (tdep->core_gregmap != NULL)
+    cb (".reg", tdep->sizeof_gregset, &sh_corefile_gregset, NULL, cb_data);
 
-  return NULL;
+  if (tdep->core_fpregmap != NULL)
+    cb (".reg2", tdep->sizeof_fpregset, &sh_corefile_fpregset, NULL, cb_data);
 }
 
 /* This is the implementation of gdbarch method
@@ -2298,7 +2298,8 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   dwarf2_frame_set_init_reg (gdbarch, sh_dwarf2_frame_init_reg);
 
-  set_gdbarch_regset_from_core_section (gdbarch, sh_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, sh_iterate_over_regset_sections);
 
   switch (info.bfd_arch_info->mach)
     {
diff --git a/gdb/sh-tdep.h b/gdb/sh-tdep.h
index 5d64c74..da96a84 100644
--- a/gdb/sh-tdep.h
+++ b/gdb/sh-tdep.h
@@ -95,10 +95,12 @@ struct gdbarch_tdep
      where each general-purpose register is stored inside the associated
      core file section.  */
   struct sh_corefile_regmap *core_gregmap;
+  int sizeof_gregset;
   /* Non-NULL when debugging from a core file and when FP registers are
      available.  Provides the offset where each FP register is stored
      inside the associated core file section.  */
   struct sh_corefile_regmap *core_fpregmap;
+  int sizeof_fpregset;
 };
 
 extern const struct regset sh_corefile_gregset;
diff --git a/gdb/shnbsd-tdep.c b/gdb/shnbsd-tdep.c
index 2936661..a81c2a1 100644
--- a/gdb/shnbsd-tdep.c
+++ b/gdb/shnbsd-tdep.c
@@ -64,6 +64,7 @@ shnbsd_init_abi (struct gdbarch_info info,
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
+  tdep->sizeof_gregset = 84;
 
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (19 preceding siblings ...)
  2014-09-12 15:40 ` [PATCH 08/26] HPPA: " Andreas Arnez
@ 2014-09-12 16:14 ` Andreas Arnez
  2014-09-12 16:15 ` [PATCH 10/26] M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:14 UTC (permalink / raw)
  To: gdb-patches

This adds the 'regset' parameter to the iterator callback.
Consequently the 'regset_from_core_section' method is dropped for all
targets that provide the iterator method.

This change prepares for replacing regset_from_core_section
everywhere, thereby eliminating one gdbarch interface.  Since the
iterator is usually no more complex than regset_from_core_section
alone, targets that previously didn't define core_regset_sections will
then gain multi-arch capable core file generation support without
increased complexity.

gdb/ChangeLog:

	* gdbarch.sh (iterate_over_regset_sections_cb): Add regset
	parameter.
	* gdbarch.h: Regenerate.
	* corelow.c (sniff_core_bfd): Don't sniff if gdbarch has a regset
	iterator.
	(get_core_register_section): Add parameter 'regset' and use it, if
	set.  Add parameter 'min_size' and verify the bfd section size
	against it.
	(get_core_registers_cb): Add parameter 'regset' and pass it to
	get_core_register section.  For the "standard" register sections
	".reg" and ".reg2", set an appropriate default for human_name.
	(get_core_registers): Don't abort when the gdbarch has an iterator
	but no regset_from_core_section.  Add NULL/0 for parameters
	'regset'/'min_size' in calls to get_core_register_section.
	* linux-tdep.c (linux_collect_regset_section_cb): Add parameter
	'regset' and use it instead of calling the
	regset_from_core_section gdbarch method.
	* i386-tdep.h (struct gdbarch_tdep): Add field 'fpregset'.
	* i386-tdep.c (i386_supply_xstateregset)
	(i386_collect_xstateregset, i386_xstateregset): Moved to
	i386-linux-tdep.c.
	(i386_regset_from_core_section): Drop handling for .reg-xfp and
	.reg-xstate.
	(i386_gdbarch_init): Set tdep field 'fpregset'.  Enable generic
	core file support only if the regset iterator hasn't been set.
	* i386-linux-tdep.c (i386_linux_supply_xstateregset)
	(i386_linux_collect_xstateregset, i386_linux_xstateregset): New.
	Moved from i386-tdep.c and renamed to *_linux*.
	(i386_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.  Allow any .reg-xstate size when reading
	from a core file.
	* amd64-tdep.c (amd64_supply_xstateregset)
	(amd64_collect_xstateregset, amd64_xstateregset): Moved to
	amd64-linux-tdep.c.
	(amd64_regset_from_core_section): Remove.
	(amd64_init_abi): Set new tdep field 'fpregset'.  No longer
	install an amd64-specific regset_from_core_section gdbarch method.
	* amd64-linux-tdep.c (amd64_linux_supply_xstateregset)
	(amd64_linux_collect_xstateregset, amd64_linux_xstateregset): New.
	Moved from amd64-tdep.c and renamed to *_linux*.
	(amd64_linux_iterate_over_regset_sections): Add regset parameter
	to each callback invocation.  Allow any .reg-xstate size when
	reading from a core file.
	* arm-linux-tdep.c (arm_linux_regset_from_core_section): Remove.
	(arm_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(arm_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* ppc-linux-tdep.c (ppc_linux_regset_from_core_section): Remove.
	(ppc_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(ppc_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* s390-linux-tdep.c (struct gdbarch_tdep): Remove the fields
	gregset, sizeof_gregset, fpregset, and sizeof_fpregset.
	(s390_regset_from_core_section): Remove.
	(s390_iterate_over_regset_sections): Add regset parameter to each
	callback invocation.
	(s390_gdbarch_init): No longer set the regset_from_core_section
	gdbarch method.  Drop initialization of deleted tdep fields.
---
 gdb/amd64-linux-tdep.c | 36 +++++++++++++++++++++++---
 gdb/amd64-tdep.c       | 51 ++-----------------------------------
 gdb/amd64-tdep.h       |  2 ++
 gdb/arm-linux-tdep.c   | 33 ++++--------------------
 gdb/corelow.c          | 52 +++++++++++++++++++++++++++----------
 gdb/gdbarch.h          |  3 ++-
 gdb/gdbarch.sh         |  3 ++-
 gdb/i386-linux-tdep.c  | 40 ++++++++++++++++++++++++++---
 gdb/i386-tdep.c        | 42 +++++-------------------------
 gdb/i386-tdep.h        |  6 +++++
 gdb/linux-tdep.c       |  3 +--
 gdb/ppc-linux-tdep.c   | 35 ++++++-------------------
 gdb/s390-linux-tdep.c  | 69 ++++++++++----------------------------------------
 13 files changed, 157 insertions(+), 218 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 2432bae..edbb1b3 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1600,6 +1600,33 @@ amd64_linux_core_read_description (struct gdbarch *gdbarch,
     }
 }
 
+/* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
+
+static void
+amd64_linux_supply_xstateregset (const struct regset *regset,
+				 struct regcache *regcache, int regnum,
+				 const void *xstateregs, size_t len)
+{
+  amd64_supply_xsave (regcache, regnum, xstateregs);
+}
+
+/* Similar to amd64_collect_fpregset, but use XSAVE extended state.  */
+
+static void
+amd64_linux_collect_xstateregset (const struct regset *regset,
+				  const struct regcache *regcache,
+				  int regnum, void *xstateregs, size_t len)
+{
+  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
+}
+
+static const struct regset amd64_linux_xstateregset =
+  {
+    NULL,
+    amd64_linux_supply_xstateregset,
+    amd64_linux_collect_xstateregset
+  };
+
 /* Iterate over core file register note sections.  */
 
 static void
@@ -1608,9 +1635,12 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  cb (".reg", 27 * 8, "general-purpose", cb_data);
-  cb (".reg2", 512, "floating-point", cb_data);
-  cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  cb (".reg", 27 * 8, &i386_gregset, NULL, cb_data);
+  cb (".reg2", 512, &amd64_fpregset, NULL, cb_data);
+  cb (".reg-xstate",  regcache ? X86_XSTATE_MAX_SIZE : 0,
+      &amd64_linux_xstateregset, "XSAVE extended state", cb_data);
 }
 
 static void
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index abd9c48..7c8575a 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2868,53 +2868,10 @@ amd64_collect_fpregset (const struct regset *regset,
   amd64_collect_fxsave (regcache, regnum, fpregs);
 }
 
-/* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
-
-static void
-amd64_supply_xstateregset (const struct regset *regset,
-			   struct regcache *regcache, int regnum,
-			   const void *xstateregs, size_t len)
-{
-  amd64_supply_xsave (regcache, regnum, xstateregs);
-}
-
-/* Similar to amd64_collect_fpregset, but use XSAVE extended state.  */
-
-static void
-amd64_collect_xstateregset (const struct regset *regset,
-			    const struct regcache *regcache,
-			    int regnum, void *xstateregs, size_t len)
-{
-  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
-}
-
-static const struct regset amd64_fpregset =
+const struct regset amd64_fpregset =
   {
     NULL, amd64_supply_fpregset, amd64_collect_fpregset
   };
-
-static const struct regset amd64_xstateregset =
-  {
-    NULL, amd64_supply_xstateregset, amd64_collect_xstateregset
-  };
-
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-
-static const struct regset *
-amd64_regset_from_core_section (struct gdbarch *gdbarch,
-				const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
-    return &amd64_fpregset;
-
-  if (strcmp (sect_name, ".reg-xstate") == 0)
-    return &amd64_xstateregset;
-
-  return i386_regset_from_core_section (gdbarch, sect_name, sect_size);
-}
 \f
 
 /* Figure out where the longjmp will land.  Slurp the jmp_buf out of
@@ -2973,6 +2930,7 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* AMD64 generally uses `fxsave' instead of `fsave' for saving its
      floating-point registers.  */
   tdep->sizeof_fpregset = I387_SIZEOF_FXSAVE;
+  tdep->fpregset = &amd64_fpregset;
 
   if (! tdesc_has_registers (tdesc))
     tdesc = tdesc_amd64;
@@ -3086,11 +3044,6 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   frame_unwind_append_unwinder (gdbarch, &amd64_frame_unwind);
   frame_base_set_default (gdbarch, &amd64_frame_base);
 
-  /* If we have a register mapping, enable the generic core file support.  */
-  if (tdep->gregset_reg_offset)
-    set_gdbarch_regset_from_core_section (gdbarch,
-					  amd64_regset_from_core_section);
-
   set_gdbarch_get_longjmp_target (gdbarch, amd64_get_longjmp_target);
 
   set_gdbarch_relocate_instruction (gdbarch, amd64_relocate_instruction);
diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
index f1b039e..641eef3 100644
--- a/gdb/amd64-tdep.h
+++ b/gdb/amd64-tdep.h
@@ -119,6 +119,8 @@ extern void amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 extern void amd64_collect_xsave (const struct regcache *regcache,
 				 int regnum, void *xsave, int gcore);
 \f
+/* Floating-point register set. */
+extern const struct regset amd64_fpregset;
 
 /* Variables exported from amd64-linux-tdep.c.  */
 extern int amd64_linux_gregset_reg_offset[];
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 22decd5..e3587f3 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -731,28 +731,6 @@ static const struct regset arm_linux_vfpregset =
     NULL, arm_linux_supply_vfp, arm_linux_collect_vfp
   };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-
-static const struct regset *
-arm_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
-{
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size == ARM_LINUX_SIZEOF_GREGSET)
-    return &arm_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size == ARM_LINUX_SIZEOF_NWFPE)
-    return &arm_linux_fpregset;
-
-  if (strcmp (sect_name, ".reg-arm-vfp") == 0
-      && sect_size == ARM_LINUX_SIZEOF_VFP)
-    return &arm_linux_vfpregset;
-
-  return NULL;
-}
-
 /* Iterate over core file register note sections.  */
 
 static void
@@ -763,13 +741,14 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose", cb_data);
+  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, &arm_linux_gregset, NULL, cb_data);
 
   if (tdep->have_vfp_registers)
-    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point",
-	cb_data);
+    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, &arm_linux_vfpregset,
+	"VFP floating-point", cb_data);
   else if (tdep->have_fpa_registers)
-    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point", cb_data);
+    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, &arm_linux_fpregset,
+	"FPA floating-point", cb_data);
 }
 
 /* Determine target description from core file.  */
@@ -1457,8 +1436,6 @@ arm_linux_init_abi (struct gdbarch_info info,
 				&arm_kernel_linux_restart_syscall_tramp_frame);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section (gdbarch,
-					arm_linux_regset_from_core_section);
   set_gdbarch_iterate_over_regset_sections
     (gdbarch, arm_linux_iterate_over_regset_sections);
   set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description);
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 7e64e1d..42af7f4 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -134,7 +134,9 @@ sniff_core_bfd (bfd *abfd)
 
   /* Don't sniff if we have support for register sets in
      CORE_GDBARCH.  */
-  if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (core_gdbarch
+      && (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
+	  || gdbarch_regset_from_core_section_p (core_gdbarch)))
     return NULL;
 
   for (cf = core_file_fns; cf != NULL; cf = cf->next)
@@ -489,7 +491,9 @@ core_detach (struct target_ops *ops, const char *args, int from_tty)
 
 static void
 get_core_register_section (struct regcache *regcache,
+			   const struct regset *regset,
 			   const char *name,
+			   int min_size,
 			   int which,
 			   const char *human_name,
 			   int required)
@@ -517,6 +521,12 @@ get_core_register_section (struct regcache *regcache,
     }
 
   size = bfd_section_size (core_bfd, section);
+  if (size < min_size)
+    {
+      warning (_("Section `%s' in core file too small."), section_name);
+      return;
+    }
+
   contents = alloca (size);
   if (! bfd_get_section_contents (core_bfd, section, contents,
 				  (file_ptr) 0, size))
@@ -526,10 +536,9 @@ get_core_register_section (struct regcache *regcache,
       return;
     }
 
-  if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (regset == NULL
+      && core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
     {
-      const struct regset *regset;
-
       regset = gdbarch_regset_from_core_section (core_gdbarch,
 						 name, size);
       if (regset == NULL)
@@ -539,7 +548,10 @@ get_core_register_section (struct regcache *regcache,
 		     human_name);
 	  return;
 	}
+    }
 
+  if (regset != NULL)
+    {
       regset->supply_regset (regset, regcache, -1, contents, size);
       return;
     }
@@ -555,16 +567,28 @@ get_core_register_section (struct regcache *regcache,
 
 static void
 get_core_registers_cb (const char *sect_name, int size,
+		       const struct regset *regset,
 		       const char *human_name, void *cb_data)
 {
   struct regcache *regcache = (struct regcache *) cb_data;
+  int required = 0;
 
   if (strcmp (sect_name, ".reg") == 0)
-    get_core_register_section (regcache, sect_name, 0, human_name, 1);
+    {
+      required = 1;
+      if (human_name == NULL)
+	human_name = "general-purpose";
+    }
   else if (strcmp (sect_name, ".reg2") == 0)
-    get_core_register_section (regcache, sect_name, 2, human_name, 0);
-  else
-    get_core_register_section (regcache, sect_name, 3, human_name, 0);
+    {
+      if (human_name == NULL)
+	human_name = "floating-point";
+    }
+
+  /* The 'which' parameter is only used when no regset is provided.
+     Thus we just set it to -1. */
+  get_core_register_section (regcache, regset, sect_name,
+			     size, -1, human_name, required);
 }
 
 /* Get the registers out of a core file.  This is the machine-
@@ -581,7 +605,9 @@ get_core_registers (struct target_ops *ops,
   int i;
   struct gdbarch *gdbarch;
 
-  if (!(core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (!(core_gdbarch
+	&& (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
+	    || gdbarch_regset_from_core_section_p (core_gdbarch)))
       && (core_vec == NULL || core_vec->core_read_registers == NULL))
     {
       fprintf_filtered (gdb_stderr,
@@ -596,10 +622,10 @@ get_core_registers (struct target_ops *ops,
 					  (void *) regcache, NULL);
   else
     {
-      get_core_register_section (regcache,
-				 ".reg", 0, "general-purpose", 1);
-      get_core_register_section (regcache,
-				 ".reg2", 2, "floating-point", 0);
+      get_core_register_section (regcache, NULL,
+				 ".reg", 0, 0, "general-purpose", 1);
+      get_core_register_section (regcache, NULL,
+				 ".reg2", 0, 2, "floating-point", 0);
     }
 
   /* Mark all registers not found in the core as unavailable.  */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index bbda3da..90a63ca 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -82,7 +82,8 @@ typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
 
 typedef void (iterate_over_regset_sections_cb)
-  (const char *sect_name, int size, const char *human_name, void *cb_data);
+  (const char *sect_name, int size, const struct regset *regset,
+   const char *human_name, void *cb_data);
 
 
 /* The following are pre-initialized by GDBARCH.  */
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 80d3eec..293854f 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1176,7 +1176,8 @@ typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
 
 typedef void (iterate_over_regset_sections_cb)
-  (const char *sect_name, int size, const char *human_name, void *cb_data);
+  (const char *sect_name, int size, const struct regset *regset,
+   const char *human_name, void *cb_data);
 EOF
 
 # function typedef's
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 4ee6874..7feb21d 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -648,6 +648,35 @@ i386_linux_core_read_description (struct gdbarch *gdbarch,
     return tdesc_i386_mmx_linux;
 }
 
+/* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
+
+static void
+i386_linux_supply_xstateregset (const struct regset *regset,
+				struct regcache *regcache, int regnum,
+				const void *xstateregs, size_t len)
+{
+  i387_supply_xsave (regcache, regnum, xstateregs);
+}
+
+/* Similar to i386_collect_fpregset, but use XSAVE extended state.  */
+
+static void
+i386_linux_collect_xstateregset (const struct regset *regset,
+				 const struct regcache *regcache,
+				 int regnum, void *xstateregs, size_t len)
+{
+  i387_collect_xsave (regcache, regnum, xstateregs, 1);
+}
+
+/* Register set definitions.  */
+
+static const struct regset i386_linux_xstateregset =
+  {
+    NULL,
+    i386_linux_supply_xstateregset,
+    i386_linux_collect_xstateregset
+  };
+
 /* Iterate over core file register note sections.  */
 
 static void
@@ -658,14 +687,17 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  cb (".reg", 68, "general-purpose", cb_data);
+  cb (".reg", 68, &i386_gregset, NULL, cb_data);
 
   if (tdep->xcr0 & X86_XSTATE_AVX)
-    cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+    /* Use max size for writing, accept any size when reading.  */
+    cb (".reg-xstate", regcache ? X86_XSTATE_MAX_SIZE : 0,
+	&i386_linux_xstateregset, "XSAVE extended state", cb_data);
   else if (tdep->xcr0 & X86_XSTATE_SSE)
-    cb (".reg-xfp", 512, "extended floating-point", cb_data);
+    cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
+	cb_data);
   else
-    cb (".reg2", 108, "floating-point", cb_data);
+    cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
 }
 
 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 1e68505..8f8cc99 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3806,26 +3806,6 @@ i386_collect_fpregset (const struct regset *regset,
   i387_collect_fsave (regcache, regnum, fpregs);
 }
 
-/* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
-
-static void
-i386_supply_xstateregset (const struct regset *regset,
-			  struct regcache *regcache, int regnum,
-			  const void *xstateregs, size_t len)
-{
-  i387_supply_xsave (regcache, regnum, xstateregs);
-}
-
-/* Similar to i386_collect_fpregset , but use XSAVE extended state.  */
-
-static void
-i386_collect_xstateregset (const struct regset *regset,
-			   const struct regcache *regcache,
-			   int regnum, void *xstateregs, size_t len)
-{
-  i387_collect_xsave (regcache, regnum, xstateregs, 1);
-}
-
 /* Register set definitions.  */
 
 const struct regset i386_gregset =
@@ -3833,16 +3813,11 @@ const struct regset i386_gregset =
     NULL, i386_supply_gregset, i386_collect_gregset
   };
 
-static const struct regset i386_fpregset =
+const struct regset i386_fpregset =
   {
     NULL, i386_supply_fpregset, i386_collect_fpregset
   };
 
-static const struct regset i386_xstateregset =
-  {
-    NULL, i386_supply_xstateregset, i386_collect_xstateregset
-  };
-
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 
@@ -3853,15 +3828,10 @@ i386_regset_from_core_section (struct gdbarch *gdbarch,
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
-      return &i386_gregset;
-
-  if ((strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
-      || (strcmp (sect_name, ".reg-xfp") == 0
-	  && sect_size == I387_SIZEOF_FXSAVE))
-    return &i386_fpregset;
+    return &i386_gregset;
 
-  if (strcmp (sect_name, ".reg-xstate") == 0)
-    return &i386_xstateregset;
+  if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
+    return tdep->fpregset;
 
   return NULL;
 }
@@ -8291,6 +8261,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Floating-point registers.  */
   tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
+  tdep->fpregset = &i386_fpregset;
 
   /* The default settings include the FPU registers, the MMX registers
      and the SSE registers.  This can be overridden for a specific ABI
@@ -8595,7 +8566,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* If we have a register mapping, enable the generic core file
      support, unless it has already been enabled.  */
   if (tdep->gregset_reg_offset
-      && !gdbarch_regset_from_core_section_p (gdbarch))
+      && !gdbarch_regset_from_core_section_p (gdbarch)
+      && !gdbarch_iterate_over_regset_sections_p (gdbarch))
     set_gdbarch_regset_from_core_section (gdbarch,
 					  i386_regset_from_core_section);
 
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index e0950a3..db8f4f7 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -237,6 +237,9 @@ struct gdbarch_tdep
   int (*i386_sysenter_record) (struct regcache *regcache);
   /* Parse syscall args.  */
   int (*i386_syscall_record) (struct regcache *regcache);
+
+  /* Regsets. */
+  const struct regset *fpregset;
 };
 
 /* Floating-point registers.  */
@@ -387,6 +390,9 @@ extern void i386_supply_gregset (const struct regset *regset,
 /* General-purpose register set. */
 extern const struct regset i386_gregset;
 
+/* Floating-point register set. */
+extern const struct regset i386_fpregset;
+
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 extern const struct regset *
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 3d8b1fc..fcba93b 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1105,16 +1105,15 @@ struct linux_collect_regset_section_cb_data
 
 static void
 linux_collect_regset_section_cb (const char *sect_name, int size,
+				 const struct regset *regset,
 				 const char *human_name, void *cb_data)
 {
-  const struct regset *regset;
   char *buf;
   struct linux_collect_regset_section_cb_data *data = cb_data;
 
   if (data->abort_iteration)
     return;
 
-  regset = gdbarch_regset_from_core_section (data->gdbarch, sect_name, size);
   gdb_assert (regset && regset->collect_regset);
 
   buf = xmalloc (size);
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 7ab3255..4d7d051 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -489,27 +489,6 @@ ppc_linux_fpregset (void)
   return &ppc32_linux_fpregset;
 }
 
-static const struct regset *
-ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
-				    const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
-  if (strcmp (sect_name, ".reg") == 0)
-    {
-      if (tdep->wordsize == 4)
-	return &ppc32_linux_gregset;
-      else
-	return &ppc64_linux_gregset;
-    }
-  if (strcmp (sect_name, ".reg2") == 0)
-    return &ppc32_linux_fpregset;
-  if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
-    return &ppc32_linux_vrregset;
-  if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
-    return &ppc32_linux_vsxregset;
-  return NULL;
-}
-
 /* Iterate over supported core file register note sections. */
 
 static void
@@ -522,14 +501,18 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
 
-  cb (".reg", 48 * tdep->wordsize, "general-purpose", cb_data);
-  cb (".reg2", 264, "floating-point", cb_data);
+  if (tdep->wordsize == 4)
+    cb (".reg", 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
+  else
+    cb (".reg", 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
+
+  cb (".reg2", 264, &ppc32_linux_fpregset, NULL, cb_data);
 
   if (have_altivec)
-    cb (".reg-ppc-vmx", 544, "ppc Altivec", cb_data);
+    cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset, "ppc Altivec", cb_data);
 
   if (have_vsx)
-    cb (".reg-ppc-vsx", 256, "POWER7 VSX", cb_data);
+    cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
 }
 
 static void
@@ -1385,8 +1368,6 @@ ppc_linux_init_abi (struct gdbarch_info info,
     set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
 					      elfcore_write_ppc_linux_prpsinfo32);
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					ppc_linux_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
   set_gdbarch_iterate_over_regset_sections (gdbarch,
 					    ppc_linux_iterate_over_regset_sections);
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 840431d..abd2e40 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -82,13 +82,6 @@ struct gdbarch_tdep
   int pc_regnum;
   int cc_regnum;
 
-  /* Core file register sets.  */
-  const struct regset *gregset;
-  int sizeof_gregset;
-
-  const struct regset *fpregset;
-  int sizeof_fpregset;
-
   int have_linux_v1;
   int have_linux_v2;
   int have_tdb;
@@ -536,36 +529,6 @@ const struct regset s390_tdb_regset = {
   regcache_collect_regset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-static const struct regset *
-s390_regset_from_core_section (struct gdbarch *gdbarch,
-			       const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset)
-    return tdep->gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset)
-    return tdep->fpregset;
-
-  if (strcmp (sect_name, ".reg-s390-high-gprs") == 0 && sect_size >= 16*4)
-    return &s390_upper_regset;
-
-  if (strcmp (sect_name, ".reg-s390-last-break") == 0 && sect_size >= 8)
-    return (gdbarch_ptr_bit (gdbarch) == 32
-	    ?  &s390_last_break_regset : &s390x_last_break_regset);
-
-  if (strcmp (sect_name, ".reg-s390-system-call") == 0 && sect_size >= 4)
-    return &s390_system_call_regset;
-
-  if (strcmp (sect_name, ".reg-s390-tdb") == 0 && sect_size >= 256)
-    return &s390_tdb_regset;
-
-  return NULL;
-}
-
 /* Iterate over supported core file register note sections. */
 
 static void
@@ -575,18 +538,25 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
+			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
-  cb (".reg", tdep->sizeof_gregset, "general-purpose", cb_data);
-  cb (".reg2", s390_sizeof_fpregset, "floating-point", cb_data);
+  cb (".reg", gregset_size, &s390_gregset, NULL, cb_data);
+  cb (".reg2", s390_sizeof_fpregset, &s390_fpregset, NULL, cb_data);
 
   if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1)
-    cb (".reg-s390-high-gprs", 16 * 4, "s390 GPR upper halves", cb_data);
+    cb (".reg-s390-high-gprs", 16 * 4, &s390_upper_regset,
+	"s390 GPR upper halves", cb_data);
 
   if (tdep->have_linux_v1)
-    cb (".reg-s390-last-break", 8, "s930 last-break address", cb_data);
+    cb (".reg-s390-last-break", 8,
+	(gdbarch_ptr_bit (gdbarch) == 32
+	 ? &s390_last_break_regset : &s390x_last_break_regset),
+	"s930 last-break address", cb_data);
 
   if (tdep->have_linux_v2)
-    cb (".reg-s390-system-call", 4, "s390 system-call", cb_data);
+    cb (".reg-s390-system-call", 4, &s390_system_call_regset,
+	"s390 system-call", cb_data);
 
   /* If regcache is set, we are in "write" (gcore) mode.  In this
      case, don't iterate over the TDB unless its registers are
@@ -595,7 +565,8 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
       && (regcache == NULL
 	  || REG_VALID == regcache_register_status (regcache,
 						    S390_TDB_DWORD0_REGNUM)))
-    cb (".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB", cb_data);
+    cb (".reg-s390-tdb", s390_sizeof_tdbregset, &s390_tdb_regset,
+	"s390 TDB", cb_data);
 }
 
 static const struct target_desc *
@@ -3067,8 +3038,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
   set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
-  set_gdbarch_regset_from_core_section (gdbarch,
-					s390_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, s390_core_read_description);
   set_gdbarch_iterate_over_regset_sections (gdbarch,
 					    s390_iterate_over_regset_sections);
@@ -3134,11 +3103,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   switch (tdep->abi)
     {
     case ABI_LINUX_S390:
-      tdep->gregset = &s390_gregset;
-      tdep->sizeof_gregset = s390_sizeof_gregset;
-      tdep->fpregset = &s390_fpregset;
-      tdep->sizeof_fpregset = s390_sizeof_fpregset;
-
       set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
       set_solib_svr4_fetch_link_map_offsets
 	(gdbarch, svr4_ilp32_fetch_link_map_offsets);
@@ -3147,11 +3111,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       break;
 
     case ABI_LINUX_ZSERIES:
-      tdep->gregset = &s390_gregset;
-      tdep->sizeof_gregset = s390x_sizeof_gregset;
-      tdep->fpregset = &s390_fpregset;
-      tdep->sizeof_fpregset = s390_sizeof_fpregset;
-
       set_gdbarch_long_bit (gdbarch, 64);
       set_gdbarch_long_long_bit (gdbarch, 64);
       set_gdbarch_ptr_bit (gdbarch, 64);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 10/26] M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (20 preceding siblings ...)
  2014-09-12 16:14 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
@ 2014-09-12 16:15 ` Andreas Arnez
  2014-09-12 16:17 ` [PATCH 15/26] MN10300: " Andreas Arnez
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:15 UTC (permalink / raw)
  To: gdb-patches

For m32r GNU/Linux targets, don't define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m32r-linux-tdep.c (M32R_LINUX_GREGS_SIZE): New macro.
	(m32r_linux_regset_from_core_section): Remove.
	(m32r_linux_iterate_over_regset_sections): New.
	(m32r_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/m32r-linux-tdep.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/gdb/m32r-linux-tdep.c b/gdb/m32r-linux-tdep.c
index 5499902..2133c0c 100644
--- a/gdb/m32r-linux-tdep.c
+++ b/gdb/m32r-linux-tdep.c
@@ -344,6 +344,8 @@ static int m32r_pt_regs_offset[] = {
 #define SPU_OFFSET (4 * 23)
 #define SPI_OFFSET (4 * 26)
 
+#define M32R_LINUX_GREGS_SIZE (4 * 28)
+
 static void
 m32r_linux_supply_gregset (const struct regset *regset,
 			   struct regcache *regcache, int regnum,
@@ -433,14 +435,13 @@ static const struct regset m32r_linux_gregset = {
   m32r_linux_supply_gregset, m32r_linux_collect_gregset
 };
 
-static const struct regset *
-m32r_linux_regset_from_core_section (struct gdbarch *core_arch,
-				     const char *sect_name, size_t sect_size)
+static void
+m32r_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
-  if (strcmp (sect_name, ".reg") == 0)
-    return &m32r_linux_gregset;
-  return NULL;
+  cb (".reg", M32R_LINUX_GREGS_SIZE, &m32r_linux_gregset, NULL, cb_data);
 }
 
 static void
@@ -462,8 +463,8 @@ m32r_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m32r_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m32r_linux_iterate_over_regset_sections);
 
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 15/26] MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'.
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (21 preceding siblings ...)
  2014-09-12 16:15 ` [PATCH 10/26] M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
@ 2014-09-12 16:17 ` Andreas Arnez
  2014-09-12 16:18 ` [PATCH 18/26] SCORE: " Andreas Arnez
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:17 UTC (permalink / raw)
  To: gdb-patches

For MN10300 GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* mn10300-linux-tdep.c (am33_regset_from_core_section): Remove.
	(am33_iterate_over_regset_sections): New.
	(am33_linux_init_osabi): Adjust gdbarch initialization.
---
 gdb/mn10300-linux-tdep.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/mn10300-linux-tdep.c b/gdb/mn10300-linux-tdep.c
index 023c61d..9e6844d 100644
--- a/gdb/mn10300-linux-tdep.c
+++ b/gdb/mn10300-linux-tdep.c
@@ -457,17 +457,18 @@ static const struct regset am33_fpregset =
     NULL, am33_supply_fpregset_method, am33_collect_fpregset_method
   };
 
-/* Create a struct regset from a corefile register section.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-am33_regset_from_core_section (struct gdbarch *gdbarch, 
-			       const char *sect_name, 
-			       size_t sect_size)
+static void
+am33_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				   iterate_over_regset_sections_cb *cb,
+				   void *cb_data,
+				   const struct regcache *regcache)
 {
-  if (sect_size == sizeof (mn10300_elf_fpregset_t))
-    return &am33_fpregset;
-  else
-    return &am33_gregset;
+  cb (".reg", sizeof (mn10300_elf_gregset_t), &am33_gregset,
+      NULL, cb_data);
+  cb (".reg2", sizeof(mn10300_elf_fpregset_t), &am33_fpregset,
+      NULL, cb_data);
 }
 \f
 static void
@@ -714,8 +715,8 @@ am33_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   linux_init_abi (info, gdbarch);
 
-  set_gdbarch_regset_from_core_section (gdbarch, 
-					am33_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, am33_iterate_over_regset_sections);
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (23 preceding siblings ...)
  2014-09-12 16:18 ` [PATCH 18/26] SCORE: " Andreas Arnez
@ 2014-09-12 16:18 ` Andreas Arnez
  2014-09-12 16:18 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:18 UTC (permalink / raw)
  To: gdb-patches

Now that all Linux targets use the regset iterator, the fall back to
the deprecated target method is dropped.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_collect_thread_registers): Remove.
	(linux_nat_make_corefile_notes): Remove.
	(linux_target_install_ops): Do not set target method
	'make_corefile_notes'.
	* linux-tdep.c (struct linux_corefile_thread_data)<collect>:
	Remove field.
	(linux_corefile_thread_callback): Instead of args->collect, call
	linux_collect_thread_registers.
	(linux_make_corefile_notes): Remove 'collect' parameter.  Return
	NULL unless there is a regset iterator.
	(linux_make_corefile_notes_1): Remove.
	(linux_init_abi): Replace reference to linux_make_corefile_notes_1
	by linux_make_corefile_notes.
	* linux-tdep.h (linux_make_corefile_notes): Remove prototype.
---
 gdb/linux-nat.c  | 57 --------------------------------------------------------
 gdb/linux-tdep.c | 36 +++++++++++------------------------
 gdb/linux-tdep.h |  3 ---
 3 files changed, 11 insertions(+), 85 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 0898442..643e9ab 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4059,62 +4059,6 @@ linux_child_pid_to_exec_file (struct target_ops *self, int pid)
   return buf;
 }
 
-/* Records the thread's register state for the corefile note
-   section.  */
-
-static char *
-linux_nat_collect_thread_registers (const struct regcache *regcache,
-				    ptid_t ptid, bfd *obfd,
-				    char *note_data, int *note_size,
-				    enum gdb_signal stop_signal)
-{
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  const struct regset *regset;
-  int core_regset_p;
-  gdb_gregset_t gregs;
-  gdb_fpregset_t fpregs;
-
-  core_regset_p = gdbarch_regset_from_core_section_p (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, ptid_get_lwp (ptid),
-			  gdb_signal_to_host (stop_signal), &gregs);
-
-  if (core_regset_p
-      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
-						     sizeof (fpregs)))
-	  != NULL && regset->collect_regset != NULL)
-    regset->collect_regset (regset, regcache, -1, &fpregs, sizeof (fpregs));
-  else
-    fill_fpregset (regcache, &fpregs, -1);
-
-  note_data = (char *) elfcore_write_prfpreg (obfd, note_data, note_size,
-					      &fpregs, sizeof (fpregs));
-
-  return note_data;
-}
-
-/* Fills the "to_make_corefile_note" target vector.  Builds the note
-   section for a corefile, and returns it in a malloc buffer.  */
-
-static char *
-linux_nat_make_corefile_notes (struct target_ops *self,
-			       bfd *obfd, int *note_size)
-{
-  /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been
-     converted to gdbarch_core_regset_sections, this function can go away.  */
-  return linux_make_corefile_notes (target_gdbarch (), obfd, note_size,
-				    linux_nat_collect_thread_registers);
-}
-
 /* Implement the to_xfer_partial interface for memory reads using the /proc
    filesystem.  Because we can use a single read() call for /proc, this
    can be much more efficient than banging away at PTRACE_PEEKTEXT,
@@ -4511,7 +4455,6 @@ linux_target_install_ops (struct target_ops *t)
   t->to_post_startup_inferior = linux_child_post_startup_inferior;
   t->to_post_attach = linux_child_post_attach;
   t->to_follow_fork = linux_child_follow_fork;
-  t->to_make_corefile_notes = linux_nat_make_corefile_notes;
 
   super_xfer_partial = t->to_xfer_partial;
   t->to_xfer_partial = linux_xfer_partial;
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index fcba93b..7a76670 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1211,7 +1211,6 @@ struct linux_corefile_thread_data
   char *note_data;
   int *note_size;
   enum gdb_signal stop_signal;
-  linux_collect_thread_registers_ftype collect;
 };
 
 /* Called by gdbthread.c once per thread.  Records the thread's
@@ -1244,9 +1243,9 @@ linux_corefile_thread_callback (struct thread_info *info, void *data)
 
       old_chain = make_cleanup (xfree, siginfo_data);
 
-      args->note_data = args->collect (regcache, info->ptid, args->obfd,
-				       args->note_data, args->note_size,
-				       args->stop_signal);
+      args->note_data = linux_collect_thread_registers
+	(regcache, info->ptid, args->obfd, args->note_data,
+	 args->note_size, args->stop_signal);
 
       /* Don't return anything if we got no register information above,
          such a core file is useless.  */
@@ -1466,12 +1465,11 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
   return 1;
 }
 
-/* Fills the "to_make_corefile_note" target vector.  Builds the note
-   section for a corefile, and returns it in a malloc buffer.  */
+/* Build the note section for a corefile, and return it in a malloc
+   buffer.  */
 
-char *
-linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
-			   linux_collect_thread_registers_ftype collect)
+static char *
+linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
 {
   struct linux_corefile_thread_data thread_args;
   struct elf_internal_linux_prpsinfo prpsinfo;
@@ -1480,6 +1478,9 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   int auxv_len;
   volatile struct gdb_exception e;
 
+  if (! gdbarch_iterate_over_regset_sections_p (gdbarch))
+    return NULL;
+
   if (linux_fill_prpsinfo (&prpsinfo))
     {
       if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch))
@@ -1514,7 +1515,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   thread_args.note_data = note_data;
   thread_args.note_size = note_size;
   thread_args.stop_signal = find_stop_signal ();
-  thread_args.collect = collect;
   iterate_over_threads (linux_corefile_thread_callback, &thread_args);
   note_data = thread_args.note_data;
   if (!note_data)
@@ -1545,20 +1545,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   return note_data;
 }
 
-static char *
-linux_make_corefile_notes_1 (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
-{
-  /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been
-     converted to gdbarch_core_regset_sections, we no longer need to fall back
-     to the target method at this point.  */
-
-  if (!gdbarch_iterate_over_regset_sections_p (gdbarch))
-    return target_make_corefile_notes (obfd, note_size);
-  else
-    return linux_make_corefile_notes (gdbarch, obfd, note_size,
-				      linux_collect_thread_registers);
-}
-
 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
    gdbarch.h.  This function is not static because it is exported to
    other -tdep files.  */
@@ -1820,7 +1806,7 @@ linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_info_proc (gdbarch, linux_info_proc);
   set_gdbarch_core_info_proc (gdbarch, linux_core_info_proc);
   set_gdbarch_find_memory_regions (gdbarch, linux_find_memory_regions);
-  set_gdbarch_make_corefile_notes (gdbarch, linux_make_corefile_notes_1);
+  set_gdbarch_make_corefile_notes (gdbarch, linux_make_corefile_notes);
   set_gdbarch_has_shared_address_space (gdbarch,
 					linux_has_shared_address_space);
   set_gdbarch_gdb_signal_from_target (gdbarch,
diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h
index 610e2f0..2354603 100644
--- a/gdb/linux-tdep.h
+++ b/gdb/linux-tdep.h
@@ -29,9 +29,6 @@ typedef char *(*linux_collect_thread_registers_ftype) (const struct regcache *,
 						       bfd *, char *, int *,
 						       enum gdb_signal);
 
-char *linux_make_corefile_notes (struct gdbarch *, bfd *, int *,
-                                 linux_collect_thread_registers_ftype);
-
 struct type *linux_get_siginfo_type (struct gdbarch *);
 
 extern enum gdb_signal linux_gdb_signal_from_target (struct gdbarch *gdbarch,
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 18/26] SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (22 preceding siblings ...)
  2014-09-12 16:17 ` [PATCH 15/26] MN10300: " Andreas Arnez
@ 2014-09-12 16:18 ` Andreas Arnez
  2014-09-12 16:18 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:18 UTC (permalink / raw)
  To: gdb-patches

For S+core targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* score-tdep.c (score7_linux_regset_from_core_section): Remove.
	(score7_linux_iterate_over_regset_sections): New.
	(score_gdbarch_init): Adjust gdbarch initialization.
---
 gdb/score-tdep.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index d61faf0..dd438f9 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -1445,21 +1445,16 @@ static const struct regset score7_linux_gregset =
     regcache_collect_regset
   };
 
-/* Return the appropriate register set from the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-score7_linux_regset_from_core_section(struct gdbarch *gdbarch,
-                    const char *sect_name, size_t sect_size)
+static void
+score7_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					   iterate_over_regset_sections_cb *cb,
+					   void *cb_data,
+					   const struct regcache *regcache)
 {
-  gdb_assert (gdbarch != NULL);
-  gdb_assert (sect_name != NULL);
-
-  if (strcmp(sect_name, ".reg") == 0
-      && sect_size == SCORE7_LINUX_SIZEOF_GREGSET)
-    return &score7_linux_gregset;
-
-  return NULL;
+  cb (".reg", SCORE7_LINUX_SIZEOF_GREGSET, &score7_linux_gregset,
+      NULL, cb_data);
 }
 
 static struct gdbarch *
@@ -1504,8 +1499,8 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_register_name (gdbarch, score7_register_name);
       set_gdbarch_num_regs (gdbarch, SCORE7_NUM_REGS);
       /* Core file support.  */
-      set_gdbarch_regset_from_core_section (gdbarch,
-					    score7_linux_regset_from_core_section);
+      set_gdbarch_iterate_over_regset_sections
+	(gdbarch, score7_linux_iterate_over_regset_sections);
       break;
 
     case bfd_mach_score3:
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (24 preceding siblings ...)
  2014-09-12 16:18 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
@ 2014-09-12 16:18 ` Andreas Arnez
  2014-09-12 18:31 ` [PATCH 15/26] MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 16:18 UTC (permalink / raw)
  To: gdb-patches

Now that all users of the target method 'fbsd_make_corefile_notes'
have been converted to the version in fbsd-tdep.c, the old method is
removed.

gdb/ChangeLog:

	* fbsd-nat.c (find_signalled_thread, find_stop_signal)
	(fbsd_collect_regset_section_cb, fbsd_make_corefile_notes):
	Remove.
	* fbsd-nat.h (fbsd_make_corefile_notes): Remove prototype.
---
 gdb/fbsd-nat.c | 76 ----------------------------------------------------------
 gdb/fbsd-nat.h |  6 -----
 2 files changed, 82 deletions(-)

diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index e9db30e..3bccc77 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -137,79 +137,3 @@ fbsd_find_memory_regions (struct target_ops *self,
   do_cleanups (cleanup);
   return 0;
 }
-
-static int
-find_signalled_thread (struct thread_info *info, void *data)
-{
-  if (info->suspend.stop_signal != GDB_SIGNAL_0
-      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
-    return 1;
-
-  return 0;
-}
-
-static enum gdb_signal
-find_stop_signal (void)
-{
-  struct thread_info *info =
-    iterate_over_threads (find_signalled_thread, NULL);
-
-  if (info)
-    return info->suspend.stop_signal;
-  else
-    return GDB_SIGNAL_0;
-}
-
-/* Create appropriate note sections for a corefile, returning them in
-   allocated memory.  */
-
-char *
-fbsd_make_corefile_notes (struct target_ops *self, bfd *obfd, int *note_size)
-{
-  const struct regcache *regcache = get_current_regcache ();
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  gregset_t gregs;
-  fpregset_t fpregs;
-  char *note_data = NULL;
-  Elf_Internal_Ehdr *i_ehdrp;
-  const struct regset *regset;
-  size_t size;
-
-  /* Put a "FreeBSD" label in the ELF header.  */
-  i_ehdrp = elf_elfheader (obfd);
-  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
-
-  gdb_assert (gdbarch_regset_from_core_section_p (gdbarch));
-
-  size = sizeof gregs;
-  regset = gdbarch_regset_from_core_section (gdbarch, ".reg", size);
-  gdb_assert (regset && regset->collect_regset);
-  regset->collect_regset (regset, regcache, -1, &gregs, size);
-
-  note_data = elfcore_write_prstatus (obfd, note_data, note_size,
-				      ptid_get_pid (inferior_ptid),
-				      find_stop_signal (), &gregs);
-
-  size = sizeof fpregs;
-  regset = gdbarch_regset_from_core_section (gdbarch, ".reg2", size);
-  gdb_assert (regset && regset->collect_regset);
-  regset->collect_regset (regset, regcache, -1, &fpregs, size);
-
-  note_data = elfcore_write_prfpreg (obfd, note_data, note_size,
-				     &fpregs, sizeof (fpregs));
-
-  if (get_exec_file (0))
-    {
-      const char *fname = lbasename (get_exec_file (0));
-      char *psargs = xstrdup (fname);
-
-      if (get_inferior_args ())
-	psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
-			   (char *) NULL);
-
-      note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
-					  fname, psargs);
-    }
-
-  return note_data;
-}
diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h
index a3f51d6..531fe4f 100644
--- a/gdb/fbsd-nat.h
+++ b/gdb/fbsd-nat.h
@@ -32,10 +32,4 @@ extern char *fbsd_pid_to_exec_file (struct target_ops *self, int pid);
 extern int fbsd_find_memory_regions (struct target_ops *self,
 				     find_memory_region_ftype func, void *obfd);
 
-/* Create appropriate note sections for a corefile, returning them in
-   allocated memory.  */
-
-extern char *fbsd_make_corefile_notes (struct target_ops *self,
-				       bfd *obfd, int *note_size);
-
 #endif /* fbsd-nat.h */
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 15/26] MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'.
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (25 preceding siblings ...)
  2014-09-12 16:18 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
@ 2014-09-12 18:31 ` Andreas Arnez
  2014-09-12 18:31 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kevin Buettner

For MN10300 GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* mn10300-linux-tdep.c (am33_regset_from_core_section): Remove.
	(am33_iterate_over_regset_sections): New.
	(am33_linux_init_osabi): Adjust gdbarch initialization.
---
 gdb/mn10300-linux-tdep.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/mn10300-linux-tdep.c b/gdb/mn10300-linux-tdep.c
index 023c61d..9e6844d 100644
--- a/gdb/mn10300-linux-tdep.c
+++ b/gdb/mn10300-linux-tdep.c
@@ -457,17 +457,18 @@ static const struct regset am33_fpregset =
     NULL, am33_supply_fpregset_method, am33_collect_fpregset_method
   };
 
-/* Create a struct regset from a corefile register section.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-am33_regset_from_core_section (struct gdbarch *gdbarch, 
-			       const char *sect_name, 
-			       size_t sect_size)
+static void
+am33_iterate_over_regset_sections (struct gdbarch *gdbarch,
+				   iterate_over_regset_sections_cb *cb,
+				   void *cb_data,
+				   const struct regcache *regcache)
 {
-  if (sect_size == sizeof (mn10300_elf_fpregset_t))
-    return &am33_fpregset;
-  else
-    return &am33_gregset;
+  cb (".reg", sizeof (mn10300_elf_gregset_t), &am33_gregset,
+      NULL, cb_data);
+  cb (".reg2", sizeof(mn10300_elf_fpregset_t), &am33_fpregset,
+      NULL, cb_data);
 }
 \f
 static void
@@ -714,8 +715,8 @@ am33_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   linux_init_abi (info, gdbarch);
 
-  set_gdbarch_regset_from_core_section (gdbarch, 
-					am33_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, am33_iterate_over_regset_sections);
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (27 preceding siblings ...)
  2014-09-12 18:31 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
@ 2014-09-12 18:31 ` Andreas Arnez
  2014-09-12 18:32 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:31 UTC (permalink / raw)
  To: gdb-patches

Now that all Linux targets use the regset iterator, the fall back to
the deprecated target method is dropped.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_collect_thread_registers): Remove.
	(linux_nat_make_corefile_notes): Remove.
	(linux_target_install_ops): Do not set target method
	'make_corefile_notes'.
	* linux-tdep.c (struct linux_corefile_thread_data)<collect>:
	Remove field.
	(linux_corefile_thread_callback): Instead of args->collect, call
	linux_collect_thread_registers.
	(linux_make_corefile_notes): Remove 'collect' parameter.  Return
	NULL unless there is a regset iterator.
	(linux_make_corefile_notes_1): Remove.
	(linux_init_abi): Replace reference to linux_make_corefile_notes_1
	by linux_make_corefile_notes.
	* linux-tdep.h (linux_make_corefile_notes): Remove prototype.
---
 gdb/linux-nat.c  | 57 --------------------------------------------------------
 gdb/linux-tdep.c | 36 +++++++++++------------------------
 gdb/linux-tdep.h |  3 ---
 3 files changed, 11 insertions(+), 85 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 0898442..643e9ab 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4059,62 +4059,6 @@ linux_child_pid_to_exec_file (struct target_ops *self, int pid)
   return buf;
 }
 
-/* Records the thread's register state for the corefile note
-   section.  */
-
-static char *
-linux_nat_collect_thread_registers (const struct regcache *regcache,
-				    ptid_t ptid, bfd *obfd,
-				    char *note_data, int *note_size,
-				    enum gdb_signal stop_signal)
-{
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  const struct regset *regset;
-  int core_regset_p;
-  gdb_gregset_t gregs;
-  gdb_fpregset_t fpregs;
-
-  core_regset_p = gdbarch_regset_from_core_section_p (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, ptid_get_lwp (ptid),
-			  gdb_signal_to_host (stop_signal), &gregs);
-
-  if (core_regset_p
-      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
-						     sizeof (fpregs)))
-	  != NULL && regset->collect_regset != NULL)
-    regset->collect_regset (regset, regcache, -1, &fpregs, sizeof (fpregs));
-  else
-    fill_fpregset (regcache, &fpregs, -1);
-
-  note_data = (char *) elfcore_write_prfpreg (obfd, note_data, note_size,
-					      &fpregs, sizeof (fpregs));
-
-  return note_data;
-}
-
-/* Fills the "to_make_corefile_note" target vector.  Builds the note
-   section for a corefile, and returns it in a malloc buffer.  */
-
-static char *
-linux_nat_make_corefile_notes (struct target_ops *self,
-			       bfd *obfd, int *note_size)
-{
-  /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been
-     converted to gdbarch_core_regset_sections, this function can go away.  */
-  return linux_make_corefile_notes (target_gdbarch (), obfd, note_size,
-				    linux_nat_collect_thread_registers);
-}
-
 /* Implement the to_xfer_partial interface for memory reads using the /proc
    filesystem.  Because we can use a single read() call for /proc, this
    can be much more efficient than banging away at PTRACE_PEEKTEXT,
@@ -4511,7 +4455,6 @@ linux_target_install_ops (struct target_ops *t)
   t->to_post_startup_inferior = linux_child_post_startup_inferior;
   t->to_post_attach = linux_child_post_attach;
   t->to_follow_fork = linux_child_follow_fork;
-  t->to_make_corefile_notes = linux_nat_make_corefile_notes;
 
   super_xfer_partial = t->to_xfer_partial;
   t->to_xfer_partial = linux_xfer_partial;
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index fcba93b..7a76670 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1211,7 +1211,6 @@ struct linux_corefile_thread_data
   char *note_data;
   int *note_size;
   enum gdb_signal stop_signal;
-  linux_collect_thread_registers_ftype collect;
 };
 
 /* Called by gdbthread.c once per thread.  Records the thread's
@@ -1244,9 +1243,9 @@ linux_corefile_thread_callback (struct thread_info *info, void *data)
 
       old_chain = make_cleanup (xfree, siginfo_data);
 
-      args->note_data = args->collect (regcache, info->ptid, args->obfd,
-				       args->note_data, args->note_size,
-				       args->stop_signal);
+      args->note_data = linux_collect_thread_registers
+	(regcache, info->ptid, args->obfd, args->note_data,
+	 args->note_size, args->stop_signal);
 
       /* Don't return anything if we got no register information above,
          such a core file is useless.  */
@@ -1466,12 +1465,11 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
   return 1;
 }
 
-/* Fills the "to_make_corefile_note" target vector.  Builds the note
-   section for a corefile, and returns it in a malloc buffer.  */
+/* Build the note section for a corefile, and return it in a malloc
+   buffer.  */
 
-char *
-linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
-			   linux_collect_thread_registers_ftype collect)
+static char *
+linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
 {
   struct linux_corefile_thread_data thread_args;
   struct elf_internal_linux_prpsinfo prpsinfo;
@@ -1480,6 +1478,9 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   int auxv_len;
   volatile struct gdb_exception e;
 
+  if (! gdbarch_iterate_over_regset_sections_p (gdbarch))
+    return NULL;
+
   if (linux_fill_prpsinfo (&prpsinfo))
     {
       if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch))
@@ -1514,7 +1515,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   thread_args.note_data = note_data;
   thread_args.note_size = note_size;
   thread_args.stop_signal = find_stop_signal ();
-  thread_args.collect = collect;
   iterate_over_threads (linux_corefile_thread_callback, &thread_args);
   note_data = thread_args.note_data;
   if (!note_data)
@@ -1545,20 +1545,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   return note_data;
 }
 
-static char *
-linux_make_corefile_notes_1 (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
-{
-  /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been
-     converted to gdbarch_core_regset_sections, we no longer need to fall back
-     to the target method at this point.  */
-
-  if (!gdbarch_iterate_over_regset_sections_p (gdbarch))
-    return target_make_corefile_notes (obfd, note_size);
-  else
-    return linux_make_corefile_notes (gdbarch, obfd, note_size,
-				      linux_collect_thread_registers);
-}
-
 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
    gdbarch.h.  This function is not static because it is exported to
    other -tdep files.  */
@@ -1820,7 +1806,7 @@ linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_info_proc (gdbarch, linux_info_proc);
   set_gdbarch_core_info_proc (gdbarch, linux_core_info_proc);
   set_gdbarch_find_memory_regions (gdbarch, linux_find_memory_regions);
-  set_gdbarch_make_corefile_notes (gdbarch, linux_make_corefile_notes_1);
+  set_gdbarch_make_corefile_notes (gdbarch, linux_make_corefile_notes);
   set_gdbarch_has_shared_address_space (gdbarch,
 					linux_has_shared_address_space);
   set_gdbarch_gdb_signal_from_target (gdbarch,
diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h
index 610e2f0..2354603 100644
--- a/gdb/linux-tdep.h
+++ b/gdb/linux-tdep.h
@@ -29,9 +29,6 @@ typedef char *(*linux_collect_thread_registers_ftype) (const struct regcache *,
 						       bfd *, char *, int *,
 						       enum gdb_signal);
 
-char *linux_make_corefile_notes (struct gdbarch *, bfd *, int *,
-                                 linux_collect_thread_registers_ftype);
-
 struct type *linux_get_siginfo_type (struct gdbarch *);
 
 extern enum gdb_signal linux_gdb_signal_from_target (struct gdbarch *gdbarch,
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (26 preceding siblings ...)
  2014-09-12 18:31 ` [PATCH 15/26] MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
@ 2014-09-12 18:31 ` Andreas Arnez
  2014-09-12 18:31 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis

Now that all users of the target method 'fbsd_make_corefile_notes'
have been converted to the version in fbsd-tdep.c, the old method is
removed.

gdb/ChangeLog:

	* fbsd-nat.c (find_signalled_thread, find_stop_signal)
	(fbsd_collect_regset_section_cb, fbsd_make_corefile_notes):
	Remove.
	* fbsd-nat.h (fbsd_make_corefile_notes): Remove prototype.
---
 gdb/fbsd-nat.c | 76 ----------------------------------------------------------
 gdb/fbsd-nat.h |  6 -----
 2 files changed, 82 deletions(-)

diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index e9db30e..3bccc77 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -137,79 +137,3 @@ fbsd_find_memory_regions (struct target_ops *self,
   do_cleanups (cleanup);
   return 0;
 }
-
-static int
-find_signalled_thread (struct thread_info *info, void *data)
-{
-  if (info->suspend.stop_signal != GDB_SIGNAL_0
-      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
-    return 1;
-
-  return 0;
-}
-
-static enum gdb_signal
-find_stop_signal (void)
-{
-  struct thread_info *info =
-    iterate_over_threads (find_signalled_thread, NULL);
-
-  if (info)
-    return info->suspend.stop_signal;
-  else
-    return GDB_SIGNAL_0;
-}
-
-/* Create appropriate note sections for a corefile, returning them in
-   allocated memory.  */
-
-char *
-fbsd_make_corefile_notes (struct target_ops *self, bfd *obfd, int *note_size)
-{
-  const struct regcache *regcache = get_current_regcache ();
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  gregset_t gregs;
-  fpregset_t fpregs;
-  char *note_data = NULL;
-  Elf_Internal_Ehdr *i_ehdrp;
-  const struct regset *regset;
-  size_t size;
-
-  /* Put a "FreeBSD" label in the ELF header.  */
-  i_ehdrp = elf_elfheader (obfd);
-  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
-
-  gdb_assert (gdbarch_regset_from_core_section_p (gdbarch));
-
-  size = sizeof gregs;
-  regset = gdbarch_regset_from_core_section (gdbarch, ".reg", size);
-  gdb_assert (regset && regset->collect_regset);
-  regset->collect_regset (regset, regcache, -1, &gregs, size);
-
-  note_data = elfcore_write_prstatus (obfd, note_data, note_size,
-				      ptid_get_pid (inferior_ptid),
-				      find_stop_signal (), &gregs);
-
-  size = sizeof fpregs;
-  regset = gdbarch_regset_from_core_section (gdbarch, ".reg2", size);
-  gdb_assert (regset && regset->collect_regset);
-  regset->collect_regset (regset, regcache, -1, &fpregs, size);
-
-  note_data = elfcore_write_prfpreg (obfd, note_data, note_size,
-				     &fpregs, sizeof (fpregs));
-
-  if (get_exec_file (0))
-    {
-      const char *fname = lbasename (get_exec_file (0));
-      char *psargs = xstrdup (fname);
-
-      if (get_inferior_args ())
-	psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
-			   (char *) NULL);
-
-      note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
-					  fname, psargs);
-    }
-
-  return note_data;
-}
diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h
index a3f51d6..531fe4f 100644
--- a/gdb/fbsd-nat.h
+++ b/gdb/fbsd-nat.h
@@ -32,10 +32,4 @@ extern char *fbsd_pid_to_exec_file (struct target_ops *self, int pid);
 extern int fbsd_find_memory_regions (struct target_ops *self,
 				     find_memory_region_ftype func, void *obfd);
 
-/* Create appropriate note sections for a corefile, returning them in
-   allocated memory.  */
-
-extern char *fbsd_make_corefile_notes (struct target_ops *self,
-				       bfd *obfd, int *note_size);
-
 #endif /* fbsd-nat.h */
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (28 preceding siblings ...)
  2014-09-12 18:31 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
@ 2014-09-12 18:32 ` Andreas Arnez
  2014-09-12 18:32 ` [PATCH 18/26] SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:32 UTC (permalink / raw)
  To: gdb-patches
  Cc: Ulrich Weigand, Kevin Buettner, Mark Kettenis, Richard Earnshaw

This adds the 'regset' parameter to the iterator callback.
Consequently the 'regset_from_core_section' method is dropped for all
targets that provide the iterator method.

This change prepares for replacing regset_from_core_section
everywhere, thereby eliminating one gdbarch interface.  Since the
iterator is usually no more complex than regset_from_core_section
alone, targets that previously didn't define core_regset_sections will
then gain multi-arch capable core file generation support without
increased complexity.

gdb/ChangeLog:

	* gdbarch.sh (iterate_over_regset_sections_cb): Add regset
	parameter.
	* gdbarch.h: Regenerate.
	* corelow.c (sniff_core_bfd): Don't sniff if gdbarch has a regset
	iterator.
	(get_core_register_section): Add parameter 'regset' and use it, if
	set.  Add parameter 'min_size' and verify the bfd section size
	against it.
	(get_core_registers_cb): Add parameter 'regset' and pass it to
	get_core_register section.  For the "standard" register sections
	".reg" and ".reg2", set an appropriate default for human_name.
	(get_core_registers): Don't abort when the gdbarch has an iterator
	but no regset_from_core_section.  Add NULL/0 for parameters
	'regset'/'min_size' in calls to get_core_register_section.
	* linux-tdep.c (linux_collect_regset_section_cb): Add parameter
	'regset' and use it instead of calling the
	regset_from_core_section gdbarch method.
	* i386-tdep.h (struct gdbarch_tdep): Add field 'fpregset'.
	* i386-tdep.c (i386_supply_xstateregset)
	(i386_collect_xstateregset, i386_xstateregset): Moved to
	i386-linux-tdep.c.
	(i386_regset_from_core_section): Drop handling for .reg-xfp and
	.reg-xstate.
	(i386_gdbarch_init): Set tdep field 'fpregset'.  Enable generic
	core file support only if the regset iterator hasn't been set.
	* i386-linux-tdep.c (i386_linux_supply_xstateregset)
	(i386_linux_collect_xstateregset, i386_linux_xstateregset): New.
	Moved from i386-tdep.c and renamed to *_linux*.
	(i386_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.  Allow any .reg-xstate size when reading
	from a core file.
	* amd64-tdep.c (amd64_supply_xstateregset)
	(amd64_collect_xstateregset, amd64_xstateregset): Moved to
	amd64-linux-tdep.c.
	(amd64_regset_from_core_section): Remove.
	(amd64_init_abi): Set new tdep field 'fpregset'.  No longer
	install an amd64-specific regset_from_core_section gdbarch method.
	* amd64-linux-tdep.c (amd64_linux_supply_xstateregset)
	(amd64_linux_collect_xstateregset, amd64_linux_xstateregset): New.
	Moved from amd64-tdep.c and renamed to *_linux*.
	(amd64_linux_iterate_over_regset_sections): Add regset parameter
	to each callback invocation.  Allow any .reg-xstate size when
	reading from a core file.
	* arm-linux-tdep.c (arm_linux_regset_from_core_section): Remove.
	(arm_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(arm_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* ppc-linux-tdep.c (ppc_linux_regset_from_core_section): Remove.
	(ppc_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(ppc_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* s390-linux-tdep.c (struct gdbarch_tdep): Remove the fields
	gregset, sizeof_gregset, fpregset, and sizeof_fpregset.
	(s390_regset_from_core_section): Remove.
	(s390_iterate_over_regset_sections): Add regset parameter to each
	callback invocation.
	(s390_gdbarch_init): No longer set the regset_from_core_section
	gdbarch method.  Drop initialization of deleted tdep fields.
---
 gdb/amd64-linux-tdep.c | 36 +++++++++++++++++++++++---
 gdb/amd64-tdep.c       | 51 ++-----------------------------------
 gdb/amd64-tdep.h       |  2 ++
 gdb/arm-linux-tdep.c   | 33 ++++--------------------
 gdb/corelow.c          | 52 +++++++++++++++++++++++++++----------
 gdb/gdbarch.h          |  3 ++-
 gdb/gdbarch.sh         |  3 ++-
 gdb/i386-linux-tdep.c  | 40 ++++++++++++++++++++++++++---
 gdb/i386-tdep.c        | 42 +++++-------------------------
 gdb/i386-tdep.h        |  6 +++++
 gdb/linux-tdep.c       |  3 +--
 gdb/ppc-linux-tdep.c   | 35 ++++++-------------------
 gdb/s390-linux-tdep.c  | 69 ++++++++++----------------------------------------
 13 files changed, 157 insertions(+), 218 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 2432bae..edbb1b3 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1600,6 +1600,33 @@ amd64_linux_core_read_description (struct gdbarch *gdbarch,
     }
 }
 
+/* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
+
+static void
+amd64_linux_supply_xstateregset (const struct regset *regset,
+				 struct regcache *regcache, int regnum,
+				 const void *xstateregs, size_t len)
+{
+  amd64_supply_xsave (regcache, regnum, xstateregs);
+}
+
+/* Similar to amd64_collect_fpregset, but use XSAVE extended state.  */
+
+static void
+amd64_linux_collect_xstateregset (const struct regset *regset,
+				  const struct regcache *regcache,
+				  int regnum, void *xstateregs, size_t len)
+{
+  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
+}
+
+static const struct regset amd64_linux_xstateregset =
+  {
+    NULL,
+    amd64_linux_supply_xstateregset,
+    amd64_linux_collect_xstateregset
+  };
+
 /* Iterate over core file register note sections.  */
 
 static void
@@ -1608,9 +1635,12 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  cb (".reg", 27 * 8, "general-purpose", cb_data);
-  cb (".reg2", 512, "floating-point", cb_data);
-  cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  cb (".reg", 27 * 8, &i386_gregset, NULL, cb_data);
+  cb (".reg2", 512, &amd64_fpregset, NULL, cb_data);
+  cb (".reg-xstate",  regcache ? X86_XSTATE_MAX_SIZE : 0,
+      &amd64_linux_xstateregset, "XSAVE extended state", cb_data);
 }
 
 static void
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index abd9c48..7c8575a 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2868,53 +2868,10 @@ amd64_collect_fpregset (const struct regset *regset,
   amd64_collect_fxsave (regcache, regnum, fpregs);
 }
 
-/* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
-
-static void
-amd64_supply_xstateregset (const struct regset *regset,
-			   struct regcache *regcache, int regnum,
-			   const void *xstateregs, size_t len)
-{
-  amd64_supply_xsave (regcache, regnum, xstateregs);
-}
-
-/* Similar to amd64_collect_fpregset, but use XSAVE extended state.  */
-
-static void
-amd64_collect_xstateregset (const struct regset *regset,
-			    const struct regcache *regcache,
-			    int regnum, void *xstateregs, size_t len)
-{
-  amd64_collect_xsave (regcache, regnum, xstateregs, 1);
-}
-
-static const struct regset amd64_fpregset =
+const struct regset amd64_fpregset =
   {
     NULL, amd64_supply_fpregset, amd64_collect_fpregset
   };
-
-static const struct regset amd64_xstateregset =
-  {
-    NULL, amd64_supply_xstateregset, amd64_collect_xstateregset
-  };
-
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-
-static const struct regset *
-amd64_regset_from_core_section (struct gdbarch *gdbarch,
-				const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
-    return &amd64_fpregset;
-
-  if (strcmp (sect_name, ".reg-xstate") == 0)
-    return &amd64_xstateregset;
-
-  return i386_regset_from_core_section (gdbarch, sect_name, sect_size);
-}
 \f
 
 /* Figure out where the longjmp will land.  Slurp the jmp_buf out of
@@ -2973,6 +2930,7 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* AMD64 generally uses `fxsave' instead of `fsave' for saving its
      floating-point registers.  */
   tdep->sizeof_fpregset = I387_SIZEOF_FXSAVE;
+  tdep->fpregset = &amd64_fpregset;
 
   if (! tdesc_has_registers (tdesc))
     tdesc = tdesc_amd64;
@@ -3086,11 +3044,6 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   frame_unwind_append_unwinder (gdbarch, &amd64_frame_unwind);
   frame_base_set_default (gdbarch, &amd64_frame_base);
 
-  /* If we have a register mapping, enable the generic core file support.  */
-  if (tdep->gregset_reg_offset)
-    set_gdbarch_regset_from_core_section (gdbarch,
-					  amd64_regset_from_core_section);
-
   set_gdbarch_get_longjmp_target (gdbarch, amd64_get_longjmp_target);
 
   set_gdbarch_relocate_instruction (gdbarch, amd64_relocate_instruction);
diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
index f1b039e..641eef3 100644
--- a/gdb/amd64-tdep.h
+++ b/gdb/amd64-tdep.h
@@ -119,6 +119,8 @@ extern void amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 extern void amd64_collect_xsave (const struct regcache *regcache,
 				 int regnum, void *xsave, int gcore);
 \f
+/* Floating-point register set. */
+extern const struct regset amd64_fpregset;
 
 /* Variables exported from amd64-linux-tdep.c.  */
 extern int amd64_linux_gregset_reg_offset[];
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 22decd5..e3587f3 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -731,28 +731,6 @@ static const struct regset arm_linux_vfpregset =
     NULL, arm_linux_supply_vfp, arm_linux_collect_vfp
   };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-
-static const struct regset *
-arm_linux_regset_from_core_section (struct gdbarch *gdbarch,
-				    const char *sect_name, size_t sect_size)
-{
-  if (strcmp (sect_name, ".reg") == 0
-      && sect_size == ARM_LINUX_SIZEOF_GREGSET)
-    return &arm_linux_gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0
-      && sect_size == ARM_LINUX_SIZEOF_NWFPE)
-    return &arm_linux_fpregset;
-
-  if (strcmp (sect_name, ".reg-arm-vfp") == 0
-      && sect_size == ARM_LINUX_SIZEOF_VFP)
-    return &arm_linux_vfpregset;
-
-  return NULL;
-}
-
 /* Iterate over core file register note sections.  */
 
 static void
@@ -763,13 +741,14 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose", cb_data);
+  cb (".reg", ARM_LINUX_SIZEOF_GREGSET, &arm_linux_gregset, NULL, cb_data);
 
   if (tdep->have_vfp_registers)
-    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point",
-	cb_data);
+    cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, &arm_linux_vfpregset,
+	"VFP floating-point", cb_data);
   else if (tdep->have_fpa_registers)
-    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point", cb_data);
+    cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, &arm_linux_fpregset,
+	"FPA floating-point", cb_data);
 }
 
 /* Determine target description from core file.  */
@@ -1457,8 +1436,6 @@ arm_linux_init_abi (struct gdbarch_info info,
 				&arm_kernel_linux_restart_syscall_tramp_frame);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section (gdbarch,
-					arm_linux_regset_from_core_section);
   set_gdbarch_iterate_over_regset_sections
     (gdbarch, arm_linux_iterate_over_regset_sections);
   set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description);
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 7e64e1d..42af7f4 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -134,7 +134,9 @@ sniff_core_bfd (bfd *abfd)
 
   /* Don't sniff if we have support for register sets in
      CORE_GDBARCH.  */
-  if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (core_gdbarch
+      && (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
+	  || gdbarch_regset_from_core_section_p (core_gdbarch)))
     return NULL;
 
   for (cf = core_file_fns; cf != NULL; cf = cf->next)
@@ -489,7 +491,9 @@ core_detach (struct target_ops *ops, const char *args, int from_tty)
 
 static void
 get_core_register_section (struct regcache *regcache,
+			   const struct regset *regset,
 			   const char *name,
+			   int min_size,
 			   int which,
 			   const char *human_name,
 			   int required)
@@ -517,6 +521,12 @@ get_core_register_section (struct regcache *regcache,
     }
 
   size = bfd_section_size (core_bfd, section);
+  if (size < min_size)
+    {
+      warning (_("Section `%s' in core file too small."), section_name);
+      return;
+    }
+
   contents = alloca (size);
   if (! bfd_get_section_contents (core_bfd, section, contents,
 				  (file_ptr) 0, size))
@@ -526,10 +536,9 @@ get_core_register_section (struct regcache *regcache,
       return;
     }
 
-  if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (regset == NULL
+      && core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
     {
-      const struct regset *regset;
-
       regset = gdbarch_regset_from_core_section (core_gdbarch,
 						 name, size);
       if (regset == NULL)
@@ -539,7 +548,10 @@ get_core_register_section (struct regcache *regcache,
 		     human_name);
 	  return;
 	}
+    }
 
+  if (regset != NULL)
+    {
       regset->supply_regset (regset, regcache, -1, contents, size);
       return;
     }
@@ -555,16 +567,28 @@ get_core_register_section (struct regcache *regcache,
 
 static void
 get_core_registers_cb (const char *sect_name, int size,
+		       const struct regset *regset,
 		       const char *human_name, void *cb_data)
 {
   struct regcache *regcache = (struct regcache *) cb_data;
+  int required = 0;
 
   if (strcmp (sect_name, ".reg") == 0)
-    get_core_register_section (regcache, sect_name, 0, human_name, 1);
+    {
+      required = 1;
+      if (human_name == NULL)
+	human_name = "general-purpose";
+    }
   else if (strcmp (sect_name, ".reg2") == 0)
-    get_core_register_section (regcache, sect_name, 2, human_name, 0);
-  else
-    get_core_register_section (regcache, sect_name, 3, human_name, 0);
+    {
+      if (human_name == NULL)
+	human_name = "floating-point";
+    }
+
+  /* The 'which' parameter is only used when no regset is provided.
+     Thus we just set it to -1. */
+  get_core_register_section (regcache, regset, sect_name,
+			     size, -1, human_name, required);
 }
 
 /* Get the registers out of a core file.  This is the machine-
@@ -581,7 +605,9 @@ get_core_registers (struct target_ops *ops,
   int i;
   struct gdbarch *gdbarch;
 
-  if (!(core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch))
+  if (!(core_gdbarch
+	&& (gdbarch_iterate_over_regset_sections_p (core_gdbarch)
+	    || gdbarch_regset_from_core_section_p (core_gdbarch)))
       && (core_vec == NULL || core_vec->core_read_registers == NULL))
     {
       fprintf_filtered (gdb_stderr,
@@ -596,10 +622,10 @@ get_core_registers (struct target_ops *ops,
 					  (void *) regcache, NULL);
   else
     {
-      get_core_register_section (regcache,
-				 ".reg", 0, "general-purpose", 1);
-      get_core_register_section (regcache,
-				 ".reg2", 2, "floating-point", 0);
+      get_core_register_section (regcache, NULL,
+				 ".reg", 0, 0, "general-purpose", 1);
+      get_core_register_section (regcache, NULL,
+				 ".reg2", 0, 2, "floating-point", 0);
     }
 
   /* Mark all registers not found in the core as unavailable.  */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index bbda3da..90a63ca 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -82,7 +82,8 @@ typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
 
 typedef void (iterate_over_regset_sections_cb)
-  (const char *sect_name, int size, const char *human_name, void *cb_data);
+  (const char *sect_name, int size, const struct regset *regset,
+   const char *human_name, void *cb_data);
 
 
 /* The following are pre-initialized by GDBARCH.  */
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 80d3eec..293854f 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1176,7 +1176,8 @@ typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
   (struct objfile *objfile, void *cb_data);
 
 typedef void (iterate_over_regset_sections_cb)
-  (const char *sect_name, int size, const char *human_name, void *cb_data);
+  (const char *sect_name, int size, const struct regset *regset,
+   const char *human_name, void *cb_data);
 EOF
 
 # function typedef's
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 4ee6874..7feb21d 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -648,6 +648,35 @@ i386_linux_core_read_description (struct gdbarch *gdbarch,
     return tdesc_i386_mmx_linux;
 }
 
+/* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
+
+static void
+i386_linux_supply_xstateregset (const struct regset *regset,
+				struct regcache *regcache, int regnum,
+				const void *xstateregs, size_t len)
+{
+  i387_supply_xsave (regcache, regnum, xstateregs);
+}
+
+/* Similar to i386_collect_fpregset, but use XSAVE extended state.  */
+
+static void
+i386_linux_collect_xstateregset (const struct regset *regset,
+				 const struct regcache *regcache,
+				 int regnum, void *xstateregs, size_t len)
+{
+  i387_collect_xsave (regcache, regnum, xstateregs, 1);
+}
+
+/* Register set definitions.  */
+
+static const struct regset i386_linux_xstateregset =
+  {
+    NULL,
+    i386_linux_supply_xstateregset,
+    i386_linux_collect_xstateregset
+  };
+
 /* Iterate over core file register note sections.  */
 
 static void
@@ -658,14 +687,17 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  cb (".reg", 68, "general-purpose", cb_data);
+  cb (".reg", 68, &i386_gregset, NULL, cb_data);
 
   if (tdep->xcr0 & X86_XSTATE_AVX)
-    cb (".reg-xstate", X86_XSTATE_MAX_SIZE, "XSAVE extended state", cb_data);
+    /* Use max size for writing, accept any size when reading.  */
+    cb (".reg-xstate", regcache ? X86_XSTATE_MAX_SIZE : 0,
+	&i386_linux_xstateregset, "XSAVE extended state", cb_data);
   else if (tdep->xcr0 & X86_XSTATE_SSE)
-    cb (".reg-xfp", 512, "extended floating-point", cb_data);
+    cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
+	cb_data);
   else
-    cb (".reg2", 108, "floating-point", cb_data);
+    cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
 }
 
 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 1e68505..8f8cc99 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3806,26 +3806,6 @@ i386_collect_fpregset (const struct regset *regset,
   i387_collect_fsave (regcache, regnum, fpregs);
 }
 
-/* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
-
-static void
-i386_supply_xstateregset (const struct regset *regset,
-			  struct regcache *regcache, int regnum,
-			  const void *xstateregs, size_t len)
-{
-  i387_supply_xsave (regcache, regnum, xstateregs);
-}
-
-/* Similar to i386_collect_fpregset , but use XSAVE extended state.  */
-
-static void
-i386_collect_xstateregset (const struct regset *regset,
-			   const struct regcache *regcache,
-			   int regnum, void *xstateregs, size_t len)
-{
-  i387_collect_xsave (regcache, regnum, xstateregs, 1);
-}
-
 /* Register set definitions.  */
 
 const struct regset i386_gregset =
@@ -3833,16 +3813,11 @@ const struct regset i386_gregset =
     NULL, i386_supply_gregset, i386_collect_gregset
   };
 
-static const struct regset i386_fpregset =
+const struct regset i386_fpregset =
   {
     NULL, i386_supply_fpregset, i386_collect_fpregset
   };
 
-static const struct regset i386_xstateregset =
-  {
-    NULL, i386_supply_xstateregset, i386_collect_xstateregset
-  };
-
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 
@@ -3853,15 +3828,10 @@ i386_regset_from_core_section (struct gdbarch *gdbarch,
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
-      return &i386_gregset;
-
-  if ((strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
-      || (strcmp (sect_name, ".reg-xfp") == 0
-	  && sect_size == I387_SIZEOF_FXSAVE))
-    return &i386_fpregset;
+    return &i386_gregset;
 
-  if (strcmp (sect_name, ".reg-xstate") == 0)
-    return &i386_xstateregset;
+  if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
+    return tdep->fpregset;
 
   return NULL;
 }
@@ -8291,6 +8261,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Floating-point registers.  */
   tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
+  tdep->fpregset = &i386_fpregset;
 
   /* The default settings include the FPU registers, the MMX registers
      and the SSE registers.  This can be overridden for a specific ABI
@@ -8595,7 +8566,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* If we have a register mapping, enable the generic core file
      support, unless it has already been enabled.  */
   if (tdep->gregset_reg_offset
-      && !gdbarch_regset_from_core_section_p (gdbarch))
+      && !gdbarch_regset_from_core_section_p (gdbarch)
+      && !gdbarch_iterate_over_regset_sections_p (gdbarch))
     set_gdbarch_regset_from_core_section (gdbarch,
 					  i386_regset_from_core_section);
 
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index e0950a3..db8f4f7 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -237,6 +237,9 @@ struct gdbarch_tdep
   int (*i386_sysenter_record) (struct regcache *regcache);
   /* Parse syscall args.  */
   int (*i386_syscall_record) (struct regcache *regcache);
+
+  /* Regsets. */
+  const struct regset *fpregset;
 };
 
 /* Floating-point registers.  */
@@ -387,6 +390,9 @@ extern void i386_supply_gregset (const struct regset *regset,
 /* General-purpose register set. */
 extern const struct regset i386_gregset;
 
+/* Floating-point register set. */
+extern const struct regset i386_fpregset;
+
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 extern const struct regset *
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 3d8b1fc..fcba93b 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1105,16 +1105,15 @@ struct linux_collect_regset_section_cb_data
 
 static void
 linux_collect_regset_section_cb (const char *sect_name, int size,
+				 const struct regset *regset,
 				 const char *human_name, void *cb_data)
 {
-  const struct regset *regset;
   char *buf;
   struct linux_collect_regset_section_cb_data *data = cb_data;
 
   if (data->abort_iteration)
     return;
 
-  regset = gdbarch_regset_from_core_section (data->gdbarch, sect_name, size);
   gdb_assert (regset && regset->collect_regset);
 
   buf = xmalloc (size);
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 7ab3255..4d7d051 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -489,27 +489,6 @@ ppc_linux_fpregset (void)
   return &ppc32_linux_fpregset;
 }
 
-static const struct regset *
-ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
-				    const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
-  if (strcmp (sect_name, ".reg") == 0)
-    {
-      if (tdep->wordsize == 4)
-	return &ppc32_linux_gregset;
-      else
-	return &ppc64_linux_gregset;
-    }
-  if (strcmp (sect_name, ".reg2") == 0)
-    return &ppc32_linux_fpregset;
-  if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
-    return &ppc32_linux_vrregset;
-  if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
-    return &ppc32_linux_vsxregset;
-  return NULL;
-}
-
 /* Iterate over supported core file register note sections. */
 
 static void
@@ -522,14 +501,18 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
 
-  cb (".reg", 48 * tdep->wordsize, "general-purpose", cb_data);
-  cb (".reg2", 264, "floating-point", cb_data);
+  if (tdep->wordsize == 4)
+    cb (".reg", 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
+  else
+    cb (".reg", 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
+
+  cb (".reg2", 264, &ppc32_linux_fpregset, NULL, cb_data);
 
   if (have_altivec)
-    cb (".reg-ppc-vmx", 544, "ppc Altivec", cb_data);
+    cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset, "ppc Altivec", cb_data);
 
   if (have_vsx)
-    cb (".reg-ppc-vsx", 256, "POWER7 VSX", cb_data);
+    cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
 }
 
 static void
@@ -1385,8 +1368,6 @@ ppc_linux_init_abi (struct gdbarch_info info,
     set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
 					      elfcore_write_ppc_linux_prpsinfo32);
 
-  set_gdbarch_regset_from_core_section (gdbarch,
-					ppc_linux_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
   set_gdbarch_iterate_over_regset_sections (gdbarch,
 					    ppc_linux_iterate_over_regset_sections);
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 840431d..abd2e40 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -82,13 +82,6 @@ struct gdbarch_tdep
   int pc_regnum;
   int cc_regnum;
 
-  /* Core file register sets.  */
-  const struct regset *gregset;
-  int sizeof_gregset;
-
-  const struct regset *fpregset;
-  int sizeof_fpregset;
-
   int have_linux_v1;
   int have_linux_v2;
   int have_tdb;
@@ -536,36 +529,6 @@ const struct regset s390_tdb_regset = {
   regcache_collect_regset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
-static const struct regset *
-s390_regset_from_core_section (struct gdbarch *gdbarch,
-			       const char *sect_name, size_t sect_size)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset)
-    return tdep->gregset;
-
-  if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset)
-    return tdep->fpregset;
-
-  if (strcmp (sect_name, ".reg-s390-high-gprs") == 0 && sect_size >= 16*4)
-    return &s390_upper_regset;
-
-  if (strcmp (sect_name, ".reg-s390-last-break") == 0 && sect_size >= 8)
-    return (gdbarch_ptr_bit (gdbarch) == 32
-	    ?  &s390_last_break_regset : &s390x_last_break_regset);
-
-  if (strcmp (sect_name, ".reg-s390-system-call") == 0 && sect_size >= 4)
-    return &s390_system_call_regset;
-
-  if (strcmp (sect_name, ".reg-s390-tdb") == 0 && sect_size >= 256)
-    return &s390_tdb_regset;
-
-  return NULL;
-}
-
 /* Iterate over supported core file register note sections. */
 
 static void
@@ -575,18 +538,25 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
+			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
-  cb (".reg", tdep->sizeof_gregset, "general-purpose", cb_data);
-  cb (".reg2", s390_sizeof_fpregset, "floating-point", cb_data);
+  cb (".reg", gregset_size, &s390_gregset, NULL, cb_data);
+  cb (".reg2", s390_sizeof_fpregset, &s390_fpregset, NULL, cb_data);
 
   if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1)
-    cb (".reg-s390-high-gprs", 16 * 4, "s390 GPR upper halves", cb_data);
+    cb (".reg-s390-high-gprs", 16 * 4, &s390_upper_regset,
+	"s390 GPR upper halves", cb_data);
 
   if (tdep->have_linux_v1)
-    cb (".reg-s390-last-break", 8, "s930 last-break address", cb_data);
+    cb (".reg-s390-last-break", 8,
+	(gdbarch_ptr_bit (gdbarch) == 32
+	 ? &s390_last_break_regset : &s390x_last_break_regset),
+	"s930 last-break address", cb_data);
 
   if (tdep->have_linux_v2)
-    cb (".reg-s390-system-call", 4, "s390 system-call", cb_data);
+    cb (".reg-s390-system-call", 4, &s390_system_call_regset,
+	"s390 system-call", cb_data);
 
   /* If regcache is set, we are in "write" (gcore) mode.  In this
      case, don't iterate over the TDB unless its registers are
@@ -595,7 +565,8 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
       && (regcache == NULL
 	  || REG_VALID == regcache_register_status (regcache,
 						    S390_TDB_DWORD0_REGNUM)))
-    cb (".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB", cb_data);
+    cb (".reg-s390-tdb", s390_sizeof_tdbregset, &s390_tdb_regset,
+	"s390 TDB", cb_data);
 }
 
 static const struct target_desc *
@@ -3067,8 +3038,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
   set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
-  set_gdbarch_regset_from_core_section (gdbarch,
-					s390_regset_from_core_section);
   set_gdbarch_core_read_description (gdbarch, s390_core_read_description);
   set_gdbarch_iterate_over_regset_sections (gdbarch,
 					    s390_iterate_over_regset_sections);
@@ -3134,11 +3103,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   switch (tdep->abi)
     {
     case ABI_LINUX_S390:
-      tdep->gregset = &s390_gregset;
-      tdep->sizeof_gregset = s390_sizeof_gregset;
-      tdep->fpregset = &s390_fpregset;
-      tdep->sizeof_fpregset = s390_sizeof_fpregset;
-
       set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
       set_solib_svr4_fetch_link_map_offsets
 	(gdbarch, svr4_ilp32_fetch_link_map_offsets);
@@ -3147,11 +3111,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       break;
 
     case ABI_LINUX_ZSERIES:
-      tdep->gregset = &s390_gregset;
-      tdep->sizeof_gregset = s390x_sizeof_gregset;
-      tdep->fpregset = &s390_fpregset;
-      tdep->sizeof_fpregset = s390_sizeof_fpregset;
-
       set_gdbarch_long_bit (gdbarch, 64);
       set_gdbarch_long_long_bit (gdbarch, 64);
       set_gdbarch_ptr_bit (gdbarch, 64);
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 18/26] SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (29 preceding siblings ...)
  2014-09-12 18:32 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
@ 2014-09-12 18:32 ` Andreas Arnez
  2014-09-12 18:32 ` [PATCH 10/26] M32R: " Andreas Arnez
  2014-09-22 17:15 ` [PATCH 00/26] Regset rework Ulrich Weigand
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Qinwei

For S+core targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* score-tdep.c (score7_linux_regset_from_core_section): Remove.
	(score7_linux_iterate_over_regset_sections): New.
	(score_gdbarch_init): Adjust gdbarch initialization.
---
 gdb/score-tdep.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index d61faf0..dd438f9 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -1445,21 +1445,16 @@ static const struct regset score7_linux_gregset =
     regcache_collect_regset
   };
 
-/* Return the appropriate register set from the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-score7_linux_regset_from_core_section(struct gdbarch *gdbarch,
-                    const char *sect_name, size_t sect_size)
+static void
+score7_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					   iterate_over_regset_sections_cb *cb,
+					   void *cb_data,
+					   const struct regcache *regcache)
 {
-  gdb_assert (gdbarch != NULL);
-  gdb_assert (sect_name != NULL);
-
-  if (strcmp(sect_name, ".reg") == 0
-      && sect_size == SCORE7_LINUX_SIZEOF_GREGSET)
-    return &score7_linux_gregset;
-
-  return NULL;
+  cb (".reg", SCORE7_LINUX_SIZEOF_GREGSET, &score7_linux_gregset,
+      NULL, cb_data);
 }
 
 static struct gdbarch *
@@ -1504,8 +1499,8 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_register_name (gdbarch, score7_register_name);
       set_gdbarch_num_regs (gdbarch, SCORE7_NUM_REGS);
       /* Core file support.  */
-      set_gdbarch_regset_from_core_section (gdbarch,
-					    score7_linux_regset_from_core_section);
+      set_gdbarch_iterate_over_regset_sections
+	(gdbarch, score7_linux_iterate_over_regset_sections);
       break;
 
     case bfd_mach_score3:
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 10/26] M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (30 preceding siblings ...)
  2014-09-12 18:32 ` [PATCH 18/26] SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
@ 2014-09-12 18:32 ` Andreas Arnez
  2014-09-22 17:15 ` [PATCH 00/26] Regset rework Ulrich Weigand
  32 siblings, 0 replies; 37+ messages in thread
From: Andreas Arnez @ 2014-09-12 18:32 UTC (permalink / raw)
  To: gdb-patches

For m32r GNU/Linux targets, don't define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m32r-linux-tdep.c (M32R_LINUX_GREGS_SIZE): New macro.
	(m32r_linux_regset_from_core_section): Remove.
	(m32r_linux_iterate_over_regset_sections): New.
	(m32r_linux_init_abi): Adjust gdbarch initialization.
---
 gdb/m32r-linux-tdep.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/gdb/m32r-linux-tdep.c b/gdb/m32r-linux-tdep.c
index 5499902..2133c0c 100644
--- a/gdb/m32r-linux-tdep.c
+++ b/gdb/m32r-linux-tdep.c
@@ -344,6 +344,8 @@ static int m32r_pt_regs_offset[] = {
 #define SPU_OFFSET (4 * 23)
 #define SPI_OFFSET (4 * 26)
 
+#define M32R_LINUX_GREGS_SIZE (4 * 28)
+
 static void
 m32r_linux_supply_gregset (const struct regset *regset,
 			   struct regcache *regcache, int regnum,
@@ -433,14 +435,13 @@ static const struct regset m32r_linux_gregset = {
   m32r_linux_supply_gregset, m32r_linux_collect_gregset
 };
 
-static const struct regset *
-m32r_linux_regset_from_core_section (struct gdbarch *core_arch,
-				     const char *sect_name, size_t sect_size)
+static void
+m32r_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
+					 iterate_over_regset_sections_cb *cb,
+					 void *cb_data,
+					 const struct regcache *regcache)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
-  if (strcmp (sect_name, ".reg") == 0)
-    return &m32r_linux_gregset;
-  return NULL;
+  cb (".reg", M32R_LINUX_GREGS_SIZE, &m32r_linux_gregset, NULL, cb_data);
 }
 
 static void
@@ -462,8 +463,8 @@ m32r_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m32r_linux_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m32r_linux_iterate_over_regset_sections);
 
   /* Enable TLS support.  */
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/26] Regset rework
  2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
                   ` (31 preceding siblings ...)
  2014-09-12 18:32 ` [PATCH 10/26] M32R: " Andreas Arnez
@ 2014-09-22 17:15 ` Ulrich Weigand
  2014-09-26 16:20   ` Pedro Alves
  32 siblings, 1 reply; 37+ messages in thread
From: Ulrich Weigand @ 2014-09-22 17:15 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: gdb-patches

Andreas Arnez wrote:

> Now this patch series attempts the next major refactoring step in this
> area.  It has two main goals:
> 
> * Unify GDB's capabilities with respect to core files across the
>   various architectures.  In particular enable more targets for
>   multi-arch capable core file generation support.
> 
> * Streamline the regset support: reduce the gdbarch interface and
>   reduce overall complexity.
> 
> One important means to achieve these goals is by merging two existing
> gdbarch interfaces into one.  Currently, the gdbarch variable
> 'core_regset_sections' enumerates the core file register notes to be
> handled by GDB; it specifies each note section's BFD name, size, and
> human-friendly name.  In addition, the gdbarch method
> 'regset_from_core_section' translates a BFD name to a register set
> definition.  Both of these interfaces are merged into a single gdbarch
> method 'iterate_over_regset_sections', which enumerates the core file
> notes *and* provides the register set definition for each.

I've reviewed the patch set, and I agree with the general direction,
and the implementation looks good to me as well.

It would still be good to get some platform maintainer feedback (and
testing), so I'd like to wait another week or so before approving
the series.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/26] Regset rework
  2014-09-22 17:15 ` [PATCH 00/26] Regset rework Ulrich Weigand
@ 2014-09-26 16:20   ` Pedro Alves
  2014-09-29 11:22     ` Ulrich Weigand
  0 siblings, 1 reply; 37+ messages in thread
From: Pedro Alves @ 2014-09-26 16:20 UTC (permalink / raw)
  To: Ulrich Weigand, Andreas Arnez; +Cc: gdb-patches

On 09/22/2014 06:15 PM, Ulrich Weigand wrote:

> I've reviewed the patch set, and I agree with the general direction,
> and the implementation looks good to me as well.

FWIW, I read this, and I agree with it too.  Very nice work.

> It would still be good to get some platform maintainer feedback (and
> testing), so I'd like to wait another week or so before approving
> the series.

Looking forward to have this in.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/26] Regset rework
  2014-09-26 16:20   ` Pedro Alves
@ 2014-09-29 11:22     ` Ulrich Weigand
  2014-09-30  7:59       ` Andreas Krebbel
  0 siblings, 1 reply; 37+ messages in thread
From: Ulrich Weigand @ 2014-09-29 11:22 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Andreas Arnez, gdb-patches

Pedro Alves wrote:
> On 09/22/2014 06:15 PM, Ulrich Weigand wrote:
> 
> > I've reviewed the patch set, and I agree with the general direction,
> > and the implementation looks good to me as well.
> 
> FWIW, I read this, and I agree with it too.  Very nice work.

Thanks for the additional review!

> > It would still be good to get some platform maintainer feedback (and
> > testing), so I'd like to wait another week or so before approving
> > the series.
> 
> Looking forward to have this in.

I guess there's not much point in further waiting at this point.

Andreas, can you check the patch series in?

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/26] Regset rework
  2014-09-29 11:22     ` Ulrich Weigand
@ 2014-09-30  7:59       ` Andreas Krebbel
  0 siblings, 0 replies; 37+ messages in thread
From: Andreas Krebbel @ 2014-09-30  7:59 UTC (permalink / raw)
  To: Ulrich Weigand, Pedro Alves; +Cc: Andreas Arnez, gdb-patches

On 09/29/2014 01:22 PM, Ulrich Weigand wrote:
> Pedro Alves wrote:
>> On 09/22/2014 06:15 PM, Ulrich Weigand wrote:
>>
>>> I've reviewed the patch set, and I agree with the general direction,
>>> and the implementation looks good to me as well.
>>
>> FWIW, I read this, and I agree with it too.  Very nice work.
> 
> Thanks for the additional review!
> 
>>> It would still be good to get some platform maintainer feedback (and
>>> testing), so I'd like to wait another week or so before approving
>>> the series.
>>
>> Looking forward to have this in.
> 
> I guess there's not much point in further waiting at this point.
> 
> Andreas, can you check the patch series in?

I've just committed the whole patch-set.

Bye,

-Andreas-

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2014-09-30  7:59 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-12 15:40 [PATCH 00/26] Regset rework Andreas Arnez
2014-09-12 15:40 ` [PATCH 01/26] Replace 'core_regset_sections' by iterator method Andreas Arnez
2014-09-12 15:40 ` [PATCH 26/26] Drop 'regset_from_core_section' gdbarch method Andreas Arnez
2014-09-12 15:40 ` [PATCH 05/26] ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
2014-09-12 15:40 ` [PATCH 07/26] FRV: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 23/26] XTENSA: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 22/26] VAX: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 14/26] MIPS: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 21/26] TILEGX: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 12/26] IA64: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 16/26] NIOS2: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 04/26] AARCH64: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 17/26] PPC: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 11/26] M68K: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 13/26] M88K: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 09/26] X86: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 03/26] Add multi-arch capable 'fbsd_make_corefile_notes' variant Andreas Arnez
2014-09-12 15:40 ` [PATCH 06/26] ARM: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
2014-09-12 15:40 ` [PATCH 20/26] SPARC: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 19/26] SH: " Andreas Arnez
2014-09-12 15:40 ` [PATCH 08/26] HPPA: " Andreas Arnez
2014-09-12 16:14 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
2014-09-12 16:15 ` [PATCH 10/26] M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
2014-09-12 16:17 ` [PATCH 15/26] MN10300: " Andreas Arnez
2014-09-12 16:18 ` [PATCH 18/26] SCORE: " Andreas Arnez
2014-09-12 16:18 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
2014-09-12 16:18 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
2014-09-12 18:31 ` [PATCH 15/26] MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
2014-09-12 18:31 ` [PATCH 24/26] Drop target method 'fbsd_make_corefile_notes' Andreas Arnez
2014-09-12 18:31 ` [PATCH 25/26] Linux targets: drop fall back to target method for 'make_corefile_notes' Andreas Arnez
2014-09-12 18:32 ` [PATCH 02/26] Add 'regset' parameter to 'iterate_over_regset_sections_cb' Andreas Arnez
2014-09-12 18:32 ` [PATCH 18/26] SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections' Andreas Arnez
2014-09-12 18:32 ` [PATCH 10/26] M32R: " Andreas Arnez
2014-09-22 17:15 ` [PATCH 00/26] Regset rework Ulrich Weigand
2014-09-26 16:20   ` Pedro Alves
2014-09-29 11:22     ` Ulrich Weigand
2014-09-30  7:59       ` Andreas Krebbel

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).