From bf4692711232eb96cd840f96d88897a2746d8190 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 10 Oct 2017 16:45:50 +0100 Subject: Eliminate catch_errors 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 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 Tom Tromey * 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) : 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 * lib/selftest-support.exp (selftest_setup): Update for captured_command_loop's prototype change. --- gdb/symmisc.c | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'gdb/symmisc.c') diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 86422e7..ed2e8d2 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -54,15 +54,8 @@ FILE *std_err; static int block_depth (struct block *); -struct print_symbol_args - { - struct gdbarch *gdbarch; - struct symbol *symbol; - int depth; - struct ui_file *outfile; - }; - -static int print_symbol (void *); +static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, + int depth, ui_file *outfile); void @@ -357,14 +350,16 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) block, not any blocks from included symtabs. */ ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym) { - struct print_symbol_args s; - - s.gdbarch = gdbarch; - s.symbol = sym; - s.depth = depth + 1; - s.outfile = outfile; - catch_errors (print_symbol, &s, "Error printing symbol:\n", - RETURN_MASK_ERROR); + TRY + { + print_symbol (gdbarch, sym, depth + 1, outfile); + } + CATCH (ex, RETURN_MASK_ERROR) + { + exception_fprintf (gdb_stderr, ex, + "Error printing symbol:\n"); + } + END_CATCH } } fprintf_filtered (outfile, "\n"); @@ -515,18 +510,12 @@ maintenance_print_symbols (const char *args, int from_tty) } } -/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how - far to indent. ARGS is really a struct print_symbol_args *, but is - declared as char * to get it past catch_errors. Returns 0 for error, - 1 for success. */ +/* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */ -static int -print_symbol (void *args) +static void +print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, + int depth, ui_file *outfile) { - struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch; - struct symbol *symbol = ((struct print_symbol_args *) args)->symbol; - int depth = ((struct print_symbol_args *) args)->depth; - struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile; struct obj_section *section; if (SYMBOL_OBJFILE_OWNED (symbol)) @@ -546,8 +535,9 @@ print_symbol (void *args) section->the_bfd_section)); else fprintf_filtered (outfile, "\n"); - return 1; + return; } + if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) { if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol))) @@ -694,7 +684,6 @@ print_symbol (void *args) } } fprintf_filtered (outfile, "\n"); - return 1; } static void -- cgit v1.1