[v2,1/2] Change iterate_over_breakpoints to take a function_view
Commit Message
From: Christian Biesinger <cbiesinger@google.com>
This allows callers to pass in capturing lambdas. I have not changed the
signature to remove the void* argument or to change the return type to
bool; that can be done in a future cleanup.
gdb/ChangeLog:
2019-10-09 Christian Biesinger <cbiesinger@google.com>
* breakpoint.c (iterate_over_breakpoints): Change function pointer to
a gdb::function_view.
* breakpoint.h (iterate_over_breakpoints): Likewise.
---
gdb/breakpoint.c | 6 +++---
gdb/breakpoint.h | 5 +++--
2 files changed, 6 insertions(+), 5 deletions(-)
Comments
>>>>> cbiesinger <cbiesinger@chromium.org> writes:
> From: Christian Biesinger <cbiesinger@google.com>
> This allows callers to pass in capturing lambdas. I have not changed the
> signature to remove the void* argument or to change the return type to
> bool; that can be done in a future cleanup.
> gdb/ChangeLog:
> 2019-10-09 Christian Biesinger <cbiesinger@google.com>
> * breakpoint.c (iterate_over_breakpoints): Change function pointer to
> a gdb::function_view.
> * breakpoint.h (iterate_over_breakpoints): Likewise.
> +iterate_over_breakpoints
> + (gdb::function_view<int (breakpoint *, void *)> callback, void *data)
I think normally a function_view conversion would remove the "void *"
callback data, because that can be passed in via the closure now.
Tom
On Wed, Oct 9, 2019 at 4:02 PM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> cbiesinger <cbiesinger@chromium.org> writes:
>
> > From: Christian Biesinger <cbiesinger@google.com>
> > This allows callers to pass in capturing lambdas. I have not changed the
> > signature to remove the void* argument or to change the return type to
> > bool; that can be done in a future cleanup.
>
> > gdb/ChangeLog:
>
> > 2019-10-09 Christian Biesinger <cbiesinger@google.com>
>
> > * breakpoint.c (iterate_over_breakpoints): Change function pointer to
> > a gdb::function_view.
> > * breakpoint.h (iterate_over_breakpoints): Likewise.
> > +iterate_over_breakpoints
> > + (gdb::function_view<int (breakpoint *, void *)> callback, void *data)
>
> I think normally a function_view conversion would remove the "void *"
> callback data, because that can be passed in via the closure now.
OK, sent that as v3 of this patchset.
Christian
@@ -15132,14 +15132,14 @@ save_command (const char *arg, int from_tty)
}
struct breakpoint *
-iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
- void *data)
+iterate_over_breakpoints
+ (gdb::function_view<int (breakpoint *, void *)> callback, void *data)
{
struct breakpoint *b, *b_tmp;
ALL_BREAKPOINTS_SAFE (b, b_tmp)
{
- if ((*callback) (b, data))
+ if (callback (b, data))
return b;
}
@@ -29,6 +29,7 @@
#include "location.h"
#include <vector>
#include "gdbsupport/array-view.h"
+#include "gdbsupport/function-view.h"
#include "cli/cli-script.h"
struct block;
@@ -1664,8 +1665,8 @@ public:
returned. This can be useful for implementing a search for a
breakpoint with arbitrary attributes, or for applying an operation
to every breakpoint. */
-extern struct breakpoint *iterate_over_breakpoints (int (*) (struct breakpoint *,
- void *), void *);
+extern struct breakpoint *iterate_over_breakpoints
+ (gdb::function_view<int (breakpoint *, void *)>, void *);
/* Nonzero if the specified PC cannot be a location where functions
have been inlined. */