diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-05-27 14:58:37 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-05-27 14:58:37 -0400 |
commit | 240edef62f0cb5c6cb3dc6da9e35bd8f8af69e01 (patch) | |
tree | 9ca7198bcd8aae2d843b9eaa4599a6cb9cebeb07 /gdb/python | |
parent | e0d9a2704073d93b413dfa80fbb29f206ecb3762 (diff) | |
download | gdb-240edef62f0cb5c6cb3dc6da9e35bd8f8af69e01.zip gdb-240edef62f0cb5c6cb3dc6da9e35bd8f8af69e01.tar.gz gdb-240edef62f0cb5c6cb3dc6da9e35bd8f8af69e01.tar.bz2 |
gdb: remove iterate_over_breakpoints function
Now that we have range functions that let us use ranged for loops, we
can remove iterate_over_breakpoints in favor of those, which are easier
to read and write. This requires exposing the declaration of
all_breakpoints and all_breakpoints_safe in breakpoint.h, as well as the
supporting types.
Change some users of iterate_over_breakpoints to use all_breakpoints,
when they don't need to delete the breakpoint, and all_breakpoints_safe
otherwise.
gdb/ChangeLog:
* 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.
Change-Id: Idde764a1f577de0423e4f2444a7d5cdb01ba5e48
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-breakpoint.c | 27 | ||||
-rw-r--r-- | gdb/python/py-finishbreakpoint.c | 17 |
2 files changed, 16 insertions, 28 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 4710f3e..a2ce4cd 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -898,25 +898,24 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) return 0; } - +/* 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. */ @@ -931,15 +930,11 @@ gdbpy_breakpoints (PyObject *self, PyObject *args) 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 ()); } diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index d2a1ec4..1d8373d 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -342,7 +342,7 @@ 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 bool +static void bpfinishpy_detect_out_scope_cb (struct breakpoint *b, struct breakpoint *bp_stopped) { @@ -372,8 +372,6 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b, } } } - - return 0; } /* Attached to `stop' notifications, check if the execution has run @@ -384,11 +382,8 @@ bpfinishpy_handle_stop (struct bpstats *bs, int print_frame) { 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 @@ -399,10 +394,8 @@ bpfinishpy_handle_exit (struct inferior *inf) { 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. */ |