From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GD/8JN68r2D2QAAAWB0awg (envelope-from ) for ; Thu, 27 May 2021 11:38:06 -0400 Received: by simark.ca (Postfix, from userid 112) id 94BEA1F11C; Thu, 27 May 2021 11:38:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F01231EE0E for ; Thu, 27 May 2021 11:38:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E91E39574CD; Thu, 27 May 2021 15:38:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E91E39574CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622129884; bh=GANrGoyIsVNYrAAuxQJcWt4QZtoiEa6XuT5KxV65agY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pU8D1kbwtfpQ1cWpSxs20cjJcpzJzMxFVjONBKWoPBiRELu1GhrfxHqrKOYrhvCUt I//kN/QaqRHZyCyxMHhEeQcZpzAxnjA14+nDJtnSqMK92f7F8Moz6XzSQ4mRWm2exv zCuQ7zgCFqVsboKk6sIp2yEfrCAcx1PJHGz5r+rQ= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 2AB393857C77 for ; Thu, 27 May 2021 15:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2AB393857C77 X-ASG-Debug-ID: 1622129880-0c856e67e2122d280001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id CRTev5F1gX3VSHEn (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 27 May 2021 11:38:00 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 43A79441B21; Thu, 27 May 2021 11:38:00 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 8/9] gdb: remove iterate_over_breakpoints function Date: Thu, 27 May 2021 11:35:57 -0400 X-ASG-Orig-Subj: [PATCH 8/9] gdb: remove iterate_over_breakpoints function Message-Id: <20210527153558.3016335-9-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527153558.3016335-1-simon.marchi@polymtl.ca> References: <20210527153558.3016335-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1622129880 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 11441 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.90234 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 --- gdb/breakpoint.c | 28 ++++------------------------ gdb/breakpoint.h | 30 +++++++++++++++++++----------- gdb/dummy-frame.c | 7 +++---- gdb/guile/scm-breakpoint.c | 10 +++------- gdb/python/py-breakpoint.c | 27 +++++++++++---------------- gdb/python/py-finishbreakpoint.c | 17 +++++------------ gdb/solib-svr4.c | 3 ++- gdb/tui/tui-winsource.c | 5 +++-- 8 files changed, 50 insertions(+), 77 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 79f82f29dff3..751ed51cc7d3 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -493,27 +493,17 @@ bool target_exact_watchpoints = false; static struct breakpoint *breakpoint_chain; -/* Breakpoint linked list range. */ - -using breakpoint_range = next_adapter; - -/* 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; - -/* 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 ()); @@ -15191,16 +15181,6 @@ add_catch_command (const char *name, const char *docstring, set_cmd_completer (command, completer); } -struct breakpoint * -iterate_over_breakpoints (gdb::function_view 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. */ diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index f31498a54eb8..ffe042459eef 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -31,6 +31,7 @@ #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; @@ -1711,21 +1712,28 @@ class scoped_rbreak_breakpoints 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); - /* Breakpoint linked list iterator. */ using breakpoint_iterator = next_iterator; +/* Breakpoint linked list range. */ + +using breakpoint_range = next_adapter; + +/* 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; + +/* 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 diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index 155dec377f34..68a693797492 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -166,10 +166,9 @@ pop_dummy_frame (struct dummy_frame **dummy_ptr) 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. */ diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 826dfa9b0a38..4ff197e48a45 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -508,7 +508,7 @@ gdbscm_delete_breakpoint_x (SCM self) /* 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; @@ -535,8 +535,6 @@ bpscm_build_bp_list (struct breakpoint *bp, SCM *list) if (bp_smob != NULL) *list = scm_cons (bp_smob->containing_scm, *list); - - return false; } /* (breakpoints) -> list @@ -547,10 +545,8 @@ gdbscm_breakpoints (void) { 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); } diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 4710f3e9e6a6..a2ce4cdd06fd 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 d2a1ec4fa98e..1d8373d807ed 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. */ diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 2642e1ad2fdb..a8a7d1171dc6 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2059,7 +2059,8 @@ svr4_update_solib_event_breakpoint (struct breakpoint *b) 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 diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 738f69156485..afd51e95980c 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -457,7 +457,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; - iterate_over_breakpoints ([&] (breakpoint *bp) -> bool + for (breakpoint *bp : all_breakpoints ()) { if (bp == being_deleted) return false; @@ -479,7 +479,8 @@ tui_source_window_base::update_breakpoint_info } } return false; - }); + } + if (line->break_mode != mode) { line->break_mode = mode; -- 2.31.1