1 /* Exception (throw catch) mechanism, for GDB, the GNU debugger.
3 Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
27 /* Reasons for calling throw_exception(). NOTE: all reason values
28 must be less than zero. enum value 0 is reserved for internal use
29 as the return value from an initial setjmp(). The function
30 catch_exceptions() reserves values >= 0 as legal results from its
37 /* Any other error. */
41 #define RETURN_MASK(reason) (1 << (int)(-reason))
42 #define RETURN_MASK_QUIT RETURN_MASK (RETURN_QUIT)
43 #define RETURN_MASK_ERROR RETURN_MASK (RETURN_ERROR)
44 #define RETURN_MASK_ALL (RETURN_MASK_QUIT | RETURN_MASK_ERROR)
45 typedef int return_mask;
47 /* Throw an exception of type RETURN_REASON. Will execute a LONG JUMP
48 to the inner most containing exception handler established using
49 catch_exceptions() (or the legacy catch_errors()).
51 Code normally throws an exception using error() et.al. For various
52 reaons, GDB also contains code that throws an exception directly.
53 For instance, the remote*.c targets contain CNTRL-C signal handlers
54 that propogate the QUIT event up the exception chain. ``This could
55 be a good thing or a dangerous thing.'' -- the Existential Wombat. */
57 extern NORETURN void throw_exception (enum return_reason) ATTR_NORETURN;
59 /* Call FUNC(UIOUT, FUNC_ARGS) but wrapped within an exception
60 handler. If an exception (enum return_reason) is thrown using
61 throw_exception() than all cleanups installed since
62 catch_exceptions() was entered are invoked, the (-ve) exception
63 value is then returned by catch_exceptions. If FUNC() returns
64 normally (with a postive or zero return value) then that value is
65 returned by catch_exceptions(). It is an internal_error() for
66 FUNC() to return a negative value.
68 For the period of the FUNC() call: UIOUT is installed as the output
69 builder; ERRSTRING is installed as the error/quit message; and a
70 new cleanup_chain is established. The old values are restored
71 before catch_exceptions() returns.
73 The variant catch_exceptions_with_msg() is the same as
74 catch_exceptions() but adds the ability to return an allocated
75 copy of the gdb error message. This is used when a silent error is
76 issued and the caller wants to manually issue the error message.
78 FIXME; cagney/2001-08-13: The need to override the global UIOUT
79 builder variable should just go away.
81 This function superseeds catch_errors().
83 This function uses SETJMP() and LONGJUMP(). */
86 typedef int (catch_exceptions_ftype) (struct ui_out *ui_out, void *args);
87 extern int catch_exceptions (struct ui_out *uiout,
88 catch_exceptions_ftype *func, void *func_args,
89 char *errstring, return_mask mask);
90 extern int catch_exceptions_with_msg (struct ui_out *uiout,
91 catch_exceptions_ftype *func,
93 char *errstring, char **gdberrmsg,
96 /* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
97 otherwize the result from CATCH_ERRORS_FTYPE is returned. It is
98 probably useful for CATCH_ERRORS_FTYPE to always return a non-zero
99 value. It's unfortunate that, catch_errors() does not return an
100 indication of the exact exception that it caught - quit_flag might
103 This function is superseeded by catch_exceptions(). */
105 typedef int (catch_errors_ftype) (void *);
106 extern int catch_errors (catch_errors_ftype *, void *, char *, return_mask);
108 /* Template to catch_errors() that wraps calls to command
111 typedef void (catch_command_errors_ftype) (char *, int);
112 extern int catch_command_errors (catch_command_errors_ftype *func, char *command, int from_tty, return_mask);