[PATCH / RFA] Add core file support functions to elf32-frv.c

Kevin Buettner kevinb@redhat.com
Sun Feb 19 10:58:00 GMT 2006


On Fri, 17 Feb 2006 12:07:43 +0000
Nick Clifton <nickc@redhat.com> wrote:

> > +static bfd_boolean elf32_frv_grok_prstatus
> > +  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
> > +static bfd_boolean elf32_frv_grok_psinfo
> > +  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
> 
> We no longer need the PARAMS macro.  We are use ISO C now.

Would a patch which eliminates PARAMS from this file (and perhaps others)
be welcome?  (I have a script which does this.  It not only removes the
PARAMS, but reindents the affected code.)

> > +	/* pr_pid */
> 
> Likewise.
> 
> > +	elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
> 
> Just a query - is there any way to make the value of "24" more 
> explanatory ?  Is it the offset of a known field in a structure which 
> you could get with offsetof() for example ?

That's what that cryptic "pr_pid" comment was about.  (I agree that
this comment could be improved...)

The hardcoded sizes and offsets refer to fields in the target specific
elf_prstatus struct.  The layout of this struct is fairly standard,
but ABI mandated padding may affect the layouts slightly.  Also, for
FR-V, I added two new fields to this struct for communicating the
loadmap information from the kernel to GDB.

I don't believe that the layout of this struct (either for FR-V or for
the general case) is known to BFD.  We could use the strategy that GDB
sometimes employs for core file structs, which is to define a struct
which mimics that of the kernel struct using only types composed of
char arrays.  (This allows us to reproduce the padding too.) If you
are interesting in seeing how this is done, see the patch that I
recently submitted for FR-V corefile support in GDB:

    http://sources.redhat.com/ml/gdb-patches/2006-02/msg00311.html

Look for the definition of frv_elf_fpregset_t.

While GDB's approach would certainly work for the corefile grokking code
in BFD, I believe it would be overkill because BFD only really cares about
just a few select fields within the structs that it's grokking.

That said, the comments can certainly be improved to better indicate
exactly what these hardcoded constants refer to.  I have taken that
approach in my revised patch below.  If you prefer GDB's approach
to describing these structs, I'm willing to rework the code to use
that approach instead.

> With these changes applied your patch is approved - please commit.

I've committed the patch below.

	* elf32-frv.c (elf32_frv_grok_prstatus, elf32_frv_grok_psinfo):
	New functions.
	* elf_backend_grok_prstatus, elf_backend_grok_psinfo): Define.

Index: elf32-frv.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-frv.c,v
retrieving revision 1.43
diff -u -p -r1.43 elf32-frv.c
--- elf32-frv.c	15 Aug 2005 15:39:08 -0000	1.43
+++ elf32-frv.c	17 Feb 2006 18:02:51 -0000
@@ -78,6 +78,10 @@ static bfd_boolean frv_elf_merge_private
   PARAMS ((bfd *, bfd *));
 static bfd_boolean frv_elf_print_private_bfd_data
   PARAMS ((bfd *, PTR));
+static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
+					    Elf_Internal_Note * note);
+static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
+					  Elf_Internal_Note * note);
 
 static reloc_howto_type elf32_frv_howto_table [] =
 {
@@ -6823,6 +6827,86 @@ frv_elf_print_private_bfd_data (abfd, pt
 }
 
 

+/* Support for core dump NOTE sections.  */
+
+static bfd_boolean
+elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+  int offset;
+  unsigned int raw_size;
+
+  switch (note->descsz)
+    {
+      default:
+	return FALSE;
+
+      /* The Linux/FRV elf_prstatus struct is 268 bytes long.  The other
+         hardcoded offsets and sizes listed below (and contained within
+	 this lexical block) refer to fields in the target's elf_prstatus
+	 struct.  */
+      case 268:	
+	/* `pr_cursig' is at offset 12.  */
+	elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
+
+	/* `pr_pid' is at offset 24.  */
+	elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
+
+	/* `pr_reg' is at offset 72.  */
+	offset = 72;
+
+	/* Most grok_prstatus implementations set `raw_size' to the size
+	   of the pr_reg field.  For Linux/FRV, we set `raw_size' to be
+	   the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
+	   and `pr_interp_fdpic_loadmap', both of which (by design)
+	   immediately follow `pr_reg'.  This will allow these fields to
+	   be viewed by GDB as registers.
+	   
+	   `pr_reg' is 184 bytes long.  `pr_exec_fdpic_loadmap' and
+	   `pr_interp_fdpic_loadmap' are 4 bytes each.  */
+	raw_size = 184 + 4 + 4;
+
+	break;
+    }
+
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
+					  note->descpos + offset);
+}
+
+static bfd_boolean
+elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+  switch (note->descsz)
+    {
+      default:
+	return FALSE;
+
+      /* The Linux/FRV elf_prpsinfo struct is 124 bytes long.  */
+      case 124:
+
+	/* `pr_fname' is found at offset 28 and is 16 bytes long.  */
+	elf_tdata (abfd)->core_program
+	  = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
+
+	/* `pr_psargs' is found at offset 44 and is 80 bytes long.  */
+	elf_tdata (abfd)->core_command
+	  = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
+    }
+
+  /* Note that for some reason, a spurious space is tacked
+     onto the end of the args in some (at least one anyway)
+     implementations, so strip it off if it exists.  */
+
+  {
+    char *command = elf_tdata (abfd)->core_command;
+    int n = strlen (command);
+
+    if (0 < n && command[n - 1] == ' ')
+      command[n - 1] = '\0';
+  }
+
+  return TRUE;
+}
 #define ELF_ARCH		bfd_arch_frv
 #define ELF_MACHINE_CODE	EM_CYGNUS_FRV
 #define ELF_MAXPAGESIZE		0x1000
@@ -6857,6 +6941,9 @@ frv_elf_print_private_bfd_data (abfd, pt
 #define elf_backend_finish_dynamic_sections \
 		elf32_frv_finish_dynamic_sections
 
+#define elf_backend_grok_prstatus	elf32_frv_grok_prstatus
+#define elf_backend_grok_psinfo		elf32_frv_grok_psinfo
+
 #include "elf32-target.h"
 
 #undef ELF_MAXPAGESIZE



More information about the Binutils mailing list