This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[gdbserver, doc] add command line option to force core dump on fatal errors
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 14 Sep 2011 16:39:07 +0100
- Subject: [gdbserver, doc] add command line option to force core dump on fatal errors
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 <pedro@codesourcery.com>
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