gdb: add all_tracepoints function

Same idea as the previous patches, but to replace the ALL_TRACEPOINTS
macro.  Define a new filtered_iterator that only keeps the breakpoints
for which is_tracepoint returns true (just like the macro did).

I would have like to make it so tracepoint_range yields some
`tracepoint *` instead of some `breakpoint *`, that would help simplify
the callers, who wouldn't have to do the cast themselves.  But I didn't
find an obvious way to do it.  It can always be added later.

It turns out there is already an all_tracepoints function, which returns
a vector containing all the breakpoints that are tracepoint.  Remove it,
most users will just work seamlessly with the new function.  The
exception is start_tracing, which iterated multiple times on the vector.
Adapt this one so it iterates multiple times on the returned range.

Since the existing users of all_tracepoints are outside of breakpoint.c,
this requires defining all_tracepoints and a few supporting types in
breakpoint.h.  So, move breakpoint_iterator from breakpoint.c to
breakpoint.h.

gdb/ChangeLog:

	* breakpoint.h (all_tracepoints): Remove.
	(breakpoint_iterator): Move here.
	(struct tracepoint_filter): New.
	(tracepoint_iterator): New.
	(tracepoint_range): New.
	(all_tracepoints): New.
	* breakpoint.c (ALL_TRACEPOINTS): Remove, replace all users with
	all_tracepoints.
	(breakpoint_iterator): Move to header.
	(all_tracepoints): New.
	* tracepoint.c (start_tracing): Adjust.

Change-Id: I76b1bba4215dbec7a03846c568368aeef7f1e05a
This commit is contained in:
Simon Marchi
2021-05-27 14:58:36 -04:00
parent 1428b37afb
commit f6d17b2b1c
4 changed files with 58 additions and 48 deletions

View File

@@ -514,20 +514,10 @@ bool target_exact_watchpoints = false;
&& (*BP_LOCP_TMP)->address == ADDRESS); \
BP_LOCP_TMP++)
/* Iterator for tracepoints only. */
#define ALL_TRACEPOINTS(B) \
for (B = breakpoint_chain; B; B = B->next) \
if (is_tracepoint (B))
/* Chains of all breakpoints defined. */
static struct breakpoint *breakpoint_chain;
/* Breakpoint linked list iterator. */
using breakpoint_iterator = next_iterator<breakpoint>;
/* Breakpoint linked list range. */
using breakpoint_range = next_adapter<breakpoint, breakpoint_iterator>;
@@ -554,6 +544,14 @@ all_breakpoints_safe ()
return breakpoint_safe_range (all_breakpoints ());
}
/* See breakpoint.h. */
tracepoint_range
all_tracepoints ()
{
return tracepoint_range (breakpoint_chain);
}
/* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
static struct bp_location **bp_locations;
@@ -11714,12 +11712,11 @@ bp_locations_target_extensions_update (void)
static void
download_tracepoint_locations (void)
{
struct breakpoint *b;
enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
scoped_restore_current_pspace_and_thread restore_pspace_thread;
ALL_TRACEPOINTS (b)
for (breakpoint *b : all_tracepoints ())
{
struct bp_location *bl;
struct tracepoint *t;
@@ -14910,13 +14907,12 @@ delete_trace_command (const char *arg, int from_tty)
if (arg == 0)
{
int breaks_to_delete = 0;
breakpoint *tp;
/* Delete all breakpoints if no argument.
Do not delete internal or call-dummy breakpoints, these
have to be deleted with an explicit breakpoint number
argument. */
ALL_TRACEPOINTS (tp)
for (breakpoint *tp : all_tracepoints ())
if (is_tracepoint (tp) && user_breakpoint_p (tp))
{
breaks_to_delete = 1;
@@ -14973,13 +14969,11 @@ trace_pass_command (const char *args, int from_tty)
args = skip_spaces (args);
if (*args && strncasecmp (args, "all", 3) == 0)
{
struct breakpoint *b;
args += 3; /* Skip special argument "all". */
if (*args)
error (_("Junk at end of arguments."));
ALL_TRACEPOINTS (b)
for (breakpoint *b : all_tracepoints ())
{
t1 = (struct tracepoint *) b;
trace_pass_set_count (t1, count, from_tty);
@@ -15006,9 +15000,7 @@ trace_pass_command (const char *args, int from_tty)
struct tracepoint *
get_tracepoint (int num)
{
struct breakpoint *t;
ALL_TRACEPOINTS (t)
for (breakpoint *t : all_tracepoints ())
if (t->number == num)
return (struct tracepoint *) t;
@@ -15022,9 +15014,7 @@ get_tracepoint (int num)
struct tracepoint *
get_tracepoint_by_number_on_target (int num)
{
struct breakpoint *b;
ALL_TRACEPOINTS (b)
for (breakpoint *b : all_tracepoints ())
{
struct tracepoint *t = (struct tracepoint *) b;
@@ -15044,7 +15034,6 @@ struct tracepoint *
get_tracepoint_by_number (const char **arg,
number_or_range_parser *parser)
{
struct breakpoint *t;
int tpnum;
const char *instring = arg == NULL ? NULL : *arg;
@@ -15068,7 +15057,7 @@ get_tracepoint_by_number (const char **arg,
return NULL;
}
ALL_TRACEPOINTS (t)
for (breakpoint *t : all_tracepoints ())
if (t->number == tpnum)
{
return (struct tracepoint *) t;
@@ -15225,22 +15214,6 @@ save_tracepoints_command (const char *args, int from_tty)
save_breakpoints (args, from_tty, is_tracepoint);
}
/* Create a vector of all tracepoints. */
std::vector<breakpoint *>
all_tracepoints (void)
{
std::vector<breakpoint *> tp_vec;
struct breakpoint *tp;
ALL_TRACEPOINTS (tp)
{
tp_vec.push_back (tp);
}
return tp_vec;
}
/* This help string is used to consolidate all the help string for specifying
locations used by several commands. */