+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_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs 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)");
+ case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
+ default:
+ sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
+ return buff;
+ }
+}
+
+/* Note that by the ELF standard, the name field is already null byte
+ terminated, and namesz includes the terminating null byte.
+ I.E. the value of namesz for the name "FSF" is 4.
+
+ If the value of namesz is zero, there is no name present. */
+static int
+process_note (pnote)
+ Elf32_Internal_Note * pnote;
+{
+ printf (" %s\t\t0x%08lx\t%s\n",
+ pnote->namesz ? pnote->namedata : "(NONE)",
+ pnote->descsz, get_note_type (pnote->type));
+ return 1;
+}
+
+
+static int
+process_corefile_note_segment (file, offset, length)
+ FILE * file;
+ bfd_vma offset;
+ bfd_vma length;
+{
+ Elf_External_Note * pnotes;
+ Elf_External_Note * external;
+ int res = 1;
+
+ if (length <= 0)
+ return 0;
+
+ GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
+
+ external = pnotes;
+
+ printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
+ (unsigned long) offset,
+ (unsigned long) length);
+ printf (_(" Owner\t\tData size\tDescription\n"));
+
+ while (external < (Elf_External_Note *)((char *) pnotes + length))
+ {
+ Elf32_Internal_Note inote;
+ char * temp = NULL;
+
+ inote.type = BYTE_GET (external->type);
+ inote.namesz = BYTE_GET (external->namesz);
+ inote.namedata = external->name;
+ inote.descsz = BYTE_GET (external->descsz);
+ inote.descdata = inote.namedata + align_power (inote.namesz, 2);
+ inote.descpos = offset + (inote.descdata - (char *) pnotes);
+
+ external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
+
+ /* Verify that name is null terminated. It appears that at least
+ one version of Linux (RedHat 6.0) generates corefiles that don't
+ comply with the ELF spec by failing to include the null byte in
+ namesz. */
+ if (inote.namedata[inote.namesz] != '\0')
+ {
+ temp = malloc (inote.namesz + 1);
+
+ if (temp == NULL)
+ {
+ error (_("Out of memory\n"));
+ res = 0;
+ break;
+ }
+
+ strncpy (temp, inote.namedata, inote.namesz);
+ temp[inote.namesz] = 0;
+
+ /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
+ inote.namedata = temp;
+ }
+
+ res &= process_note (& inote);
+
+ if (temp != NULL)
+ {
+ free (temp);
+ temp = NULL;
+ }
+ }
+
+ free (pnotes);
+
+ return res;
+}
+
+static int
+process_corefile_note_segments (file)
+ FILE * file;
+{
+ Elf_Internal_Phdr * program_headers;
+ Elf_Internal_Phdr * segment;
+ unsigned int i;
+ int res = 1;
+
+ 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)
+ res &= process_corefile_note_segment (file,
+ (bfd_vma) segment->p_offset,
+ (bfd_vma) segment->p_filesz);
+ }
+
+ free (program_headers);
+
+ return res;
+}
+
+static int
+process_corefile_contents (file)
+ FILE * file;
+{
+ /* If we have not been asked to display the notes then do nothing. */
+ if (! do_notes)
+ return 1;
+
+ /* 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;
+ }
+
+ return process_corefile_note_segments (file);
+}
+