2005-01-19 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / utils.c
index 673dc331e9fae4793544434c0dc33d43f08aa333..243fc754db6398f470a9693f1c8b9f8857b3958a 100644 (file)
@@ -1,8 +1,8 @@
 /* General utility routines for GDB, the GNU debugger.
 
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
-   Foundation, Inc.
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
+   Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -26,6 +26,7 @@
 #include <ctype.h>
 #include "gdb_string.h"
 #include "event-top.h"
+#include "exceptions.h"
 
 #ifdef TUI
 #include "tui/tui.h"           /* For tui_get_command_dimension.   */
@@ -81,10 +82,6 @@ extern char *canonicalize_file_name (const char *);
 
 void (*deprecated_error_begin_hook) (void);
 
-/* Holds the last error message issued by gdb */
-
-static struct ui_file *gdb_lasterr;
-
 /* Prototypes for local functions */
 
 static void vfprintf_maybe_filtered (struct ui_file *, const char *,
@@ -99,9 +96,6 @@ static void prompt_for_continue (void);
 static void set_screen_size (void);
 static void set_width (void);
 
-static NORETURN void error_stream_1 (struct ui_file *stream, 
-                                    enum return_reason reason) ATTR_NORETURN;
-
 /* Chain of cleanup actions established with make_cleanup,
    to be executed if an error happens.  */
 
@@ -465,7 +459,7 @@ add_continuation (void (*continuation_hook) (struct continuation_arg *),
    before we have a chance of exhausting those that were already
    there. We need to then save the beginning of the list in a pointer
    and do the continuations from there on, instead of using the
-   global beginning of list as our iteration pointer.*/
+   global beginning of list as our iteration pointer.  */
 void
 do_all_continuations (void)
 {
@@ -479,7 +473,7 @@ do_all_continuations (void)
   continuation_ptr = cmd_continuation;
   cmd_continuation = NULL;
 
-  /* Work now on the list we have set aside. */
+  /* Work now on the list we have set aside.  */
   while (continuation_ptr)
     {
       (continuation_ptr->continuation_hook) (continuation_ptr->arg_list);
@@ -505,7 +499,8 @@ discard_all_continuations (void)
 }
 
 /* Add a continuation to the continuation list, the global list
-   intermediate_continuation. The new continuation will be added at the front.*/
+   intermediate_continuation.  The new continuation will be added at
+   the front.  */
 void
 add_intermediate_continuation (void (*continuation_hook)
                               (struct continuation_arg *),
@@ -542,7 +537,7 @@ do_all_intermediate_continuations (void)
   continuation_ptr = intermediate_continuation;
   intermediate_continuation = NULL;
 
-  /* Work now on the list we have set aside. */
+  /* Work now on the list we have set aside.  */
   while (continuation_ptr)
     {
       (continuation_ptr->continuation_hook) (continuation_ptr->arg_list);
@@ -615,10 +610,7 @@ warning (const char *string, ...)
 NORETURN void
 verror (const char *string, va_list args)
 {
-  struct ui_file *tmp_stream = mem_fileopen ();
-  make_cleanup_ui_file_delete (tmp_stream);
-  vfprintf_unfiltered (tmp_stream, string, args);
-  error_stream_1 (tmp_stream, RETURN_ERROR);
+  throw_verror (GENERIC_ERROR, string, args);
 }
 
 NORETURN void
@@ -626,7 +618,7 @@ error (const char *string, ...)
 {
   va_list args;
   va_start (args, string);
-  verror (string, args);
+  throw_verror (GENERIC_ERROR, string, args);
   va_end (args);
 }
 
@@ -637,10 +629,7 @@ error (const char *string, ...)
 NORETURN void
 vfatal (const char *string, va_list args)
 {
-  struct ui_file *tmp_stream = mem_fileopen ();
-  make_cleanup_ui_file_delete (tmp_stream);
-  vfprintf_unfiltered (tmp_stream, string, args);
-  error_stream_1 (tmp_stream, RETURN_QUIT);
+  throw_vfatal (string, args);
 }
 
 NORETURN void
@@ -648,92 +637,17 @@ fatal (const char *string, ...)
 {
   va_list args;
   va_start (args, string);
-  vfatal (string, args);
+  throw_vfatal (string, args);
   va_end (args);
 }
 
-static void
-do_write (void *data, const char *buffer, long length_buffer)
-{
-  ui_file_write (data, buffer, length_buffer);
-}
-
-/* Cause a silent error to occur.  Any error message is recorded
-   though it is not issued.  */
-NORETURN void
-error_silent (const char *string, ...)
-{
-  va_list args;
-  struct ui_file *tmp_stream = mem_fileopen ();
-  va_start (args, string);
-  make_cleanup_ui_file_delete (tmp_stream);
-  vfprintf_unfiltered (tmp_stream, string, args);
-  /* Copy the stream into the GDB_LASTERR buffer.  */
-  ui_file_rewind (gdb_lasterr);
-  ui_file_put (tmp_stream, do_write, gdb_lasterr);
-  va_end (args);
-
-  throw_exception (RETURN_ERROR);
-}
-
-/* Output an error message including any pre-print text to gdb_stderr.  */
-void
-error_output_message (char *pre_print, char *msg)
-{
-  target_terminal_ours ();
-  wrap_here ("");              /* Force out any buffered output */
-  gdb_flush (gdb_stdout);
-  annotate_error_begin ();
-  if (pre_print)
-    fputs_filtered (pre_print, gdb_stderr);
-  fputs_filtered (msg, gdb_stderr);
-  fprintf_filtered (gdb_stderr, "\n");
-}
-
-static NORETURN void
-error_stream_1 (struct ui_file *stream, enum return_reason reason)
-{
-  if (deprecated_error_begin_hook)
-    deprecated_error_begin_hook ();
-
-  /* Copy the stream into the GDB_LASTERR buffer.  */
-  ui_file_rewind (gdb_lasterr);
-  ui_file_put (stream, do_write, gdb_lasterr);
-
-  /* Write the message plus any error_pre_print to gdb_stderr.  */
-  target_terminal_ours ();
-  wrap_here ("");              /* Force out any buffered output */
-  gdb_flush (gdb_stdout);
-  annotate_error_begin ();
-  if (error_pre_print)
-    fputs_filtered (error_pre_print, gdb_stderr);
-  ui_file_put (stream, do_write, gdb_stderr);
-  fprintf_filtered (gdb_stderr, "\n");
-
-  throw_exception (reason);
-}
-
 NORETURN void
 error_stream (struct ui_file *stream)
-{
-  error_stream_1 (stream, RETURN_ERROR);
-}
-
-/* Get the last error message issued by gdb */
-
-char *
-error_last_message (void)
 {
   long len;
-  return ui_file_xstrdup (gdb_lasterr, &len);
-}
-
-/* This is to be called by main() at the very beginning */
-
-void
-error_init (void)
-{
-  gdb_lasterr = mem_fileopen ();
+  char *message = ui_file_xstrdup (stream, &len);
+  make_cleanup (xfree, message);
+  error ("%s", message);
 }
 
 /* Print a message reporting an internal error/warning. Ask the user
@@ -865,7 +779,7 @@ NORETURN void
 internal_verror (const char *file, int line, const char *fmt, va_list ap)
 {
   internal_vproblem (&internal_error_problem, file, line, fmt, ap);
-  throw_exception (RETURN_ERROR);
+  deprecated_throw_reason (RETURN_ERROR);
 }
 
 NORETURN void
@@ -1006,7 +920,7 @@ quit (void)
     fprintf_unfiltered (gdb_stderr,
                        "Quit (expect signal SIGINT when the program is resumed)\n");
 #endif
-  throw_exception (RETURN_QUIT);
+  deprecated_throw_reason (RETURN_QUIT);
 }
 
 /* Control C comes here */
This page took 0.025873 seconds and 4 git commands to generate.