From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25422 invoked by alias); 14 Sep 2011 15:39:29 -0000 Received: (qmail 25278 invoked by uid 22791); 14 Sep 2011 15:39:26 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,FROM_12LTRDOM,TW_GJ,TW_VF X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Sep 2011 15:39:12 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=EU1-MAIL.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1R3rYO-0003Qk-6B from pedro_alves@mentor.com for gdb-patches@sourceware.org; Wed, 14 Sep 2011 08:39:12 -0700 Received: from scottsdale.localnet ([172.16.63.104]) by EU1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 14 Sep 2011 16:39:09 +0100 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [gdbserver, doc] add command line option to force core dump on fatal errors Date: Wed, 14 Sep 2011 15:45:00 -0000 User-Agent: KMail/1.13.6 (Linux/2.6.38-11-generic; KDE/4.7.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201109141639.07804.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-09/txt/msg00258.txt.bz2 gdbserver does `exit(1)' on fatal errors, instead of aborting, because we don't normally want embedded/deployed targets to end up filled with core files if gdbserver happens to trip on some bug. However, when running the testsuite (and other situations) against gdbserver, it's quite useful to have it dump core. This adds a command line option to make it possible. I've based the wording and the spelling on GDB's own "maint set internal-error corefile" command. Comments? Are the docs okay? (yes, I know we should try to increase the core soft limit like gdb does before calling abort. I'm leaving that to a follow up, possibly moving dump_core to common/). -- Pedro Alves 2011-09-14 Pedro Alves gdb/gdbserver/ * utils.c (fatal_exit): New. (malloc_failure): Call it on error. (error) [!IN_PROCESS_AGENT]: Abort on error if gdbserver was started with --internal-error-corefile. (fatal, internal_error): Call `fatal_exit' instead of `exit' directly. * server.c (internal_error_corefile): New. (main): Handle --internal-error-corefile. gdb/doc/ * gdb.texinfo (Using the gdbserver Program): Document the `--internal-error-corefile' command line option. --- gdb/doc/gdb.texinfo | 8 ++++++-- gdb/gdbserver/server.c | 6 ++++++ gdb/gdbserver/server.h | 2 ++ gdb/gdbserver/utils.c | 31 +++++++++++++++++++++++-------- 4 files changed, 37 insertions(+), 10 deletions(-) Index: src/gdb/gdbserver/utils.c =================================================================== --- src.orig/gdb/gdbserver/utils.c 2011-09-14 16:06:42.000000000 +0100 +++ src/gdb/gdbserver/utils.c 2011-09-14 16:20:35.661299482 +0100 @@ -33,6 +33,17 @@ # define TOOLNAME "GDBserver" #endif +static void ATTR_NORETURN +fatal_exit (void) +{ +#ifndef IN_PROCESS_AGENT + if (internal_error_corefile) + abort (); +#endif + + exit (1); +} + /* Generally useful subroutines used throughout the program. */ void @@ -41,7 +52,7 @@ malloc_failure (long size) fprintf (stderr, PREFIX "ran out of memory while trying to allocate %lu bytes\n", (unsigned long) size); - exit (1); + fatal_exit (); } /* Copy a string into a memory buffer. @@ -106,19 +117,23 @@ perror_with_name (const char *string) void error (const char *string,...) { -#ifndef IN_PROCESS_AGENT - extern jmp_buf toplevel; -#endif va_list args; + va_start (args, string); fflush (stdout); vfprintf (stderr, string, args); fprintf (stderr, "\n"); + #ifndef IN_PROCESS_AGENT + /* Abort before the longjmp, so that we still have context of what + caused the problem in the stack. */ + if (internal_error_corefile) + abort (); + longjmp (toplevel, 1); -#else - exit (1); #endif + + exit (1); } /* Print an error message and exit reporting failure. @@ -135,7 +150,7 @@ fatal (const char *string,...) vfprintf (stderr, string, args); fprintf (stderr, "\n"); va_end (args); - exit (1); + fatal_exit (); } /* VARARGS */ @@ -163,7 +178,7 @@ internal_error (const char *file, int li vfprintf (stderr, fmt, args); fprintf (stderr, "\n"); va_end (args); - exit (1); + fatal_exit (); } /* Temporary storage using circular buffer. */ Index: src/gdb/gdbserver/server.c =================================================================== --- src.orig/gdb/gdbserver/server.c 2011-09-14 16:06:42.000000000 +0100 +++ src/gdb/gdbserver/server.c 2011-09-14 16:28:06.711299638 +0100 @@ -42,6 +42,10 @@ static int exit_requested; /* --once: Exit after the first connection has closed. */ int run_once; +/* --internal-error-corefile: Set whether GDBserver should create a + core file of GDBserver when an internal error is detected. */ +int internal_error_corefile; + int multi_process; int non_stop; @@ -2551,6 +2555,8 @@ main (int argc, char *argv[]) } else if (strcmp (*next_arg, "--once") == 0) run_once = 1; + else if (strcmp (*next_arg, "--internal-error-corefile") == 0) + internal_error_corefile = 1; else { fprintf (stderr, "Unknown argument: %s\n", *next_arg); Index: src/gdb/gdbserver/server.h =================================================================== --- src.orig/gdb/gdbserver/server.h 2011-09-14 16:06:42.000000000 +0100 +++ src/gdb/gdbserver/server.h 2011-09-14 16:23:51.051299550 +0100 @@ -296,6 +296,8 @@ extern int disable_packet_qC; extern int disable_packet_qfThreadInfo; extern int run_once; +extern int internal_error_corefile; + extern int multi_process; extern int non_stop; Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2011-09-14 16:06:42.000000000 +0100 +++ src/gdb/doc/gdb.texinfo 2011-09-14 16:24:46.241299570 +0100 @@ -16385,8 +16385,12 @@ The @option{--debug} option tells @code{ status information about the debugging process. @cindex @option{--remote-debug}, @code{gdbserver} option The @option{--remote-debug} option tells @code{gdbserver} to display -remote protocol debug output. These options are intended for -@code{gdbserver} development and for bug reports to the developers. +remote protocol debug output. +@cindex @option{--internal-error-corefile}, @code{gdbserver} option +The @option{--internal-error-corefile} option tells @code{gdbserver} +to create a core file of @code{gdbserver} when an internal error is +detected. These options are intended for @code{gdbserver} development +and for bug reports to the developers. @cindex @option{--wrapper}, @code{gdbserver} option The @option{--wrapper} option specifies a wrapper to launch programs