From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org, binutils@sourceware.org
Subject: [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes.
Date: Thu, 16 Jun 2016 06:02:00 -0000 [thread overview]
Message-ID: <20160616060202.63470-3-jhb@FreeBSD.org> (raw)
In-Reply-To: <20160616060202.63470-1-jhb@FreeBSD.org>
Move parsing of FreeBSD-specific ELF core notes out of elfcore_grok_note
into a new elfcore_grok_freebsd_note function. Add core note grok routines
for FreeBSD's psinfo and prstatus notes while here rather than depending
on the native handling in elfcore_grok_note.
bfd/ChangeLog:
* elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for
FreeBSD. Remove case for NT_FREEBSD_THRMISC.
(elfcore_grok_freebsd_psinfo): New function.
(elfcore_grok_freebsd_prstatus): New function.
(elfcore_grok_freebsd_note): New function.
(elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD"
notes.
---
bfd/ChangeLog | 10 +++++
bfd/elf.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 139 insertions(+), 9 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 344e08b..881ce6d 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2016-06-15 John Baldwin <jhb@FreeBSD.org>
+
+ * elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for
+ FreeBSD. Remove case for NT_FREEBSD_THRMISC.
+ (elfcore_grok_freebsd_psinfo): New function.
+ (elfcore_grok_freebsd_prstatus): New function.
+ (elfcore_grok_freebsd_note): New function.
+ (elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD"
+ notes.
+
2016-06-15 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Check SEC_ALLOC before
diff --git a/bfd/elf.c b/bfd/elf.c
index aaf2b53..2d8f621 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9327,9 +9327,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
if (note->namesz == 6
&& strcmp (note->namedata, "LINUX") == 0)
return elfcore_grok_xstatereg (abfd, note);
- else if (note->namesz == 8
- && strcmp (note->namedata, "FreeBSD") == 0)
- return elfcore_grok_xstatereg (abfd, note);
else
return TRUE;
@@ -9485,12 +9482,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.siginfo",
note);
- case NT_FREEBSD_THRMISC:
- if (note->namesz == 8
- && strcmp (note->namedata, "FreeBSD") == 0)
- return elfcore_make_note_pseudosection (abfd, ".thrmisc", note);
- else
- return TRUE;
}
}
@@ -9556,6 +9547,134 @@ elfobj_grok_stapsdt_note (bfd *abfd, Elf_Internal_Note *note)
}
static bfd_boolean
+elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+ offset = 4;
+
+ /* Skip over pr_psinfosz. */
+ switch (abfd->arch_info->bits_per_word)
+ {
+ case 32:
+ offset += 4;
+ break;
+
+ case 64:
+ offset += 4; /* Padding before pr_psinfosz. */
+ offset += 8;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ /* pr_fname is PRFNAMESZ (16) + 1 bytes in size. */
+ elf_tdata (abfd)->core->program
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 17);
+ offset += 17;
+
+ /* pr_psargs is PRARGSZ (80) + 1 bytes in size. */
+ elf_tdata (abfd)->core->command
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 81);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+ size_t size;
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+ offset = 4;
+
+ /* Skip over pr_statussz. */
+ switch (abfd->arch_info->bits_per_word)
+ {
+ case 32:
+ offset += 4;
+ break;
+
+ case 64:
+ offset += 4; /* Padding before pr_statussz. */
+ offset += 8;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ /* Extract size of pr_reg from pr_gregsetsz. */
+ if (abfd->arch_info->bits_per_word == 32)
+ size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ else
+ size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset);
+
+ /* Skip over pr_gregsetsz and pr_fpregsetsz. */
+ offset += (abfd->arch_info->bits_per_word / 8) * 2;
+
+ /* Skip over pr_osreldate. */
+ offset += 4;
+
+ /* Read signal from pr_cursig. */
+ if (elf_tdata (abfd)->core->signal == 0)
+ elf_tdata (abfd)->core->signal
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Read TID from pr_pid. */
+ elf_tdata (abfd)->core->lwpid
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Padding before pr_reg. */
+ if (abfd->arch_info->bits_per_word == 64)
+ offset += 4;
+
+ /* Make a ".reg/999" section and a ".reg" section. */
+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+ size, note->descpos + offset);
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ switch (note->type)
+ {
+ case NT_PRSTATUS:
+ return elfcore_grok_freebsd_prstatus (abfd, note);
+
+ case NT_FPREGSET:
+ return elfcore_grok_prfpreg (abfd, note);
+
+ case NT_PRPSINFO:
+ return elfcore_grok_freebsd_psinfo (abfd, note);
+
+ case NT_FREEBSD_THRMISC:
+ if (note->namesz == 8)
+ return elfcore_make_note_pseudosection (abfd, ".thrmisc", note);
+ else
+ return TRUE;
+
+ case NT_X86_XSTATE:
+ if (note->namesz == 8)
+ return elfcore_grok_xstatereg (abfd, note);
+ else
+ return TRUE;
+
+ default:
+ return TRUE;
+ }
+}
+
+static bfd_boolean
elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp)
{
char *cp;
@@ -10467,6 +10586,7 @@ elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
grokers[] =
{
GROKER_ELEMENT ("", elfcore_grok_note),
+ GROKER_ELEMENT ("FreeBSD", elfcore_grok_freebsd_note),
GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note),
GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note),
GROKER_ELEMENT ("QNX", elfcore_grok_nto_note),
--
2.8.4
next prev parent reply other threads:[~2016-06-16 6:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin
2016-06-16 6:02 ` John Baldwin [this message]
2016-06-17 8:28 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes Nick Clifton
2016-06-16 6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin
2016-06-17 8:27 ` Nick Clifton
2016-06-16 6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin
2016-06-20 23:43 ` Pedro Alves
2016-06-16 6:02 ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD John Baldwin
2016-06-20 23:01 ` Pedro Alves
2016-06-16 6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin
2016-06-20 23:40 ` Pedro Alves
2016-06-23 20:19 ` John Baldwin
2016-06-16 6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin
2016-06-17 8:28 ` Nick Clifton
2016-06-20 23:45 ` Pedro Alves
2016-06-20 17:10 ` [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160616060202.63470-3-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox