From patchwork Wed May 14 21:19:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omair Javaid X-Patchwork-Id: 30207 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DA4C2055D for ; Wed, 14 May 2014 21:19:27 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id hr9sf8160071vcb.2 for ; Wed, 14 May 2014 14:19:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=bG1VVhyVbVXepbeAt5Y+YowEFZ3/ngZLsOsv/R659DQ=; b=WI331wLkPlYTeMEeGDoU4Cvd+c5UgRdZ9IYneHGKmC52cdXf/aNkEZRPaK3lB0BvJo VA6Pn6E2wtQFF2YyQirfmRnbWRu42OgFzzLgOonn3r8iCOKGl6xE45gh7Vt89EswBEoR JpnjIdOKsTwV8v0OlkKnaMRGRpwmZ3WbMftLdMgejsdgl1m/yyZ9rn/Vly2NBekKzEc1 wSVf8hEcPLAqWoyp39GYWSWpgqx0hG57oBMal28Guw+G3SdU8kBs+gJ70/zJSunT1QPs QpFNZpfD/R8JoYZ098B0rtrGwpvh6DpAN1BDwdZzPeL2X/Ec3vyxYvHRIYODGkG0K5ht cqTA== X-Gm-Message-State: ALoCoQk+7fei8qbqiepS5TT4ZwuvRBUmmoq9xNBUBasxvRrenDs3E0ZSxYBZZI5fbzRO9Ytv1hbL X-Received: by 10.58.41.39 with SMTP id c7mr2927991vel.25.1400102367248; Wed, 14 May 2014 14:19:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.37 with SMTP id u34ls2679429qgu.4.gmail; Wed, 14 May 2014 14:19:27 -0700 (PDT) X-Received: by 10.220.59.65 with SMTP id k1mr4876096vch.22.1400102367160; Wed, 14 May 2014 14:19:27 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id ck5si541893vdd.19.2014.05.14.14.19.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 14:19:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ld13so3217562vcb.40 for ; Wed, 14 May 2014 14:19:27 -0700 (PDT) X-Received: by 10.58.228.163 with SMTP id sj3mr4865424vec.28.1400102367076; Wed, 14 May 2014 14:19:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp272147vcb; Wed, 14 May 2014 14:19:26 -0700 (PDT) X-Received: by 10.194.5.5 with SMTP id o5mr5041647wjo.16.1400102366234; Wed, 14 May 2014 14:19:26 -0700 (PDT) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by mx.google.com with ESMTPS id pr4si1110575wjc.161.2014.05.14.14.19.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 14:19:26 -0700 (PDT) Received-SPF: pass (google.com: domain of omair.javaid@linaro.org designates 209.85.212.173 as permitted sender) client-ip=209.85.212.173; Received: by mail-wi0-f173.google.com with SMTP id bs8so8754804wib.6 for ; Wed, 14 May 2014 14:19:25 -0700 (PDT) X-Received: by 10.180.212.48 with SMTP id nh16mr27745805wic.49.1400102365812; Wed, 14 May 2014 14:19:25 -0700 (PDT) Received: from localhost.localdomain ([182.185.131.35]) by mx.google.com with ESMTPSA id kp5sm4013896wjb.30.2014.05.14.14.19.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 May 2014 14:19:24 -0700 (PDT) From: Omair Javaid To: binutils@sourceware.org Cc: patches@linaro.org Subject: [PATCH] aarch64 linux core dump support Date: Thu, 15 May 2014 02:19:14 +0500 Message-Id: <1400102354-9296-1-git-send-email-omair.javaid@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: omair.javaid@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 2014-05-15 Omair Javaid bfd/ * elfxx-aarch64.c (stdarg.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/elfxx-aarch64.c | 102 +++++++++++++++++++++++++++++++++++++++++++--------- bfd/elfxx-aarch64.h | 12 +++++-- 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 7db6295..23e2ef1 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -20,6 +20,7 @@ #include "sysdep.h" #include "elfxx-aarch64.h" +#include #define MASK(n) ((1u << (n)) - 1) @@ -498,25 +499,94 @@ _bfd_aarch64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) switch (note->descsz) { default: - return FALSE; + return FALSE; + + /* sizeof(struct elf_prstatus) on Linux/aarch64. */ + case 392: + elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); + elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32); + offset = 112; + size = 272; + break; + } - case 392: /* sizeof(struct elf_prstatus) on Linux/arm64. */ - /* pr_cursig */ - elf_tdata (abfd)->core->signal - = bfd_get_16 (abfd, note->descdata + 12); + /* Make a ".reg/999" section. */ + return _bfd_elfcore_make_pseudosection (abfd, ".reg", + size, note->descpos + offset); +} - /* pr_pid */ - elf_tdata (abfd)->core->lwpid - = bfd_get_32 (abfd, note->descdata + 32); +bfd_boolean +_bfd_aarch64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) +{ + switch (note->descsz) + { + default: + return FALSE; + + case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */ + 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); + } - /* pr_reg */ - offset = 112; - size = 272; + /* 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. */ - break; - } + { + char *command = elf_tdata (abfd)->core->command; + int n = strlen (command); - /* Make a ".reg/999" section. */ - return _bfd_elfcore_make_pseudosection (abfd, ".reg", - size, note->descpos + offset); + 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 5ca3b7f..1d61d96 100644 --- a/bfd/elfxx-aarch64.h +++ b/bfd/elfxx-aarch64.h @@ -42,6 +42,14 @@ _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 *abfd, char *buf, int *bufsiz, + int note_type, ...); -#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_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