From 9d1e69a21488cb5b8b7553c8df18ee5c3f4d82e3 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 14 Jul 2014 19:55:31 +0100 Subject: [PATCH] Move catch_command_errors and catch_command_errors_const to main.c We'll need to add error handling code to commands run before the event loop starts (commands in .gdbinit, -ex commands, etc.). Turns out those are run through catch_command_errors, and, catch_command_errors is used nowhere else. Move it (and the _const variant) to main.c, so that we can further specialize it freely. gdb/ 2014-07-14 Pedro Alves * exceptions.c (catch_command_errors, catch_command_errors_const): Moved to main.c. * exceptions.h (catch_command_errors_ftype) (catch_command_errors_const_ftype): Moved to main.c. (catch_command_errors, catch_command_errors_const): Delete declarations. * main.c (catch_command_errors_ftype) (catch_command_errors_const_ftype): Moved here from exceptions.h. (catch_command_errors, catch_command_errors_const)): Moved here from exceptions.c and make static. --- gdb/ChangeLog | 13 +++++++++++++ gdb/exceptions.c | 32 -------------------------------- gdb/exceptions.h | 13 ------------- gdb/main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7d686b8..7a5abe0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2014-07-14 Pedro Alves + * exceptions.c (catch_command_errors, catch_command_errors_const): + Moved to main.c. + * exceptions.h (catch_command_errors_ftype) + (catch_command_errors_const_ftype): Moved to main.c. + (catch_command_errors, catch_command_errors_const): Delete + declarations. + * main.c (catch_command_errors_ftype) + (catch_command_errors_const_ftype): Moved here from exceptions.h. + (catch_command_errors, catch_command_errors_const)): Moved here + from exceptions.c and make static. + +2014-07-14 Pedro Alves + * exceptions.c (print_any_exception): Delete. (catch_exceptions_with_msg): Use exception_print instead of print_any_exception. diff --git a/gdb/exceptions.c b/gdb/exceptions.c index 8ee428d..def1f41 100644 --- a/gdb/exceptions.c +++ b/gdb/exceptions.c @@ -521,35 +521,3 @@ catch_errors (catch_errors_ftype *func, void *func_args, char *errstring, return 0; return val; } - -int -catch_command_errors (catch_command_errors_ftype *command, - char *arg, int from_tty, return_mask mask) -{ - volatile struct gdb_exception e; - - TRY_CATCH (e, mask) - { - command (arg, from_tty); - } - exception_print (gdb_stderr, e); - if (e.reason < 0) - return 0; - return 1; -} - -int -catch_command_errors_const (catch_command_errors_const_ftype *command, - const char *arg, int from_tty, return_mask mask) -{ - volatile struct gdb_exception e; - - TRY_CATCH (e, mask) - { - command (arg, from_tty); - } - exception_print (gdb_stderr, e); - if (e.reason < 0) - return 0; - return 1; -} diff --git a/gdb/exceptions.h b/gdb/exceptions.h index b8dadc7..e5e1a49 100644 --- a/gdb/exceptions.h +++ b/gdb/exceptions.h @@ -255,17 +255,4 @@ extern int catch_exceptions_with_msg (struct ui_out *uiout, typedef int (catch_errors_ftype) (void *); extern int catch_errors (catch_errors_ftype *, void *, char *, return_mask); -/* Template to catch_errors() that wraps calls to command - functions. */ - -typedef void (catch_command_errors_ftype) (char *, int); -extern int catch_command_errors (catch_command_errors_ftype *func, - char *arg, int from_tty, return_mask); - -/* Like catch_command_errors, but works with const command and args. */ - -typedef void (catch_command_errors_const_ftype) (const char *, int); -extern int catch_command_errors_const (catch_command_errors_const_ftype *func, - const char *arg, int from_tty, return_mask); - #endif diff --git a/gdb/main.c b/gdb/main.c index 0d4d512..1d77bd3 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -337,6 +337,50 @@ captured_command_loop (void *data) return 1; } +/* Type of the command callback passed to catch_command_errors. */ + +typedef void (catch_command_errors_ftype) (char *, int); + +/* Wrap calls to commands run before the event loop is started. */ + +static int +catch_command_errors (catch_command_errors_ftype *command, + char *arg, int from_tty, return_mask mask) +{ + volatile struct gdb_exception e; + + TRY_CATCH (e, mask) + { + command (arg, from_tty); + } + exception_print (gdb_stderr, e); + if (e.reason < 0) + return 0; + return 1; +} + +/* Type of the command callback passed to catch_command_errors_const. */ + +typedef void (catch_command_errors_const_ftype) (const char *, int); + +/* Like catch_command_errors, but works with const command and args. */ + +static int +catch_command_errors_const (catch_command_errors_const_ftype *command, + const char *arg, int from_tty, return_mask mask) +{ + volatile struct gdb_exception e; + + TRY_CATCH (e, mask) + { + command (arg, from_tty); + } + exception_print (gdb_stderr, e); + if (e.reason < 0) + return 0; + return 1; +} + /* Arguments of --command option and its counterpart. */ typedef struct cmdarg { /* Type of this option. */ -- 2.7.4