static void malloc_botch PARAMS ((void));
#endif
-static void
-fatal_dump_core PARAMS ((char *,...));
-
static void
prompt_for_continue PARAMS ((void));
The primary difference between warnings and errors is that a warning
does not force the return to command level. */
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
warning (const char *string,...)
-#else
-warning (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, string);
-#else
- char *string;
-
- va_start (args);
- string = va_arg (args, char *);
-#endif
if (warning_hook)
(*warning_hook) (string, args);
else
The first argument STRING is the error message, used as a fprintf string,
and the remaining args are passed as arguments to it. */
-/* VARARGS */
NORETURN void
-#ifdef ANSI_PROTOTYPES
error (const char *string,...)
-#else
-error (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, string);
-#else
- va_start (args);
-#endif
if (error_hook)
(*error_hook) ();
else
{
error_begin ();
-#ifdef ANSI_PROTOTYPES
vfprintf_filtered (gdb_stderr, string, args);
-#else
- {
- char *string1;
-
- string1 = va_arg (args, char *);
- vfprintf_filtered (gdb_stderr, string1, args);
- }
-#endif
fprintf_filtered (gdb_stderr, "\n");
va_end (args);
return_to_top_level (RETURN_ERROR);
}
-/* Print an error message and exit reporting failure.
- This is for a error that we cannot continue from.
- The arguments are printed a la printf.
-
- This function cannot be declared volatile (NORETURN) in an
- ANSI environment because exit() is not declared volatile. */
+/* Print a message reporting an internal error. Ask the user if they
+ want to continue, dump core, or just exit. */
-/* VARARGS */
NORETURN void
-#ifdef ANSI_PROTOTYPES
-fatal (char *string,...)
-#else
-fatal (va_alist)
- va_dcl
-#endif
+internal_error (char *string, ...)
{
+ static char msg[] = "Internal GDB error: recursive internal error.\n";
+ static int dejavu = 0;
va_list args;
-#ifdef ANSI_PROTOTYPES
+ int continue_p;
+ int dump_core_p;
+
+ /* don't allow infinite error recursion. */
+ switch (dejavu)
+ {
+ case 0:
+ dejavu = 1;
+ break;
+ case 1:
+ dejavu = 2;
+ fputs_unfiltered (msg, gdb_stderr);
+ abort ();
+ default:
+ dejavu = 3;
+ write (STDERR_FILENO, msg, sizeof (msg));
+ exit (1);
+ }
+
+ /* Try to get the message out */
+ fputs_unfiltered ("gdb-internal-error: ", gdb_stderr);
va_start (args, string);
-#else
- char *string;
- va_start (args);
- string = va_arg (args, char *);
-#endif
- fprintf_unfiltered (gdb_stderr, "\ngdb: ");
vfprintf_unfiltered (gdb_stderr, string, args);
- fprintf_unfiltered (gdb_stderr, "\n");
va_end (args);
- exit (1);
-}
+ fputs_unfiltered ("\n", gdb_stderr);
-/* Print an error message and exit, dumping core.
- The arguments are printed a la printf (). */
+ /* Default (no case) is to quit GDB. When in batch mode this
+ lessens the likelhood of GDB going into an infinate loop. */
+ continue_p = query ("\
+An internal GDB error was detected. This may make make further\n\
+debugging unreliable. Continue this debugging session? ");
-/* VARARGS */
-static void
-#ifdef ANSI_PROTOTYPES
-fatal_dump_core (char *string,...)
-#else
-fatal_dump_core (va_alist)
- va_dcl
-#endif
-{
- va_list args;
-#ifdef ANSI_PROTOTYPES
- va_start (args, string);
-#else
- char *string;
+ /* Default (no case) is to not dump core. Lessen the chance of GDB
+ leaving random core files around. */
+ dump_core_p = query ("\
+Create a core file containing the current state of GDB? ");
- va_start (args);
- string = va_arg (args, char *);
-#endif
- /* "internal error" is always correct, since GDB should never dump
- core, no matter what the input. */
- fprintf_unfiltered (gdb_stderr, "\ngdb internal error: ");
- vfprintf_unfiltered (gdb_stderr, string, args);
- fprintf_unfiltered (gdb_stderr, "\n");
- va_end (args);
+ if (continue_p)
+ {
+ if (dump_core_p)
+ {
+ if (fork () == 0)
+ abort ();
+ }
+ }
+ else
+ {
+ if (dump_core_p)
+ abort ();
+ else
+ exit (1);
+ }
- signal (SIGQUIT, SIG_DFL);
- kill (getpid (), SIGQUIT);
- /* We should never get here, but just in case... */
- exit (1);
+ dejavu = 0;
+ return_to_top_level (RETURN_ERROR);
}
/* The strerror() function can return NULL for errno values that are
if (quit_pre_print)
fprintf_unfiltered (gdb_stderr, quit_pre_print);
+#ifdef __MSDOS__
+ /* No steenking SIGINT will ever be coming our way when the
+ program is resumed. Don't lie. */
+ fprintf_unfiltered (gdb_stderr, "Quit\n");
+#else
if (job_control
/* If there is no terminal switching for this target, then we can't
possibly get screwed by the lack of job control. */
else
fprintf_unfiltered (gdb_stderr,
"Quit (expect signal SIGINT when the program is resumed)\n");
+#endif
return_to_top_level (RETURN_QUIT);
}
-#if defined(__GO32__)
-
-/* In the absence of signals, poll keyboard for a quit.
- Called from #define QUIT pollquit() in xm-go32.h. */
-
-void
-notice_quit ()
-{
- if (kbhit ())
- switch (getkey ())
- {
- case 1:
- quit_flag = 1;
- break;
- case 2:
- immediate_quit = 2;
- break;
- default:
- /* We just ignore it */
- /* FIXME!! Don't think this actually works! */
- fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
- break;
- }
-}
-
-#elif defined(_MSC_VER) /* should test for wingdb instead? */
+#if defined(_MSC_VER) /* should test for wingdb instead? */
/*
* Windows translates all keyboard and mouse events
static void
malloc_botch ()
{
- fatal_dump_core ("Memory corruption");
+ fprintf_unfiltered (gdb_stderr, "Memory corruption\n");
+ abort ();
}
/* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
{
if (size > 0)
{
- fatal ("virtual memory exhausted: can't allocate %ld bytes.", size);
+ internal_error ("virtual memory exhausted: can't allocate %ld bytes.", size);
}
else
{
- fatal ("virtual memory exhausted.");
+ internal_error ("virtual memory exhausted.");
}
}
/* VARARGS */
int
-#ifdef ANSI_PROTOTYPES
query (char *ctlstr,...)
-#else
-query (va_alist)
- va_dcl
-#endif
{
va_list args;
register int answer;
register int ans2;
int retval;
-#ifdef ANSI_PROTOTYPES
va_start (args, ctlstr);
-#else
- char *ctlstr;
- va_start (args);
- ctlstr = va_arg (args, char *);
-#endif
if (query_hook)
{
be call for printing things which are independent of the language
of the program being debugged. */
-void
-gdb_printchar (c, stream, quoter)
- register int c;
+static void printchar PARAMS ((int c, void (*do_fputs) (const char *, GDB_FILE*), void (*do_fprintf) (GDB_FILE*, const char *, ...), GDB_FILE *stream, int quoter));
+
+static void
+printchar (c, do_fputs, do_fprintf, stream, quoter)
+ int c;
+ void (*do_fputs) PARAMS ((const char *, GDB_FILE*));
+ void (*do_fprintf) PARAMS ((GDB_FILE*, const char *, ...));
GDB_FILE *stream;
int quoter;
{
switch (c)
{
case '\n':
- fputs_filtered ("\\n", stream);
+ do_fputs ("\\n", stream);
break;
case '\b':
- fputs_filtered ("\\b", stream);
+ do_fputs ("\\b", stream);
break;
case '\t':
- fputs_filtered ("\\t", stream);
+ do_fputs ("\\t", stream);
break;
case '\f':
- fputs_filtered ("\\f", stream);
+ do_fputs ("\\f", stream);
break;
case '\r':
- fputs_filtered ("\\r", stream);
+ do_fputs ("\\r", stream);
break;
case '\033':
- fputs_filtered ("\\e", stream);
+ do_fputs ("\\e", stream);
break;
case '\007':
- fputs_filtered ("\\a", stream);
+ do_fputs ("\\a", stream);
break;
default:
- fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
+ do_fprintf (stream, "\\%.3o", (unsigned int) c);
break;
}
}
else
{
if (c == '\\' || c == quoter)
- fputs_filtered ("\\", stream);
- fprintf_filtered (stream, "%c", c);
+ do_fputs ("\\", stream);
+ do_fprintf (stream, "%c", c);
}
}
+
+/* Print the character C on STREAM as part of the contents of a
+ literal string whose delimiter is QUOTER. Note that these routines
+ should only be call for printing things which are independent of
+ the language of the program being debugged. */
+
+void
+fputstr_filtered (str, quoter, stream)
+ const char *str;
+ int quoter;
+ GDB_FILE *stream;
+{
+ while (*str)
+ printchar (*str++, fputs_filtered, fprintf_filtered, stream, quoter);
+}
+
+void
+fputstr_unfiltered (str, quoter, stream)
+ const char *str;
+ int quoter;
+ GDB_FILE *stream;
+{
+ while (*str)
+ printchar (*str++, fputs_unfiltered, fprintf_unfiltered, stream, quoter);
+}
+
+void
+fputstrn_unfiltered (str, n, quoter, stream)
+ const char *str;
+ int n;
+ int quoter;
+ GDB_FILE *stream;
+{
+ int i;
+ for (i = 0; i < n; i++)
+ printchar (str[i], fputs_unfiltered, fprintf_unfiltered, stream, quoter);
+}
+
\f
/* Number of lines per page or UINT_MAX if paging is disabled. */
vfprintf_unfiltered (gdb_stdout, format, args);
}
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
fprintf_filtered (GDB_FILE * stream, const char *format,...)
-#else
-fprintf_filtered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- GDB_FILE *stream;
- char *format;
-
- va_start (args);
- stream = va_arg (args, GDB_FILE *);
- format = va_arg (args, char *);
-#endif
vfprintf_filtered (stream, format, args);
va_end (args);
}
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
fprintf_unfiltered (GDB_FILE * stream, const char *format,...)
-#else
-fprintf_unfiltered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- GDB_FILE *stream;
- char *format;
-
- va_start (args);
- stream = va_arg (args, GDB_FILE *);
- format = va_arg (args, char *);
-#endif
vfprintf_unfiltered (stream, format, args);
va_end (args);
}
/* Like fprintf_filtered, but prints its result indented.
Called as fprintfi_filtered (spaces, stream, format, ...); */
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
fprintfi_filtered (int spaces, GDB_FILE * stream, const char *format,...)
-#else
-fprintfi_filtered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- int spaces;
- GDB_FILE *stream;
- char *format;
-
- va_start (args);
- spaces = va_arg (args, int);
- stream = va_arg (args, GDB_FILE *);
- format = va_arg (args, char *);
-#endif
print_spaces_filtered (spaces, stream);
vfprintf_filtered (stream, format, args);
}
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
printf_filtered (const char *format,...)
-#else
-printf_filtered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- char *format;
-
- va_start (args);
- format = va_arg (args, char *);
-#endif
vfprintf_filtered (gdb_stdout, format, args);
va_end (args);
}
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
printf_unfiltered (const char *format,...)
-#else
-printf_unfiltered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- char *format;
-
- va_start (args);
- format = va_arg (args, char *);
-#endif
vfprintf_unfiltered (gdb_stdout, format, args);
va_end (args);
}
/* Like printf_filtered, but prints it's result indented.
Called as printfi_filtered (spaces, format, ...); */
-/* VARARGS */
void
-#ifdef ANSI_PROTOTYPES
printfi_filtered (int spaces, const char *format,...)
-#else
-printfi_filtered (va_alist)
- va_dcl
-#endif
{
va_list args;
-#ifdef ANSI_PROTOTYPES
va_start (args, format);
-#else
- int spaces;
- char *format;
-
- va_start (args);
- spaces = va_arg (args, int);
- format = va_arg (args, char *);
-#endif
print_spaces_filtered (spaces, gdb_stdout);
vfprintf_filtered (gdb_stdout, format, args);
va_end (args);