/* General utility routines for GDB, the GNU debugger.
Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
- 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
- Free Software Foundation, Inc.
+ 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ 2009 Free Software Foundation, Inc.
This file is part of GDB.
error (("%s"), message);
}
+/* Allow the user to configure the debugger behavior with respect to
+ what to do when an internal problem is detected. */
+
+const char internal_problem_ask[] = "ask";
+const char internal_problem_yes[] = "yes";
+const char internal_problem_no[] = "no";
+static const char *internal_problem_modes[] =
+{
+ internal_problem_ask,
+ internal_problem_yes,
+ internal_problem_no,
+ NULL
+};
+static const char *internal_problem_mode = internal_problem_ask;
+
/* Print a message reporting an internal error/warning. Ask the user
if they want to continue, dump core, or just exit. Return
something to indicate a quit. */
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;
+ const char *should_quit;
+ const char *should_dump_core;
};
/* Report a problem, internal to GDB, to the user. Once the problem
case 1:
dejavu = 2;
fputs_unfiltered (msg, gdb_stderr);
- abort (); /* NOTE: GDB has only three calls to abort(). */
+ abort (); /* NOTE: GDB has only four calls to abort(). */
default:
dejavu = 3;
- write (STDERR_FILENO, msg, sizeof (msg));
+ /* Newer GLIBC versions put the warn_unused_result attribute
+ on write, but this is one of those rare cases where
+ ignoring the return value is correct. Casting to (void)
+ does not fix this problem. This is the solution suggested
+ at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509. */
+ if (write (STDERR_FILENO, msg, sizeof (msg)) != sizeof (msg))
+ abort (); /* NOTE: GDB has only four calls to abort(). */
exit (1);
}
}
make_cleanup (xfree, reason);
}
- switch (problem->should_quit)
+ if (problem->should_quit == internal_problem_ask)
{
- case AUTO_BOOLEAN_AUTO:
/* Default (yes/batch case) is to quit GDB. When in batch mode
- this lessens the likelhood of GDB going into an infinate
- loop. */
+ this lessens the likelihood of GDB going into an infinite
+ loop. */
quit_p = query (_("%s\nQuit this debugging session? "), reason);
- break;
- case AUTO_BOOLEAN_TRUE:
- quit_p = 1;
- break;
- case AUTO_BOOLEAN_FALSE:
- quit_p = 0;
- break;
- default:
- internal_error (__FILE__, __LINE__, _("bad switch"));
}
+ else if (problem->should_quit == internal_problem_yes)
+ quit_p = 1;
+ else if (problem->should_quit == internal_problem_no)
+ quit_p = 0;
+ else
+ internal_error (__FILE__, __LINE__, _("bad switch"));
- switch (problem->should_dump_core)
+ if (problem->should_dump_core == internal_problem_ask)
{
- case AUTO_BOOLEAN_AUTO:
/* Default (yes/batch case) is to dump core. This leaves a GDB
`dropping' so that it is easier to see that something went
wrong in GDB. */
dump_core_p = query (_("%s\nCreate a core file of GDB? "), reason);
- break;
- break;
- case AUTO_BOOLEAN_TRUE:
- dump_core_p = 1;
- break;
- case AUTO_BOOLEAN_FALSE:
- dump_core_p = 0;
- break;
- default:
- internal_error (__FILE__, __LINE__, _("bad switch"));
}
+ else if (problem->should_dump_core == internal_problem_yes)
+ dump_core_p = 1;
+ else if (problem->should_dump_core == internal_problem_no)
+ dump_core_p = 0;
+ else
+ internal_error (__FILE__, __LINE__, _("bad switch"));
if (quit_p)
{
if (dump_core_p)
- abort (); /* NOTE: GDB has only three calls to abort(). */
+ abort (); /* NOTE: GDB has only four calls to abort(). */
else
exit (1);
}
{
#ifdef HAVE_WORKING_FORK
if (fork () == 0)
- abort (); /* NOTE: GDB has only three calls to abort(). */
+ abort (); /* NOTE: GDB has only four calls to abort(). */
#endif
}
}
}
static struct internal_problem internal_error_problem = {
- "internal-error", AUTO_BOOLEAN_AUTO, AUTO_BOOLEAN_AUTO
+ "internal-error", internal_problem_ask, internal_problem_ask
};
NORETURN void
}
static struct internal_problem internal_warning_problem = {
- "internal-warning", AUTO_BOOLEAN_AUTO, AUTO_BOOLEAN_AUTO
+ "internal-warning", internal_problem_ask, internal_problem_ask
};
void
va_end (ap);
}
+/* Dummy functions to keep add_prefix_cmd happy. */
+
+static void
+set_internal_problem_cmd (char *args, int from_tty)
+{
+}
+
+static void
+show_internal_problem_cmd (char *args, int from_tty)
+{
+}
+
+/* When GDB reports an internal problem (error or warning) it gives
+ the user the opportunity to quit GDB and/or create a core file of
+ the current debug session. This function registers a few commands
+ that make it possible to specify that GDB should always or never
+ quit or create a core file, without asking. The commands look
+ like:
+
+ maint set PROBLEM-NAME quit ask|yes|no
+ maint show PROBLEM-NAME quit
+ maint set PROBLEM-NAME corefile ask|yes|no
+ maint show PROBLEM-NAME corefile
+
+ Where PROBLEM-NAME is currently "internal-error" or
+ "internal-warning". */
+
+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 %s is detected."),
+ problem->name);
+
+ show_doc = xstrprintf (_("Show what GDB does when %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 will quit when an %s is detected"),
+ problem->name);
+ add_setshow_enum_cmd ("quit", class_maintenance,
+ internal_problem_modes,
+ &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 %s is detected"),
+ problem->name);
+ show_doc = xstrprintf (_("\
+Show whether GDB will create a core file of GDB when %s is detected"),
+ problem->name);
+ add_setshow_enum_cmd ("corefile", class_maintenance,
+ internal_problem_modes,
+ &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. */
void
gdb_print_host_address (const void *addr, struct ui_file *stream)
{
-
- /* We could use the %p conversion specifier to fprintf if we had any
- way of knowing whether this host supports it. But the following
- should work on the Alpha and on 32 bit machines. */
-
- fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
+ fprintf_filtered (stream, "%s", host_address_to_string (addr));
}
\f
host_address_to_string (const void *addr)
{
char *str = get_cell ();
- sprintf (str, "0x%lx", (unsigned long) addr);
+
+ xsnprintf (str, CELLSIZE, "0x%s", phex_nz ((uintptr_t) addr, sizeof (addr)));
return str;
}
nomem (0);
return argv;
}
+
+void
+_initialize_utils (void)
+{
+ add_internal_problem_command (&internal_error_problem);
+ add_internal_problem_command (&internal_warning_problem);
+}