public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: scottb <scottb@netwinder.org>
To: Nick Clifton <nickc@cygnus.com>
Cc: binutils mailing list <binutils@sourceware.cygnus.com>
Subject: Re: Patch to readelf...
Date: Mon, 30 Aug 1999 12:11:00 -0000	[thread overview]
Message-ID: <37CAD6C4.A03CF26@netwinder.org> (raw)
In-Reply-To: <199908191628.RAA28501@pathia.cygnus.co.uk>

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. */
 

  parent reply	other threads:[~1999-08-30 12:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-19  9:29 Nick Clifton
1999-08-19  9:47 ` Jakub Jelinek
1999-08-19 11:56 ` scottb
1999-08-19 12:40   ` Ian Lance Taylor
1999-08-30 12:11 ` scottb [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-08-31 10:00 Nick Clifton
1999-08-31  1:47 Nick Clifton
1999-08-31  8:40 ` scottb
1999-08-19  8:10 scottb
1999-08-19 11:24 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37CAD6C4.A03CF26@netwinder.org \
    --to=scottb@netwinder.org \
    --cc=binutils@sourceware.cygnus.com \
    --cc=nickc@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).