From d0ae9fbda7513c1cab463bf1a9b21fdef40e7c56 Mon Sep 17 00:00:00 2001 From: Omair Javaid Date: Fri, 13 Jun 2014 17:07:21 +0100 Subject: [PATCH] Add support for reading Aarch64 core dumps. * elfxx-aarch64.c (stdarg.h): Include. (string.h): Include. (_bfd_aarch64_elf_grok_prstatus): Updated. (_bfd_aarch64_elf_grok_psinfo): New function. (_bfd_aarch64_elf_write_core_note): New function. * elfxx-aarch64.h (elf_backend_grok_psinfo): Define. (elf_backend_write_core_note): Define. --- bfd/ChangeLog | 10 ++++++ bfd/elfxx-aarch64.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ bfd/elfxx-aarch64.h | 11 ++++-- 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0caff71a83c..a0402ada9f3 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2014-06-13 Omair Javaid + + * elfxx-aarch64.c (stdarg.h): Include. + (string.h): Include. + (_bfd_aarch64_elf_grok_prstatus): Updated. + (_bfd_aarch64_elf_grok_psinfo): New function. + (_bfd_aarch64_elf_write_core_note): New function. + * elfxx-aarch64.h (elf_backend_grok_psinfo): Define. + (elf_backend_write_core_note): Define. + 2014-06-13 Alan Modra * archive.c: Include bfdlink.h. diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 7db62954e14..b30e730a47c 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -20,6 +20,8 @@ #include "sysdep.h" #include "elfxx-aarch64.h" +#include +#include #define MASK(n) ((1u << (n)) - 1) @@ -520,3 +522,82 @@ _bfd_aarch64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) return _bfd_elfcore_make_pseudosection (abfd, ".reg", size, note->descpos + offset); } + +bfd_boolean +_bfd_aarch64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) +{ + switch (note->descsz) + { + default: + return FALSE; + + case 136: /* This is sizeof(struct elf_prpsinfo) on Linux/aarch64. */ + elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24); + elf_tdata (abfd)->core->program + = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); + elf_tdata (abfd)->core->command + = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); + } + + /* Note that for some reason, a spurious space is tacked + onto the end of the args in some (at least one anyway) + implementations, so strip it off if it exists. */ + + { + char *command = elf_tdata (abfd)->core->command; + int n = strlen (command); + + if (0 < n && command[n - 1] == ' ') + command[n - 1] = '\0'; + } + + return TRUE; +} + +char * +_bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, + ...) +{ + switch (note_type) + { + default: + return NULL; + + case NT_PRPSINFO: + { + char data[136]; + va_list ap; + + va_start (ap, note_type); + memset (data, 0, sizeof (data)); + strncpy (data + 40, va_arg (ap, const char *), 16); + strncpy (data + 56, va_arg (ap, const char *), 80); + va_end (ap); + + return elfcore_write_note (abfd, buf, bufsiz, "CORE", + note_type, data, sizeof (data)); + } + + case NT_PRSTATUS: + { + char data[392]; + va_list ap; + long pid; + int cursig; + const void *greg; + + va_start (ap, note_type); + memset (data, 0, sizeof (data)); + pid = va_arg (ap, long); + bfd_put_32 (abfd, pid, data + 32); + cursig = va_arg (ap, int); + bfd_put_16 (abfd, cursig, data + 12); + greg = va_arg (ap, const void *); + memcpy (data + 112, greg, 272); + va_end (ap); + + return elfcore_write_note (abfd, buf, bufsiz, "CORE", + note_type, data, sizeof (data)); + } + } +} diff --git a/bfd/elfxx-aarch64.h b/bfd/elfxx-aarch64.h index 5ca3b7f7bad..88081043866 100644 --- a/bfd/elfxx-aarch64.h +++ b/bfd/elfxx-aarch64.h @@ -23,8 +23,8 @@ #include "stdint.h" /* Take the PAGE component of an address or offset. */ -#define PG(x) ((x) & ~ (bfd_vma) 0xfff) -#define PG_OFFSET(x) ((x) & (bfd_vma) 0xfff) +#define PG(x) ((x) & ~ (bfd_vma) 0xfff) +#define PG_OFFSET(x) ((x) & (bfd_vma) 0xfff) extern bfd_reloc_status_type _bfd_aarch64_elf_put_addend (bfd *, bfd_byte *, bfd_reloc_code_real_type, @@ -42,6 +42,13 @@ _bfd_aarch64_elf_add_symbol_hook (bfd *, struct bfd_link_info *, extern bfd_boolean _bfd_aarch64_elf_grok_prstatus (bfd *, Elf_Internal_Note *); +extern bfd_boolean +_bfd_aarch64_elf_grok_psinfo (bfd *, Elf_Internal_Note *); + +extern char * +_bfd_aarch64_elf_write_core_note (bfd *, char *, int *, int, ...); #define elf_backend_add_symbol_hook _bfd_aarch64_elf_add_symbol_hook #define elf_backend_grok_prstatus _bfd_aarch64_elf_grok_prstatus +#define elf_backend_grok_psinfo _bfd_aarch64_elf_grok_psinfo +#define elf_backend_write_core_note _bfd_aarch64_elf_write_core_note -- 2.30.2