diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-05-27 14:58:36 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-05-27 14:58:36 -0400 |
commit | f6d17b2b1c042853b80d790b0c6a10d2b4347faa (patch) | |
tree | 9acfbff036d0df6246c8a45f501c90bd6883d8f3 /gdb/breakpoint.h | |
parent | 1428b37afbd8a5199e1c4b2a53ef8700208a12d4 (diff) | |
download | gdb-f6d17b2b1c042853b80d790b0c6a10d2b4347faa.zip gdb-f6d17b2b1c042853b80d790b0c6a10d2b4347faa.tar.gz gdb-f6d17b2b1c042853b80d790b0c6a10d2b4347faa.tar.bz2 |
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
Diffstat (limited to 'gdb/breakpoint.h')
-rw-r--r-- | gdb/breakpoint.h | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 54c5e42..5a10839 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -28,6 +28,7 @@ #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" @@ -1683,9 +1684,6 @@ extern struct tracepoint * 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); @@ -1717,6 +1715,31 @@ public: 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. */ |