From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aCbUFXS8r2C1QAAAWB0awg (envelope-from ) for ; Thu, 27 May 2021 11:36:20 -0400 Received: by simark.ca (Postfix, from userid 112) id 5404E1F11C; Thu, 27 May 2021 11:36:19 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 9BB551F11C for ; Thu, 27 May 2021 11:36:05 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 335433959C1C; Thu, 27 May 2021 15:36:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 335433959C1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622129765; bh=+mB0n6OhRESgP7DGEZkkbQM/9yHukCJtzdT8V1KDQZM=; 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=KCai16FozlPM3oklajxS+5IWSRfN7muuO6TMkuW8gA81DFKkz94SfLMiEn2YP7/Id gqOOx17wIPMgDvgezXp9KWseC7ebCDo+FceHNBqyH/C676wZVDaaesfFUkUC1u2rYR 4lc+CxbaddBA4kxPqZTybcUyyD7WMOE8yRKKGuDw= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 9BE0139574CD for ; Thu, 27 May 2021 15:36:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9BE0139574CD X-ASG-Debug-ID: 1622129759-0c856e67e2122cf60001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 2ZA2Tr7gfcuQz91F (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 27 May 2021 11:36: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 C29DC441D67; Thu, 27 May 2021 11:35:59 -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 3/9] gdb: add all_tracepoints function Date: Thu, 27 May 2021 11:35:52 -0400 X-ASG-Orig-Subj: [PATCH 3/9] gdb: add all_tracepoints function Message-Id: <20210527153558.3016335-4-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: 1622129760 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: 8663 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" Same idea as the previous patches, but to replace the ALL_TRACEPOINTS macro. Define a new filtered_iterator that only keeps the breakpoints for which is_tracepoint returns true (just like the macro did). I would have like to make it so tracepoint_range yields some `tracepoint *` instead of some `breakpoint *`, that would help simplify the callers, who wouldn't have to do the cast themselves. But I didn't find an obvious way to do it. It can always be added later. It turns out there is already an all_tracepoints function, which returns a vector containing all the breakpoints that are tracepoint. Remove it, most users will just work seamlessly with the new function. The exception is start_tracing, which iterated multiple times on the vector. Adapt this one so it iterates multiple times on the returned range. Since the existing users of all_tracepoints are outside of breakpoint.c, this requires defining all_tracepoints and a few supporting types in breakpoint.h. So, move breakpoint_iterator from breakpoint.c to breakpoint.h. gdb/ChangeLog: * breakpoint.h (all_tracepoints): Remove. (breakpoint_iterator): Move here. (struct tracepoint_filter): New. (tracepoint_iterator): New. (tracepoint_range): New. (all_tracepoints): New. * breakpoint.c (ALL_TRACEPOINTS): Remove, replace all users with all_tracepoints. (breakpoint_iterator): Move to header. (all_tracepoints): New. * tracepoint.c (start_tracing): Adjust. Change-Id: I76b1bba4215dbec7a03846c568368aeef7f1e05a --- gdb/breakpoint.c | 55 ++++++++++++------------------------------------ gdb/breakpoint.h | 29 ++++++++++++++++++++++--- gdb/tracepoint.c | 8 +++---- 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 06012c7374ab..eb7fc553f9c4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -514,20 +514,10 @@ bool target_exact_watchpoints = false; && (*BP_LOCP_TMP)->address == ADDRESS); \ BP_LOCP_TMP++) -/* Iterator for tracepoints only. */ - -#define ALL_TRACEPOINTS(B) \ - for (B = breakpoint_chain; B; B = B->next) \ - if (is_tracepoint (B)) - /* Chains of all breakpoints defined. */ static struct breakpoint *breakpoint_chain; -/* Breakpoint linked list iterator. */ - -using breakpoint_iterator = next_iterator; - /* Breakpoint linked list range. */ using breakpoint_range = next_adapter; @@ -554,6 +544,14 @@ all_breakpoints_safe () return breakpoint_safe_range (all_breakpoints ()); } +/* See breakpoint.h. */ + +tracepoint_range +all_tracepoints () +{ + return tracepoint_range (breakpoint_chain); +} + /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ static struct bp_location **bp_locations; @@ -11714,12 +11712,11 @@ bp_locations_target_extensions_update (void) static void download_tracepoint_locations (void) { - struct breakpoint *b; enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; scoped_restore_current_pspace_and_thread restore_pspace_thread; - ALL_TRACEPOINTS (b) + for (breakpoint *b : all_tracepoints ()) { struct bp_location *bl; struct tracepoint *t; @@ -14910,13 +14907,12 @@ delete_trace_command (const char *arg, int from_tty) if (arg == 0) { int breaks_to_delete = 0; - breakpoint *tp; /* Delete all breakpoints if no argument. Do not delete internal or call-dummy breakpoints, these have to be deleted with an explicit breakpoint number argument. */ - ALL_TRACEPOINTS (tp) + for (breakpoint *tp : all_tracepoints ()) if (is_tracepoint (tp) && user_breakpoint_p (tp)) { breaks_to_delete = 1; @@ -14973,13 +14969,11 @@ trace_pass_command (const char *args, int from_tty) args = skip_spaces (args); if (*args && strncasecmp (args, "all", 3) == 0) { - struct breakpoint *b; - args += 3; /* Skip special argument "all". */ if (*args) error (_("Junk at end of arguments.")); - ALL_TRACEPOINTS (b) + for (breakpoint *b : all_tracepoints ()) { t1 = (struct tracepoint *) b; trace_pass_set_count (t1, count, from_tty); @@ -15006,9 +15000,7 @@ trace_pass_command (const char *args, int from_tty) struct tracepoint * get_tracepoint (int num) { - struct breakpoint *t; - - ALL_TRACEPOINTS (t) + for (breakpoint *t : all_tracepoints ()) if (t->number == num) return (struct tracepoint *) t; @@ -15022,9 +15014,7 @@ get_tracepoint (int num) struct tracepoint * get_tracepoint_by_number_on_target (int num) { - struct breakpoint *b; - - ALL_TRACEPOINTS (b) + for (breakpoint *b : all_tracepoints ()) { struct tracepoint *t = (struct tracepoint *) b; @@ -15044,7 +15034,6 @@ struct tracepoint * get_tracepoint_by_number (const char **arg, number_or_range_parser *parser) { - struct breakpoint *t; int tpnum; const char *instring = arg == NULL ? NULL : *arg; @@ -15068,7 +15057,7 @@ get_tracepoint_by_number (const char **arg, return NULL; } - ALL_TRACEPOINTS (t) + for (breakpoint *t : all_tracepoints ()) if (t->number == tpnum) { return (struct tracepoint *) t; @@ -15225,22 +15214,6 @@ save_tracepoints_command (const char *args, int from_tty) save_breakpoints (args, from_tty, is_tracepoint); } -/* Create a vector of all tracepoints. */ - -std::vector -all_tracepoints (void) -{ - std::vector tp_vec; - struct breakpoint *tp; - - ALL_TRACEPOINTS (tp) - { - tp_vec.push_back (tp); - } - - return tp_vec; -} - /* This help string is used to consolidate all the help string for specifying locations used by several commands. */ diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 54c5e423e10a..5a10839603d7 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -28,6 +28,7 @@ #include "location.h" #include #include "gdbsupport/array-view.h" +#include "gdbsupport/filtered-iterator.h" #include "gdbsupport/function-view.h" #include "gdbsupport/refcounted-object.h" #include "cli/cli-script.h" @@ -1683,9 +1684,6 @@ extern struct tracepoint * get_tracepoint_by_number (const char **arg, number_or_range_parser *parser); -/* Return a vector of all tracepoints currently defined. */ -extern std::vector all_tracepoints (void); - /* Return true if B is of tracepoint kind. */ extern bool is_tracepoint (const struct breakpoint *b); @@ -1717,6 +1715,31 @@ class scoped_rbreak_breakpoints extern struct breakpoint *iterate_over_breakpoints (gdb::function_view); +/* Breakpoint linked list iterator. */ + +using breakpoint_iterator = next_iterator; + +/* Breakpoint filter to only keep tracepoints. */ + +struct tracepoint_filter +{ + bool operator() (breakpoint *b) + { return is_tracepoint (b); } +}; + +/* Breakpoint linked list iterator, filtering to only keep tracepoints. */ + +using tracepoint_iterator + = filtered_iterator; + +/* Breakpoint linked list range, filtering to only keep tracepoints. */ + +using tracepoint_range = next_adapter; + +/* Return a range to iterate over all tracepoints. */ + +tracepoint_range all_tracepoints (); + /* Nonzero if the specified PC cannot be a location where functions have been inlined. */ diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index da0e976c8694..863fb6d34d8d 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -1603,13 +1603,13 @@ start_tracing (const char *notes) int any_enabled = 0, num_to_download = 0; int ret; - std::vector tp_vec = all_tracepoints (); + auto tracepoint_range = all_tracepoints (); /* No point in tracing without any tracepoints... */ - if (tp_vec.empty ()) + if (tracepoint_range.begin () == tracepoint_range.end ()) error (_("No tracepoints defined, not starting trace")); - for (breakpoint *b : tp_vec) + for (breakpoint *b : tracepoint_range) { if (b->enable_state == bp_enabled) any_enabled = 1; @@ -1640,7 +1640,7 @@ start_tracing (const char *notes) target_trace_init (); - for (breakpoint *b : tp_vec) + for (breakpoint *b : tracepoint_range) { struct tracepoint *t = (struct tracepoint *) b; struct bp_location *loc; -- 2.31.1