This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to readelf...


Nick Clifton wrote:
> 
> If you would like to tidy the patch up, I would be happy to review it
> again.

Hi Nick, 

I decided to submit this stuff in stages.  I have cleaned up the patch,
and removed all of the ARM Linux specific stuff.  The code now simply
parses the NOTE segment and lists the type of notes it finds.
Please have a look at this an let me know if anything else needs
changing.

Scott

1999-08-30  Scott Bambrough <scottb@netwinder.org>

       * include/elf/common.h: Added NT_TASKSTRUCT note type.
       * binutils/readelf.c: Added code to list the type of notes found
	 in the note segments in elf core files.
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/readelf.c,v
retrieving revision 1.25
diff -u -p -w -r1.25 readelf.c
--- readelf.c	1999/08/28 08:13:43	1.25
+++ readelf.c	1999/08/30 18:55:12
@@ -6349,7 +6349,156 @@ process_mips_specific (file)
   return 1;
 }
 
+static char *
+get_note_type (e_type)
+     unsigned e_type;
+{
+  static char buff[64];
+  
+  switch (e_type)
+    {
+    case NT_PRSTATUS:	return _("NT_PRSTATUS (prstatus structure)");
+    case NT_FPREGSET:	return _("NT_FPREGSET (floating point registers)");
+    case NT_PRPSINFO:   return _("NT_PRPSINFO (prpsinfo structure)");
+    case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
+    case NT_PSTATUS:	return _("NT_PSTATUS (pstatus structure)");
+    case NT_FPREGS:	return _("NT_FPREGS (floating point registers)");
+    case NT_PSINFO:	return _("NT_PSINFO (psinfo structure)");
+    case NT_LWPSTATUS:	return _("NT_LWPSTATUS (lwpstatus_t structure)");
+    case NT_LWPSINFO:	return _("NT_LWPSINFO (lwpsinfo_t structure)");
+    default:
+      sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
+      return buff;
+    }
+}
+
+static int
+process_note (pnote)
+  Elf_External_Note	*pnote;
+{
+  Elf32_Internal_Note	*internal;
+  char *pname;
+  
+  internal = (Elf32_Internal_Note *)pnote;
+  pname = malloc (internal->namesz + 1);
+  if (pname == NULL)
+    {
+      error (_("Out of memory\n"));
+      return 0;
+    }
+
+  memcpy (pname, pnote->name, internal->namesz);
+  pname[internal->namesz] = '\0';
+
+  printf ("  %s\t\t0x%08lx\t%s\n", 
+  	  pname, internal->descsz, get_note_type(internal->type));
+  	   
+  free (pname);
+  return 1;
+}
+
 static int
+process_corefile_note_segment (file, offset, length)
+     FILE * file;
+     unsigned long offset;
+     unsigned long length;
+{
+  Elf_External_Note	*pnotes, *external;
+  Elf32_Internal_Note	*internal;
+  unsigned int	notesz, nlength;
+  unsigned char *p;
+  
+  if (length <= 0)
+    return 0;
+    
+  GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
+
+  external = pnotes; 
+  p = (unsigned char *)pnotes;
+  nlength = length;
+ 
+  printf ("\nNotes at offset 0x%08lx with length 0x%08lx:\n", offset, length);
+  printf ("  Owner\t\tData size\tDescription\n");
+  
+  while (nlength > 0)
+  {
+    process_note (external);
+    internal = (Elf32_Internal_Note *)p;
+    notesz = 3 * sizeof(unsigned long) + internal->namesz + internal->descsz;
+    nlength -= notesz;
+    p += notesz;
+    external = (Elf_External_Note *)p;
+  }
+
+  free (pnotes);
+  return 1;
+}
+
+static int
+process_corefile_note_segments (file)
+     FILE * file;
+{
+  Elf_Internal_Phdr * program_headers;
+  Elf_Internal_Phdr * segment;
+  unsigned int	      i;
+
+  program_headers = (Elf_Internal_Phdr *) malloc
+    (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
+
+  if (program_headers == NULL)
+    {
+      error (_("Out of memory\n"));
+      return 0;
+    }
+
+  if (is_32bit_elf)
+    i = get_32bit_program_headers (file, program_headers);
+  else
+    i = get_64bit_program_headers (file, program_headers);
+
+  if (i == 0)
+    {
+      free (program_headers);
+      return 0;
+    }
+  
+  for (i = 0, segment = program_headers;
+       i < elf_header.e_phnum;
+       i ++, segment ++)
+    {
+      if (segment->p_type == PT_NOTE)
+	{
+	  process_corefile_note_segment (file, 
+	  				 (unsigned long)segment->p_offset,
+	  				 (unsigned long)segment->p_filesz);
+	}
+    }
+    
+  free (program_headers);
+  return 1;
+}
+
+static int
+process_corefile_contents (file)
+     FILE * file;
+{
+  /* if not a core file then exit */
+  if (elf_header.e_type != ET_CORE)
+    return 1;
+    
+  /* no program headers means no NOTE segment */
+  if (elf_header.e_phnum == 0)
+    {
+      printf (_("No notes segments present in the core file.\n"));
+      return 1;
+   }
+
+  process_corefile_note_segments (file);
+
+  return 1;
+}
+
+static int
 process_arch_specific (file)
      FILE * file;
 {
@@ -6506,6 +6655,8 @@ process_file (file_name)
   process_version_sections (file);
 
   process_section_contents (file);
+  
+  process_corefile_contents (file);
 
   process_arch_specific (file);
 
Index: include/elf/common.h
===================================================================
RCS file: /cvs/binutils/binutils/include/elf/common.h,v
retrieving revision 1.3
diff -u -p -w -r1.3 common.h
--- common.h	1999/06/03 08:20:07	1.3
+++ common.h	1999/08/30 18:55:16
@@ -239,6 +239,7 @@ Foundation, Inc., 59 Temple Place - Suit
 #define NT_PRSTATUS	1		/* Contains copy of prstatus struct */
 #define NT_FPREGSET	2		/* Contains copy of fpregset struct */
 #define NT_PRPSINFO	3		/* Contains copy of prpsinfo struct */
+#define NT_TASKSTRUCT	4		/* Contains copy of task struct */
 
 /* Note segments for core files on dir-style procfs systems. */
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]