From patchwork Tue Oct 15 13:31:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 34981 Received: (qmail 736 invoked by alias); 15 Oct 2019 13:31:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 689 invoked by uid 89); 15 Oct 2019 13:31:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2019 13:31:11 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 0B7F8208EF; Tue, 15 Oct 2019 09:31:10 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 266C220806; Tue, 15 Oct 2019 09:31:05 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 0110229ECF; Tue, 15 Oct 2019 09:31:04 -0400 (EDT) X-Gerrit-PatchSet: 4 Date: Tue, 15 Oct 2019 09:31:04 -0400 From: "Sourceware to Gerrit sync (Code Review)" To: Christian Biesinger , Simon Marchi , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: Change in binutils-gdb[master]: Change iterate_over_breakpoints to take a function_view X-Gerrit-Change-Id: Ia9de4deecae562a70a40f5cd49f5a74d64570251 X-Gerrit-Change-Number: 21 X-Gerrit-ChangeURL: X-Gerrit-Commit: 95da600f404ca159242f49441d9b4ea78183852b In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, simon.marchi@polymtl.ca, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191015133105.0110229ECF@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has uploaded a new patch set version (#4) to the change originally created by Christian Biesinger. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/21 ...................................................................... Change iterate_over_breakpoints to take a function_view This allows callers to pass in capturing lambdas. Also changes the return type to bool. gdb/ChangeLog: 2019-10-15 Christian Biesinger * 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 --- M gdb/ChangeLog M gdb/breakpoint.c M gdb/breakpoint.h M gdb/dummy-frame.c M gdb/guile/scm-breakpoint.c M gdb/python/py-breakpoint.c M gdb/python/py-finishbreakpoint.c M gdb/solib-svr4.c 8 files changed, 64 insertions(+), 38 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 21d5233..39a8374 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,21 @@ +2019-10-15 Christian Biesinger + + * 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 * s390-tdep.c (s390_effective_inner_type): Ignore static fields diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 31f4005..9bbb28f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -15128,14 +15128,13 @@ } struct breakpoint * -iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), - void *data) +iterate_over_breakpoints (gdb::function_view callback) { struct breakpoint *b, *b_tmp; ALL_BREAKPOINTS_SAFE (b, b_tmp) { - if ((*callback) (b, data)) + if (callback (b)) return b; } diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 9791032..7472c0e 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -29,6 +29,7 @@ #include "location.h" #include #include "gdbsupport/array-view.h" +#include "gdbsupport/function-view.h" #include "cli/cli-script.h" struct block; @@ -1664,8 +1665,8 @@ 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); /* Nonzero if the specified PC cannot be a location where functions have been inlined. */ diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index d3ede7c..3b76d45 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -126,11 +126,9 @@ /* 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 @@ 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 @@ 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. */ diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 9a4efee..a75daa0 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -505,10 +505,9 @@ /* 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 @@ if (bp_smob != NULL) *list = scm_cons (bp_smob->containing_scm, *list); - return 0; + return false; } /* (breakpoints) -> list @@ -545,11 +544,10 @@ { 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); } diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 698d91e..65cb29f 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -871,10 +871,9 @@ -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 @@ 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 @@ /* 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 ()); diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 7784a92..7f81821 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -341,10 +341,10 @@ /* 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 @@ { 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 @@ { 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. */ diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index aa4af34..486ae12 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1991,15 +1991,15 @@ /* 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 @@ } /* Continue iterating. */ - return 0; + return false; } /* Enable or disable optional solib event breakpoints as appropriate. @@ -2036,7 +2036,7 @@ 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