+2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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.
+
2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
* breakpoint.c (breakpoint_safe_range): New.
&& (*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>;
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;
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;
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;
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);
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;
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;
get_tracepoint_by_number (const char **arg,
number_or_range_parser *parser)
{
- struct breakpoint *t;
int tpnum;
const char *instring = arg == NULL ? NULL : *arg;
return NULL;
}
- ALL_TRACEPOINTS (t)
+ for (breakpoint *t : all_tracepoints ())
if (t->number == tpnum)
{
return (struct tracepoint *) t;
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;
-}
-
\f
/* This help string is used to consolidate all the help string for specifying
locations used by several commands. */
#include "location.h"
#include <vector>
#include "gdbsupport/array-view.h"
+#include "gdbsupport/filtered-iterator.h"
#include "gdbsupport/function-view.h"
#include "gdbsupport/refcounted-object.h"
#include "cli/cli-script.h"
get_tracepoint_by_number (const char **arg,
number_or_range_parser *parser);
-/* Return a vector of all tracepoints currently defined. */
-extern std::vector<breakpoint *> all_tracepoints (void);
-
/* Return true if B is of tracepoint kind. */
extern bool is_tracepoint (const struct breakpoint *b);
extern struct breakpoint *iterate_over_breakpoints
(gdb::function_view<bool (breakpoint *)>);
+/* Breakpoint linked list iterator. */
+
+using breakpoint_iterator = next_iterator<breakpoint>;
+
+/* Breakpoint filter to only keep tracepoints. */
+
+struct tracepoint_filter
+{
+ bool operator() (breakpoint *b)
+ { return is_tracepoint (b); }
+};
+
+/* Breakpoint linked list iterator, filtering to only keep tracepoints. */
+
+using tracepoint_iterator
+ = filtered_iterator<breakpoint_iterator, tracepoint_filter>;
+
+/* Breakpoint linked list range, filtering to only keep tracepoints. */
+
+using tracepoint_range = next_adapter<breakpoint, tracepoint_iterator>;
+
+/* Return a range to iterate over all tracepoints. */
+
+tracepoint_range all_tracepoints ();
+
/* Nonzero if the specified PC cannot be a location where functions
have been inlined. */
int any_enabled = 0, num_to_download = 0;
int ret;
- std::vector<breakpoint *> tp_vec = all_tracepoints ();
+ auto tracepoint_range = all_tracepoints ();
/* No point in tracing without any tracepoints... */
- if (tp_vec.empty ())
+ if (tracepoint_range.begin () == tracepoint_range.end ())
error (_("No tracepoints defined, not starting trace"));
- for (breakpoint *b : tp_vec)
+ for (breakpoint *b : tracepoint_range)
{
if (b->enable_state == bp_enabled)
any_enabled = 1;
target_trace_init ();
- for (breakpoint *b : tp_vec)
+ for (breakpoint *b : tracepoint_range)
{
struct tracepoint *t = (struct tracepoint *) b;
struct bp_location *loc;