From patchwork Wed Aug 30 22:06:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22429 Received: (qmail 116879 invoked by alias); 30 Aug 2017 22:06:29 -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 116832 invoked by uid 89); 30 Aug 2017 22:06:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Aug 2017 22:06:18 +0000 Received: from cmgw4 (cmgw5 [10.0.90.85]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id F3319175B15 for ; Wed, 30 Aug 2017 16:06:16 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id 3a6D1w0142f2jeq01a6GK3; Wed, 30 Aug 2017 16:06:16 -0600 X-Authority-Analysis: v=2.2 cv=G8xsK5s5 c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=6pD0nNTpoQLUKi07WyUA:9 a=zjkKbev9I66YUYfv:21 a=SmrrG-oA0ORcDkeQ:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-124-214.hlrn.qwest.net ([174.16.124.214]:46366 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dnB7l-003h0e-Fw; Wed, 30 Aug 2017 16:06:13 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/3] Use function_view in a couple of places in breakpoint.c Date: Wed, 30 Aug 2017 16:06:09 -0600 Message-Id: <20170830220610.19718-3-tom@tromey.com> In-Reply-To: <20170830220610.19718-1-tom@tromey.com> References: <20170830220610.19718-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dnB7l-003h0e-Fw X-Source-Sender: 174-16-124-214.hlrn.qwest.net (bapiya.localdomain) [174.16.124.214]:46366 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes iterate_over_related_breakpoints and map_breakpoint_numbers to take a function_view. Then, it simplifies the callers by using lambdas. This then allows the removal of some bookkeeping types. ChangeLog 2017-08-30 Tom Tromey * breakpoint.c (struct commands_info, do_map_commands_command): Remove. (commands_command_1): Update. (iterate_over_related_breakpoints): Take a function_view. (do_delete_breakpoint, do_map_delete_breakpoint): Remove. (delete_command): Update. (map_breakpoint_numbers): Take a function_view. (do_disable_breakpoint, do_map_delete_breakpoint): Remove. (disable_command): Update. (do_enable_breakpoint, do_map_enable_breakpoint): Remove. (enable_command): Update. (struct disp_data, do_enable_breakpoint_disp) (do_map_enable_once_breakpoint, do_map_enable_count_breakpoint) (do_map_enable_delete_breakpoint): Remove. (enable_once_command, enable_count_command, enable_delete_command) (delete_trace_variable_command): Update. --- gdb/ChangeLog | 19 ++++ gdb/breakpoint.c | 291 +++++++++++++++++++------------------------------------ 2 files changed, 121 insertions(+), 189 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5baad20..28de155 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,24 @@ 2017-08-30 Tom Tromey + * breakpoint.c (struct commands_info, do_map_commands_command): + Remove. + (commands_command_1): Update. + (iterate_over_related_breakpoints): Take a function_view. + (do_delete_breakpoint, do_map_delete_breakpoint): Remove. + (delete_command): Update. + (map_breakpoint_numbers): Take a function_view. + (do_disable_breakpoint, do_map_delete_breakpoint): Remove. + (disable_command): Update. + (do_enable_breakpoint, do_map_enable_breakpoint): Remove. + (enable_command): Update. + (struct disp_data, do_enable_breakpoint_disp) + (do_map_enable_once_breakpoint, do_map_enable_count_breakpoint) + (do_map_enable_delete_breakpoint): Remove. + (enable_once_command, enable_count_command, enable_delete_command) + (delete_trace_variable_command): Update. + +2017-08-30 Tom Tromey + * breakpoint.c (~bpstats): Rename from bpstat_free. Update. (bpstat_clear): Use delete. (bpstats): New constructors. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 57e8479..fd28f7c 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -103,9 +103,7 @@ static void disable_command (char *, int); static void enable_command (char *, int); static void map_breakpoint_numbers (const char *, - void (*) (struct breakpoint *, - void *), - void *); + gdb::function_view); static void ignore_command (char *, int); @@ -1359,88 +1357,16 @@ check_tracepoint_command (char *line, void *closure) validate_actionline (line, b); } -/* A structure used to pass information through - map_breakpoint_numbers. */ - -struct commands_info -{ - /* True if the command was typed at a tty. */ - int from_tty; - - /* The breakpoint range spec. */ - const char *arg; - - /* Non-NULL if the body of the commands are being read from this - already-parsed command. */ - struct command_line *control; - - /* The command lines read from the user, or NULL if they have not - yet been read. */ - struct counted_command_line *cmd; -}; - -/* A callback for map_breakpoint_numbers that sets the commands for - commands_command. */ - -static void -do_map_commands_command (struct breakpoint *b, void *data) -{ - struct commands_info *info = (struct commands_info *) data; - - if (info->cmd == NULL) - { - command_line_up l; - - if (info->control != NULL) - l = copy_command_lines (info->control->body_list[0]); - else - { - struct cleanup *old_chain; - char *str; - - str = xstrprintf (_("Type commands for breakpoint(s) " - "%s, one per line."), - info->arg); - - old_chain = make_cleanup (xfree, str); - - l = read_command_lines (str, - info->from_tty, 1, - (is_tracepoint (b) - ? check_tracepoint_command : 0), - b); - - do_cleanups (old_chain); - } - - info->cmd = alloc_counted_command_line (l.release ()); - } - - /* If a breakpoint was on the list more than once, we don't need to - do anything. */ - if (b->commands != info->cmd) - { - validate_commands_for_breakpoint (b, info->cmd->commands); - incref_counted_command_line (info->cmd); - decref_counted_command_line (&b->commands); - b->commands = info->cmd; - observer_notify_breakpoint_modified (b); - } -} - static void commands_command_1 (const char *arg, int from_tty, struct command_line *control) { struct cleanup *cleanups; - struct commands_info info; + struct counted_command_line *cmd = NULL; - info.from_tty = from_tty; - info.control = control; - info.cmd = NULL; /* If we read command lines from the user, then `info' will hold an extra reference to the commands that we must clean up. */ - cleanups = make_cleanup_decref_counted_command_line (&info.cmd); + cleanups = make_cleanup_decref_counted_command_line (&cmd); std::string new_arg; @@ -1451,15 +1377,54 @@ commands_command_1 (const char *arg, int from_tty, breakpoint_count); else if (breakpoint_count > 0) new_arg = string_printf ("%d", breakpoint_count); - } - else - new_arg = arg; - - info.arg = new_arg.c_str (); - - map_breakpoint_numbers (info.arg, do_map_commands_command, &info); + arg = new_arg.c_str (); + } + + map_breakpoint_numbers + (arg, [&] (breakpoint *b) + { + if (cmd == NULL) + { + command_line_up l; + + if (control != NULL) + l = copy_command_lines (control->body_list[0]); + else + { + struct cleanup *old_chain; + char *str; + + str = xstrprintf (_("Type commands for breakpoint(s) " + "%s, one per line."), + arg); + + old_chain = make_cleanup (xfree, str); + + l = read_command_lines (str, + from_tty, 1, + (is_tracepoint (b) + ? check_tracepoint_command : 0), + b); + + do_cleanups (old_chain); + } + + cmd = alloc_counted_command_line (l.release ()); + } + + /* If a breakpoint was on the list more than once, we don't need to + do anything. */ + if (b->commands != cmd) + { + validate_commands_for_breakpoint (b, cmd->commands); + incref_counted_command_line (cmd); + decref_counted_command_line (&b->commands); + b->commands = cmd; + observer_notify_breakpoint_modified (b); + } + }); - if (info.cmd == NULL) + if (cmd == NULL) error (_("No breakpoints specified.")); do_cleanups (cleanups); @@ -13727,9 +13692,7 @@ make_cleanup_delete_breakpoint (struct breakpoint *b) static void iterate_over_related_breakpoints (struct breakpoint *b, - void (*function) (struct breakpoint *, - void *), - void *data) + gdb::function_view function) { struct breakpoint *related; @@ -13744,7 +13707,7 @@ iterate_over_related_breakpoints (struct breakpoint *b, if (next == related) { /* RELATED is the last ring entry. */ - function (related, data); + function (related); /* FUNCTION may have deleted it, so we'd never reach back to B. There's nothing left to do anyway, so just break @@ -13752,28 +13715,13 @@ iterate_over_related_breakpoints (struct breakpoint *b, break; } else - function (related, data); + function (related); related = next; } while (related != b); } -static void -do_delete_breakpoint (struct breakpoint *b, void *ignore) -{ - delete_breakpoint (b); -} - -/* A callback for map_breakpoint_numbers that calls - delete_breakpoint. */ - -static void -do_map_delete_breakpoint (struct breakpoint *b, void *ignore) -{ - iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); -} - void delete_command (char *arg, int from_tty) { @@ -13805,7 +13753,11 @@ delete_command (char *arg, int from_tty) } } else - map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); + map_breakpoint_numbers + (arg, [&] (breakpoint *b) + { + iterate_over_related_breakpoints (b, delete_breakpoint); + }); } /* Return true if all locations of B bound to PSPACE are pending. If @@ -14540,9 +14492,7 @@ ignore_command (char *args, int from_tty) static void map_breakpoint_numbers (const char *args, - void (*function) (struct breakpoint *, - void *), - void *data) + gdb::function_view function) { int num; struct breakpoint *b, *tmp; @@ -14568,7 +14518,7 @@ map_breakpoint_numbers (const char *args, if (b->number == num) { match = true; - function (b, data); + function (b); break; } if (!match) @@ -14651,23 +14601,6 @@ disable_breakpoint (struct breakpoint *bpt) observer_notify_breakpoint_modified (bpt); } -/* A callback for iterate_over_related_breakpoints. */ - -static void -do_disable_breakpoint (struct breakpoint *b, void *ignore) -{ - disable_breakpoint (b); -} - -/* A callback for map_breakpoint_numbers that calls - disable_breakpoint. */ - -static void -do_map_disable_breakpoint (struct breakpoint *b, void *ignore) -{ - iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); -} - static void disable_command (char *args, int from_tty) { @@ -14704,7 +14637,11 @@ disable_command (char *args, int from_tty) update_global_location_list (UGLL_DONT_INSERT); } else - map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); + map_breakpoint_numbers + (num, [&] (breakpoint *b) + { + iterate_over_related_breakpoints (b, disable_breakpoint); + }); num = extract_arg (&args); } } @@ -14780,21 +14717,6 @@ enable_breakpoint (struct breakpoint *bpt) enable_breakpoint_disp (bpt, bpt->disposition, 0); } -static void -do_enable_breakpoint (struct breakpoint *bpt, void *arg) -{ - enable_breakpoint (bpt); -} - -/* A callback for map_breakpoint_numbers that calls - enable_breakpoint. */ - -static void -do_map_enable_breakpoint (struct breakpoint *b, void *ignore) -{ - iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); -} - /* The enable command enables the specified breakpoints (or all defined breakpoints) so they once again become (or continue to be) effective in stopping the inferior. */ @@ -14835,49 +14757,28 @@ enable_command (char *args, int from_tty) update_global_location_list (UGLL_MAY_INSERT); } else - map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); + map_breakpoint_numbers + (num, [&] (breakpoint *b) + { + iterate_over_related_breakpoints (b, enable_breakpoint); + }); num = extract_arg (&args); } } } -/* This struct packages up disposition data for application to multiple - breakpoints. */ - -struct disp_data -{ - enum bpdisp disp; - int count; -}; - -static void -do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) -{ - struct disp_data disp_data = *(struct disp_data *) arg; - - enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); -} - -static void -do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) -{ - struct disp_data disp = { disp_disable, 1 }; - - iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); -} - static void enable_once_command (char *args, int from_tty) { - map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); -} - -static void -do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) -{ - struct disp_data disp = { disp_disable, *(int *) countptr }; - - iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); + map_breakpoint_numbers + (args, [&] (breakpoint *b) + { + iterate_over_related_breakpoints + (b, [&] (breakpoint *bpt) + { + enable_breakpoint_disp (bpt, disp_disable, 1); + }); + }); } static void @@ -14890,21 +14791,29 @@ enable_count_command (char *args, int from_tty) count = get_number (&args); - map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); -} - -static void -do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) -{ - struct disp_data disp = { disp_del, 1 }; - - iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); + map_breakpoint_numbers + (args, [&] (breakpoint *b) + { + iterate_over_related_breakpoints + (b, [&] (breakpoint *bpt) + { + enable_breakpoint_disp (bpt, disp_disable, count); + }); + }); } static void enable_delete_command (char *args, int from_tty) { - map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); + map_breakpoint_numbers + (args, [&] (breakpoint *b) + { + iterate_over_related_breakpoints + (b, [&] (breakpoint *bpt) + { + enable_breakpoint_disp (bpt, disp_del, 1); + }); + }); } static void @@ -15304,7 +15213,11 @@ delete_trace_command (char *arg, int from_tty) } } else - map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); + map_breakpoint_numbers + (arg, [&] (breakpoint *b) + { + iterate_over_related_breakpoints (b, delete_breakpoint); + }); } /* Helper function for trace_pass_command. */