From 6c5b2ebeacc2538cf342cfd13c4c98ff018e6c9a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 4 Sep 2017 17:10:13 +0100 Subject: struct symtabs_and_lines -> std::vector This replaces "struct symtabs_and_lines" with std::vector in most cases. This removes a number of cleanups. In some cases, the sals objects do not own the sals they point at. Instead they point at some sal that lives on the stack. Typically something like this: struct symtab_and_line sal; struct symtabs_and_lines sals; // fill in sal sals.nelts = 1; sals.sals = &sal; // use sals Instead of switching those cases to std::vector too, such usages are replaced by gdb::array_view instead. This avoids introducing heap allocations. gdb/ChangeLog: 2017-09-04 Pedro Alves * ax-gdb.c (agent_command_1): Use range-for. * break-catch-throw.c (re_set_exception_catchpoint): Update. * breakpoint.c: Include "common/array-view.h". (init_breakpoint_sal, create_breakpoint_sal): Change sals parameter from struct symtabs_and_lines to array_view. Adjust. Use range-for. Update. (breakpoint_sals_to_pc): Change sals parameter from struct symtabs_and_lines to std::vector reference. (check_fast_tracepoint_sals): Change sals parameter from struct symtabs_and_lines to std::array_view. Use range-for. (decode_static_tracepoint_spec): Return a std::vector instead of symtabs_and_lines. Update. (create_breakpoint): Update. (break_range_command, until_break_command, clear_command): Update. (base_breakpoint_decode_location, bkpt_decode_location) (bkpt_probe_create_sals_from_location) (bkpt_probe_decode_location, tracepoint_decode_location) (tracepoint_probe_decode_location) (strace_marker_create_sals_from_location): Return a std::vector instead of symtabs_and_lines. (strace_marker_create_breakpoints_sal): Update. (strace_marker_decode_location): Return a std::vector instead of symtabs_and_lines. Update. (update_breakpoint_locations): Change struct symtabs_and_lines parameters to gdb::array_view. Adjust. (location_to_sals): Return a std::vector instead of symtabs_and_lines. Update. (breakpoint_re_set_default): Use std::vector instead of struct symtabs_and_lines. (decode_location_default): Return a std::vector instead of symtabs_and_lines. Update. * breakpoint.h: Include "common/array-view.h". (struct breakpoint_ops) : Now returns a std::vector instead of returning a symtabs_and_lines via output parameter. (update_breakpoint_locations): Change sals parameters to use gdb::array_view. * cli/cli-cmds.c (edit_command, list_command): Update to use std::vector and gdb::array_view. (ambiguous_line_spec): Adjust to use gdb::array_view and range-for. (compare_symtabs): Rename to ... (cmp_symtabs): ... this. Change parameters to symtab_and_line const reference and adjust. (filter_sals): Rewrite using std::vector and standard algorithms. * elfread.c (elf_gnu_ifunc_resolver_return_stop): Simplify. (jump_command): Update to use std::vector. * linespec.c (struct linespec_state) : Update comment. (add_sal_to_sals_basic): Delete. (add_sal_to_sals, filter_results, convert_results_to_lsals) (decode_line_2, create_sals_line_offset) (convert_address_location_to_sals, convert_linespec_to_sals) (convert_explicit_location_to_sals, parse_linespec) (event_location_to_sals, decode_line_full, decode_line_1) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc) (decode_digits_list_mode, decode_digits_ordinary, minsym_found) (linespec_result::~linespec_result): Adjust to use std::vector instead of symtabs_and_lines. * linespec.h (linespec_sals::sals): Now a std::vector. (struct linespec_result): Use std::vector, bool, and in-class initialization. (decode_line_1, decode_line_with_current_source) (decode_line_with_last_displayed): Return std::vector. * macrocmd.c (info_macros_command): Use std::vector. * mi/mi-main.c (mi_cmd_trace_find): Use std::vector. * probe.c (parse_probes_in_pspace, parse_probes): Adjust to use std::vector. * probe.h (parse_probes): Return a std::vector. * python/python.c (gdbpy_decode_line): Use std::vector and gdb::array_view. * source.c (select_source_symtab, line_info): Use std::vector. * stack.c (func_command): Use std::vector. * symtab.h (struct symtabs_and_lines): Delete. * tracepoint.c (tfind_line_command, scope_info): Use std::vector. --- gdb/python/python.c | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'gdb/python/python.c') diff --git a/gdb/python/python.c b/gdb/python/python.c index c53e10f..f40fe89 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -647,10 +647,6 @@ gdbpy_solib_name (PyObject *self, PyObject *args) static PyObject * gdbpy_decode_line (PyObject *self, PyObject *args) { - struct gdb_exception except = exception_none; - struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to - appease gcc. */ - struct symtab_and_line sal; char *arg = NULL; gdbpy_ref<> result; gdbpy_ref<> unparsed; @@ -659,54 +655,43 @@ gdbpy_decode_line (PyObject *self, PyObject *args) if (! PyArg_ParseTuple (args, "|s", &arg)) return NULL; - sals.sals = NULL; - if (arg != NULL) location = string_to_event_location_basic (&arg, python_language); + std::vector decoded_sals; + symtab_and_line def_sal; + gdb::array_view sals; TRY { if (location != NULL) - sals = decode_line_1 (location.get (), 0, NULL, NULL, 0); + { + decoded_sals = decode_line_1 (location.get (), 0, NULL, NULL, 0); + sals = decoded_sals; + } else { set_default_source_symtab_and_line (); - sal = get_current_source_symtab_and_line (); - sals.sals = &sal; - sals.nelts = 1; + def_sal = get_current_source_symtab_and_line (); + sals = def_sal; } } CATCH (ex, RETURN_MASK_ALL) { - except = ex; - } - END_CATCH - - /* Ensure that the sals data is freed, when needed. */ - gdb::unique_xmalloc_ptr free_sals; - if (sals.sals != NULL && sals.sals != &sal) - free_sals.reset (sals.sals); - - if (except.reason < 0) - { /* We know this will always throw. */ - gdbpy_convert_exception (except); + gdbpy_convert_exception (ex); return NULL; } + END_CATCH - if (sals.nelts) + if (!sals.empty ()) { - int i; - - result.reset (PyTuple_New (sals.nelts)); + result.reset (PyTuple_New (sals.size ())); if (result == NULL) return NULL; - for (i = 0; i < sals.nelts; ++i) + for (size_t i = 0; i < sals.size (); ++i) { - PyObject *obj; - - obj = symtab_and_line_to_sal_object (sals.sals[i]); - if (! obj) + PyObject *obj = symtab_and_line_to_sal_object (sals[i]); + if (obj == NULL) return NULL; PyTuple_SetItem (result.get (), i, obj); -- cgit v1.1