summaryrefslogtreecommitdiff
path: root/gdb/source.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-09-04 17:10:13 +0100
committerPedro Alves <palves@redhat.com>2017-09-04 17:11:15 +0100
commit6c5b2ebeacc2538cf342cfd13c4c98ff018e6c9a (patch)
treebaf0e08108974014d60f12733b3349e803dabe70 /gdb/source.c
parent7c44b49cb63662b76c6301fdc8e022d7aca655bf (diff)
struct symtabs_and_lines -> std::vector<symtab_and_line>
This replaces "struct symtabs_and_lines" with std::vector<symtab_and_line> 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<symtab_and_line> instead. This avoids introducing heap allocations. gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * 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<symtab_and_line>. 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) <decode_location>: 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) <canonical_names>: 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.
Diffstat (limited to 'gdb/source.c')
-rw-r--r--gdb/source.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/gdb/source.c b/gdb/source.c
index 55540e6702..b63db8a725 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -258,8 +258,6 @@ clear_current_source_symtab_and_line (void)
void
select_source_symtab (struct symtab *s)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
struct objfile *ofp;
struct compunit_symtab *cu;
@@ -278,10 +276,10 @@ select_source_symtab (struct symtab *s)
if one exists. */
if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0).symbol)
{
- sals = decode_line_with_current_source (main_name (),
- DECODE_LINE_FUNFIRSTLINE);
- sal = sals.sals[0];
- xfree (sals.sals);
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (main_name (),
+ DECODE_LINE_FUNFIRSTLINE);
+ const symtab_and_line &sal = sals[0];
current_source_pspace = sal.pspace;
current_source_symtab = sal.symtab;
current_source_line = std::max (sal.line - (lines_to_list - 1), 1);
@@ -1492,41 +1490,37 @@ print_source_lines (struct symtab *s, int line, int stopline,
static void
info_line_command (char *arg, int from_tty)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
CORE_ADDR start_pc, end_pc;
- int i;
- struct cleanup *cleanups;
- init_sal (&sal); /* initialize to zeroes */
+ std::vector<symtab_and_line> decoded_sals;
+ symtab_and_line curr_sal;
+ gdb::array_view<symtab_and_line> sals;
if (arg == 0)
{
- sal.symtab = current_source_symtab;
- sal.pspace = current_program_space;
+ init_sal (&curr_sal); /* initialize to zeroes */
+ curr_sal.symtab = current_source_symtab;
+ curr_sal.pspace = current_program_space;
if (last_line_listed != 0)
- sal.line = last_line_listed;
+ curr_sal.line = last_line_listed;
else
- sal.line = current_source_line;
+ curr_sal.line = current_source_line;
- sals.nelts = 1;
- sals.sals = XNEW (struct symtab_and_line);
- sals.sals[0] = sal;
+ sals = curr_sal;
}
else
{
- sals = decode_line_with_last_displayed (arg, DECODE_LINE_LIST_MODE);
+ decoded_sals = decode_line_with_last_displayed (arg,
+ DECODE_LINE_LIST_MODE);
+ sals = decoded_sals;
dont_repeat ();
}
- cleanups = make_cleanup (xfree, sals.sals);
-
/* C++ More than one line may have been specified, as when the user
specifies an overloaded function name. Print info on them all. */
- for (i = 0; i < sals.nelts; i++)
+ for (const auto &sal : sals)
{
- sal = sals.sals[i];
if (sal.pspace != current_program_space)
continue;
@@ -1587,7 +1581,7 @@ info_line_command (char *arg, int from_tty)
/* If this is the only line, show the source code. If it could
not find the file, don't do anything special. */
- if (annotation_level && sals.nelts == 1)
+ if (annotation_level && sals.size () == 1)
identify_source_line (sal.symtab, sal.line, 0, start_pc);
}
else
@@ -1597,7 +1591,6 @@ info_line_command (char *arg, int from_tty)
printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
sal.line, symtab_to_filename_for_display (sal.symtab));
}
- do_cleanups (cleanups);
}
/* Commands to search the source file for a regexp. */