Show contents NT_FILE core note in readelf
authorPetr Machata <pmachata@redhat.com>
Thu, 26 Sep 2013 19:02:22 +0000 (21:02 +0200)
committerPetr Machata <pmachata@redhat.com>
Mon, 30 Sep 2013 11:43:57 +0000 (13:43 +0200)
Signed-off-by: Petr Machata <pmachata@redhat.com>
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/run-readelf-mixed-corenote.sh

index 9d4c2e2..e538a57 100644 (file)
@@ -1,5 +1,10 @@
 2013-09-26  Petr Machata  <pmachata@redhat.com>
 
+       * readelf.c (handle_file_note): New function.
+       (handle_notes_data): Call it to handle NT_FILE notes.
+
+2013-09-26  Petr Machata  <pmachata@redhat.com>
+
        * readelf.c (handle_siginfo_note): New function.
        (handle_notes_data): Call it to handle NT_SIGINFO notes.
        (buf_read_int, buf_read_ulong, buf_has_data): New functions.
index da3661c..d1a5b68 100644 (file)
@@ -8716,6 +8716,53 @@ handle_siginfo_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos)
 }
 
 static void
+handle_file_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos)
+{
+  Elf_Data *data = elf_getdata_rawchunk (core, desc_pos, descsz, ELF_T_BYTE);
+  if (data == NULL)
+    error (EXIT_FAILURE, 0,
+          gettext ("cannot convert core note data: %s"), elf_errmsg (-1));
+
+  unsigned char const *ptr = data->d_buf;
+  unsigned char const *const end = data->d_buf + data->d_size;
+
+  uint64_t count, page_size;
+  if (! buf_read_ulong (core, &ptr, end, &count)
+      || ! buf_read_ulong (core, &ptr, end, &page_size))
+    {
+    fail:
+      printf ("    Not enough data in NT_FILE note.\n");
+      return;
+    }
+
+  /* Where file names are stored.  */
+  unsigned char const *const fstart
+    = ptr + 3 * count * gelf_fsize (core, ELF_T_ADDR, 1, EV_CURRENT);
+  char const *fptr = (char *) fstart;
+
+  printf ("    %" PRId64 " files:\n", count);
+  for (uint64_t i = 0; i < count; ++i)
+    {
+      uint64_t mstart, mend, moffset;
+      if (! buf_read_ulong (core, &ptr, fstart, &mstart)
+         || ! buf_read_ulong (core, &ptr, fstart, &mend)
+         || ! buf_read_ulong (core, &ptr, fstart, &moffset))
+       goto fail;
+
+      const char *fnext = memchr (fptr, '\0', (char *) end - fptr);
+      if (fnext == NULL)
+       goto fail;
+
+      int ct = printf ("      %08" PRIx64 "-%08" PRIx64
+                      " %08" PRIx64 " %" PRId64,
+                      mstart, mend, moffset * page_size, mend - mstart);
+      printf ("%*s%s\n", ct > 50 ? 3 : 53 - ct, "", fptr);
+
+      fptr = fnext + 1;
+    }
+}
+
+static void
 handle_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
                  const char *name, const void *desc)
 {
@@ -8788,10 +8835,22 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
                  && !memcmp (name, "CORE", 4))
                handle_auxv_note (ebl, ebl->elf, nhdr.n_descsz,
                                  start + desc_offset);
-             else if (nhdr.n_type == NT_SIGINFO
-                      && nhdr.n_namesz == 5 && strcmp (name, "CORE") == 0)
-               handle_siginfo_note (ebl->elf, nhdr.n_descsz,
-                                    start + desc_offset);
+             else if (nhdr.n_namesz == 5 && strcmp (name, "CORE") == 0)
+               switch (nhdr.n_type)
+                 {
+                 case NT_SIGINFO:
+                   handle_siginfo_note (ebl->elf, nhdr.n_descsz,
+                                        start + desc_offset);
+                   break;
+
+                 case NT_FILE:
+                   handle_file_note (ebl->elf, nhdr.n_descsz,
+                                     start + desc_offset);
+                   break;
+
+                 default:
+                   handle_core_note (ebl, &nhdr, name, desc);
+                 }
              else
                handle_core_note (ebl, &nhdr, name, desc);
            }
index 7e71661..622af0c 100644 (file)
@@ -1,5 +1,10 @@
 2013-09-26  Petr Machata  <pmachata@redhat.com>
 
+       * run-readelf-mixed-corenote.sh: Update output of testfile71
+       dump--readelf can newly decode the NT_FILE note.
+
+2013-09-26  Petr Machata  <pmachata@redhat.com>
+
        * Makefile.am (EXTRA_DIST): Add testfile71.bz2.
        * run-readelf-mixed-corenote.sh: New test for this file.
        * testfile71.bz2: New file.
index 8823c3e..9a43809 100755 (executable)
@@ -272,6 +272,17 @@ Note segment of 1476 bytes at offset 0x430:
     PLATFORM: 0x7fff69fe3d29
     NULL
   CORE                 469  FILE
+    10 files:
+      00400000-00401000 00000000 4096                /home/petr/a.out
+      00600000-00601000 00000000 4096                /home/petr/a.out
+      00601000-00602000 00001000 4096                /home/petr/a.out
+      3dffa00000-3dffa21000 00000000 135168          /usr/lib64/ld-2.17.so
+      3dffc20000-3dffc21000 00020000 4096            /usr/lib64/ld-2.17.so
+      3dffc21000-3dffc22000 00021000 4096            /usr/lib64/ld-2.17.so
+      3dffe00000-3dfffb6000 00000000 1794048         /usr/lib64/libc-2.17.so
+      3dfffb6000-3e001b6000 001b6000 2097152         /usr/lib64/libc-2.17.so
+      3e001b6000-3e001ba000 001b6000 16384           /usr/lib64/libc-2.17.so
+      3e001ba000-3e001bc000 001ba000 8192            /usr/lib64/libc-2.17.so
 EOF
 
 exit 0