From d75e3c94b3e236ab6aadcad497264f32b48c921e Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Fri, 5 Nov 2004 20:32:04 +0000 Subject: [PATCH] 2004-11-05 Jeff Johnston * defs.h (fatal, vfatal): New function prototypes. * stack.c (backtrace_command_stub): Stub to call backtrace_command_1 via catch_errors. (backtrace_command): Change to call backtrace_command_stub via catch_errors instead of calling backtrace_command_1 directly. (backtrace_full_command): Ditto. * utils.c (error_stream_1): New static function. (verror): Change to call error_stream_1 instead of error_stream. (error_stream): Call error_stream_1 with RETURN_ERROR argument. (vfatal, fatal): New functions. --- gdb/ChangeLog | 13 +++++++++++++ gdb/defs.h | 4 ++++ gdb/stack.c | 28 ++++++++++++++++++++++++++-- gdb/utils.c | 39 +++++++++++++++++++++++++++++++++++---- 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 62312f3d239..cd8aac4bffa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2004-11-05 Jeff Johnston + + * defs.h (fatal, vfatal): New function prototypes. + * stack.c (backtrace_command_stub): Stub to call backtrace_command_1 + via catch_errors. + (backtrace_command): Change to call backtrace_command_stub via + catch_errors instead of calling backtrace_command_1 directly. + (backtrace_full_command): Ditto. + * utils.c (error_stream_1): New static function. + (verror): Change to call error_stream_1 instead of error_stream. + (error_stream): Call error_stream_1 with RETURN_ERROR argument. + (vfatal, fatal): New functions. + 2004-11-05 Andrew Cagney * stack.c (parse_frame_specification_1): Clear selected_frame_p diff --git a/gdb/defs.h b/gdb/defs.h index fd96665d44b..a652fce6007 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -911,6 +911,10 @@ extern char *error_last_message (void); /* Output arbitrary error message. */ extern void error_output_message (char *pre_print, char *msg); +extern NORETURN void vfatal (const char *fmt, va_list ap) ATTR_NORETURN; + +extern NORETURN void fatal (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2); + extern NORETURN void internal_verror (const char *file, int line, const char *, va_list ap) ATTR_NORETURN; diff --git a/gdb/stack.c b/gdb/stack.c index a04d8483b9f..c7cded067f4 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1218,6 +1218,22 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty) printf_filtered ("(More stack frames follow...)\n"); } +struct backtrace_command_args + { + char *count_exp; + int show_locals; + int from_tty; + }; + +/* Stub to call backtrace_command_1 by way of an error catcher. */ +static int +backtrace_command_stub (void *data) +{ + struct backtrace_command_args *args = (struct backtrace_command_args *)data; + backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty); + return 0; +} + static void backtrace_command (char *arg, int from_tty) { @@ -1225,6 +1241,7 @@ backtrace_command (char *arg, int from_tty) char **argv = (char **) NULL; int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0; char *argPtr = arg; + struct backtrace_command_args btargs; if (arg != (char *) NULL) { @@ -1274,7 +1291,10 @@ backtrace_command (char *arg, int from_tty) } } - backtrace_command_1 (argPtr, (argIndicatingFullTrace >= 0), from_tty); + btargs.count_exp = argPtr; + btargs.show_locals = (argIndicatingFullTrace >= 0); + btargs.from_tty = from_tty; + catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR); if (argIndicatingFullTrace >= 0 && totArgLen > 0) xfree (argPtr); @@ -1287,7 +1307,11 @@ static void backtrace_full_command (char *arg, int from_tty); static void backtrace_full_command (char *arg, int from_tty) { - backtrace_command_1 (arg, 1, from_tty); + struct backtrace_command_args btargs; + btargs.count_exp = arg; + btargs.show_locals = 1; + btargs.from_tty = from_tty; + catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR); } diff --git a/gdb/utils.c b/gdb/utils.c index e30808c38b4..0f4ea5a9109 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -104,6 +104,9 @@ static void prompt_for_continue (void); static void set_screen_size (void); static void set_width (void); +static NORETURN void error_stream_1 (struct ui_file *stream, + enum return_reason reason) ATTR_NORETURN; + /* Chain of cleanup actions established with make_cleanup, to be executed if an error happens. */ @@ -620,7 +623,7 @@ verror (const char *string, va_list args) struct ui_file *tmp_stream = mem_fileopen (); make_cleanup_ui_file_delete (tmp_stream); vfprintf_unfiltered (tmp_stream, string, args); - error_stream (tmp_stream); + error_stream_1 (tmp_stream, RETURN_ERROR); } NORETURN void @@ -632,6 +635,28 @@ error (const char *string, ...) va_end (args); } +/* Print an error message and quit. + The first argument STRING is the error message, used as a fprintf string, + and the remaining args are passed as arguments to it. */ + +NORETURN void +vfatal (const char *string, va_list args) +{ + struct ui_file *tmp_stream = mem_fileopen (); + make_cleanup_ui_file_delete (tmp_stream); + vfprintf_unfiltered (tmp_stream, string, args); + error_stream_1 (tmp_stream, RETURN_QUIT); +} + +NORETURN void +fatal (const char *string, ...) +{ + va_list args; + va_start (args, string); + vfatal (string, args); + va_end (args); +} + static void do_write (void *data, const char *buffer, long length_buffer) { @@ -670,8 +695,8 @@ error_output_message (char *pre_print, char *msg) fprintf_filtered (gdb_stderr, "\n"); } -NORETURN void -error_stream (struct ui_file *stream) +static NORETURN void +error_stream_1 (struct ui_file *stream, enum return_reason reason) { if (deprecated_error_begin_hook) deprecated_error_begin_hook (); @@ -690,7 +715,13 @@ error_stream (struct ui_file *stream) ui_file_put (stream, do_write, gdb_stderr); fprintf_filtered (gdb_stderr, "\n"); - throw_exception (RETURN_ERROR); + throw_exception (reason); +} + +NORETURN void +error_stream (struct ui_file *stream) +{ + error_stream_1 (stream, RETURN_ERROR); } /* Get the last error message issued by gdb */ -- 2.30.2