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:
> 
> Anyway this patch looks much more reasonable.  A couple of minor
> niggles which wouldn't stop the patch from being accepted, but which
> it would be nice to see fixed:

The niggles are now fixed :).  process_corefile_note_segment() still has
to return an int due to the GET_DATA_ALLOC macro.

Scott
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/readelf.c,v
retrieving revision 1.25
diff -u -w -r1.25 readelf.c
--- readelf.c	1999/08/28 08:13:43	1.25
+++ readelf.c	1999/08/31 15:32:05
@@ -194,6 +194,12 @@
 static const char *       get_osabi_name              PARAMS ((unsigned char));
 static int		  guess_is_rela               PARAMS ((unsigned long));
 
+static char * 		  get_note_type		         PARAMS ((unsigned int));
+static void		  process_note		         PARAMS ((Elf_External_Note *));
+static int		  process_corefile_note_segment  PARAMS ((FILE *, unsigned long, unsigned long));
+static void		  process_corefile_note_segments PARAMS ((FILE *));
+static int 		  process_corefile_contents	 PARAMS ((FILE *));
+
 typedef int Elf32_Word;
 
 #ifndef TRUE
@@ -6349,6 +6355,153 @@
   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 void
+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;
+    }
+
+  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);
+}
+
+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 void
+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;
+    }
+
+  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;
+    }
+  
+  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);
+}
+
+static int
+process_corefile_contents (file)
+     FILE * file;
+{
+  /* If file is 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 note 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 +6659,8 @@
   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 -w -r1.3 common.h
--- common.h	1999/06/03 08:20:07	1.3
+++ common.h	1999/08/31 15:32:05
@@ -239,6 +239,7 @@
 #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]