mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-24 02:24:46 +08:00
bf46927112
If you want to use catch_errors with a function with parameters, then currently you have to manually write a "capture" struct wrapping the arguments and marshall/unmarshall that. https://sourceware.org/ml/gdb-patches/2017-09/msg00834.html proposed adjusting catch_errors to use gdb::function_view, which would allow passing lambdas with automatic captures. However, it seems like using TRY/CATCH directly instead ends up producing clearer and easier to debug code. This is what this commit does. Note that removing catch_errors exposes further cleanup opportunities around no longer having to follow catch_errors callback type, and also removes a few cleanups. I didn't do anything to save/restore current_uiout because I think that should be the responsibility of the code that changes current_uiout in the first place. (Another approach could be to make catch_errors a variadic template like: template<typename Function, typename... Args> int catch_errors (const char *errstring, return_mask mask, Function &&func, Args... args); and then with: extern void function_with_args (int, int); extern void function_with_no_args (); calls to the above functions would be wrapped like this: catch_errors ("some error happened", RETURN_MASK_ERROR, function_with_args, arg1, arg2); catch_errors ("some error happened", RETURN_MASK_ERROR, function_with_no_args); but I'm thinking that that doesn't improve much if at all either.) gdb/ChangeLog 2017-10-10 Pedro Alves <palves@redhat.com> Tom Tromey <tom@tromey.com> * breakpoint.c (breakpoint_cond_eval): Change return type to bool and reverse logic. (WP_DELETED, WP_VALUE_CHANGED, WP_VALUE_NOT_CHANGED, WP_IGNORE): No longer macros. Instead ... (enum wp_check_result): They're now values of this new enumeration. (watchpoint_check): Change return type to wp_check_result and parameter type to bpstat. (bpstat_check_watchpoint): Use TRY/CATCH instead of catch_errors. (bpstat_check_breakpoint_conditions): Use TRY/CATCH instead of catch_errors. Reverse logic of watchpoint_check call. (breakpoint_re_set_one): Now returns void and takes a breakpoint pointer as parameter. (breakpoint_re_set): Use TRY/CATCH instead of catch_errors. * common/common-exceptions.c (throw_exception_sjlj): Update comments to avoid mentioning catch_errors. * exceptions.c (catch_errors): Delete. * exceptions.h: Update comments to avoid mentioning catch_errors. (catch_errors_ftype, catch_errors): Delete. * infrun.c (normal_stop): Use TRY/CATCH instead of catch_errors. (hook_stop_stub): Delete. (restore_selected_frame): Change return type to void, and parameter type to const frame_id &. (restore_infcall_control_state): Use TRY/CATCH instead of catch_errors. * main.c (captured_command_loop): Return void and remove parameter. Remove references to catch_errors. (captured_main): Use TRY/CATCH instead of catch_errors. * objc-lang.c (objc_submethod_helper_data) (find_objc_msgcall_submethod_helper): Delete. (find_objc_msgcall_submethod): Use TRY/CATCH instead of catch_errors. * record-full.c (record_full_message): Return void. (record_full_message_args, record_full_message_wrapper): Delete. (record_full_message_wrapper_safe): Return bool and use TRY/CATCH instead of catch_errors. * solib-aix.c (solib_aix_open_symbol_file_object): Change parameter type to int. * solib-darwin.c (open_symbol_file_object): Ditto. * solib-dsbt.c (open_symbol_file_object): Ditto. * solib-frv.c (open_symbol_file_object): Ditto. * solib-svr4.c (open_symbol_file_object): Ditto. * solib-target.c (solib_target_open_symbol_file_object): Ditto. * solib.c (update_solib_list): Use TRY/CATCH instead of catch_errors. * solist.h (struct target_so_ops) <open_symbol_file_object>: Change type. * symmisc.c (struct print_symbol_args): Remove. (dump_symtab_1): Use TRY/CATCH instead of catch_errors. (print_symbol): Change type. * windows-nat.c (handle_load_dll, handle_unload_dll): Return void and remove parameters. (catch_errors): New. (get_windows_debug_event): Adjust. gdb/testsuite/ChangeLog: 2017-10-10 Pedro Alves <palves@redhat.com> * lib/selftest-support.exp (selftest_setup): Update for captured_command_loop's prototype change.
78 lines
3.4 KiB
C
78 lines
3.4 KiB
C
/* Exception (throw catch) mechanism, for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 1986-2017 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef EXCEPTIONS_H
|
|
#define EXCEPTIONS_H
|
|
|
|
#include "ui-out.h"
|
|
|
|
/* If E is an exception, print it's error message on the specified
|
|
stream. For _fprintf, prefix the message with PREFIX... */
|
|
extern void exception_print (struct ui_file *file, struct gdb_exception e);
|
|
extern void exception_fprintf (struct ui_file *file, struct gdb_exception e,
|
|
const char *prefix,
|
|
...) ATTRIBUTE_PRINTF (3, 4);
|
|
|
|
/* Call FUNC(UIOUT, FUNC_ARGS) but wrapped within an exception
|
|
handler. If an exception (enum return_reason) is thrown using
|
|
throw_exception() than all cleanups installed since
|
|
catch_exceptions() was entered are invoked, the (-ve) exception
|
|
value is then returned by catch_exceptions. If FUNC() returns
|
|
normally (with a positive or zero return value) then that value is
|
|
returned by catch_exceptions(). It is an internal_error() for
|
|
FUNC() to return a negative value.
|
|
|
|
For the period of the FUNC() call: UIOUT is installed as the output
|
|
builder; ERRSTRING is installed as the error/quit message; and a
|
|
new cleanup_chain is established. The old values are restored
|
|
before catch_exceptions() returns.
|
|
|
|
The variant catch_exceptions_with_msg() is the same as
|
|
catch_exceptions() but adds the ability to return an allocated
|
|
copy of the gdb error message. This is used when a silent error is
|
|
issued and the caller wants to manually issue the error message.
|
|
|
|
MASK specifies what to catch; it is normally set to RETURN_MASK_ALL
|
|
if the code which calls catch_exceptions is not 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_exceptions. Note that quit should return to the command line
|
|
fairly quickly, even if some further processing is being done.
|
|
|
|
FIXME; cagney/2001-08-13: The need to override the global UIOUT
|
|
builder variable should just go away. */
|
|
|
|
struct ui_out;
|
|
typedef int (catch_exceptions_ftype) (struct ui_out *ui_out, void *args);
|
|
extern int catch_exceptions (struct ui_out *uiout,
|
|
catch_exceptions_ftype *func, void *func_args,
|
|
return_mask mask);
|
|
typedef void (catch_exception_ftype) (struct ui_out *ui_out, void *args);
|
|
extern int catch_exceptions_with_msg (struct ui_out *uiout,
|
|
catch_exceptions_ftype *func,
|
|
void *func_args,
|
|
char **gdberrmsg,
|
|
return_mask mask);
|
|
|
|
/* Compare two exception objects for print equality. */
|
|
extern int exception_print_same (struct gdb_exception e1,
|
|
struct gdb_exception e2);
|
|
#endif
|