aboutsummaryrefslogtreecommitdiff
path: root/gdb/windows-nat.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-10-10 16:45:50 +0100
committerPedro Alves <palves@redhat.com>2017-10-10 16:45:50 +0100
commitbf4692711232eb96cd840f96d88897a2746d8190 (patch)
tree4265f7df621c17be94bf23919a0d550ed4825b71 /gdb/windows-nat.c
parent6c699715f68be7d8c468e965fbefce997f7ed937 (diff)
downloadgdb-bf4692711232eb96cd840f96d88897a2746d8190.zip
gdb-bf4692711232eb96cd840f96d88897a2746d8190.tar.gz
gdb-bf4692711232eb96cd840f96d88897a2746d8190.tar.bz2
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<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.
Diffstat (limited to 'gdb/windows-nat.c')
-rw-r--r--gdb/windows-nat.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 98c32d8..58d7e11 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -756,8 +756,8 @@ get_image_name (HANDLE h, void *address, int unicode)
do_initial_windows_stuff and windows_add_all_dlls for more info
on how we handle DLL loading during that phase). */
-static int
-handle_load_dll (void *dummy)
+static void
+handle_load_dll ()
{
LOAD_DLL_DEBUG_INFO *event = &current_event.u.LoadDll;
char *dll_name;
@@ -770,7 +770,7 @@ handle_load_dll (void *dummy)
dll_name = get_image_name (current_process_handle,
event->lpImageName, event->fUnicode);
if (!dll_name)
- return 1;
+ return;
solib_end->next = windows_make_so (dll_name, event->lpBaseOfDll);
solib_end = solib_end->next;
@@ -779,8 +779,6 @@ handle_load_dll (void *dummy)
DEBUG_EVENTS (("gdb: Loading dll \"%s\" at %s.\n", solib_end->so_name,
host_address_to_string (li->load_addr)));
-
- return 1;
}
static void
@@ -800,8 +798,8 @@ windows_free_so (struct so_list *so)
do_initial_windows_stuff and windows_add_all_dlls for more info
on how we handle DLL loading during that phase). */
-static int
-handle_unload_dll (void *dummy)
+static void
+handle_unload_dll ()
{
LPVOID lpBaseOfDll = current_event.u.UnloadDll.lpBaseOfDll;
struct so_list *so;
@@ -820,7 +818,7 @@ handle_unload_dll (void *dummy)
DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name));
windows_free_so (sodel);
- return 1;
+ return;
}
}
@@ -833,8 +831,23 @@ handle_unload_dll (void *dummy)
32bit and 64bit worlds). */
complaint (&symfile_complaints, _("dll starting at %s not found."),
host_address_to_string (lpBaseOfDll));
+}
- return 0;
+/* Call FUNC wrapped in a TRY/CATCH that swallows all GDB
+ exceptions. */
+
+static void
+catch_errors (void (*func) ())
+{
+ TRY
+ {
+ func ();
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_print (gdb_stderr, ex);
+ }
+ END_CATCH
}
/* Clear list of loaded DLLs. */
@@ -1542,7 +1555,7 @@ get_windows_debug_event (struct target_ops *ops,
CloseHandle (current_event.u.LoadDll.hFile);
if (saw_create != 1 || ! windows_initialization_done)
break;
- catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
+ catch_errors (handle_load_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
thread_id = main_thread_id;
@@ -1555,7 +1568,7 @@ get_windows_debug_event (struct target_ops *ops,
"UNLOAD_DLL_DEBUG_EVENT"));
if (saw_create != 1 || ! windows_initialization_done)
break;
- catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
+ catch_errors (handle_unload_dll);
ourstatus->kind = TARGET_WAITKIND_LOADED;
ourstatus->value.integer = 0;
thread_id = main_thread_id;