-NORETURN static void
-print_and_throw (enum return_reason reason, enum errors error,
- const char *prefix, const char *fmt,
- va_list ap) ATTR_NORETURN;
-NORETURN static void
-print_and_throw (enum return_reason reason, enum errors error,
- const char *prefix, const char *fmt, va_list ap)
-{
- /* FIXME: cagney/2005-01-13: While xstrvprintf is simpler it alters
- GDB's output. Instead of the message being printed
- line-at-a-time the message comes out all at once. The problem is
- that the MI testsuite is checks for line-at-a-time messages and
- changing this behavior means updating the testsuite. */
-
- struct exception e;
- struct ui_file *tmp_stream;
- long len;
-
- /* Convert the message into a print stream. */
- tmp_stream = mem_fileopen ();
- make_cleanup_ui_file_delete (tmp_stream);
- vfprintf_unfiltered (tmp_stream, fmt, ap);
-
- /* Save the message. */
- xfree (last_message);
- last_message = ui_file_xstrdup (tmp_stream, &len);
-
- /* Print the mesage to stderr, but only if the catcher isn't going
- to handle/print it locally. */
- if (current_catcher->print_message)
- {
- if (deprecated_error_begin_hook)
- deprecated_error_begin_hook ();
-
- /* Write the message plus any 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 (tmp_stream, do_write, gdb_stderr);
- fprintf_filtered (gdb_stderr, "\n");
- }
-
- /* Throw the exception. */
- e.reason = reason;
- e.error = error;
- e.message = last_message;
- throw_exception (e);
-}
-
-NORETURN void
-throw_verror (enum errors error, const char *fmt, va_list ap)
-{
- print_and_throw (RETURN_ERROR, error, error_pre_print, fmt, ap);
-}
-
-NORETURN void
-throw_vfatal (const char *fmt, va_list ap)
-{
- print_and_throw (RETURN_QUIT, NO_ERROR, quit_pre_print, fmt, ap);
-}
-
-NORETURN void
-throw_error (enum errors error, const char *fmt, ...)
-{
- va_list args;
- va_start (args, fmt);
- print_and_throw (RETURN_ERROR, error, error_pre_print, fmt, args);
- va_end (args);
-}
-
-/* Call FUNC() with args FUNC_UIOUT and FUNC_ARGS, catching any
- errors. Set FUNC_CAUGHT to an ``enum return_reason'' if the
- function is aborted (using throw_exception() or zero if the
- function returns normally. Set FUNC_VAL to the value returned by
- the function or 0 if the function was aborted.
-
- Must not be called with immediate_quit in effect (bad things might
- happen, say we got a signal in the middle of a memcpy to quit_return).
- This is an OK restriction; with very few exceptions immediate_quit can
- be replaced by judicious use of QUIT.
-
- MASK specifies what to catch; it is normally set to
- RETURN_MASK_ALL, if for no other reason than that the code which
- calls catch_errors might not be set up to deal with a quit which
- isn't caught. But if the code can deal with it, it generally
- should be RETURN_MASK_ERROR, unless for some reason it is more
- useful to abort only the portion of the operation inside the
- catch_errors. Note that quit should return to the command line
- fairly quickly, even if some further processing is being done. */
-
-/* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
- error() et.al. could maintain a set of flags that indicate the the
- current state of each of the longjmp buffers. This would give the
- longjmp code the chance to detect a longjmp botch (before it gets
- to longjmperror()). Prior to 1999-11-05 this wasn't possible as
- code also randomly used a SET_TOP_LEVEL macro that directly
- initialize the longjmp buffers. */
-
-/* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
- be consolidated into a single file instead of being distributed
- between utils.c and top.c? */