From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4687 invoked by alias); 21 Oct 2011 18:56:29 -0000 Received: (qmail 4665 invoked by uid 22791); 21 Oct 2011 18:56:27 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,MSGID_FROM_MTA_HEADER,RP_MATCHES_RCVD,TW_CP X-Spam-Check-By: sourceware.org Received: from mtagate3.uk.ibm.com (HELO mtagate3.uk.ibm.com) (194.196.100.163) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 18:56:12 +0000 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p9LIuAaG015278; Fri, 21 Oct 2011 18:56:10 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9LIuAGp2383892; Fri, 21 Oct 2011 19:56:10 +0100 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 p9LIuAHx012453; Fri, 21 Oct 2011 12:56:10 -0600 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 p9LIu92B012443; Fri, 21 Oct 2011 12:56:09 -0600 Message-Id: <201110211856.p9LIu92B012443@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Fri, 21 Oct 2011 20:56:09 +0200 Subject: [rfc][1/3] Remote core file generation: BFD support To: gdb-patches@sourceware.org Date: Fri, 21 Oct 2011 18:56:00 -0000 From: "Ulrich Weigand" Cc: binutils@sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00202.txt.bz2 Hello, when implementing support for core file generation with remote targets in GDB I ran into the problem that the elfcore_write_prpsinfo and elfcore_write_prstatus are only defined for native targets. This is even though they could be implemented for remote targets if the back-end provides the backend_write_core_note callback. The following patch provides those functions unconditionally, so that they can use the back-end callback if present, and return NULL to signal failure if the callback is not available. The patch in addition implements the callback for ARM Linux. 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. Index: bfd/elf.c =================================================================== RCS file: /cvs/src/src/bfd/elf.c,v retrieving revision 1.544 diff -u -p -r1.544 elf.c --- bfd/elf.c 30 Sep 2011 10:39:44 -0000 1.544 +++ bfd/elf.c 21 Oct 2011 16:49:52 -0000 @@ -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: bfd/elf32-arm.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-arm.c,v retrieving revision 1.278 diff -u -p -r1.278 elf32-arm.c --- bfd/elf32-arm.c 19 Oct 2011 07:17:13 -0000 1.278 +++ bfd/elf32-arm.c 21 Oct 2011 16:49:54 -0000 @@ -1986,6 +1986,55 @@ 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, 28); + 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, 72); + 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); + memset (data + 144, 0, 4); + 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 +2042,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; -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com