components/gdb/patches/gdb.bfd.elf32-i386.c.patch
author April Chin <april.chin@oracle.com>
Fri, 15 Jul 2016 07:22:25 -0700
changeset 6420 65948e9e205b
parent 1511 4d3b0b480760
permissions -rw-r--r--
22928258 update gdb to 7.11 20745970 need to investigate if gdb tests can be added to Makefile test target

# 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