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 <tromey@adacore.com> * xml-support.c (struct gdb_xml_parser) <set_error>: 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.
This commit is contained in:
parent
680d7fd5fc
commit
94aeb44b00
20 changed files with 110 additions and 63 deletions
|
@ -469,9 +469,9 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
|
|||
{
|
||||
set_breakpoint_condition (self_bp->bp, exp, 0);
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
||||
|
@ -540,9 +540,9 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
|
|||
counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
|
||||
breakpoint_set_commands (self_bp->bp, std::move (lines));
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
||||
|
|
|
@ -574,9 +574,9 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||
{
|
||||
write_memory_with_notification (addr, buffer, length);
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
|
@ -728,9 +728,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||
buffer, pattern_size,
|
||||
&found_addr);
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
|
|
|
@ -229,7 +229,7 @@ gdbpy_err_fetch::type_to_string () const
|
|||
This sets the Python error indicator. */
|
||||
|
||||
void
|
||||
gdbpy_convert_exception (struct gdb_exception exception)
|
||||
gdbpy_convert_exception (const struct gdb_exception &exception)
|
||||
{
|
||||
PyObject *exc_class;
|
||||
|
||||
|
|
|
@ -1031,9 +1031,9 @@ valpy_getitem (PyObject *self, PyObject *key)
|
|||
if (res_val)
|
||||
result = value_to_value_object (res_val);
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
|
@ -1498,9 +1498,9 @@ valpy_nonzero (PyObject *self)
|
|||
/* All other values are True. */
|
||||
nonzero = 1;
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
catch (gdb_exception &ex)
|
||||
{
|
||||
except = ex;
|
||||
except = std::move (ex);
|
||||
}
|
||||
|
||||
/* This is not documented in the Python documentation, but if this
|
||||
|
|
|
@ -729,7 +729,7 @@ extern PyObject *gdbpy_gdb_error;
|
|||
extern PyObject *gdbpy_gdb_memory_error;
|
||||
extern PyObject *gdbpy_gdberror_exc;
|
||||
|
||||
extern void gdbpy_convert_exception (struct gdb_exception)
|
||||
extern void gdbpy_convert_exception (const struct gdb_exception &)
|
||||
CPYCHECKER_SETS_EXCEPTION;
|
||||
|
||||
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue