-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)
-{
- struct exception e;
-
- /* Save the message. */
- xfree (last_message);
- last_message = xstrvprintf (fmt, ap);
-
- /* Create the exception. */
- e.reason = reason;
- e.error = error;
- e.message = last_message;
-
- /* Print the mesage to stderr, but only if the catcher isn't going
- to handle/print it locally. */
- if (current_catcher->print_message)
- {
- /* Write the message plus any pre_print to gdb_stderr. */
- print_flush ();
- if (error_pre_print)
- fputs_filtered (error_pre_print, gdb_stderr);
- print_exception (gdb_stderr, e);
- }
-
- /* Throw the exception. */
- 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? */
-
-int
-catch_exceptions (struct ui_out *uiout,
- catch_exceptions_ftype *func,
- void *func_args,
- return_mask mask)
-{
- return catch_exceptions_with_msg (uiout, func, func_args, NULL, mask);
-}
-
-struct exception
-catch_exception (struct ui_out *uiout,
- catch_exception_ftype *func,
- void *func_args,
- return_mask mask)
-{
- volatile struct exception exception;
- SIGJMP_BUF *catch;
- catch = catcher_init (uiout, NULL, &exception, mask, 0);
- for (SIGSETJMP ((*catch));
- catcher_state_machine (CATCH_ITER);)
- (*func) (uiout, func_args);
- return exception;
-}
-
-int
-catch_exceptions_with_msg (struct ui_out *uiout,
- catch_exceptions_ftype *func,
- void *func_args,
- char **gdberrmsg,
- return_mask mask)
-{
- volatile struct exception exception;
- volatile int val = 0;
- SIGJMP_BUF *catch = catcher_init (uiout, NULL, &exception, mask, 1);
- for (SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
- val = (*func) (uiout, func_args);
- gdb_assert (val >= 0);
- gdb_assert (exception.reason <= 0);
- if (exception.reason < 0)
- {
- /* If caller wants a copy of the low-level error message, make
- one. This is used in the case of a silent error whereby the
- caller may optionally want to issue the message. */
- if (gdberrmsg != NULL)
- {
- if (exception.message != NULL)
- *gdberrmsg = xstrdup (exception.message);
- else
- *gdberrmsg = NULL;
- }
- return exception.reason;
- }
- return val;
-}