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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

cbiesinger
From: Christian Biesinger <[hidden email]>

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  <[hidden email]>

        * 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(-)

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.  */
--
2.23.0.581.g78d2f28ef7-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 2/2] Make tui-winsource not use breakpoint_chain

cbiesinger
From: Christian Biesinger <[hidden email]>

That's an internal variable of breakpoint.c. Insted, use
iterate_over_breakpoints to update the breakpoint list.

gdb/ChangeLog:

2019-10-09  Christian Biesinger  <[hidden email]>

        * breakpoint.c (breakpoint_chain): Make static.
        * tui/tui-winsource.c: Call iterate_over_breakpoints instead
        of accessing breakpoint_chain.
---
 gdb/breakpoint.c        |  2 +-
 gdb/tui/tui-winsource.c | 12 +++++-------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 698411d707f..531ab044557 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -521,7 +521,7 @@ bool target_exact_watchpoints = false;
 
 /* Chains of all breakpoints defined.  */
 
-struct breakpoint *breakpoint_chain;
+static struct breakpoint *breakpoint_chain;
 
 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS.  */
 
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 683856de817..fb64075cbff 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -401,8 +401,6 @@ tui_source_window_base::update_breakpoint_info
 
   for (i = 0; i < content.size (); i++)
     {
-      struct breakpoint *bp;
-      extern struct breakpoint *breakpoint_chain;
       struct tui_source_element *line;
 
       line = &content[i];
@@ -413,9 +411,7 @@ tui_source_window_base::update_breakpoint_info
          do with it.  Identify enable/disabled breakpoints as well as
          those that we already hit.  */
       tui_bp_flags mode = 0;
-      for (bp = breakpoint_chain;
-           bp != NULL;
-           bp = bp->next)
+      iterate_over_breakpoints ([&] (struct breakpoint *bp, void*) -> int
         {
   struct bp_location *loc;
 
@@ -423,7 +419,7 @@ tui_source_window_base::update_breakpoint_info
       || line->line_or_addr.loa == LOA_ADDRESS);
 
   if (bp == being_deleted)
-    continue;
+    return false;
 
   for (loc = bp->loc; loc != NULL; loc = loc->next)
     {
@@ -441,12 +437,14 @@ tui_source_window_base::update_breakpoint_info
     mode |= TUI_BP_HARDWARE;
  }
     }
-        }
+  return false;
+        }, nullptr);
       if (line->break_mode != mode)
         {
           line->break_mode = mode;
           need_refresh = true;
         }
+      return false;
     }
   return need_refresh;
 }
--
2.23.0.581.g78d2f28ef7-goog

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 1/2] Change iterate_over_breakpoints to take a function_view

Tom Tromey-2
In reply to this post by cbiesinger
>>>>> cbiesinger  <[hidden email]> writes:

> From: Christian Biesinger <[hidden email]>
> 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  <[hidden email]>

> * 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
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 1/2] Change iterate_over_breakpoints to take a function_view

Sourceware - gdb-patches mailing list
On Wed, Oct 9, 2019 at 4:02 PM Tom Tromey <[hidden email]> wrote:

>
> >>>>> cbiesinger  <[hidden email]> writes:
>
> > From: Christian Biesinger <[hidden email]>
> > 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  <[hidden email]>
>
> >       * 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