PR7580 - Command to force abort when internal error

Pedro Alves
2008-12-29T03:35:44Z

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

I've wanted what Cagney proposed here before:

http://sourceware.org/ml/gdb/2002-08/msg00166.html
http://sourceware.org/bugzilla/show_bug.cgi?id=7580

In a nutshell, these new commands:

maint set internal-error quit [on|off|auto]
maint set internal-error corefile [on|off|auto]

The reaction seemed to be good at the time.

I've wanted it for slightly different reasons for this, though. I find that
running the testsuite and collecting a bunch of core dumps of GDB (using sysctl
kernel.core_pattern), instead of looking at internal_errors in log files
helps find issues faster when I'm developing new features, or reworking
some all-affecting component.

So, here's a patch that adds those new commands so I don't have to
keep patching GDB whenever I want this behaviour. :-)

Comments? Eli, is the documentation proper?

--
Pedro Alves

[-- Attachment #2: pr7580.diff --]
[-- Type: text/x-diff, Size: 5439 bytes --]

gdb/
2008-12-29 Pedro Alves <pedro@codesourcery.com>

Add "maint set|show internal-error|internal-warning quit|corefile
on|off|auto".

PR gdb/7580:
* utils.c (struct internal_problem): Remove FIXME.
(set_internal_problem_cmd, show_internal_problem_cmd): New dummy
functions.
(add_internal_problem_command): New.
(_initialize_utils): New.

gdb/doc/
2008-12-29 Pedro Alves <pedro@codesourcery.com>

PR gdb/7580:
* gdb.texinfo (Maintenance Commands): Document "maint set|show
internal-error|internal-warning quit|corefile on|off|auto".

---
gdb/doc/gdb.texinfo | 23 +++++++++++++
gdb/utils.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 107 insertions(+), 2 deletions(-)

Index: src/gdb/utils.c
===================================================================
--- src.orig/gdb/utils.c 2008-12-29 02:26:03.000000000 +0000
+++ src/gdb/utils.c 2008-12-29 03:30:18.000000000 +0000
@@ -832,8 +832,6 @@ error_stream (struct ui_file *stream)
struct internal_problem
{
const char *name;
- /* FIXME: cagney/2002-08-15: There should be ``maint set/show''
- commands available for controlling these variables. */
enum auto_boolean should_quit;
enum auto_boolean should_dump_core;
};
@@ -987,6 +985,83 @@ internal_warning (const char *file, int
va_end (ap);
}

+static void
+set_internal_problem_cmd (char *args, int from_tty)
+{
+}
+
+static void
+show_internal_problem_cmd (char *args, int from_tty)
+{
+}
+
+static void
+add_internal_problem_command (struct internal_problem *problem)
+{
+ struct cmd_list_element **set_cmd_list;
+ struct cmd_list_element **show_cmd_list;
+ char *set_doc;
+ char *show_doc;
+
+ set_cmd_list = xmalloc (sizeof (*set_cmd_list));
+ show_cmd_list = xmalloc (sizeof (*set_cmd_list));
+ *set_cmd_list = NULL;
+ *show_cmd_list = NULL;
+
+ set_doc = xstrprintf (_("Configure what GDB does when an %s is detected."),
+ problem->name);
+
+ show_doc = xstrprintf (_("Show what GDB does when an %s is detected."),
+ problem->name);
+
+ add_prefix_cmd ((char*) problem->name,
+ class_maintenance, set_internal_problem_cmd, set_doc,
+ set_cmd_list,
+ concat ("maintenance set ", problem->name, " ", NULL),
+ 0/*allow-unknown*/, &maintenance_set_cmdlist);
+
+ add_prefix_cmd ((char*) problem->name,
+ class_maintenance, show_internal_problem_cmd, show_doc,
+ show_cmd_list,
+ concat ("maintenance show ", problem->name, " ", NULL),
+ 0/*allow-unknown*/, &maintenance_show_cmdlist);
+
+ set_doc = xstrprintf (_("\
+Set whether GDB should quit when an %s is detected"),
+ problem->name);
+ show_doc = xstrprintf (_("\
+Show whether GDB should quit when an %s is detected"),
+ problem->name);
+
+ add_setshow_auto_boolean_cmd ("quit",
+ class_maintenance,
+ &problem->should_quit,
+ set_doc,
+ show_doc,
+ NULL, /* help_doc */
+ NULL, /* setfunc */
+ NULL, /* showfunc */
+ set_cmd_list,
+ show_cmd_list);
+
+ set_doc = xstrprintf (_("\
+Set whether GDB should create a core file of GDB when an %s is detected"),
+ problem->name);
+ show_doc = xstrprintf (_("\
+Show whether GDB will create a core file of GDB when an %s is detected"),
+ problem->name);
+ add_setshow_auto_boolean_cmd ("corefile",
+ class_maintenance,
+ &problem->should_dump_core,
+ set_doc,
+ show_doc,
+ NULL, /* help_doc */
+ NULL, /* setfunc */
+ NULL, /* showfunc */
+ set_cmd_list,
+ show_cmd_list);
+}
+
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered.
Then return to command level. */
@@ -3441,3 +3516,10 @@ gdb_buildargv (const char *s)
nomem (0);
return argv;
}
+
+void
+_initialize_utils (void)
+{
+ add_internal_problem_command (&internal_error_problem);
+ add_internal_problem_command (&internal_warning_problem);
+}
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2008-12-29 02:33:57.000000000 +0000
+++ src/gdb/doc/gdb.texinfo 2008-12-29 03:03:54.000000000 +0000
@@ -24796,6 +24796,29 @@ Create a core file? (y or n) @kbd{n}
(@value{GDBP})
@end smallexample

+@kindex maint set internal-error quit
+@kindex maint show internal-error quit
+@kindex maint set internal-error corefile
+@kindex maint show internal-error corefile
+@kindex maint set internal-warning quit
+@kindex maint show internal-warning quit
+@kindex maint set internal-warning corefile
+@kindex maint show internal-warning corefile
+@item maint set internal-error quit [on|off|auto]
+@itemx maint show internal-error quit
+@itemx maint set internal-error corefile [on|off|auto]
+@itemx maint show internal-error corefile
+@itemx maint set internal-warning quit [on|off|auto]
+@itemx maint show internal-warning quit
+@itemx maint set internal-warning corefile [on|off|auto]
+@itemx maint show internal-warning corefile
+When @value{GDBN} reports an internal problem (error or warning) it
+gives the user the oportunity to both quit @value{GDBN} and create a
+core file of the current @value{GDBN} session. These commands let you
+override the default (auto) of prompting the user. You can specify
+that @value{GDBN} should always (on) or never (off) quit or create a
+core file.
+
@kindex maint packet
@item maint packet @var{text}
If @value{GDBN} is talking to an inferior via the serial protocol,