From 94aeb44b001ab2d632806242a3bacb0a879abe15 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 24 Apr 2019 06:50:06 -0600 Subject: Make exception handling more efficient This makes exception handling more efficient in a few spots, through the use of const- and rvalue-references. I wrote this patch by commenting out the gdb_exception copy constructor and then examining the resulting error messages one by one, introducing the use of std::move where appropriate. gdb/ChangeLog 2019-04-25 Tom Tromey * xml-support.c (struct gdb_xml_parser) : Take an rvalue reference. (gdb_xml_start_element_wrapper, gdb_xml_end_element_wrapper) (gdb_xml_parser::parse): Use std::move. * python/python-internal.h (gdbpy_convert_exception): Take a const reference. * python/py-value.c (valpy_getitem, valpy_nonzero): Use std::move. * python/py-utils.c (gdbpy_convert_exception): Take a const reference. * python/py-inferior.c (infpy_write_memory, infpy_search_memory): Use std::move. * python/py-breakpoint.c (bppy_set_condition, bppy_set_commands): Use std::move. * mi/mi-main.c (mi_print_exception): Take a const reference. * main.c (handle_command_errors): Take a const reference. * linespec.c (parse_linespec): Use std::move. * infcall.c (run_inferior_call): Use std::move. (call_function_by_hand_dummy): Use std::move. * exec.c (try_open_exec_file): Use std::move. * exceptions.h (exception_print, exception_fprintf) (exception_print_same): Update. * exceptions.c (print_exception, exception_print) (exception_fprintf, exception_print_same): Change parameters to const reference. * event-top.c (gdb_rl_callback_read_char_wrapper): Update. * common/new-op.c: Use std::move. * common/common-exceptions.h (struct gdb_exception): Add move constructor. (struct gdb_exception_error, struct gdb_exception_quit, struct gdb_quit_bad_alloc): Change constructor to move constructor. (throw_exception): Change parameter to rvalue reference. * common/common-exceptions.c (throw_exception): Take rvalue reference. * cli/cli-interp.c (safe_execute_command): Use std::move. * breakpoint.c (insert_bp_location, location_to_sals): Use std::move. --- gdb/breakpoint.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'gdb/breakpoint.c') diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c74fc61..f6d2f36 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2545,9 +2545,9 @@ insert_bp_location (struct bp_location *bl, if (val) bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } - catch (const gdb_exception &e) + catch (gdb_exception &e) { - bp_excpt = e; + bp_excpt = std::move (e); } } else @@ -2584,9 +2584,9 @@ insert_bp_location (struct bp_location *bl, bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } - catch (const gdb_exception &e) + catch (gdb_exception &e) { - bp_excpt = e; + bp_excpt = std::move (e); } if (bp_excpt.reason != 0) @@ -2608,9 +2608,9 @@ insert_bp_location (struct bp_location *bl, if (val) bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } - catch (const gdb_exception &e) + catch (gdb_exception &e) { - bp_excpt = e; + bp_excpt = std::move (e); } } else @@ -13603,12 +13603,10 @@ location_to_sals (struct breakpoint *b, struct event_location *location, { sals = b->ops->decode_location (b, location, search_pspace); } - catch (const gdb_exception_error &e) + catch (gdb_exception_error &e) { int not_found_and_ok = 0; - exception = e; - /* For pending breakpoints, it's expected that parsing will fail until the right shared library is loaded. User has already told to create pending breakpoints and don't need @@ -13637,6 +13635,8 @@ location_to_sals (struct breakpoint *b, struct event_location *location, b->enable_state = bp_disabled; throw; } + + exception = std::move (e); } if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) -- cgit v1.1