Change iterate_over_breakpoints to take a function_view
authorChristian Biesinger <cbiesinger@google.com>
Wed, 9 Oct 2019 18:50:20 +0000 (13:50 -0500)
committerChristian Biesinger <cbiesinger@google.com>
Tue, 15 Oct 2019 13:29:55 +0000 (15:29 +0200)
This allows callers to pass in capturing lambdas.  Also changes the return
type to bool.

gdb/ChangeLog:

2019-10-15  Christian Biesinger  <cbiesinger@google.com>

* breakpoint.c (iterate_over_breakpoints): Change function pointer
to a gdb::function_view and return value to bool.
* breakpoint.h (iterate_over_breakpoints): Likewise.
* dummy-frame.c (pop_dummy_frame_bpt): Update.
(pop_dummy_frame): Update.
* guile/scm-breakpoint.c (bpscm_build_bp_list): Update.
(gdbscm_breakpoints): Update.
* python/py-breakpoint.c (build_bp_list): Update.
(gdbpy_breakpoints): Update.
* python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb):
Update.
(bpfinishpy_handle_stop): Update.
(bpfinishpy_handle_exit): Update.
* solib-svr4.c (svr4_update_solib_event_breakpoint): Update.
(svr4_update_solib_event_breakpoints): Update.

Change-Id: Ia9de4deecae562a70a40f5cd49f5a74d64570251

gdb/ChangeLog
gdb/breakpoint.c
gdb/breakpoint.h
gdb/dummy-frame.c
gdb/guile/scm-breakpoint.c
gdb/python/py-breakpoint.c
gdb/python/py-finishbreakpoint.c
gdb/solib-svr4.c

index 21d5233f5bbd8a36a0ed9809643ddceb33b2163e..39a83741f7f95087e0de1977cbc4ef78e008f053 100644 (file)
@@ -1,3 +1,21 @@
+2019-10-15  Christian Biesinger  <cbiesinger@google.com>
+
+       * breakpoint.c (iterate_over_breakpoints): Change function pointer
+       to a gdb::function_view and return value to bool.
+       * breakpoint.h (iterate_over_breakpoints): Likewise.
+       * dummy-frame.c (pop_dummy_frame_bpt): Update.
+       (pop_dummy_frame): Update.
+       * guile/scm-breakpoint.c (bpscm_build_bp_list): Update.
+       (gdbscm_breakpoints): Update.
+       * python/py-breakpoint.c (build_bp_list): Update.
+       (gdbpy_breakpoints): Update.
+       * python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb):
+       Update.
+       (bpfinishpy_handle_stop): Update.
+       (bpfinishpy_handle_exit): Update.
+       * solib-svr4.c (svr4_update_solib_event_breakpoint): Update.
+       (svr4_update_solib_event_breakpoints): Update.
+
 2019-10-15  Andreas Arnez  <arnez@linux.ibm.com>
 
        * s390-tdep.c (s390_effective_inner_type): Ignore static fields
index 31f4005ec7f9c7c07aada509f42c0630ed9f4425..9bbb28f5277c30a17b1058e9ee6de6242834fcac 100644 (file)
@@ -15128,14 +15128,13 @@ 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<bool (breakpoint *)> callback)
 {
   struct breakpoint *b, *b_tmp;
 
   ALL_BREAKPOINTS_SAFE (b, b_tmp)
     {
-      if ((*callback) (b, data))
+      if (callback (b))
        return b;
     }
 
index 9791032c5e84a0ae766da50c819978807fc817c3..7472c0ecc45c7819e9880a585ee9ef3a3dc34425 100644 (file)
@@ -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<bool (breakpoint *)>);
 
 /* Nonzero if the specified PC cannot be a location where functions
    have been inlined.  */
index d3ede7c9a0cba1d14550330a88379902d85606ce..3b76d456b7b134b5d524263898278ca98ff0b380 100644 (file)
@@ -126,11 +126,9 @@ remove_dummy_frame (struct dummy_frame **dummy_ptr)
 /* Delete any breakpoint B which is a momentary breakpoint for return from
    inferior call matching DUMMY_VOIDP.  */
 
-static int
-pop_dummy_frame_bpt (struct breakpoint *b, void *dummy_voidp)
+static bool
+pop_dummy_frame_bpt (struct breakpoint *b, struct dummy_frame *dummy)
 {
-  struct dummy_frame *dummy = (struct dummy_frame *) dummy_voidp;
-
   if (b->thread == dummy->id.thread->global_num
       && b->disposition == disp_del && frame_id_eq (b->frame_id, dummy->id.id))
     {
@@ -140,11 +138,11 @@ pop_dummy_frame_bpt (struct breakpoint *b, void *dummy_voidp)
       delete_breakpoint (b);
 
       /* Stop the traversal.  */
-      return 1;
+      return true;
     }
 
   /* Continue the traversal.  */
-  return 0;
+  return false;
 }
 
 /* Pop *DUMMY_PTR, restoring program state to that before the
@@ -168,7 +166,10 @@ pop_dummy_frame (struct dummy_frame **dummy_ptr)
 
   restore_infcall_suspend_state (dummy->caller_state);
 
-  iterate_over_breakpoints (pop_dummy_frame_bpt, dummy);
+  iterate_over_breakpoints ([dummy] (breakpoint* bp)
+    {
+      return pop_dummy_frame_bpt (bp, dummy);
+    });
 
   /* restore_infcall_control_state frees inf_state,
      all that remains is to pop *dummy_ptr.  */
index 9a4efee92dc2b0710e27932547f2db7621fbdca4..a75daa000196dcb48ca01c1b5901fc2ee3f549ae 100644 (file)
@@ -505,10 +505,9 @@ gdbscm_delete_breakpoint_x (SCM self)
 
 /* iterate_over_breakpoints function for gdbscm_breakpoints.  */
 
-static int
-bpscm_build_bp_list (struct breakpoint *bp, void *arg)
+static bool
+bpscm_build_bp_list (struct breakpoint *bp, SCM *list)
 {
-  SCM *list = (SCM *) arg;
   breakpoint_smob *bp_smob = bp->scm_bp_object;
 
   /* Lazily create wrappers for breakpoints created outside Scheme.  */
@@ -534,7 +533,7 @@ bpscm_build_bp_list (struct breakpoint *bp, void *arg)
   if (bp_smob != NULL)
     *list = scm_cons (bp_smob->containing_scm, *list);
 
-  return 0;
+  return false;
 }
 
 /* (breakpoints) -> list
@@ -545,11 +544,10 @@ gdbscm_breakpoints (void)
 {
   SCM list = SCM_EOL;
 
-  /* If iterate_over_breakpoints returns non-NULL it means the iteration
-     terminated early.
-     In that case abandon building the list and return #f.  */
-  if (iterate_over_breakpoints (bpscm_build_bp_list, &list) != NULL)
-    return SCM_BOOL_F;
+  iterate_over_breakpoints ([&] (breakpoint *bp)
+    {
+      return bpscm_build_bp_list(bp, &list);
+    });
 
   return scm_reverse_x (list, SCM_EOL);
 }
index 698d91e9d32599817f2f8fab00a069769ab1bfb0..65cb29fdca63417d6f4610ba17c6b98121aeed17 100644 (file)
@@ -871,10 +871,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
 \f
 
-static int
-build_bp_list (struct breakpoint *b, void *arg)
+static bool
+build_bp_list (struct breakpoint *b, PyObject *list)
 {
-  PyObject *list = (PyObject *) arg;
   PyObject *bp = (PyObject *) b->py_bp_object;
   int iserr = 0;
 
@@ -886,9 +885,9 @@ build_bp_list (struct breakpoint *b, void *arg)
     iserr = PyList_Append (list, bp);
 
   if (iserr == -1)
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
 /* Static function to return a tuple holding all breakpoints.  */
@@ -906,7 +905,11 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
   /* If iterate_over_breakpoints returns non NULL it signals an error
      condition.  In that case abandon building the list and return
      NULL.  */
-  if (iterate_over_breakpoints (build_bp_list, list.get ()) != NULL)
+  auto callback = [&] (breakpoint *bp)
+    {
+      return build_bp_list(bp, list.get ());
+    };
+  if (iterate_over_breakpoints (callback) != NULL)
     return NULL;
 
   return PyList_AsTuple (list.get ());
index 7784a92bffb1990f87d9e6a59f1dcfd97eca659a..7f818213bd20376fd52a46d4a3df1543d0888b43 100644 (file)
@@ -341,10 +341,10 @@ bpfinishpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj)
 /* Callback for `bpfinishpy_detect_out_scope'.  Triggers Python's
    `B->out_of_scope' function if B is a FinishBreakpoint out of its scope.  */
 
-static int
-bpfinishpy_detect_out_scope_cb (struct breakpoint *b, void *args)
+static bool
+bpfinishpy_detect_out_scope_cb (struct breakpoint *b,
+                               struct breakpoint *bp_stopped)
 {
-  struct breakpoint *bp_stopped = (struct breakpoint *) args;
   PyObject *py_bp = (PyObject *) b->py_bp_object;
 
   /* Trigger out_of_scope if this is a FinishBreakpoint and its frame is
@@ -383,8 +383,11 @@ bpfinishpy_handle_stop (struct bpstats *bs, int print_frame)
 {
   gdbpy_enter enter_py (get_current_arch (), current_language);
 
-  iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb,
-                            bs == NULL ? NULL : bs->breakpoint_at);
+  iterate_over_breakpoints ([&] (breakpoint *bp)
+    {
+      return bpfinishpy_detect_out_scope_cb
+       (bp, bs == NULL ? NULL : bs->breakpoint_at);
+    });
 }
 
 /* Attached to `exit' notifications, triggers all the necessary out of
@@ -395,7 +398,10 @@ bpfinishpy_handle_exit (struct inferior *inf)
 {
   gdbpy_enter enter_py (target_gdbarch (), current_language);
 
-  iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb, NULL);
+  iterate_over_breakpoints ([&] (breakpoint *bp)
+    {
+      return bpfinishpy_detect_out_scope_cb (bp, nullptr);
+    });
 }
 
 /* Initialize the Python finish breakpoint code.  */
index aa4af346b453c8f36a5bdb8c68495170e877f23b..486ae1215b0b3181017daf3b8fb3ac3da7c63136 100644 (file)
@@ -1991,15 +1991,15 @@ svr4_handle_solib_event (void)
 
 /* Helper function for svr4_update_solib_event_breakpoints.  */
 
-static int
-svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
+static bool
+svr4_update_solib_event_breakpoint (struct breakpoint *b)
 {
   struct bp_location *loc;
 
   if (b->type != bp_shlib_event)
     {
       /* Continue iterating.  */
-      return 0;
+      return false;
     }
 
   for (loc = b->loc; loc != NULL; loc = loc->next)
@@ -2027,7 +2027,7 @@ svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
     }
 
   /* Continue iterating.  */
-  return 0;
+  return false;
 }
 
 /* Enable or disable optional solib event breakpoints as appropriate.
@@ -2036,7 +2036,7 @@ svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
 static void
 svr4_update_solib_event_breakpoints (void)
 {
-  iterate_over_breakpoints (svr4_update_solib_event_breakpoint, NULL);
+  iterate_over_breakpoints (svr4_update_solib_event_breakpoint);
 }
 
 /* Create and register solib event breakpoints.  PROBES is an array
This page took 0.04002 seconds and 4 git commands to generate.