23640945 gdb has problems reading 32-bit core files
authorApril Chin <april.chin@oracle.com>
Thu, 28 Jul 2016 13:38:15 -0700
changeset 6522 aa2a5fa92400
parent 6521 7759c923339e
child 6523 c9a4ec7f76d7
23640945 gdb has problems reading 32-bit core files
components/gdb/patches/gdb.bfd.elf.c.patch
components/gdb/patches/gdb.bfd.elf32-i386.c.patch
components/gdb/patches/gdb.bfd.elf32-sparc.c.patch
--- a/components/gdb/patches/gdb.bfd.elf.c.patch	Fri Jul 29 10:16:41 2016 -0700
+++ b/components/gdb/patches/gdb.bfd.elf.c.patch	Thu Jul 28 13:38:15 2016 -0700
@@ -1,5 +1,8 @@
---- gdb-7.11-orig/bfd/elf.c	Tue Feb  9 19:19:39 2016
-+++ gdb-7.11/bfd/elf.c	Tue Jun  7 14:34:18 2016
+# Solaris-specific ELF information.
+# Will contribute upstream if possible.
+
+--- gdb-7.11-orig/bfd/elf.c	2016-02-09 19:19:39.000000000 -0800
++++ gdb-7.11/bfd/elf.c	2016-07-25 23:22:10.564146882 -0700
 @@ -8654,7 +8654,10 @@
  static bfd_boolean
  elfcore_grok_prfpreg (bfd *abfd, Elf_Internal_Note *note)
@@ -48,7 +51,7 @@
  #endif
  
      case NT_FPREGSET:		/* FIXME: rename to NT_PRFPREG */
-@@ -9483,7 +9487,298 @@
+@@ -9483,6 +9487,297 @@
    return TRUE;
  }
  
@@ -58,7 +61,7 @@
 +#include <sys/regset.h>
 +#include <sys/auxv.h>
 +
- static bfd_boolean
++static bfd_boolean
 +elfcore_grok_solaris_note (bfd *abfd, Elf_Internal_Note *note)
 +{
 +  asection *sect;
@@ -216,7 +219,7 @@
 +          {
 +            if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
 +                    prgregset_size,
-+                    note->descpos + 356)) != TRUE)
++                    note->descpos + 344)) != TRUE)
 +              return FALSE;
 +          }
 +          sect = bfd_get_section_by_name (abfd, reg2_section_name);
@@ -274,7 +277,7 @@
 +          {
 +            if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
 +                    prgregset_size,
-+                    note->descpos + 356)) != TRUE)
++                    note->descpos + 344)) != TRUE)
 +              return FALSE;
 +          }
 +          sect = bfd_get_section_by_name (abfd, reg2_section_name);
@@ -343,10 +346,9 @@
 +  return TRUE;
 +}
 +
-+static bfd_boolean
+ static bfd_boolean
  elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note)
  {
-   if (note->type == NT_OPENBSD_PROCINFO)
 @@ -10282,7 +10577,12 @@
  	      GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note),
  	      GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note),
@@ -354,7 +356,7 @@
 -	      GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note)
 +	      GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note),
 +#ifdef SOLARIS
-+	      GROKER_ELEMENT ("CORE", elfcore_grok_solaris_note),
++	      GROKER_ELEMENT ("CORE", elfcore_grok_solaris_note)
 +#else
 +	      GROKER_ELEMENT ("CORE", elfcore_grok_note)
 +#endif
--- a/components/gdb/patches/gdb.bfd.elf32-i386.c.patch	Fri Jul 29 10:16:41 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-# Solaris-specific ELF information.
-# Will contribute upstream if possible.
-
---- gdb-7.11-orig/bfd/elf32-i386.c	Wed Feb 24 01:55:15 2016
-+++ gdb-7.11/bfd/elf32-i386.c	Thu Mar 10 13:12:46 2016
-@@ -442,6 +442,45 @@
-       offset = 28;
-       size = bfd_get_32 (abfd, note->descdata + 8);
-     }
-+  else if (note->namesz == 5 && strncmp (note->namedata, "CORE", 4) == 0)
-+  {
-+    if (note->descsz == 432) /* sizeof(prstatus_t) Solaris Intel 32 */
-+    {
-+      /* pr_cursig */
-+      elf_tdata (abfd)->core->signal =
-+        bfd_get_16 (abfd, note->descdata + 136);
-+
-+      /* pr_pid */
-+      elf_tdata (abfd)->core->pid =
-+        bfd_get_32 (abfd, note->descdata + 216);
-+
-+      /* pr_lwpid */
-+      elf_tdata (abfd)->core->lwpid =
-+        bfd_get_32 (abfd, note->descdata + 308);
-+
-+      /* pr_reg */
-+      offset = 356;
-+      size = 76;
-+    }
-+    else if (note->descsz == 824) /* sizeof(prstatus_t) Solaris Intel 64 */
-+    {
-+      /* pr_cursig */
-+      elf_tdata (abfd)->core->signal =
-+        bfd_get_16 (abfd, note->descdata + 264);
-+
-+      /* pr_pid */
-+      elf_tdata (abfd)->core->pid =
-+        bfd_get_32 (abfd, note->descdata + 360);
-+
-+      /* pr_lwpid */
-+      elf_tdata (abfd)->core->lwpid =
-+        bfd_get_32 (abfd, note->descdata + 520);
-+
-+      /* pr_reg */
-+      offset = 600;
-+      size = 224;
-+    }
-+  }
-   else
-     {
-       switch (note->descsz)
-@@ -484,6 +523,31 @@
-       elf_tdata (abfd)->core->command
- 	= _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
-     }
-+  else if (note->namesz == 5 && strncmp (note->namedata, "CORE", 4) == 0)
-+  {
-+    switch (note->descsz)
-+    {
-+      default:
-+        return FALSE;
-+        break;
-+      case 260: /* sizeof(prpsinfo_t) on 32-bit Solaris */
-+        elf_tdata (abfd)->core->pid =
-+          bfd_get_32 (abfd, note->descdata + 16);
-+        elf_tdata (abfd)->core->program =
-+          _bfd_elfcore_strndup (abfd, note->descdata + 84, 16);
-+        elf_tdata (abfd)->core->command =
-+          _bfd_elfcore_strndup (abfd, note->descdata + 100, 80);
-+        break;
-+      case 328: /* sizeof(prpsinfo_t) on 64-bit Solaris */
-+        elf_tdata (abfd)->core->pid =
-+          bfd_get_32 (abfd, note->descdata + 16);
-+        elf_tdata (abfd)->core->program =
-+          _bfd_elfcore_strndup (abfd, note->descdata + 120, 16);
-+        elf_tdata (abfd)->core->command =
-+          _bfd_elfcore_strndup (abfd, note->descdata + 136, 80);
-+        break;
-+    }
-+  }
-   else
-     {
-       switch (note->descsz)
-@@ -515,6 +579,83 @@
-   return TRUE;
- }
- 
-+static bfd_boolean
-+elf_i386_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note)
-+{
-+  asection *sect;
-+  char reg2_section_name[16];
-+  size_t gregset_size;
-+  size_t fpregset_size;
-+
-+  /* Solaris */
-+  if (note->namesz == 5 && strncmp (note->namedata, "CORE", 4) == 0)
-+  {
-+    switch (note->descsz)
-+    {
-+      default:
-+        return FALSE;
-+        break;
-+      case 800: /* sizeof(lwpstatus_t) on Intel 32-bit */
-+        gregset_size = 76;
-+        fpregset_size = 380;
-+
-+        (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2", 1);
-+        sect = bfd_get_section_by_name (abfd, reg2_section_name);
-+        if (sect != NULL)
-+        {
-+          sect->size = fpregset_size;
-+          sect->filepos = note->descpos + 420;
-+          sect->alignment_power = 2;
-+        }
-+        else
-+          return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
-+              fpregset_size, note->descpos + 420);
-+
-+        sect = bfd_get_section_by_name (abfd, ".reg");
-+        if (sect != NULL)
-+        {
-+          sect->size = gregset_size;
-+          sect->filepos = note->descpos + 344;
-+          sect->alignment_power = 2;
-+        }
-+        else
-+          return _bfd_elfcore_make_pseudosection (abfd, ".reg",
-+              gregset_size, note->descpos + 344);
-+        break;
-+      case 1296: /* sizeof(lwpstatus_t) on Intel 64-bit */
-+        gregset_size = 224;
-+        fpregset_size = 528;
-+
-+        (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2", 1);
-+        sect = bfd_get_section_by_name (abfd, reg2_section_name);
-+        if (sect != NULL)
-+        {
-+          sect->size = fpregset_size;
-+          sect->filepos = note->descpos + 420;
-+          sect->alignment_power = 2;
-+        }
-+        else
-+          return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
-+              fpregset_size, note->descpos + 420);
-+
-+        sect = bfd_get_section_by_name (abfd, ".reg");
-+        if (sect != NULL)
-+        {
-+          sect->size = gregset_size;
-+          sect->filepos = note->descpos + 344;
-+          sect->alignment_power = 2;
-+        }
-+        else
-+          return _bfd_elfcore_make_pseudosection (abfd, ".reg",
-+              gregset_size, note->descpos + 344);
-+        break;
-+    }
-+  }
-+  return TRUE;
-+}
-+
-+
-+
- /* Functions for the i386 ELF linker.
- 
-    In order to gain some understanding of code in this file without
-@@ -5790,6 +5931,7 @@
- #define elf_backend_gc_mark_hook	      elf_i386_gc_mark_hook
- #define elf_backend_gc_sweep_hook	      elf_i386_gc_sweep_hook
- #define elf_backend_grok_prstatus	      elf_i386_grok_prstatus
-+#define elf_backend_grok_lwpstatus	      elf_i386_grok_lwpstatus
- #define elf_backend_grok_psinfo		      elf_i386_grok_psinfo
- #define elf_backend_reloc_type_class	      elf_i386_reloc_type_class
- #define elf_backend_relocate_section	      elf_i386_relocate_section
--- a/components/gdb/patches/gdb.bfd.elf32-sparc.c.patch	Fri Jul 29 10:16:41 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-# Solaris-specific ELF information.
-# Will contribute upstream if possible.
-
---- gdb-7.11-orig/bfd/elf32-sparc.c	Tue Feb  9 19:19:39 2016
-+++ gdb-7.11/bfd/elf32-sparc.c	Thu Mar 10 13:12:46 2016
-@@ -28,34 +28,135 @@
- #include "elfxx-sparc.h"
- #include "elf-vxworks.h"
- 
--/* Support for core dump NOTE sections.  */
-+#include <stddef.h>
-+#include <sys/elf.h>
-+#include <sys/procfs.h>
-+#include <sys/regset.h>
-+#include <sys/auxv.h>
- 
-+/* Support for Solaris core dump NOTE sections.  */
- static bfd_boolean
--elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
--{
--  switch (note->descsz)
-+solaris_elf32_sparc_grok_info (bfd *abfd, Elf_Internal_Note *note)
-     {
--    default:
--      return FALSE;
-+  asection *sect;
-+  /* 32-bit regset sizes */
-+  size_t gregset_size = 152;
-+  size_t fpregset_size = 144;
-+  char reg2_section_name[16];
-+  auxv_t* p_auxv = NULL;
- 
--    case 260:			/* Solaris prpsinfo_t.  */
-+  switch (note->type)
-+  {
-+    case SOLARIS_NT_PRSTATUS:
-+      if (note->descsz == 508) /* sizeof(prstatus_t) */
-+      {
-+        elf_tdata (abfd)->core->signal =
-+          bfd_get_16 (abfd, note->descdata + 136);
-+        elf_tdata (abfd)->core->pid =
-+          bfd_get_32 (abfd, note->descdata + 216);
-+        elf_tdata (abfd)->core->lwpid =
-+          bfd_get_32 (abfd, note->descdata + 308);
-+
-+        sect = bfd_get_section_by_name (abfd, ".reg");
-+
-+        if (sect != NULL)
-+          sect->size = sizeof(prgregset_t);
-+
-+         return _bfd_elfcore_make_pseudosection (abfd, ".reg", gregset_size,
-+             note->descpos + 356);
-+      }
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_PRFPREG:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_PRPSINFO:
-+      if (note->descsz == 260) /* sizeof(prpsinfo_t) */
-+      {
-       elf_tdata (abfd)->core->program
- 	= _bfd_elfcore_strndup (abfd, note->descdata + 84, 16);
-       elf_tdata (abfd)->core->command
- 	= _bfd_elfcore_strndup (abfd, note->descdata + 100, 80);
-+      }
-+      return TRUE;
-       break;
--
--    case 336:			/* Solaris psinfo_t.  */
-+    case SOLARIS_NT_PRXREG:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_PLATFORM:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_AUXV:
-+      return TRUE;
-+    case SOLARIS_NT_PSTATUS:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_PSINFO:
-+      if (note->descsz == 336) /* sizeof(psinfo_t) */
-+      {
-       elf_tdata (abfd)->core->program
- 	= _bfd_elfcore_strndup (abfd, note->descdata + 88, 16);
-       elf_tdata (abfd)->core->command
- 	= _bfd_elfcore_strndup (abfd, note->descdata + 104, 80);
-+      }
-+      return TRUE;
-       break;
-+    case SOLARIS_NT_PRCRED:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_UTSNAME:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_LWPSTATUS:
-+      if (note->descsz == 896) /* sizeof(lwpstatus_t) */
-+      {
-+        (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2", 1);
-+        sect = bfd_get_section_by_name (abfd, reg2_section_name);
-+        if (sect != NULL)
-+        {
-+          sect->size = fpregset_size;
-+          sect->filepos = note->descpos + 496;
-+          sect->alignment_power = 2;
-+          return TRUE;
-+        }
-+        else
-+          return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
-+              fpregset_size, note->descpos + 496);
-+      }
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_LWPSINFO:
-+      return TRUE;
-+      break;
-+    case SOLARIS_NT_PRCPUXREG:
-+      return TRUE;
-+      break;
-+    default:
-+      return TRUE;
-+      break;
-     }
--
-   return TRUE;
- }
- 
-+static bfd_boolean
-+elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
-+{
-+  return solaris_elf32_sparc_grok_info (abfd, note);
-+}
-+
-+
-+static bfd_boolean
-+elf32_sparc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
-+{
-+  return solaris_elf32_sparc_grok_info (abfd, note);
-+}
-+
-+static bfd_boolean
-+elf32_sparc_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note)
-+{
-+  return solaris_elf32_sparc_grok_info (abfd, note);
-+}
-+
- /* Functions for dealing with the e_flags field.
- 
-    We don't define set_private_flags or copy_private_bfd_data because
-@@ -202,6 +303,9 @@
- #define elf_backend_final_write_processing \
- 					elf32_sparc_final_write_processing
- #define elf_backend_grok_psinfo		elf32_sparc_grok_psinfo
-+#define elf_backend_grok_prstatus       elf32_sparc_grok_prstatus
-+#define elf_backend_grok_lwpstatus      elf32_sparc_grok_lwpstatus
-+#define elf_backend_grok_lwpinfo        elf32_sparc_grok_lwpinfo
- #define elf_backend_reloc_type_class	elf32_sparc_reloc_type_class
- 
- #define elf_info_to_howto		_bfd_sparc_elf_info_to_howto