Patchwork [v2,1/2] Change iterate_over_breakpoints to take a function_view

login
register
mail settings
Submitter cbiesinger@chromium.org
Date Oct. 9, 2019, 7:39 p.m.
Message ID <20191009193938.147076-1-cbiesinger@chromium.org>
Download mbox | patch
Permalink /patch/34889/
State New
Headers show

Comments

cbiesinger@chromium.org - Oct. 9, 2019, 7:39 p.m.
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(-)
Tom Tromey - Oct. 9, 2019, 9:02 p.m.
>>>>> 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
Doug Evans via gdb-patches - Oct. 10, 2019, 12:12 a.m.
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

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 0a705163386..698411d707f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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;
     }
 
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 9791032c5e8..ea1a2bb5f76 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -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.  */