From: scottb <scottb@netwinder.org>
To: Nick Clifton <nickc@cygnus.com>
Cc: binutils@sourceware.cygnus.com
Subject: Re: Patch to readelf...
Date: Tue, 31 Aug 1999 08:40:00 -0000 [thread overview]
Message-ID: <37CBF6CD.DC643F63@netwinder.org> (raw)
In-Reply-To: <199908310847.JAA19452@pathia.cygnus.co.uk>
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. */
next prev parent reply other threads:[~1999-08-31 8:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-31 1:47 Nick Clifton
1999-08-31 8:40 ` scottb [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-08-31 10:00 Nick Clifton
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
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=37CBF6CD.DC643F63@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).