From patchwork Fri Jan 20 18:16:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 6330 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A2AD623E81 for ; Fri, 20 Jan 2012 18:16:56 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 845CEA181F7 for ; Fri, 20 Jan 2012 18:16:56 +0000 (UTC) Received: by bkar19 with SMTP id r19so770673bka.11 for ; Fri, 20 Jan 2012 10:16:56 -0800 (PST) Received: by 10.204.152.20 with SMTP id e20mr12019837bkw.117.1327083415522; Fri, 20 Jan 2012 10:16:55 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs13166bkc; Fri, 20 Jan 2012 10:16:55 -0800 (PST) Received: by 10.213.16.77 with SMTP id n13mr1386033eba.81.1327083413987; Fri, 20 Jan 2012 10:16:53 -0800 (PST) Received: from e06smtp16.uk.ibm.com (e06smtp16.uk.ibm.com. [195.75.94.112]) by mx.google.com with ESMTPS id r60si2332263eeh.183.2012.01.20.10.16.53 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 Jan 2012 10:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of uweigand@de.ibm.com designates 195.75.94.112 as permitted sender) client-ip=195.75.94.112; Authentication-Results: mx.google.com; spf=pass (google.com: domain of uweigand@de.ibm.com designates 195.75.94.112 as permitted sender) smtp.mail=uweigand@de.ibm.com Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 20 Jan 2012 18:16:53 -0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com (9.149.39.193) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 20 Jan 2012 18:16:50 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q0KIGnD92134034 for ; Fri, 20 Jan 2012 18:16:49 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q0KIGn1E008460 for ; Fri, 20 Jan 2012 11:16:49 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q0KIGm21008338 for ; Fri, 20 Jan 2012 11:16:48 -0700 Message-Id: <201201201816.q0KIGm21008338@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Fri, 20 Jan 2012 19:16:48 +0100 Subject: [rfc v2][1/3] Remote core file generation: BFD support To: patches@linaro.org Date: Fri, 20 Jan 2012 19:16:48 +0100 (CET) From: "Ulrich Weigand" X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 x-cbid: 12012018-3548-0000-0000-000000D08384 http://sourceware.org/ml/gdb-patches/2011-12/msg00014.html Hello, this implements the suggestion to always zero out the contents of the generated note in elf_backend_write_core_note. Retested on powerpc64-linux (Cell/B.E.) and arm-linux. OK for BFD mainline? Bye, Ulrich ChangeLog: * elf.c (elfcore_write_prpsinfo): Provide unconditionally. Return NULL if core file generation is unsupported. (elfcore_write_prstatus): Likewise. * elf32-arm.c (elf32_arm_nabi_write_core_note): New function. (elf_backend_write_core_note): Define. * elf32-ppc.c (ppc_elf_write_core_note): Always zero out all unused parts of generated note section. * elf64-ppc.c (ppc64_elf_write_core_note): Likewise. Index: gdb-head/bfd/elf.c =================================================================== --- gdb-head.orig/bfd/elf.c +++ gdb-head/bfd/elf.c @@ -8863,7 +8863,6 @@ elfcore_write_note (bfd *abfd, return buf; } -#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) char * elfcore_write_prpsinfo (bfd *abfd, char *buf, @@ -8871,7 +8870,6 @@ elfcore_write_prpsinfo (bfd *abfd, const char *fname, const char *psargs) { - const char *note_name = "CORE"; const struct elf_backend_data *bed = get_elf_backend_data (abfd); if (bed->elf_backend_write_core_note != NULL) @@ -8883,6 +8881,7 @@ elfcore_write_prpsinfo (bfd *abfd, return ret; } +#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) #if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T) if (bed->s->elfclass == ELFCLASS32) { @@ -8898,7 +8897,7 @@ elfcore_write_prpsinfo (bfd *abfd, strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); return elfcore_write_note (abfd, buf, bufsiz, - note_name, note_type, &data, sizeof (data)); + "CORE", note_type, &data, sizeof (data)); } else #endif @@ -8915,12 +8914,14 @@ elfcore_write_prpsinfo (bfd *abfd, strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); return elfcore_write_note (abfd, buf, bufsiz, - note_name, note_type, &data, sizeof (data)); + "CORE", note_type, &data, sizeof (data)); } -} #endif /* PSINFO_T or PRPSINFO_T */ -#if defined (HAVE_PRSTATUS_T) + free (buf); + return NULL; +} + char * elfcore_write_prstatus (bfd *abfd, char *buf, @@ -8929,7 +8930,6 @@ elfcore_write_prstatus (bfd *abfd, int cursig, const void *gregs) { - const char *note_name = "CORE"; const struct elf_backend_data *bed = get_elf_backend_data (abfd); if (bed->elf_backend_write_core_note != NULL) @@ -8942,6 +8942,7 @@ elfcore_write_prstatus (bfd *abfd, return ret; } +#if defined (HAVE_PRSTATUS_T) #if defined (HAVE_PRSTATUS32_T) if (bed->s->elfclass == ELFCLASS32) { @@ -8951,7 +8952,7 @@ elfcore_write_prstatus (bfd *abfd, prstat.pr_pid = pid; prstat.pr_cursig = cursig; memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); - return elfcore_write_note (abfd, buf, bufsiz, note_name, + return elfcore_write_note (abfd, buf, bufsiz, "CORE", NT_PRSTATUS, &prstat, sizeof (prstat)); } else @@ -8963,12 +8964,15 @@ elfcore_write_prstatus (bfd *abfd, prstat.pr_pid = pid; prstat.pr_cursig = cursig; memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); - return elfcore_write_note (abfd, buf, bufsiz, note_name, + return elfcore_write_note (abfd, buf, bufsiz, "CORE", NT_PRSTATUS, &prstat, sizeof (prstat)); } -} #endif /* HAVE_PRSTATUS_T */ + free (buf); + return NULL; +} + #if defined (HAVE_LWPSTATUS_T) char * elfcore_write_lwpstatus (bfd *abfd, Index: gdb-head/bfd/elf32-arm.c =================================================================== --- gdb-head.orig/bfd/elf32-arm.c +++ gdb-head/bfd/elf32-arm.c @@ -1986,6 +1986,54 @@ elf32_arm_nabi_grok_psinfo (bfd *abfd, E return TRUE; } +static char * +elf32_arm_nabi_write_core_note (bfd *abfd, char *buf, int *bufsiz, + int note_type, ...) +{ + switch (note_type) + { + default: + return NULL; + + case NT_PRPSINFO: + { + char data[124]; + va_list ap; + + va_start (ap, note_type); + memset (data, 0, sizeof (data)); + strncpy (data + 28, va_arg (ap, const char *), 16); + strncpy (data + 44, 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[148]; + 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 + 24); + cursig = va_arg (ap, int); + bfd_put_16 (abfd, cursig, data + 12); + greg = va_arg (ap, const void *); + memcpy (data + 72, greg, 72); + va_end (ap); + + return elfcore_write_note (abfd, buf, bufsiz, + "CORE", note_type, data, sizeof (data)); + } + } +} + #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec #define TARGET_LITTLE_NAME "elf32-littlearm" #define TARGET_BIG_SYM bfd_elf32_bigarm_vec @@ -1993,6 +2041,7 @@ elf32_arm_nabi_grok_psinfo (bfd *abfd, E #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo +#define elf_backend_write_core_note elf32_arm_nabi_write_core_note typedef unsigned long int insn32; typedef unsigned short int insn16; Index: gdb-head/bfd/elf32-ppc.c =================================================================== --- gdb-head.orig/bfd/elf32-ppc.c +++ gdb-head/bfd/elf32-ppc.c @@ -1920,7 +1920,7 @@ ppc_elf_write_core_note (bfd *abfd, char va_list ap; va_start (ap, note_type); - memset (data, 0, 32); + memset (data, 0, sizeof (data)); strncpy (data + 32, va_arg (ap, const char *), 16); strncpy (data + 48, va_arg (ap, const char *), 80); va_end (ap); @@ -1937,14 +1937,13 @@ ppc_elf_write_core_note (bfd *abfd, char const void *greg; va_start (ap, note_type); - memset (data, 0, 72); + memset (data, 0, sizeof (data)); pid = va_arg (ap, long); bfd_put_32 (abfd, pid, data + 24); cursig = va_arg (ap, int); bfd_put_16 (abfd, cursig, data + 12); greg = va_arg (ap, const void *); memcpy (data + 72, greg, 192); - memset (data + 264, 0, 4); va_end (ap); return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, data, sizeof (data)); Index: gdb-head/bfd/elf64-ppc.c =================================================================== --- gdb-head.orig/bfd/elf64-ppc.c +++ gdb-head/bfd/elf64-ppc.c @@ -2714,7 +2714,7 @@ ppc64_elf_write_core_note (bfd *abfd, ch va_list ap; va_start (ap, note_type); - memset (data, 0, 40); + 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); @@ -2731,14 +2731,13 @@ ppc64_elf_write_core_note (bfd *abfd, ch const void *greg; va_start (ap, note_type); - memset (data, 0, 112); + 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, 384); - memset (data + 496, 0, 8); va_end (ap); return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, data, sizeof (data));