This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

handle new Linux core notes in readelf


The Linux kernel recently added a couple new ELF notes to core files.
See:

https://lkml.org/lkml/2012/9/12/920
https://patchwork.kernel.org/patch/1481921/

This patch adds some support for these to readelf.

I added somewhat full dumping for the NT_FILE note, since this seemed
handy and in keeping with what is done for other notes.  Here is sample
output from a core file I made using a kernel from Fedora rawhide:

barimba. ../build/binutils/readelf -n new-note-example.core 

Notes at offset 0x00000430 with length 0x000007d0:
  Owner                 Data size	Description
  CORE                 0x00000150	NT_PRSTATUS (prstatus structure)
  CORE                 0x00000088	NT_PRPSINFO (prpsinfo structure)
  CORE                 0x00000080	NT_SIGINFO (siginfo_t data)
  CORE                 0x00000130	NT_AUXV (auxiliary vector)
  CORE                 0x000001cf	NT_FILE (mapped files)
    Page size: 4096
                 Start                 End         Page Offset
    0x0000000000400000  0x0000000000401000  0x0000000000000000
        /home/tromey/q
    0x0000000000600000  0x0000000000601000  0x0000000000000000
        /home/tromey/q
    0x0000000000601000  0x0000000000602000  0x0000000000000001
        /home/tromey/q
    0x0000003399c00000  0x0000003399c20000  0x0000000000000000
        /usr/lib64/ld-2.16.so
    0x0000003399e20000  0x0000003399e21000  0x0000000000000020
        /usr/lib64/ld-2.16.so
    0x0000003399e21000  0x0000003399e22000  0x0000000000000021
        /usr/lib64/ld-2.16.so
    0x000000339a000000  0x000000339a1ad000  0x0000000000000000
        /usr/lib64/libc-2.16.so
    0x000000339a1ad000  0x000000339a3ad000  0x00000000000001ad
        /usr/lib64/libc-2.16.so
    0x000000339a3ad000  0x000000339a3b1000  0x00000000000001ad
        /usr/lib64/libc-2.16.so
  CORE                 0x00000200	NT_FPREGSET (floating point registers)


I also tested this using "make check" in binutils.
There were no regressions.

Tom

binutils/ChangeLog:
2012-10-22  Tom Tromey  <tromey@redhat.com>

	* readelf.c (get_note_type): Handle NT_SIGINFO, NT_FILE.
	(print_core_note): New function.
	(process_note): Call it.

include/elf/ChangeLog:
2012-10-22  Tom Tromey  <tromey@redhat.com>

	* common.h (NT_SIGINFO, NT_FILE): New defines.

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 2fbf2ae..4bed07a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -12612,6 +12612,10 @@ get_note_type (unsigned e_type)
 	return _("NT_LWPSINFO (lwpsinfo_t structure)");
       case NT_WIN32PSTATUS:
 	return _("NT_WIN32PSTATUS (win32_pstatus structure)");
+      case NT_SIGINFO:
+	return _("NT_SIGINFO (siginfo_t data)");
+      case NT_FILE:
+	return _("NT_FILE (mapped files)");
       default:
 	break;
       }
@@ -12630,6 +12634,92 @@ get_note_type (unsigned e_type)
   return buff;
 }
 
+static int
+print_core_note (Elf_Internal_Note *pnote)
+{
+  unsigned int addr_size = is_32bit_elf ? 4 : 8;
+  bfd_vma count, page_size;
+  unsigned char *descdata, *filenames, *descend;
+
+  if (pnote->type != NT_FILE)
+    return 1;
+
+#ifndef BFD64
+  if (!is_32bit_elf)
+    {
+      printf (_("    Cannot decode 64-bit note in 32-bit build\n"));
+      /* Still "successful".  */
+      return 1;
+    }
+#endif
+
+  if (pnote->descsz < 2 * addr_size)
+    {
+      printf (_("    Malformed note - too short for header\n"));
+      return 0;
+    }
+
+  descdata = (unsigned char *) pnote->descdata;
+  descend = descdata + pnote->descsz;
+
+  if (descdata[pnote->descsz - 1] != '\0')
+    {
+      printf (_("    Malformed note - does not end with \\0\n"));
+      return 0;
+    }
+
+  count = byte_get (descdata, addr_size);
+  descdata += addr_size;
+
+  page_size = byte_get (descdata, addr_size);
+  descdata += addr_size;
+
+  if (pnote->descsz < 2 * addr_size + count * 3 * addr_size)
+    {
+      printf (_("    Malformed note - too short for supplied file count\n"));
+      return 0;
+    }
+
+  printf (_("    Page size: "));
+  print_vma (page_size, DEC);
+  printf ("\n");
+
+  printf (_("    %*s%*s%*s\n"),
+	  (int) (2 + 2 * addr_size), _("Start"),
+	  (int) (4 + 2 * addr_size), _("End"),
+	  (int) (4 + 2 * addr_size), _("Page Offset"));
+  filenames = descdata + count * 3 * addr_size;
+  while (--count > 0)
+    {
+      bfd_vma start, end, file_ofs;
+
+      if (filenames == descend)
+	{
+	  printf (_("    Malformed note - filenames end too early\n"));
+	  return 0;
+	}
+
+      start = byte_get (descdata, addr_size);
+      descdata += addr_size;
+      end = byte_get (descdata, addr_size);
+      descdata += addr_size;
+      file_ofs = byte_get (descdata, addr_size);
+      descdata += addr_size;
+
+      printf ("    ");
+      print_vma (start, FULL_HEX);
+      printf ("  ");
+      print_vma (end, FULL_HEX);
+      printf ("  ");
+      print_vma (file_ofs, FULL_HEX);
+      printf ("\n        %s\n", filenames);
+
+      filenames += 1 + strlen ((char *) filenames);
+    }
+
+  return 1;
+}
+
 static const char *
 get_gnu_elf_note_type (unsigned e_type)
 {
@@ -12990,6 +13080,8 @@ process_note (Elf_Internal_Note * pnote)
     return print_gnu_note (pnote);
   else if (const_strneq (pnote->namedata, "stapsdt"))
     return print_stapsdt_note (pnote);
+  else if (const_strneq (pnote->namedata, "CORE"))
+    return print_core_note (pnote);
   else
     return 1;
 }
diff --git a/include/elf/common.h b/include/elf/common.h
index 1c681d5..be228cd 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -549,6 +549,8 @@
 					/*   note name must be "LINUX".  */
 #define NT_ARM_VFP	0x400		/* ARM VFP registers */
 					/*   note name must be "LINUX".  */
+#define NT_SIGINFO	0x53494749	/* Fields of siginfo_t.  */
+#define NT_FILE		0x46494c45	/* Description of mapped files.  */
 
 /* 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]