-
-const struct exception exception_none = { 0, NO_ERROR, NULL };
-
-/* One should use catch_errors rather than manipulating these
- directly. */
-#if defined(HAVE_SIGSETJMP)
-#define SIGJMP_BUF sigjmp_buf
-#define SIGSETJMP(buf) sigsetjmp((buf), 1)
-#define SIGLONGJMP(buf,val) siglongjmp((buf), (val))
-#else
-#define SIGJMP_BUF jmp_buf
-#define SIGSETJMP(buf) setjmp(buf)
-#define SIGLONGJMP(buf,val) longjmp((buf), (val))
-#endif
-
-/* Possible catcher states. */
-enum catcher_state {
- /* Initial state, a new catcher has just been created. */
- CATCHER_CREATED,
- /* The catch code is running. */
- CATCHER_RUNNING,
- CATCHER_RUNNING_1,
- /* The catch code threw an exception. */
- CATCHER_ABORTING
-};
-
-/* Possible catcher actions. */
-enum catcher_action {
- CATCH_ITER,
- CATCH_ITER_1,
- CATCH_THROWING
-};
-
-struct catcher
-{
- enum catcher_state state;
- /* Jump buffer pointing back at the exception handler. */
- SIGJMP_BUF buf;
- /* Status buffer belonging to the exception handler. */
- volatile struct exception *exception;
- /* Saved/current state. */
- int mask;
- struct ui_out *saved_uiout;
- struct cleanup *saved_cleanup_chain;
- /* Back link. */
- struct catcher *prev;
-};
-
-/* Where to go for throw_exception(). */
-static struct catcher *current_catcher;
-
-static SIGJMP_BUF *
-catcher_init (struct ui_out *func_uiout,
- volatile struct exception *exception,
- return_mask mask)
-{
- struct catcher *new_catcher = XZALLOC (struct catcher);
-
- /* Start with no exception, save it's address. */
- exception->reason = 0;
- exception->error = NO_ERROR;
- exception->message = NULL;
- new_catcher->exception = exception;
-
- new_catcher->mask = mask;
-
- /* Override the global ``struct ui_out'' builder. */
- new_catcher->saved_uiout = uiout;
- uiout = func_uiout;
-
- /* Prevent error/quit during FUNC from calling cleanups established
- prior to here. */
- new_catcher->saved_cleanup_chain = save_cleanups ();
-
- /* Push this new catcher on the top. */
- new_catcher->prev = current_catcher;
- current_catcher = new_catcher;
- new_catcher->state = CATCHER_CREATED;
-
- return &new_catcher->buf;
-}
-
-static void
-catcher_pop (void)
-{
- struct catcher *old_catcher = current_catcher;
- current_catcher = old_catcher->prev;
-
- /* Restore the cleanup chain, the error/quit messages, and the uiout
- builder, to their original states. */
-
- restore_cleanups (old_catcher->saved_cleanup_chain);
-
- uiout = old_catcher->saved_uiout;
-
- xfree (old_catcher);
-}
-
-/* Catcher state machine. Returns non-zero if the m/c should be run
- again, zero if it should abort. */
-
-int
-catcher_state_machine (enum catcher_action action)
-{
- switch (current_catcher->state)
- {
- case CATCHER_CREATED:
- switch (action)
- {
- case CATCH_ITER:
- /* Allow the code to run the catcher. */
- current_catcher->state = CATCHER_RUNNING;
- return 1;
- default:
- internal_error (__FILE__, __LINE__, "bad state");
- }
- case CATCHER_RUNNING:
- switch (action)
- {
- case CATCH_ITER:
- /* No error/quit has occured. Just clean up. */
- catcher_pop ();
- return 0;
- case CATCH_ITER_1:
- current_catcher->state = CATCHER_RUNNING_1;
- return 1;
- case CATCH_THROWING:
- current_catcher->state = CATCHER_ABORTING;
- /* See also throw_exception. */
- return 1;
- default:
- internal_error (__FILE__, __LINE__, "bad switch");
- }
- case CATCHER_RUNNING_1:
- switch (action)
- {
- case CATCH_ITER:
- /* The did a "break" from the inner while loop. */
- catcher_pop ();
- return 0;
- case CATCH_ITER_1:
- current_catcher->state = CATCHER_RUNNING;
- return 0;
- case CATCH_THROWING:
- current_catcher->state = CATCHER_ABORTING;
- /* See also throw_exception. */
- return 1;
- default:
- internal_error (__FILE__, __LINE__, "bad switch");
- }
- case CATCHER_ABORTING:
- switch (action)
- {
- case CATCH_ITER:
- {
- struct exception exception = *current_catcher->exception;
- if (current_catcher->mask & RETURN_MASK (exception.reason))
- {
- /* Exit normally if this catcher can handle this
- exception. The caller analyses the func return
- values. */
- catcher_pop ();
- return 0;
- }
- /* The caller didn't request that the event be caught,
- relay the event to the next containing
- catch_errors(). */
- catcher_pop ();
- throw_exception (exception);
- }
- default:
- internal_error (__FILE__, __LINE__, "bad state");
- }
- default:
- internal_error (__FILE__, __LINE__, "bad switch");
- }
-}
-
-/* Return EXCEPTION to the nearest containing catch_errors(). */
-
-NORETURN void
-throw_exception (struct exception exception)
-{
- quit_flag = 0;
- immediate_quit = 0;
-
- /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
- I can think of a reason why that is vital, though). */
- bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
-
- disable_current_display ();
- do_cleanups (ALL_CLEANUPS);
- if (target_can_async_p () && !target_executing)
- do_exec_cleanups (ALL_CLEANUPS);
- if (sync_execution)
- do_exec_error_cleanups (ALL_CLEANUPS);
-
- /* Jump to the containing catch_errors() call, communicating REASON
- to that call via setjmp's return value. Note that REASON can't
- be zero, by definition in defs.h. */
- catcher_state_machine (CATCH_THROWING);
- *current_catcher->exception = exception;
- SIGLONGJMP (current_catcher->buf, exception.reason);
-}
-
-static char *last_message;
-
-NORETURN void
-deprecated_throw_reason (enum return_reason reason)
-{
- struct exception exception;
- memset (&exception, 0, sizeof exception);
-
- exception.reason = reason;
- switch (reason)
- {
- case RETURN_QUIT:
- break;
- case RETURN_ERROR:
- exception.error = GENERIC_ERROR;
- break;
- default:
- internal_error (__FILE__, __LINE__, "bad switch");
- }
-
- throw_exception (exception);
-}