+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.
+
2017-09-04 Pedro Alves <palves@redhat.com>
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
if (check_for_argument (&exp, "-at", sizeof ("-at") - 1))
{
struct linespec_result canonical;
- int ix;
- struct linespec_sals *iter;
exp = skip_spaces (exp);
exp++;
exp = skip_spaces (exp);
}
- for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
- {
- int i;
-
- for (i = 0; i < iter->sals.nelts; i++)
- agent_eval_command_one (exp, eval, iter->sals.sals[i].pc);
- }
+ for (const auto &lsal : canonical.lsals)
+ for (const auto &sal : lsal.sals)
+ agent_eval_command_one (exp, eval, sal.pc);
}
else
agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ()));
static void
re_set_exception_catchpoint (struct breakpoint *self)
{
- struct symtabs_and_lines sals = {0};
- struct symtabs_and_lines sals_end = {0};
- struct cleanup *cleanup;
+ std::vector<symtab_and_line> sals;
enum exception_event_kind kind = classify_exception_breakpoint (self);
struct program_space *filter_pspace = current_program_space;
explicit_loc.function_name
= ASTRDUP (exception_functions[kind].function);
event_location_up location = new_explicit_location (&explicit_loc);
- self->ops->decode_location (self, location.get (), filter_pspace,
- &sals);
+ sals = self->ops->decode_location (self, location.get (),
+ filter_pspace);
}
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
- cleanup = make_cleanup (xfree, sals.sals);
- update_breakpoint_locations (self, filter_pspace, sals, sals_end);
- do_cleanups (cleanup);
+ update_breakpoint_locations (self, filter_pspace, sals, {});
}
static enum print_stop_action
#include "extension.h"
#include <algorithm>
#include "progspace-and-thread.h"
+#include "common/array-view.h"
/* Enums for exception-handling support. */
enum exception_event_kind
const struct breakpoint_ops *,
int, int, int, unsigned);
-static void decode_location_default (struct breakpoint *b,
- const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals);
+static std::vector<symtab_and_line> decode_location_default
+ (struct breakpoint *b, const struct event_location *location,
+ struct program_space *search_pspace);
static void clear_command (char *, int);
static void
init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
- struct symtabs_and_lines sals,
+ gdb::array_view<const symtab_and_line> sals,
event_location_up &&location,
gdb::unique_xmalloc_ptr<char> filter,
gdb::unique_xmalloc_ptr<char> cond_string,
error (_("Hardware breakpoints used exceeds limit."));
}
- gdb_assert (sals.nelts > 0);
+ gdb_assert (!sals.empty ());
- for (i = 0; i < sals.nelts; ++i)
+ for (const auto &sal : sals)
{
- struct symtab_and_line sal = sals.sals[i];
struct bp_location *loc;
if (from_tty)
sal.pspace, sal.pc, sal.section, thread);
}
- if (i == 0)
+ if (&sal == &sals[0])
{
init_raw_breakpoint (b, gdbarch, sal, type, ops);
b->thread = thread;
static void
create_breakpoint_sal (struct gdbarch *gdbarch,
- struct symtabs_and_lines sals,
+ gdb::array_view<const symtab_and_line> sals,
event_location_up &&location,
gdb::unique_xmalloc_ptr<char> filter,
gdb::unique_xmalloc_ptr<char> cond_string,
const struct breakpoint_ops *ops, int from_tty,
int enabled, int internal, unsigned flags)
{
- int i;
- struct linespec_sals *lsal;
-
if (canonical->pre_expanded)
- gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
+ gdb_assert (canonical->lsals.size () == 1);
- for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
+ for (const auto &lsal : canonical->lsals)
{
/* Note that 'location' can be NULL in the case of a plain
'break', without arguments. */
= (canonical->location != NULL
? copy_event_location (canonical->location.get ()) : NULL);
gdb::unique_xmalloc_ptr<char> filter_string
- (lsal->canonical != NULL ? xstrdup (lsal->canonical) : NULL);
+ (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
- create_breakpoint_sal (gdbarch, lsal->sals,
+ create_breakpoint_sal (gdbarch, lsal.sals,
std::move (location),
std::move (filter_string),
std::move (cond_string),
breakpoint address. */
if (last_displayed_sal_is_valid ())
{
- struct linespec_sals lsal;
struct symtab_and_line sal;
CORE_ADDR pc;
init_sal (&sal); /* Initialize to zeroes. */
- lsal.sals.sals = XNEW (struct symtab_and_line);
/* Set sal's pspace, pc, symtab, and line to the values
corresponding to the last call to print_frame_info.
sal.pc = pc;
sal.explicit_pc = 1;
- lsal.sals.sals[0] = sal;
- lsal.sals.nelts = 1;
+ struct linespec_sals lsal;
+ lsal.sals = {sal};
lsal.canonical = NULL;
- VEC_safe_push (linespec_sals, canonical->sals, &lsal);
+ canonical->lsals.push_back (std::move (lsal));
return;
}
else
inserted as a breakpoint. If it can't throw an error. */
static void
-breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
+breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
{
- int i;
-
- for (i = 0; i < sals->nelts; i++)
- resolve_sal_pc (&sals->sals[i]);
+ for (auto &sal : sals)
+ resolve_sal_pc (&sal);
}
/* Fast tracepoints may have restrictions on valid locations. For
static void
check_fast_tracepoint_sals (struct gdbarch *gdbarch,
- struct symtabs_and_lines *sals)
+ gdb::array_view<const symtab_and_line> sals)
{
- int i, rslt;
- struct symtab_and_line *sal;
+ int rslt;
char *msg;
struct cleanup *old_chain;
- for (i = 0; i < sals->nelts; i++)
+ for (const auto &sal : sals)
{
struct gdbarch *sarch;
- sal = &sals->sals[i];
-
- sarch = get_sal_arch (*sal);
+ sarch = get_sal_arch (sal);
/* We fall back to GDBARCH if there is no architecture
associated with SAL. */
if (sarch == NULL)
sarch = gdbarch;
- rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg);
+ rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg);
old_chain = make_cleanup (xfree, msg);
if (!rslt)
error (_("May not have a fast tracepoint at %s%s"),
- paddress (sarch, sal->pc), (msg ? msg : ""));
+ paddress (sarch, sal.pc), (msg ? msg : ""));
do_cleanups (old_chain);
}
/* Decode a static tracepoint marker spec. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
decode_static_tracepoint_spec (const char **arg_p)
{
VEC(static_tracepoint_marker_p) *markers = NULL;
- struct symtabs_and_lines sals;
struct cleanup *old_chain;
const char *p = &(*arg_p)[3];
const char *endp;
if (VEC_empty(static_tracepoint_marker_p, markers))
error (_("No known static tracepoint marker named %s"), marker_str);
- sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
- sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
+ std::vector<symtab_and_line> sals;
+ sals.reserve (VEC_length(static_tracepoint_marker_p, markers));
- for (i = 0; i < sals.nelts; i++)
+ for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++)
{
struct static_tracepoint_marker *marker;
marker = VEC_index (static_tracepoint_marker_p, markers, i);
- init_sal (&sals.sals[i]);
+ symtab_and_line sal;
+ init_sal (&sal);
- sals.sals[i] = find_pc_line (marker->address, 0);
- sals.sals[i].pc = marker->address;
+ sal = find_pc_line (marker->address, 0);
+ sal.pc = marker->address;
+ sals.push_back (sal);
release_static_tracepoint_marker (marker);
}
}
END_CATCH
- if (!pending && VEC_empty (linespec_sals, canonical.sals))
+ if (!pending && canonical.lsals.empty ())
return 0;
/* ----------------------------- SNIP -----------------------------
are ok for the target. */
if (!pending)
{
- int ix;
- struct linespec_sals *iter;
-
- for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
- breakpoint_sals_to_pc (&iter->sals);
+ for (auto &lsal : canonical.lsals)
+ breakpoint_sals_to_pc (lsal.sals);
}
/* Fast tracepoints may have additional restrictions on location. */
if (!pending && type_wanted == bp_fast_tracepoint)
{
- int ix;
- struct linespec_sals *iter;
-
- for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
- check_fast_tracepoint_sals (gdbarch, &iter->sals);
+ for (const auto &lsal : canonical.lsals)
+ check_fast_tracepoint_sals (gdbarch, lsal.sals);
}
/* Verify that condition can be parsed, before setting any
{
char *rest;
char *cond;
- struct linespec_sals *lsal;
- lsal = VEC_index (linespec_sals, canonical.sals, 0);
+ const linespec_sals &lsal = canonical.lsals[0];
/* Here we only parse 'arg' to separate condition
from thread number, so parsing in context of first
sal is OK. When setting the breakpoint we'll
re-parse it in context of each sal. */
- find_condition_and_thread (extra_string, lsal->sals.sals[0].pc,
+ find_condition_and_thread (extra_string, lsal.sals[0].pc,
&cond, &thread, &task, &rest);
cond_string_copy.reset (cond);
extra_string_copy.reset (rest);
install_breakpoint (internal, std::move (b), 0);
}
- if (VEC_length (linespec_sals, canonical.sals) > 1)
+ if (canonical.lsals.size () > 1)
{
warning (_("Multiple breakpoints were set.\nUse the "
"\"delete\" command to delete unwanted breakpoints."));
int bp_count, can_use_bp, length;
CORE_ADDR end;
struct breakpoint *b;
- struct symtab_and_line sal_start, sal_end;
struct cleanup *cleanup_bkpt;
- struct linespec_sals *lsal_start, *lsal_end;
/* We don't support software ranged breakpoints. */
if (target_ranged_break_num_registers () < 0)
if (arg[0] != ',')
error (_("Too few arguments."));
- else if (VEC_empty (linespec_sals, canonical_start.sals))
+ else if (canonical_start.lsals.empty ())
error (_("Could not find location of the beginning of the range."));
- lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
+ const linespec_sals &lsal_start = canonical_start.lsals[0];
- if (VEC_length (linespec_sals, canonical_start.sals) > 1
- || lsal_start->sals.nelts != 1)
+ if (canonical_start.lsals.size () > 1
+ || lsal_start.sals.size () != 1)
error (_("Cannot create a ranged breakpoint with multiple locations."));
- sal_start = lsal_start->sals.sals[0];
+ const symtab_and_line &sal_start = lsal_start.sals[0];
addr_string_start = savestring (arg_start, arg - arg_start);
cleanup_bkpt = make_cleanup (xfree, addr_string_start);
sal_start.symtab, sal_start.line,
&canonical_end, NULL, NULL);
- if (VEC_empty (linespec_sals, canonical_end.sals))
+ if (canonical_end.lsals.empty ())
error (_("Could not find location of the end of the range."));
- lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
- if (VEC_length (linespec_sals, canonical_end.sals) > 1
- || lsal_end->sals.nelts != 1)
+ const linespec_sals &lsal_end = canonical_end.lsals[0];
+ if (canonical_end.lsals.size () > 1
+ || lsal_end.sals.size () != 1)
error (_("Cannot create a ranged breakpoint with multiple locations."));
- sal_end = lsal_end->sals.sals[0];
+ const symtab_and_line &sal_end = lsal_end.sals[0];
end = find_breakpoint_range_end (sal_end);
if (sal_start.pc > end)
void
until_break_command (char *arg, int from_tty, int anywhere)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
struct frame_info *frame;
struct gdbarch *frame_gdbarch;
struct frame_id stack_frame_id;
event_location_up location = string_to_event_location (&arg, current_language);
- if (last_displayed_sal_is_valid ())
- sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
- get_last_displayed_symtab (),
- get_last_displayed_line ());
- else
- sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
- NULL, (struct symtab *) NULL, 0);
+ std::vector<symtab_and_line> sals
+ = (last_displayed_sal_is_valid ()
+ ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
+ get_last_displayed_symtab (),
+ get_last_displayed_line ())
+ : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
+ NULL, (struct symtab *) NULL, 0));
- if (sals.nelts != 1)
+ if (sals.size () != 1)
error (_("Couldn't get information on specified line."));
- sal = sals.sals[0];
- xfree (sals.sals); /* malloc'd, so freed. */
+ symtab_and_line &sal = sals[0];
if (*arg)
error (_("Junk at end of arguments."));
VEC(breakpoint_p) *found = 0;
int ix;
int default_match;
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
int i;
struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
+ std::vector<symtab_and_line> decoded_sals;
+ symtab_and_line last_sal;
+ gdb::array_view<symtab_and_line> sals;
if (arg)
{
- sals = decode_line_with_current_source (arg,
- (DECODE_LINE_FUNFIRSTLINE
- | DECODE_LINE_LIST_MODE));
- make_cleanup (xfree, sals.sals);
+ decoded_sals
+ = decode_line_with_current_source (arg,
+ (DECODE_LINE_FUNFIRSTLINE
+ | DECODE_LINE_LIST_MODE));
default_match = 0;
+ sals = decoded_sals;
}
else
{
- sals.sals = XNEW (struct symtab_and_line);
- make_cleanup (xfree, sals.sals);
- init_sal (&sal); /* Initialize to zeroes. */
+ init_sal (&last_sal); /* Initialize to zeroes. */
/* Set sal's line, symtab, pc, and pspace to the values
corresponding to the last call to print_frame_info. If the
codepoint is not valid, this will set all the fields to 0. */
- get_last_displayed_sal (&sal);
- if (sal.symtab == 0)
+ get_last_displayed_sal (&last_sal);
+ if (last_sal.symtab == 0)
error (_("No source file specified."));
- sals.sals[0] = sal;
- sals.nelts = 1;
-
default_match = 1;
+ sals = last_sal;
}
/* We don't call resolve_sal_pc here. That's not as bad as it
found = NULL;
make_cleanup (VEC_cleanup (breakpoint_p), &found);
- for (i = 0; i < sals.nelts; i++)
+ for (const auto &sal : sals)
{
const char *sal_fullname;
0 0 line
1 0 <can't happen> */
- sal = sals.sals[i];
sal_fullname = (sal.symtab == NULL
? NULL : symtab_to_fullname (sal.symtab));
internal_error_pure_virtual_called ();
}
-static void
+static std::vector<symtab_and_line>
base_breakpoint_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
internal_error_pure_virtual_called ();
}
enabled, internal, flags);
}
-static void
+static std::vector<symtab_and_line>
bkpt_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
- decode_location_default (b, location, search_pspace, sals);
+ return decode_location_default (b, location, search_pspace);
}
/* Virtual table for internal breakpoints. */
lsal.sals = parse_probes (location, NULL, canonical);
lsal.canonical
= xstrdup (event_location_to_string (canonical->location.get ()));
- VEC_safe_push (linespec_sals, canonical->sals, &lsal);
+ canonical->lsals.push_back (std::move (lsal));
}
-static void
+static std::vector<symtab_and_line>
bkpt_probe_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
- *sals = parse_probes (location, search_pspace, NULL);
- if (!sals->sals)
+ std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
+ if (sals.empty ())
error (_("probe not found"));
+ return sals;
}
/* The breakpoint_ops structure to be used in tracepoints. */
enabled, internal, flags);
}
-static void
+static std::vector<symtab_and_line>
tracepoint_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
- decode_location_default (b, location, search_pspace, sals);
+ return decode_location_default (b, location, search_pspace);
}
struct breakpoint_ops tracepoint_breakpoint_ops;
bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
}
-static void
+static std::vector<symtab_and_line>
tracepoint_probe_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
/* We use the same method for breakpoint on probes. */
- bkpt_probe_decode_location (b, location, search_pspace, sals);
+ return bkpt_probe_decode_location (b, location, search_pspace);
}
static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
lsal.canonical
= xstrdup (event_location_to_string (canonical->location.get ()));
- VEC_safe_push (linespec_sals, canonical->sals, &lsal);
+ canonical->lsals.push_back (std::move (lsal));
}
static void
int from_tty, int enabled,
int internal, unsigned flags)
{
- int i;
- struct linespec_sals *lsal = VEC_index (linespec_sals,
- canonical->sals, 0);
+ const linespec_sals &lsal = canonical->lsals[0];
/* If the user is creating a static tracepoint by marker id
(strace -m MARKER_ID), then store the sals index, so that
expand multiple locations for each sal, given than SALS
already should contain all sals for MARKER_ID. */
- for (i = 0; i < lsal->sals.nelts; ++i)
+ for (size_t i = 0; i < lsal.sals.size (); i++)
{
- struct symtabs_and_lines expanded;
- event_location_up location;
-
- expanded.nelts = 1;
- expanded.sals = &lsal->sals.sals[i];
-
- location = copy_event_location (canonical->location.get ());
+ event_location_up location
+ = copy_event_location (canonical->location.get ());
std::unique_ptr<tracepoint> tp (new tracepoint ());
- init_breakpoint_sal (tp.get (), gdbarch, expanded,
+ init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i],
std::move (location), NULL,
std::move (cond_string),
std::move (extra_string),
}
}
-static void
+static std::vector<symtab_and_line>
strace_marker_decode_location (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
struct tracepoint *tp = (struct tracepoint *) b;
const char *s = get_linespec_location (location);
- *sals = decode_static_tracepoint_spec (&s);
- if (sals->nelts > tp->static_trace_marker_id_idx)
+ std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
+ if (sals.size () > tp->static_trace_marker_id_idx)
{
- sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
- sals->nelts = 1;
+ sals[0] = sals[tp->static_trace_marker_id_idx];
+ sals.resize (1);
+ return sals;
}
else
error (_("marker %s not found"), tp->static_trace_marker_id);
void
update_breakpoint_locations (struct breakpoint *b,
struct program_space *filter_pspace,
- struct symtabs_and_lines sals,
- struct symtabs_and_lines sals_end)
+ gdb::array_view<const symtab_and_line> sals,
+ gdb::array_view<const symtab_and_line> sals_end)
{
int i;
struct bp_location *existing_locations;
- if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
+ if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
{
/* Ranged breakpoints have only one start location and one end
location. */
We'd like to retain the location, so that when the library is
loaded again, we don't loose the enabled/disabled status of the
individual locations. */
- if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0)
+ if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
return;
existing_locations = hoist_existing_locations (b, filter_pspace);
- for (i = 0; i < sals.nelts; ++i)
+ for (const auto &sal : sals)
{
struct bp_location *new_loc;
- switch_to_program_space_and_thread (sals.sals[i].pspace);
+ switch_to_program_space_and_thread (sal.pspace);
- new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
+ new_loc = add_location_to_breakpoint (b, &sal);
/* Reparse conditions, they might contain references to the
old symtab. */
s = b->cond_string;
TRY
{
- new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
- block_for_pc (sals.sals[i].pc),
+ new_loc->cond = parse_exp_1 (&s, sal.pc,
+ block_for_pc (sal.pc),
0);
}
CATCH (e, RETURN_MASK_ERROR)
END_CATCH
}
- if (sals_end.nelts)
+ if (!sals_end.empty ())
{
- CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
+ CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
- new_loc->length = end - sals.sals[0].pc + 1;
+ new_loc->length = end - sals[0].pc + 1;
}
}
/* Find the SaL locations corresponding to the given LOCATION.
On return, FOUND will be 1 if any SaL was found, zero otherwise. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
location_to_sals (struct breakpoint *b, struct event_location *location,
struct program_space *search_pspace, int *found)
{
- struct symtabs_and_lines sals = {0};
struct gdb_exception exception = exception_none;
gdb_assert (b->ops != NULL);
+ std::vector<symtab_and_line> sals;
+
TRY
{
- b->ops->decode_location (b, location, search_pspace, &sals);
+ sals = b->ops->decode_location (b, location, search_pspace);
}
CATCH (e, RETURN_MASK_ERROR)
{
if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
{
- int i;
-
- for (i = 0; i < sals.nelts; ++i)
- resolve_sal_pc (&sals.sals[i]);
+ for (auto &sal : sals)
+ resolve_sal_pc (&sal);
if (b->condition_not_parsed && b->extra_string != NULL)
{
char *cond_string, *extra_string;
int thread, task;
- find_condition_and_thread (b->extra_string, sals.sals[0].pc,
+ find_condition_and_thread (b->extra_string, sals[0].pc,
&cond_string, &thread, &task,
&extra_string);
gdb_assert (b->cond_string == NULL);
}
if (b->type == bp_static_tracepoint && !strace_marker_p (b))
- sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
+ sals[0] = update_static_tracepoint (b, sals[0]);
*found = 1;
}
static void
breakpoint_re_set_default (struct breakpoint *b)
{
- int found;
- struct symtabs_and_lines sals, sals_end;
- struct symtabs_and_lines expanded = {0};
- struct symtabs_and_lines expanded_end = {0};
struct program_space *filter_pspace = current_program_space;
+ std::vector<symtab_and_line> expanded, expanded_end;
- sals = location_to_sals (b, b->location.get (), filter_pspace, &found);
+ int found;
+ std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
+ filter_pspace, &found);
if (found)
- {
- make_cleanup (xfree, sals.sals);
- expanded = sals;
- }
+ expanded = std::move (sals);
if (b->location_range_end != NULL)
{
- sals_end = location_to_sals (b, b->location_range_end.get (),
- filter_pspace, &found);
+ std::vector<symtab_and_line> sals_end
+ = location_to_sals (b, b->location_range_end.get (),
+ filter_pspace, &found);
if (found)
- {
- make_cleanup (xfree, sals_end.sals);
- expanded_end = sals_end;
- }
+ expanded_end = std::move (sals_end);
}
update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
/* Decode the line represented by S by calling decode_line_full. This is the
default function for the `decode_location' method of breakpoint_ops. */
-static void
+static std::vector<symtab_and_line>
decode_location_default (struct breakpoint *b,
const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals)
+ struct program_space *search_pspace)
{
struct linespec_result canonical;
b->filter);
/* We should get 0 or 1 resulting SALs. */
- gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
+ gdb_assert (canonical.lsals.size () < 2);
- if (VEC_length (linespec_sals, canonical.sals) > 0)
+ if (!canonical.lsals.empty ())
{
- struct linespec_sals *lsal;
-
- lsal = VEC_index (linespec_sals, canonical.sals, 0);
- *sals = lsal->sals;
- /* Arrange it so the destructor does not free the
- contents. */
- lsal->sals.sals = NULL;
+ const linespec_sals &lsal = canonical.lsals[0];
+ return std::move (lsal.sals);
}
+ return {};
}
/* Prepare the global context for a re-set of breakpoint B. */
#include "probe.h"
#include "location.h"
#include <vector>
+#include "common/array-view.h"
struct value;
struct block;
int, int, int, unsigned);
/* Given the location (second parameter), this method decodes it and
- provides the SAL locations related to it. For ordinary
+ returns the SAL locations related to it. For ordinary
breakpoints, it calls `decode_line_full'. If SEARCH_PSPACE is
not NULL, symbol search is restricted to just that program space.
This function is called inside `location_to_sals'. */
- void (*decode_location) (struct breakpoint *b,
- const struct event_location *location,
- struct program_space *search_pspace,
- struct symtabs_and_lines *sals);
+ std::vector<symtab_and_line> (*decode_location)
+ (struct breakpoint *b,
+ const struct event_location *location,
+ struct program_space *search_pspace);
/* Return true if this breakpoint explains a signal. See
bpstat_explains_signal. */
/* Initialize a struct bp_location. */
-extern void update_breakpoint_locations (struct breakpoint *b,
- struct program_space *filter_pspace,
- struct symtabs_and_lines sals,
- struct symtabs_and_lines sals_end);
+extern void update_breakpoint_locations
+ (struct breakpoint *b,
+ struct program_space *filter_pspace,
+ gdb::array_view<const symtab_and_line> sals,
+ gdb::array_view<const symtab_and_line> sals_end);
extern void breakpoint_re_set (void);
/* Prototypes for local utility functions */
-static void ambiguous_line_spec (struct symtabs_and_lines *,
+static void ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
const char *format, ...)
ATTRIBUTE_PRINTF (2, 3);
-static void filter_sals (struct symtabs_and_lines *);
+static void filter_sals (std::vector<symtab_and_line> &);
\f
/* Limit the call depth of user-defined commands */
static void
edit_command (char *arg, int from_tty)
{
- struct symtabs_and_lines sals;
struct symtab_and_line sal;
struct symbol *sym;
const char *editor;
arg1 = arg;
event_location_up location = string_to_event_location (&arg1,
current_language);
- sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
- NULL, NULL, 0);
+ std::vector<symtab_and_line> sals = decode_line_1 (location.get (),
+ DECODE_LINE_LIST_MODE,
+ NULL, NULL, 0);
- filter_sals (&sals);
- if (! sals.nelts)
+ filter_sals (sals);
+ if (sals.empty ())
{
/* C++ */
return;
}
- if (sals.nelts > 1)
+ if (sals.size () > 1)
{
- ambiguous_line_spec (&sals,
+ ambiguous_line_spec (sals,
_("Specified line is ambiguous:\n"));
- xfree (sals.sals);
return;
}
- sal = sals.sals[0];
- xfree (sals.sals);
+ sal = sals[0];
if (*arg1)
error (_("Junk at end of line specification."));
static void
list_command (char *arg, int from_tty)
{
- struct symtabs_and_lines sals, sals_end;
struct symtab_and_line sal = { 0 };
struct symtab_and_line sal_end = { 0 };
struct symtab_and_line cursal = { 0 };
if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
- sals.nelts = 0;
- sals.sals = NULL;
+ std::vector<symtab_and_line> sals;
+
arg1 = arg;
if (*arg1 == ',')
dummy_beg = 1;
current_language);
sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
NULL, NULL, 0);
-
- filter_sals (&sals);
- if (!sals.nelts)
+ filter_sals (sals);
+ if (sals.empty ())
{
/* C++ */
return;
}
- sal = sals.sals[0];
+ sal = sals[0];
}
/* Record whether the BEG arg is all digits. */
if (*arg1 == ',')
{
no_end = 0;
- if (sals.nelts > 1)
+ if (sals.size () > 1)
{
- ambiguous_line_spec (&sals,
+ ambiguous_line_spec (sals,
_("Specified first line '%.*s' is ambiguous:\n"),
(int) beg_len, beg);
- xfree (sals.sals);
return;
}
arg1++;
event_location_up location
= string_to_event_location (&arg1, current_language);
- if (dummy_beg)
- sals_end = decode_line_1 (location.get (),
- DECODE_LINE_LIST_MODE, NULL, NULL, 0);
- else
- sals_end = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
- NULL, sal.symtab, sal.line);
- filter_sals (&sals_end);
- if (sals_end.nelts == 0)
+ std::vector<symtab_and_line> sals_end
+ = (dummy_beg
+ ? decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+ NULL, NULL, 0)
+ : decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+ NULL, sal.symtab, sal.line));
+
+ filter_sals (sals_end);
+ if (sals_end.empty ())
+ return;
+ if (sals_end.size () > 1)
{
- xfree (sals.sals);
- return;
- }
- if (sals_end.nelts > 1)
- {
- ambiguous_line_spec (&sals_end,
+ ambiguous_line_spec (sals_end,
_("Specified last line '%s' is ambiguous:\n"),
end_arg);
- xfree (sals_end.sals);
- xfree (sals.sals);
return;
}
- sal_end = sals_end.sals[0];
- xfree (sals_end.sals);
+ sal_end = sals_end[0];
}
}
error (_("No default source file yet. Do \"help list\"."));
else if (no_end)
{
- for (int i = 0; i < sals.nelts; i++)
+ for (int i = 0; i < sals.size (); i++)
{
- sal = sals.sals[i];
+ sal = sals[i];
int first_line = sal.line - get_lines_to_list () / 2;
if (first_line < 1)
first_line = 1;
- if (sals.nelts > 1)
+ if (sals.size () > 1)
{
printf_filtered (_("file: \"%s\", line number: %d\n"),
symtab_to_filename_for_display (sal.symtab),
? sal.line + get_lines_to_list ()
: sal_end.line + 1),
0);
- xfree (sals.sals);
}
/* Subroutine of disassemble_command to simplify it.
\f
/* Print a list of files and line numbers which a user may choose from
in order to list a function which was specified ambiguously (as
- with `list classname::overloadedfuncname', for example). The
- vector in SALS provides the filenames and line numbers. FORMAT is
- a printf-style format string used to tell the user what was
+ with `list classname::overloadedfuncname', for example). The SALS
+ array provides the filenames and line numbers. FORMAT is a
+ printf-style format string used to tell the user what was
ambiguous. */
static void
-ambiguous_line_spec (struct symtabs_and_lines *sals, const char *format, ...)
+ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
+ const char *format, ...)
{
- int i;
-
va_list ap;
va_start (ap, format);
vprintf_filtered (format, ap);
va_end (ap);
- for (i = 0; i < sals->nelts; ++i)
+ for (const auto &sal : sals)
printf_filtered (_("file: \"%s\", line number: %d\n"),
- symtab_to_filename_for_display (sals->sals[i].symtab),
- sals->sals[i].line);
+ symtab_to_filename_for_display (sal.symtab),
+ sal.line);
}
-/* Sort function for filter_sals. */
+/* Comparison function for filter_sals. Returns a qsort-style
+ result. */
static int
-compare_symtabs (const void *a, const void *b)
+cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb)
{
- const struct symtab_and_line *sala = (const struct symtab_and_line *) a;
- const struct symtab_and_line *salb = (const struct symtab_and_line *) b;
- const char *dira = SYMTAB_DIRNAME (sala->symtab);
- const char *dirb = SYMTAB_DIRNAME (salb->symtab);
+ const char *dira = SYMTAB_DIRNAME (sala.symtab);
+ const char *dirb = SYMTAB_DIRNAME (salb.symtab);
int r;
if (dira == NULL)
return r;
}
- r = filename_cmp (sala->symtab->filename, salb->symtab->filename);
+ r = filename_cmp (sala.symtab->filename, salb.symtab->filename);
if (r)
return r;
- if (sala->line < salb->line)
+ if (sala.line < salb.line)
return -1;
- return sala->line == salb->line ? 0 : 1;
+ return sala.line == salb.line ? 0 : 1;
}
/* Remove any SALs that do not match the current program space, or
which appear to be "file:line" duplicates. */
static void
-filter_sals (struct symtabs_and_lines *sals)
+filter_sals (std::vector<symtab_and_line> &sals)
{
- int i, out, prev;
-
- out = 0;
- for (i = 0; i < sals->nelts; ++i)
- {
- if (sals->sals[i].pspace == current_program_space
- && sals->sals[i].symtab != NULL)
- {
- sals->sals[out] = sals->sals[i];
- ++out;
- }
- }
- sals->nelts = out;
-
- qsort (sals->sals, sals->nelts, sizeof (struct symtab_and_line),
- compare_symtabs);
-
- out = 1;
- prev = 0;
- for (i = 1; i < sals->nelts; ++i)
- {
- if (compare_symtabs (&sals->sals[prev], &sals->sals[i]))
- {
- /* Symtabs differ. */
- sals->sals[out] = sals->sals[i];
- prev = out;
- ++out;
- }
- }
-
- if (sals->nelts == 0)
- {
- xfree (sals->sals);
- sals->sals = NULL;
- }
- else
- sals->nelts = out;
+ /* Remove SALs that do not match. */
+ auto from = std::remove_if (sals.begin (), sals.end (),
+ [&] (const symtab_and_line &sal)
+ { return (sal.pspace != current_program_space || sal.symtab == NULL); });
+
+ /* Remove dups. */
+ std::sort (sals.begin (), from,
+ [] (const symtab_and_line &sala, const symtab_and_line &salb)
+ { return cmp_symtabs (sala, salb) < 0; });
+
+ from = std::unique (sals.begin (), from,
+ [&] (const symtab_and_line &sala,
+ const symtab_and_line &salb)
+ { return cmp_symtabs (sala, salb) == 0; });
+
+ sals.erase (from, sals.end ());
}
static void
struct value *func_func;
struct value *value;
CORE_ADDR resolved_address, resolved_pc;
- struct symtab_and_line sal;
- struct symtabs_and_lines sals, sals_end;
gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
elf_gnu_ifunc_record_cache (event_location_to_string (b->location.get ()),
resolved_pc);
- sal = find_pc_line (resolved_pc, 0);
- sals.nelts = 1;
- sals.sals = &sal;
- sals_end.nelts = 0;
-
b->type = bp_breakpoint;
- update_breakpoint_locations (b, current_program_space, sals, sals_end);
+ update_breakpoint_locations (b, current_program_space,
+ find_pc_line (resolved_pc, 0), {});
}
/* A helper function for elf_symfile_read that reads the minimal
{
struct gdbarch *gdbarch = get_current_arch ();
CORE_ADDR addr;
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
struct symbol *fn;
struct symbol *sfn;
int async_exec;
if (!arg)
error_no_arg (_("starting address"));
- sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
- if (sals.nelts != 1)
- {
- error (_("Unreasonable jump request"));
- }
-
- sal = sals.sals[0];
- xfree (sals.sals);
+ std::vector<symtab_and_line> sals
+ = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
+ if (sals.size () != 1)
+ error (_("Unreasonable jump request"));
/* Done with ARGS. */
do_cleanups (args_chain);
+ symtab_and_line &sal = sals[0];
+
if (sal.symtab == 0 && sal.pc == 0)
error (_("No source file has been specified."));
/* The 'canonical' value passed to decode_line_full, or NULL. */
struct linespec_result *canonical;
- /* Canonical strings that mirror the symtabs_and_lines result. */
+ /* Canonical strings that mirror the std::vector<symtab_and_line> result. */
struct linespec_canonical_name *canonical_names;
/* This is a set of address_entry objects which is used to prevent
CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
-static struct symtabs_and_lines decode_objc (struct linespec_state *self,
- linespec_p ls,
- const char *arg);
+static std::vector<symtab_and_line> decode_objc (struct linespec_state *self,
+ linespec_p ls,
+ const char *arg);
static VEC (symtab_ptr) *symtabs_from_filename (const char *,
struct program_space *pspace);
collect_symtabs_from_filename (const char *file,
struct program_space *pspace);
-static void decode_digits_ordinary (struct linespec_state *self,
- linespec_p ls,
- int line,
- struct symtabs_and_lines *sals,
- struct linetable_entry **best_entry);
+static std::vector<symtab_and_line> decode_digits_ordinary
+ (struct linespec_state *self,
+ linespec_p ls,
+ int line,
+ linetable_entry **best_entry);
-static void decode_digits_list_mode (struct linespec_state *self,
- linespec_p ls,
- struct symtabs_and_lines *values,
- struct symtab_and_line val);
+static std::vector<symtab_and_line> decode_digits_list_mode
+ (struct linespec_state *self,
+ linespec_p ls,
+ struct symtab_and_line val);
static void minsym_found (struct linespec_state *self, struct objfile *objfile,
struct minimal_symbol *msymbol,
- struct symtabs_and_lines *result);
+ std::vector<symtab_and_line> *result);
static int compare_symbols (const void *a, const void *b);
/* Helper functions. */
-/* Add SAL to SALS. */
-
-static void
-add_sal_to_sals_basic (struct symtabs_and_lines *sals,
- struct symtab_and_line *sal)
-{
- ++sals->nelts;
- sals->sals = XRESIZEVEC (struct symtab_and_line, sals->sals, sals->nelts);
- sals->sals[sals->nelts - 1] = *sal;
-}
-
/* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
the new sal, if needed. If not NULL, SYMNAME is the name of the
symbol to use when constructing the new canonical name.
static void
add_sal_to_sals (struct linespec_state *self,
- struct symtabs_and_lines *sals,
+ std::vector<symtab_and_line> *sals,
struct symtab_and_line *sal,
const char *symname, int literal_canonical)
{
- add_sal_to_sals_basic (sals, sal);
+ sals->push_back (*sal);
if (self->canonical)
{
struct linespec_canonical_name *canonical;
self->canonical_names = XRESIZEVEC (struct linespec_canonical_name,
- self->canonical_names, sals->nelts);
- canonical = &self->canonical_names[sals->nelts - 1];
+ self->canonical_names,
+ sals->size ());
+ canonical = &self->canonical_names[sals->size () - 1];
if (!literal_canonical && sal->symtab)
{
symtab_to_fullname (sal->symtab);
static void
filter_results (struct linespec_state *self,
- struct symtabs_and_lines *result,
+ std::vector<symtab_and_line> *result,
VEC (const_char_ptr) *filters)
{
int i;
for (i = 0; VEC_iterate (const_char_ptr, filters, i, name); ++i)
{
- struct linespec_sals lsal;
- int j;
-
- memset (&lsal, 0, sizeof (lsal));
+ linespec_sals lsal;
- for (j = 0; j < result->nelts; ++j)
+ for (size_t j = 0; j < result->size (); ++j)
{
const struct linespec_canonical_name *canonical;
char *fullform;
cleanup = make_cleanup (xfree, fullform);
if (strcmp (name, fullform) == 0)
- add_sal_to_sals_basic (&lsal.sals, &result->sals[j]);
+ lsal.sals.push_back ((*result)[j]);
do_cleanups (cleanup);
}
- if (lsal.sals.nelts > 0)
+ if (!lsal.sals.empty ())
{
lsal.canonical = xstrdup (name);
- VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
+ self->canonical->lsals.push_back (std::move (lsal));
}
}
static void
convert_results_to_lsals (struct linespec_state *self,
- struct symtabs_and_lines *result)
+ std::vector<symtab_and_line> *result)
{
struct linespec_sals lsal;
lsal.canonical = NULL;
- lsal.sals = *result;
- VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
+ lsal.sals = std::move (*result);
+ self->canonical->lsals.push_back (std::move (lsal));
}
/* A structure that contains two string representations of a struct
static void
decode_line_2 (struct linespec_state *self,
- struct symtabs_and_lines *result,
+ std::vector<symtab_and_line> *result,
const char *select_mode)
{
char *args;
gdb_assert (select_mode != multiple_symbols_all);
gdb_assert (self->canonical != NULL);
- gdb_assert (result->nelts >= 1);
+ gdb_assert (!result->empty ());
old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &filters);
/* Prepare ITEMS array. */
- items_count = result->nelts;
+ items_count = result->size ();
items = XNEWVEC (struct decode_line_2_item, items_count);
make_cleanup (xfree, items);
for (i = 0; i < items_count; ++i)
/* Given a line offset in LS, construct the relevant SALs. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
create_sals_line_offset (struct linespec_state *self,
linespec_p ls)
{
- struct symtabs_and_lines values;
struct symtab_and_line val;
int use_default = 0;
init_sal (&val);
- values.sals = NULL;
- values.nelts = 0;
/* This is where we need to make sure we have good defaults.
We must guarantee that this section of code is never executed
break; /* No need to adjust val.line. */
}
+ std::vector<symtab_and_line> values;
if (self->list_mode)
- decode_digits_list_mode (self, ls, &values, val);
+ values = decode_digits_list_mode (self, ls, val);
else
{
struct linetable_entry *best_entry = NULL;
int *filter;
const struct block **blocks;
- struct cleanup *cleanup;
- struct symtabs_and_lines intermediate_results;
int i, j;
- intermediate_results.sals = NULL;
- intermediate_results.nelts = 0;
-
- decode_digits_ordinary (self, ls, val.line, &intermediate_results,
- &best_entry);
- if (intermediate_results.nelts == 0 && best_entry != NULL)
- decode_digits_ordinary (self, ls, best_entry->line,
- &intermediate_results, &best_entry);
-
- cleanup = make_cleanup (xfree, intermediate_results.sals);
+ std::vector<symtab_and_line> intermediate_results
+ = decode_digits_ordinary (self, ls, val.line, &best_entry);
+ if (intermediate_results.empty () && best_entry != NULL)
+ intermediate_results = decode_digits_ordinary (self, ls,
+ best_entry->line,
+ &best_entry);
/* For optimized code, the compiler can scatter one source line
across disjoint ranges of PC values, even when no duplicate
above, we see if there are other PCs that are in the same
block. If yes, the other PCs are filtered out. */
- filter = XNEWVEC (int, intermediate_results.nelts);
- make_cleanup (xfree, filter);
- blocks = XNEWVEC (const struct block *, intermediate_results.nelts);
+ filter = XNEWVEC (int, intermediate_results.size ());
+ struct cleanup *cleanup = make_cleanup (xfree, filter);
+ blocks = XNEWVEC (const struct block *, intermediate_results.size ());
make_cleanup (xfree, blocks);
- for (i = 0; i < intermediate_results.nelts; ++i)
+ for (i = 0; i < intermediate_results.size (); ++i)
{
- set_current_program_space (intermediate_results.sals[i].pspace);
+ set_current_program_space (intermediate_results[i].pspace);
filter[i] = 1;
- blocks[i] = block_for_pc_sect (intermediate_results.sals[i].pc,
- intermediate_results.sals[i].section);
+ blocks[i] = block_for_pc_sect (intermediate_results[i].pc,
+ intermediate_results[i].section);
}
- for (i = 0; i < intermediate_results.nelts; ++i)
+ for (i = 0; i < intermediate_results.size (); ++i)
{
if (blocks[i] != NULL)
- for (j = i + 1; j < intermediate_results.nelts; ++j)
+ for (j = i + 1; j < intermediate_results.size (); ++j)
{
if (blocks[j] == blocks[i])
{
}
}
- for (i = 0; i < intermediate_results.nelts; ++i)
+ for (i = 0; i < intermediate_results.size (); ++i)
if (filter[i])
{
struct symbol *sym = (blocks[i]
: NULL);
if (self->funfirstline)
- skip_prologue_sal (&intermediate_results.sals[i]);
+ skip_prologue_sal (&intermediate_results[i]);
/* Make sure the line matches the request, not what was
found. */
- intermediate_results.sals[i].line = val.line;
- add_sal_to_sals (self, &values, &intermediate_results.sals[i],
+ intermediate_results[i].line = val.line;
+ add_sal_to_sals (self, &values, &intermediate_results[i],
sym ? SYMBOL_NATURAL_NAME (sym) : NULL, 0);
}
do_cleanups (cleanup);
}
- if (values.nelts == 0)
+ if (values.empty ())
{
if (ls->explicit_loc.source_filename)
throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."),
/* Convert the given ADDRESS into SaLs. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
convert_address_location_to_sals (struct linespec_state *self,
CORE_ADDR address)
{
- struct symtab_and_line sal;
- struct symtabs_and_lines sals = {NULL, 0};
-
- sal = find_pc_line (address, 0);
+ symtab_and_line sal = find_pc_line (address, 0);
sal.pc = address;
sal.section = find_pc_overlay (address);
sal.explicit_pc = 1;
+
+ std::vector<symtab_and_line> sals;
add_sal_to_sals (self, &sals, &sal, core_addr_to_string (address), 1);
return sals;
/* Create and return SALs from the linespec LS. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
{
- struct symtabs_and_lines sals = {NULL, 0};
+ std::vector<symtab_and_line> sals;
if (ls->labels.label_symbols != NULL)
{
canonicalize_linespec (state, ls);
- if (sals.nelts > 0 && state->canonical != NULL)
+ if (!sals.empty () && state->canonical != NULL)
state->canonical->pre_expanded = 1;
return sals;
/* Convert the explicit location EXPLICIT_LOC into SaLs. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
convert_explicit_location_to_sals (struct linespec_state *self,
linespec_p result,
const struct explicit_location *explicit_loc)
/* Parse the linespec in ARG. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
parse_linespec (linespec_parser *parser, const char *arg)
{
linespec_token token;
- struct symtabs_and_lines values;
struct gdb_exception file_exception = exception_none;
struct cleanup *cleanup;
- values.nelts = 0;
- values.sals = NULL;
-
/* A special case to start. It has become quite popular for
IDEs to work around bugs in the previous parser by quoting
the entire linespec, so we attempt to deal with this nicely. */
/* Objective-C shortcut. */
if (parser->completion_tracker == NULL)
{
- values = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), arg);
- if (values.sals != NULL)
+ std::vector<symtab_and_line> values
+ = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), arg);
+ if (!values.empty ())
return values;
}
else
/* Convert the data in PARSER_RESULT to SALs. */
if (parser->completion_tracker == NULL)
- values = convert_linespec_to_sals (PARSER_STATE (parser),
- PARSER_RESULT (parser));
+ return convert_linespec_to_sals (PARSER_STATE (parser),
+ PARSER_RESULT (parser));
- return values;
+ return {};
}
}
/* A helper function for decode_line_full and decode_line_1 to
- turn LOCATION into symtabs_and_lines. */
+ turn LOCATION into std::vector<symtab_and_line>. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
event_location_to_sals (linespec_parser *parser,
const struct event_location *location)
{
- struct symtabs_and_lines result = {NULL, 0};
+ std::vector<symtab_and_line> result;
switch (event_location_type (location))
{
const char *select_mode,
const char *filter)
{
- struct symtabs_and_lines result;
struct cleanup *cleanups;
VEC (const_char_ptr) *filters = NULL;
linespec_parser parser;
scoped_restore_current_program_space restore_pspace;
- result = event_location_to_sals (&parser, location);
+ std::vector<symtab_and_line> result = event_location_to_sals (&parser,
+ location);
state = PARSER_STATE (&parser);
- gdb_assert (result.nelts == 1 || canonical->pre_expanded);
+ gdb_assert (result.size () == 1 || canonical->pre_expanded);
canonical->pre_expanded = 1;
/* Arrange for allocated canonical names to be freed. */
- if (result.nelts > 0)
+ if (!result.empty ())
{
int i;
make_cleanup (xfree, state->canonical_names);
- for (i = 0; i < result.nelts; ++i)
+ for (i = 0; i < result.size (); ++i)
{
gdb_assert (state->canonical_names[i].suffix != NULL);
make_cleanup (xfree, state->canonical_names[i].suffix);
/* See linespec.h. */
-struct symtabs_and_lines
+std::vector<symtab_and_line>
decode_line_1 (const struct event_location *location, int flags,
struct program_space *search_pspace,
struct symtab *default_symtab,
int default_line)
{
- struct symtabs_and_lines result;
linespec_parser parser;
struct cleanup *cleanups;
scoped_restore_current_program_space restore_pspace;
- result = event_location_to_sals (&parser, location);
+ std::vector<symtab_and_line> result = event_location_to_sals (&parser,
+ location);
do_cleanups (cleanups);
return result;
/* See linespec.h. */
-struct symtabs_and_lines
+std::vector<symtab_and_line>
decode_line_with_current_source (char *string, int flags)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line cursal;
-
if (string == 0)
error (_("Empty line specification."));
/* We use whatever is set as the current source line. We do not try
and get a default source symtab+line or it will recursively call us! */
- cursal = get_current_source_symtab_and_line ();
+ symtab_and_line cursal = get_current_source_symtab_and_line ();
event_location_up location = string_to_event_location (&string,
current_language);
- sals = decode_line_1 (location.get (), flags, NULL,
- cursal.symtab, cursal.line);
+ std::vector<symtab_and_line> sals
+ = decode_line_1 (location.get (), flags, NULL, cursal.symtab, cursal.line);
if (*string)
error (_("Junk at end of line specification: %s"), string);
/* See linespec.h. */
-struct symtabs_and_lines
+std::vector<symtab_and_line>
decode_line_with_last_displayed (char *string, int flags)
{
- struct symtabs_and_lines sals;
-
if (string == 0)
error (_("Empty line specification."));
event_location_up location = string_to_event_location (&string,
current_language);
- if (last_displayed_sal_is_valid ())
- sals = decode_line_1 (location.get (), flags, NULL,
- get_last_displayed_symtab (),
- get_last_displayed_line ());
- else
- sals = decode_line_1 (location.get (), flags, NULL,
- (struct symtab *) NULL, 0);
+ std::vector<symtab_and_line> sals
+ = (last_displayed_sal_is_valid ()
+ ? decode_line_1 (location.get (), flags, NULL,
+ get_last_displayed_symtab (),
+ get_last_displayed_line ())
+ : decode_line_1 (location.get (), flags, NULL,
+ (struct symtab *) NULL, 0));
if (*string)
error (_("Junk at end of line specification: %s"), string);
than one method that could represent the selector, then use some of
the existing C++ code to let the user choose one. */
-static struct symtabs_and_lines
+static std::vector<symtab_and_line>
decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
{
struct collect_info info;
VEC (const_char_ptr) *symbol_names = NULL;
- struct symtabs_and_lines values;
const char *new_argptr;
struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
&symbol_names);
make_cleanup (VEC_cleanup (symtab_ptr), &info.file_symtabs);
info.result.symbols = NULL;
info.result.minimal_symbols = NULL;
- values.nelts = 0;
- values.sals = NULL;
new_argptr = find_imps (arg, &symbol_names);
if (VEC_empty (const_char_ptr, symbol_names))
{
do_cleanups (cleanup);
- return values;
+ return {};
}
add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
+ std::vector<symtab_and_line> values;
if (!VEC_empty (symbolp, info.result.symbols)
|| !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
{
/* A helper for create_sals_line_offset that handles the 'list_mode' case. */
-static void
+static std::vector<symtab_and_line>
decode_digits_list_mode (struct linespec_state *self,
linespec_p ls,
- struct symtabs_and_lines *values,
struct symtab_and_line val)
{
int ix;
gdb_assert (self->list_mode);
+ std::vector<symtab_and_line> values;
+
for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt);
++ix)
{
val.pc = 0;
val.explicit_line = 1;
- add_sal_to_sals (self, values, &val, NULL, 0);
+ add_sal_to_sals (self, &values, &val, NULL, 0);
}
+
+ return values;
}
/* A helper for create_sals_line_offset that iterates over the symtabs,
adding lines to the VEC. */
-static void
+static std::vector<symtab_and_line>
decode_digits_ordinary (struct linespec_state *self,
linespec_p ls,
int line,
- struct symtabs_and_lines *sals,
struct linetable_entry **best_entry)
{
int ix;
struct symtab *elt;
+ std::vector<symtab_and_line> sals;
for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix)
{
std::vector<CORE_ADDR> pcs;
sal.symtab = elt;
sal.line = line;
sal.pc = pc;
- add_sal_to_sals_basic (sals, &sal);
+ sals.push_back (std::move (sal));
}
}
+
+ return sals;
}
\f
static void
minsym_found (struct linespec_state *self, struct objfile *objfile,
struct minimal_symbol *msymbol,
- struct symtabs_and_lines *result)
+ std::vector<symtab_and_line> *result)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
CORE_ADDR pc;
linespec_result::~linespec_result ()
{
- int i;
- struct linespec_sals *lsal;
-
- for (i = 0; VEC_iterate (linespec_sals, sals, i, lsal); ++i)
- {
- xfree (lsal->canonical);
- xfree (lsal->sals.sals);
- }
- VEC_free (linespec_sals, sals);
+ for (linespec_sals &lsal : lsals)
+ xfree (lsal.canonical);
}
/* Return the quote characters permitted by the linespec parser. */
destructor. */
char *canonical;
- /* Sals. The 'sals' field is destroyed by the linespec_result
- destructor. */
- struct symtabs_and_lines sals;
+ /* Sals. */
+ std::vector<symtab_and_line> sals;
};
-typedef struct linespec_sals linespec_sals;
-DEF_VEC_O (linespec_sals);
-
/* An instance of this may be filled in by decode_line_1. The caller
must make copies of any data that it needs to keep. */
struct linespec_result
{
- linespec_result ()
- : special_display (0),
- pre_expanded (0),
- sals (NULL)
- {
- }
-
+ linespec_result () = default;
~linespec_result ();
linespec_result (const linespec_result &) = delete;
linespec_result &operator= (const linespec_result &) = delete;
- /* If non-zero, the linespec should be displayed to the user. This
+ /* If true, the linespec should be displayed to the user. This
is used by "unusual" linespecs where the ordinary `info break'
display mechanism would do the wrong thing. */
- int special_display;
+ bool special_display = false;
- /* If non-zero, the linespec result should be considered to be a
+ /* If true, the linespec result should be considered to be a
"pre-expanded" multi-location linespec. A pre-expanded linespec
holds all matching locations in a single linespec_sals
object. */
- int pre_expanded;
+ bool pre_expanded = false;
/* If PRE_EXPANDED is non-zero, this is set to the location entered
by the user. */
event_location_up location;
/* The sals. The vector will be freed by the destructor. */
- VEC (linespec_sals) *sals;
+ std::vector<linespec_sals> lsals;
};
/* Decode a linespec using the provided default symtab and line. */
-extern struct symtabs_and_lines
+extern std::vector<symtab_and_line>
decode_line_1 (const struct event_location *location, int flags,
struct program_space *search_pspace,
struct symtab *default_symtab, int default_line);
source symtab and line as defaults.
This is for commands like "list" and "breakpoint". */
-extern struct symtabs_and_lines decode_line_with_current_source (char *, int);
+extern std::vector<symtab_and_line> decode_line_with_current_source (char *, int);
/* Given a string, return the line specified by it, using the last displayed
codepoint's values as defaults, or nothing if they aren't valid. */
-extern struct symtabs_and_lines decode_line_with_last_displayed (char *, int);
+extern std::vector<symtab_and_line> decode_line_with_last_displayed (char *, int);
/* Does P represent one of the keywords? If so, return
the keyword. If not, return NULL. */
ms = default_macro_scope ();
else
{
- struct symtabs_and_lines sals =
- decode_line_with_current_source (args, 0);
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (args, 0);
- if (sals.nelts)
- ms = sal_macro_scope (sals.sals[0]);
+ if (!sals.empty ())
+ ms = sal_macro_scope (sals[0]);
}
if (! ms || ! ms->file || ! ms->file->table)
}
else if (strcmp (mode, "line") == 0)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
- static CORE_ADDR start_pc, end_pc;
- struct cleanup *back_to;
-
if (argc != 2)
error (_("Line is required"));
- sals = decode_line_with_current_source (argv[1],
- DECODE_LINE_FUNFIRSTLINE);
- back_to = make_cleanup (xfree, sals.sals);
-
- sal = sals.sals[0];
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (argv[1],
+ DECODE_LINE_FUNFIRSTLINE);
+ const symtab_and_line &sal = sals[0];
if (sal.symtab == 0)
error (_("Could not find the specified line"));
+ CORE_ADDR start_pc, end_pc;
if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
tfind_1 (tfind_range, 0, start_pc, end_pc - 1, 0);
else
error (_("Could not find the specified line"));
-
- do_cleanups (back_to);
}
else
error (_("Invalid mode '%s'"), mode);
const char *objfile_namestr,
const char *provider,
const char *name,
- struct symtabs_and_lines *result)
+ std::vector<symtab_and_line> *result)
{
struct objfile *objfile;
for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
{
- struct symtab_and_line *sal;
-
if (probe_ops != &probe_ops_any && probe->pops != probe_ops)
continue;
if (strcmp (probe->name, name) != 0)
continue;
- ++result->nelts;
- result->sals = XRESIZEVEC (struct symtab_and_line, result->sals,
- result->nelts);
- sal = &result->sals[result->nelts - 1];
+ symtab_and_line sal;
+
+ init_sal (&sal);
- init_sal (sal);
+ sal.pc = get_probe_address (probe, objfile);
+ sal.explicit_pc = 1;
+ sal.section = find_pc_overlay (sal.pc);
+ sal.pspace = search_pspace;
+ sal.probe = probe;
+ sal.objfile = objfile;
- sal->pc = get_probe_address (probe, objfile);
- sal->explicit_pc = 1;
- sal->section = find_pc_overlay (sal->pc);
- sal->pspace = search_pspace;
- sal->probe = probe;
- sal->objfile = objfile;
+ result->push_back (std::move (sal));
}
}
}
/* See definition in probe.h. */
-struct symtabs_and_lines
+std::vector<symtab_and_line>
parse_probes (const struct event_location *location,
struct program_space *search_pspace,
struct linespec_result *canonical)
char *arg_end, *arg;
char *objfile_namestr = NULL, *provider = NULL, *name, *p;
struct cleanup *cleanup;
- struct symtabs_and_lines result;
const struct probe_ops *probe_ops;
const char *arg_start, *cs;
- result.sals = NULL;
- result.nelts = 0;
-
gdb_assert (event_location_type (location) == PROBE_LOCATION);
arg_start = get_probe_location (location);
if (objfile_namestr && *objfile_namestr == '\0')
error (_("invalid objfile name"));
+ std::vector<symtab_and_line> result;
if (search_pspace != NULL)
{
parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
provider, name, &result);
}
- if (result.nelts == 0)
+ if (result.empty ())
{
throw_error (NOT_FOUND_ERROR,
_("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
struct objfile *objfile;
};
-/* A helper for linespec that decodes a probe specification. It returns a
- symtabs_and_lines object and updates LOC or throws an error. */
-
-extern struct symtabs_and_lines parse_probes (const struct event_location *loc,
- struct program_space *pspace,
- struct linespec_result *canon);
+/* A helper for linespec that decodes a probe specification. It
+ returns a std::vector<symtab_and_line> object and updates LOC or
+ throws an error. */
+
+extern std::vector<symtab_and_line> parse_probes
+ (const struct event_location *loc,
+ struct program_space *pspace,
+ struct linespec_result *canon);
/* Helper function to register the proper probe_ops to a newly created probe.
This function is mainly called from `sym_get_probes'. */
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;
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<symtab_and_line> decoded_sals;
+ symtab_and_line def_sal;
+ gdb::array_view<symtab_and_line> 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<struct symtab_and_line> 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);
void
select_source_symtab (struct symtab *s)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
struct objfile *ofp;
struct compunit_symtab *cu;
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);
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;
/* 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
printf_filtered (_("Line number %d is out of range for \"%s\".\n"),
sal.line, symtab_to_filename_for_display (sal.symtab));
}
- do_cleanups (cleanups);
}
\f
/* Commands to search the source file for a regexp. */
{
struct frame_info *frame;
int found = 0;
- struct symtabs_and_lines sals;
- int i;
int level = 1;
struct function_bounds *func_bounds = NULL;
- struct cleanup *cleanups;
if (arg == NULL)
return;
frame = get_current_frame ();
- sals = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
- cleanups = make_cleanup (xfree, sals.sals);
- func_bounds = XNEWVEC (struct function_bounds, sals.nelts);
- make_cleanup (xfree, func_bounds);
- for (i = 0; (i < sals.nelts && !found); i++)
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
+ func_bounds = XNEWVEC (struct function_bounds, sals.size ());
+ struct cleanup *cleanups = make_cleanup (xfree, func_bounds);
+ for (size_t i = 0; (i < sals.size () && !found); i++)
{
- if (sals.sals[i].pspace != current_program_space)
+ if (sals[i].pspace != current_program_space)
func_bounds[i].low = func_bounds[i].high = 0;
- else if (sals.sals[i].pc == 0
- || find_pc_partial_function (sals.sals[i].pc, NULL,
+ else if (sals[i].pc == 0
+ || find_pc_partial_function (sals[i].pc, NULL,
&func_bounds[i].low,
&func_bounds[i].high) == 0)
{
do
{
- for (i = 0; (i < sals.nelts && !found); i++)
+ for (size_t i = 0; (i < sals.size () && !found); i++)
found = (get_frame_pc (frame) >= func_bounds[i].low
&& get_frame_pc (frame) < func_bounds[i].high);
if (!found)
extern void init_sal (struct symtab_and_line *sal);
-struct symtabs_and_lines
-{
- struct symtab_and_line *sals;
- int nelts;
-};
\f
/* Given a pc value, return line number it is in. Second arg nonzero means
static void
tfind_line_command (char *args, int from_tty)
{
- static CORE_ADDR start_pc, end_pc;
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
- struct cleanup *old_chain;
-
check_trace_running (current_trace_status ());
+ symtab_and_line sal;
if (args == 0 || *args == 0)
{
sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
- sals.nelts = 1;
- sals.sals = XNEW (struct symtab_and_line);
- sals.sals[0] = sal;
}
else
{
- sals = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE);
- sal = sals.sals[0];
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE);
+ sal = sals[0];
}
-
- old_chain = make_cleanup (xfree, sals.sals);
+
if (sal.symtab == 0)
error (_("No line number information available."));
+ CORE_ADDR start_pc, end_pc;
if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
{
if (start_pc == end_pc)
tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty);
else
tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty);
- do_cleanups (old_chain);
}
/* tfind range command */
static void
info_scope_command (char *args, int from_tty)
{
- struct symtabs_and_lines sals;
struct symbol *sym;
struct bound_minimal_symbol msym;
const struct block *block;
event_location_up location = string_to_event_location (&args,
current_language);
- sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
- NULL, NULL, 0);
- if (sals.nelts == 0)
+ std::vector<symtab_and_line> sals
+ = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
+ NULL, NULL, 0);
+ if (sals.empty ())
{
/* Presumably decode_line_1 has already warned. */
return;
}
/* Resolve line numbers to PC. */
- resolve_sal_pc (&sals.sals[0]);
- block = block_for_pc (sals.sals[0].pc);
+ resolve_sal_pc (&sals[0]);
+ block = block_for_pc (sals[0].pc);
while (block != 0)
{