# 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)
{
+ asection *sect = bfd_get_section_by_name (abfd, ".reg2");
+ if (sect == NULL)
return elfcore_make_note_pseudosection (abfd, ".reg2", note);
+ return TRUE;
}
/* Linux dumps the Intel SSE regs in a note named "LINUX" with a note
@@ -8919,7 +8922,6 @@
}
#endif /* defined (HAVE_PSTATUS_T) */
-#if defined (HAVE_LWPSTATUS_T)
static bfd_boolean
elfcore_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note)
{
@@ -9001,7 +9003,6 @@
return elfcore_maybe_make_sect (abfd, ".reg2", sect);
}
-#endif /* defined (HAVE_LWPSTATUS_T) */
static bfd_boolean
elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
@@ -9112,14 +9113,17 @@
return TRUE;
#endif
-#if defined (HAVE_PSTATUS_T)
case NT_PSTATUS:
return elfcore_grok_pstatus (abfd, note);
-#endif
-#if defined (HAVE_LWPSTATUS_T)
case NT_LWPSTATUS:
+ if (bed->elf_backend_grok_lwpstatus)
+ if ((*bed->elf_backend_grok_lwpstatus) (abfd, note))
+ return TRUE;
+#if defined (HAVE_LWPSTATUS_T)
return elfcore_grok_lwpstatus (abfd, note);
+#else
+ return TRUE;
#endif
case NT_FPREGSET: /* FIXME: rename to NT_PRFPREG */
@@ -9483,6 +9487,297 @@
return TRUE;
}
+#include <sys/types.h>
+#include <sys/elf.h>
+#include <sys/procfs.h>
+#include <sys/regset.h>
+#include <sys/auxv.h>
+
+static bfd_boolean
+elfcore_grok_solaris_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ asection *sect;
+ size_t gregset_size;
+ size_t fpregset_size;
+ size_t prgregset_size;
+ size_t prgregset_offset;
+ char reg2_section_name[16];
+
+#ifdef DEBUG
+ static const char* note_type[] = { "NONE (0)", "NT_PRSTATUS", "NT_PRFPREG",
+ "NT_PRPSINFO", "NT_PRXREG", "NT_PLATFORM", "NT_AUXV", "NT_GWINDOWS",
+ "NT_ASRS", "NT_LDT", "NT_PSTATUS", "INVALID (11)", "INVALID (12)",
+ "NT_PSINFO", "NT_PRCRED", "NT_UTSNAME", "NT_LWPSTATUS", "NT_LWPSINFO",
+ "NT_PRPRIV", "NT_PRPRIVINFO", "NT_CONTENT", "NT_ZONENAME",
+ "NT_PRCPUXREG", NULL };
+#endif
+
+ if (note == NULL)
+ return TRUE;
+
+ sect = bfd_get_section_by_name (abfd, reg2_section_name);
+
+ switch ((int) note->type)
+ {
+ case SOLARIS_NT_PRSTATUS:
+ if (note->descsz == 508) /* sizeof(prstatus_t) SPARC 32-bit */
+ {
+ gregset_size = 152;
+ fpregset_size = 144;
+ prgregset_size = 152; /* sizeof(prgregset_t) SPARC 32-bit */
+ prgregset_offset = 356; /* offsetof(prstatus_t, pr_reg */
+
+ 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);
+ (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2",
+ *(int*)(note->descdata + 308));
+ }
+ else if (note->descsz == 904) /* sizeof(prstatus_t) SPARC 64-bit */
+ {
+ gregset_size = 168;
+ fpregset_size = 288;
+ prgregset_size = 304; /* sizeof(prgregset_t) SPARC 64-bit */
+ prgregset_offset = 600; /* offsetof(prstatus_t, pr_reg */
+
+ elf_tdata (abfd)->core->signal =
+ bfd_get_16 (abfd, note->descdata + 264);
+ elf_tdata (abfd)->core->pid =
+ bfd_get_32 (abfd, note->descdata + 360);
+ elf_tdata (abfd)->core->lwpid =
+ bfd_get_32 (abfd, note->descdata + 520);
+ (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2",
+ *(int*)(note->descdata + 520));
+ }
+ else if (note->descsz == 432) /* sizeof(prstatus_t) Intel 32-bit */
+ {
+ gregset_size = 76;
+ fpregset_size = 380;
+ prgregset_size = 76;
+ prgregset_offset = 356; /* offsetof(prstatus_t, pr_reg */
+
+ 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);
+ (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2",
+ *(int*)(note->descdata + 308));
+ }
+ else if (note->descsz == 824) /* sizeof(prstatus_t) Intel 64-bit */
+ {
+ gregset_size = 224;
+ fpregset_size = 528;
+ prgregset_size = 224;
+ prgregset_offset = 600; /* offsetof(prstatus_t, pr_reg */
+
+ elf_tdata (abfd)->core->signal =
+ bfd_get_16 (abfd, note->descdata + 264);
+ elf_tdata (abfd)->core->pid =
+ bfd_get_32 (abfd, note->descdata + 360);
+ elf_tdata (abfd)->core->lwpid =
+ bfd_get_32 (abfd, note->descdata + 520);
+ (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2",
+ *(int*)(note->descdata + 520));
+ }
+
+ sect = bfd_get_section_by_name (abfd, ".reg");
+
+ if (sect != NULL)
+ sect->size = prgregset_size;
+
+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+ prgregset_size, note->descpos + prgregset_offset);
+ break;
+ case SOLARIS_NT_PRFPREG:
+ 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);
+ }
+ break;
+ case SOLARIS_NT_PRXREG:
+ case SOLARIS_NT_PLATFORM:
+ case SOLARIS_NT_GWINDOWS:
+ case SOLARIS_NT_ASRS:
+ case SOLARIS_NT_LDT:
+ case SOLARIS_NT_PSTATUS:
+ break;
+ case SOLARIS_NT_PSINFO:
+ if (note->descsz == 336) /* sizeof(psinfo_t) SPARC */
+ {
+ 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);
+ }
+ else if (note->descsz == 360) /* sizeof(psinfo_t) Intel */
+ {
+ 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);
+ }
+ break;
+ case SOLARIS_NT_PRCRED:
+ case SOLARIS_NT_UTSNAME:
+ break;
+ case SOLARIS_NT_LWPSTATUS:
+ elf_tdata (abfd)->core->lwpid =
+ bfd_get_32 (abfd, note->descdata + 4);
+ elf_tdata (abfd)->core->signal =
+ bfd_get_16 (abfd, note->descdata + 12);
+ (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2",
+ *(int*)(note->descdata + 4));
+
+ if (note->descsz == 896) /* sizeof(lwpstatus_t) SPARC 32-bit */
+ {
+ gregset_size = 152;
+ fpregset_size = 400;
+ prgregset_size = 152; /* sizeof(prgregset_t) SPARC 32-bit */
+
+ sect = bfd_get_section_by_name (abfd, ".reg");
+ if (sect != NULL)
+ sect->size = sizeof(prgregset_t);
+ else
+ {
+ if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
+ prgregset_size,
+ note->descpos + 344)) != TRUE)
+ return FALSE;
+ }
+ 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);
+ }
+ else if (note->descsz == 1392) /* sizeof(lwpstatus_t) SPARC 64-bit */
+ {
+ gregset_size = 304;
+ fpregset_size = 544;
+ prgregset_size = 304; /* sizeof(prgregset_t) SPARC 64-bit */
+
+ sect = bfd_get_section_by_name (abfd, ".reg");
+ if (sect != NULL)
+ sect->size = sizeof(prgregset_t);
+ else
+ {
+ if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
+ prgregset_size,
+ note->descpos + 544)) != TRUE)
+ return FALSE;
+ }
+ sect = bfd_get_section_by_name (abfd, reg2_section_name);
+
+ if (sect != NULL)
+ {
+ sect->size = fpregset_size;
+ sect->filepos = note->descpos + 848;
+ sect->alignment_power = 2;
+ return TRUE;
+ }
+ else
+ return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
+ fpregset_size, note->descpos + 848);
+ }
+ else if (note->descsz == 800) /* sizeof(lwpstatus_t) Intel 32 */
+ {
+ gregset_size = 76;
+ fpregset_size = 380;
+ prgregset_size = 76;
+
+ sect = bfd_get_section_by_name (abfd, ".reg");
+ if (sect != NULL)
+ sect->size = prgregset_size;
+ else
+ {
+ if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
+ prgregset_size,
+ note->descpos + 344)) != TRUE)
+ return FALSE;
+ }
+ 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;
+ return TRUE;
+ }
+ else
+ return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
+ fpregset_size, note->descpos + 420);
+ }
+ else if (note->descsz == 1296) /* sizeof(lwpstatus_t) Intel 64 */
+ {
+ gregset_size = 224;
+ fpregset_size = 528;
+ prgregset_size = 224;
+
+ sect = bfd_get_section_by_name (abfd, ".reg");
+ if (sect != NULL)
+ sect->size = prgregset_size;
+ else
+ {
+ if ((_bfd_elfcore_make_pseudosection (abfd, ".reg",
+ prgregset_size,
+ note->descpos + 544)) != TRUE)
+ return FALSE;
+ }
+ sect = bfd_get_section_by_name (abfd, reg2_section_name);
+
+ if (sect != NULL)
+ {
+ sect->size = fpregset_size;
+ sect->filepos = note->descpos + 768;
+ sect->alignment_power = 2;
+ return TRUE;
+ }
+ else
+ return _bfd_elfcore_make_pseudosection (abfd, reg2_section_name,
+ fpregset_size, note->descpos + 768);
+ }
+ break;
+ case SOLARIS_NT_LWPSINFO:
+ if (note->descsz == 128) /* sizeof(lwpsinfo_t) Intel and SPARC */
+ {
+ elf_tdata (abfd)->core->lwpid =
+ bfd_get_32 (abfd, note->descdata + 4);
+ }
+ break;
+ case SOLARIS_NT_PRPRIV:
+ case SOLARIS_NT_PRPRIVINFO:
+ case SOLARIS_NT_CONTENT:
+ case SOLARIS_NT_ZONENAME:
+ case SOLARIS_NT_PRCPUXREG:
+ case SOLARIS_NT_AUXV:
+ break;
+ default:
+ break;
+ }
+
+ /* add support for .auxv sections */
+ sect = bfd_get_section_by_name (abfd, ".auxv");
+ return TRUE;
+}
+
static bfd_boolean
elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note)
{
@@ -10282,7 +10577,12 @@
GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note),
GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note),
GROKER_ELEMENT ("QNX", elfcore_grok_nto_note),
- GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note)
+ GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note),
+#ifdef SOLARIS
+ GROKER_ELEMENT ("CORE", elfcore_grok_solaris_note)
+#else
+ GROKER_ELEMENT ("CORE", elfcore_grok_note)
+#endif
};
#undef GROKER_ELEMENT
int i;