+2021-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * breakpoint.h (iterate_over_breakpoints): Remove.  Update
+       callers to use all_breakpoints or all_breakpoints_safe.
+       (breakpoint_range, all_breakpoints, breakpoint_safe_range,
+       all_breakpoints_safe): Move here.
+       * breakpoint.c (all_breakpoints, all_breakpoints_safe): Make
+       non-static.
+       (iterate_over_breakpoints): Remove.
+       * python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb):
+       Return void.
+       * python/py-breakpoint.c (build_bp_list): Add comment, reverse
+       return value logic.
+       * guile/scm-breakpoint.c (bpscm_build_bp_list): Return void.
+
 2021-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * breakpoint.c (get_first_locp_gte_addr): Remove.
 
 
 static struct breakpoint *breakpoint_chain;
 
-/* Breakpoint linked list range.  */
-
-using breakpoint_range = next_adapter<breakpoint, breakpoint_iterator>;
-
-/* Return a range to iterate over all breakpoints.  */
+/* See breakpoint.h.  */
 
-static breakpoint_range
+breakpoint_range
 all_breakpoints ()
 {
   return breakpoint_range (breakpoint_chain);
 }
 
-/* Breakpoint linked list range, safe against deletion of the current
-   breakpoint while iterating.  */
-
-using breakpoint_safe_range = basic_safe_range<breakpoint_range>;
-
-/* Return a range to iterate over all breakpoints.  This range is safe against
-   deletion of the current breakpoint while iterating.  */
+/* See breakpoint.h.  */
 
-static breakpoint_safe_range
+breakpoint_safe_range
 all_breakpoints_safe ()
 {
   return breakpoint_safe_range (all_breakpoints ());
   set_cmd_completer (command, completer);
 }
 
-struct breakpoint *
-iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback)
-{
-  for (breakpoint *b : all_breakpoints_safe ())
-    if (callback (b))
-      return b;
-
-  return NULL;
-}
-
 /* Zero if any of the breakpoint's locations could be a location where
    functions have been inlined, nonzero otherwise.  */
 
 
 #include "gdbsupport/filtered-iterator.h"
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/refcounted-object.h"
+#include "gdbsupport/safe-iterator.h"
 #include "cli/cli-script.h"
 
 struct block;
   DISABLE_COPY_AND_ASSIGN (scoped_rbreak_breakpoints);
 };
 
-/* Breakpoint iterator function.
-
-   Calls a callback function once for each breakpoint, so long as the
-   callback function returns false.  If the callback function returns
-   true, the iteration will end and the current breakpoint will be
-   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
-  (gdb::function_view<bool (breakpoint *)>);
-
 /* Breakpoint linked list iterator.  */
 
 using breakpoint_iterator = next_iterator<breakpoint>;
 
+/* Breakpoint linked list range.  */
+
+using breakpoint_range = next_adapter<breakpoint, breakpoint_iterator>;
+
+/* Return a range to iterate over all breakpoints.  */
+
+breakpoint_range all_breakpoints ();
+
+/* Breakpoint linked list range, safe against deletion of the current
+   breakpoint while iterating.  */
+
+using breakpoint_safe_range = basic_safe_range<breakpoint_range>;
+
+/* Return a range to iterate over all breakpoints.  This range is safe against
+   deletion of the current breakpoint while iterating.  */
+
+breakpoint_safe_range all_breakpoints_safe ();
+
 /* Breakpoint filter to only keep tracepoints.  */
 
 struct tracepoint_filter
 
 
   restore_infcall_suspend_state (dummy->caller_state);
 
-  iterate_over_breakpoints ([dummy] (breakpoint* bp)
-    {
-      return pop_dummy_frame_bpt (bp, dummy);
-    });
+  for (breakpoint *bp : all_breakpoints_safe ())
+    if (pop_dummy_frame_bpt (bp, dummy))
+      break;
 
   /* restore_infcall_control_state frees inf_state,
      all that remains is to pop *dummy_ptr.  */
 
 
 /* iterate_over_breakpoints function for gdbscm_breakpoints.  */
 
-static bool
+static void
 bpscm_build_bp_list (struct breakpoint *bp, SCM *list)
 {
   breakpoint_smob *bp_smob = bp->scm_bp_object;
 
   if (bp_smob != NULL)
     *list = scm_cons (bp_smob->containing_scm, *list);
-
-  return false;
 }
 
 /* (breakpoints) -> list
 {
   SCM list = SCM_EOL;
 
-  iterate_over_breakpoints ([&] (breakpoint *bp)
-    {
-      return bpscm_build_bp_list(bp, &list);
-    });
+  for (breakpoint *bp : all_breakpoints ())
+    bpscm_build_bp_list (bp, &list);
 
   return scm_reverse_x (list, SCM_EOL);
 }
 
   return 0;
 }
 
-\f
+/* Append to LIST the breakpoint Python object associated to B.
+
+   Return true on success.  Return false on failure, with the Python error
+   indicator set.  */
 
 static bool
 build_bp_list (struct breakpoint *b, PyObject *list)
 {
   PyObject *bp = (PyObject *) b->py_bp_object;
-  int iserr = 0;
 
   /* Not all breakpoints will have a companion Python object.
      Only breakpoints that were created via bppy_new, or
      breakpoints that were created externally and are tracked by
      the Python Scripting API.  */
-  if (bp)
-    iserr = PyList_Append (list, bp);
-
-  if (iserr == -1)
+  if (bp == nullptr)
     return true;
 
-  return false;
+  return PyList_Append (list, bp) == 0;
 }
 
 /* Static function to return a tuple holding all breakpoints.  */
   if (list == NULL)
     return NULL;
 
-  /* If iterate_over_breakpoints returns non NULL it signals an error
-     condition.  In that case abandon building the list and return
-     NULL.  */
-  auto callback = [&] (breakpoint *bp)
-    {
-      return build_bp_list(bp, list.get ());
-    };
-  if (iterate_over_breakpoints (callback) != NULL)
-    return NULL;
+  /* If build_bp_list returns false, it signals an error condition.  In that
+     case abandon building the list and return nullptr.  */
+  for (breakpoint *bp : all_breakpoints ())
+    if (!build_bp_list (bp, list.get ()))
+      return nullptr;
 
   return PyList_AsTuple (list.get ());
 }
 
 /* Callback for `bpfinishpy_detect_out_scope'.  Triggers Python's
    `B->out_of_scope' function if B is a FinishBreakpoint out of its scope.  */
 
-static bool
+static void
 bpfinishpy_detect_out_scope_cb (struct breakpoint *b,
                                struct breakpoint *bp_stopped)
 {
            }
        }
     }
-
-  return 0;
 }
 
 /* Attached to `stop' notifications, check if the execution has run
 {
   gdbpy_enter enter_py (get_current_arch (), current_language);
 
-  iterate_over_breakpoints ([&] (breakpoint *bp)
-    {
-      return bpfinishpy_detect_out_scope_cb
-       (bp, bs == NULL ? NULL : bs->breakpoint_at);
-    });
+  for (breakpoint *bp : all_breakpoints_safe ())
+    bpfinishpy_detect_out_scope_cb (bp, bs == NULL ? NULL : bs->breakpoint_at);
 }
 
 /* Attached to `exit' notifications, triggers all the necessary out of
 {
   gdbpy_enter enter_py (target_gdbarch (), current_language);
 
-  iterate_over_breakpoints ([&] (breakpoint *bp)
-    {
-      return bpfinishpy_detect_out_scope_cb (bp, nullptr);
-    });
+  for (breakpoint *bp : all_breakpoints_safe ())
+    bpfinishpy_detect_out_scope_cb (bp, nullptr);
 }
 
 /* Initialize the Python finish breakpoint code.  */
 
 static void
 svr4_update_solib_event_breakpoints (void)
 {
-  iterate_over_breakpoints (svr4_update_solib_event_breakpoint);
+  for (breakpoint *bp : all_breakpoints_safe ())
+    svr4_update_solib_event_breakpoint (bp);
 }
 
 /* Create and register solib event breakpoints.  PROBES is an array
 
         do with it.  Identify enable/disabled breakpoints as well as
         those that we already hit.  */
       tui_bp_flags mode = 0;
-      iterate_over_breakpoints ([&] (breakpoint *bp) -> bool
+      for (breakpoint *bp : all_breakpoints ())
        {
          if (bp == being_deleted)
            return false;
                }
            }
          return false;
-       });
+       }
+
       if (line->break_mode != mode)
        {
          line->break_mode = mode;