Files removed as of the 1999-08-23 snapshot.
[deliverable/binutils-gdb.git] / gdb / utils.c
index f181d0cbdc6369a0895b2fa49c1ed4dd6e35aead..314a8310b45737ef28ed49c146be87cee7708a30 100644 (file)
@@ -65,9 +65,6 @@ static void fputs_maybe_filtered PARAMS ((const char *, GDB_FILE *, int));
 static void malloc_botch PARAMS ((void));
 #endif
 
-static void
-fatal_dump_core PARAMS ((char *,...));
-
 static void
 prompt_for_continue PARAMS ((void));
 
@@ -431,24 +428,11 @@ warning_begin ()
    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
@@ -487,36 +471,17 @@ error_begin ()
    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);
@@ -524,69 +489,70 @@ error (va_alist)
 }
 
 
-/* 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
@@ -708,6 +674,11 @@ quit ()
   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.  */
@@ -716,36 +687,12 @@ quit ()
   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 
@@ -847,7 +794,8 @@ init_malloc (md)
 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
@@ -898,11 +846,11 @@ nomem (size)
 {
   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.");
     }
 }
 
@@ -1075,25 +1023,14 @@ gdb_print_address (addr, stream)
 
 /* 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)
     {
@@ -1273,9 +1210,13 @@ parse_escape (string_ptr)
    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;
 {
@@ -1289,38 +1230,76 @@ gdb_printchar (c, stream, 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.  */
@@ -2401,50 +2380,20 @@ vprintf_unfiltered (format, args)
   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);
 }
@@ -2452,28 +2401,11 @@ fprintf_unfiltered (va_alist)
 /* 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);
@@ -2481,47 +2413,21 @@ fprintfi_filtered (va_alist)
 }
 
 
-/* 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);
 }
@@ -2529,26 +2435,11 @@ printf_unfiltered (va_alist)
 /* 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);
This page took 0.028419 seconds and 4 git commands to generate.