From patchwork Wed Aug 30 22:06:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22430 Received: (qmail 117810 invoked by alias); 30 Aug 2017 22:06:35 -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 117777 invoked by uid 89); 30 Aug 2017 22:06:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=TRY X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Aug 2017 22:06:18 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id 95F351E06B1 for ; Wed, 30 Aug 2017 16:06:17 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 3a6E1w00c2f2jeq01a6Hq7; Wed, 30 Aug 2017 16:06:17 -0600 X-Authority-Analysis: v=2.2 cv=IspuSP3g c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=gxdDHOyOSJnp0NH32VkA:9 a=U9Ev2xO6AMlwnmG6:21 a=UdebdXGPZdhdNmxO: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 1dnB7m-003h0e-2o; Wed, 30 Aug 2017 16:06:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/3] Change counted_command_line to a shared_ptr Date: Wed, 30 Aug 2017 16:06:10 -0600 Message-Id: <20170830220610.19718-4-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: 1dnB7m-003h0e-2o 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: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes counted_command_line to be a typedef for std::shared_ptr and removes the associated cleanups. In the long run I believe that cmd_list_element should also be changed to use a shared_ptr. ChangeLog 2017-08-30 Tom Tromey * breakpoint.c (struct counted_command_line): Remove. (breakpoint_commands): Update. (alloc_counted_command_line, incref_counted_command_line) (decref_counted_command_line, do_cleanup_counted_command_line) (make_cleanup_decref_counted_command_line): Remove. (breakpoint_set_commands, commands_command_1, ~bpstats, bpstats) (bpstat_clear_actions, bpstat_do_actions_1, watchpoint_check) (bpstat_stop_status, print_one_breakpoint_location, ~breakpoint) (save_breakpoints): Update. * breakpoint.h (counted_command_line): Now a typedef to shared_ptr. (struct breakpoint) : Now a counted_command_line. (struct bpstats) : Likewise. --- gdb/ChangeLog | 16 +++++++ gdb/breakpoint.c | 130 ++++++++----------------------------------------------- gdb/breakpoint.h | 9 ++-- 3 files changed, 39 insertions(+), 116 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 28de155..0816cdd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,21 @@ 2017-08-30 Tom Tromey + * breakpoint.c (struct counted_command_line): Remove. + (breakpoint_commands): Update. + (alloc_counted_command_line, incref_counted_command_line) + (decref_counted_command_line, do_cleanup_counted_command_line) + (make_cleanup_decref_counted_command_line): Remove. + (breakpoint_set_commands, commands_command_1, ~bpstats, bpstats) + (bpstat_clear_actions, bpstat_do_actions_1, watchpoint_check) + (bpstat_stop_status, print_one_breakpoint_location, ~breakpoint) + (save_breakpoints): Update. + * breakpoint.h (counted_command_line): Now a typedef to + shared_ptr. + (struct breakpoint) : Now a counted_command_line. + (struct bpstats) : Likewise. + +2017-08-30 Tom Tromey + * breakpoint.c (struct commands_info, do_map_commands_command): Remove. (commands_command_1): Update. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index fd28f7c..72de69a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -358,21 +358,10 @@ static char *dprintf_channel; has disconnected. */ static int disconnected_dprintf = 1; -/* A reference-counted struct command_line. This lets multiple - breakpoints share a single command list. */ -struct counted_command_line -{ - /* The reference count. */ - int refc; - - /* The command list. */ - struct command_line *commands; -}; - struct command_line * breakpoint_commands (struct breakpoint *b) { - return b->commands ? b->commands->commands : NULL; + return b->commands ? b->commands.get () : NULL; } /* Flag indicating that a command has proceeded the inferior past the @@ -718,64 +707,6 @@ clear_breakpoint_hit_counts (void) b->hit_count = 0; } -/* Allocate a new counted_command_line with reference count of 1. - The new structure owns COMMANDS. */ - -static struct counted_command_line * -alloc_counted_command_line (struct command_line *commands) -{ - struct counted_command_line *result = XNEW (struct counted_command_line); - - result->refc = 1; - result->commands = commands; - - return result; -} - -/* Increment reference count. This does nothing if CMD is NULL. */ - -static void -incref_counted_command_line (struct counted_command_line *cmd) -{ - if (cmd) - ++cmd->refc; -} - -/* Decrement reference count. If the reference count reaches 0, - destroy the counted_command_line. Sets *CMDP to NULL. This does - nothing if *CMDP is NULL. */ - -static void -decref_counted_command_line (struct counted_command_line **cmdp) -{ - if (*cmdp) - { - if (--(*cmdp)->refc == 0) - { - free_command_lines (&(*cmdp)->commands); - xfree (*cmdp); - } - *cmdp = NULL; - } -} - -/* A cleanup function that calls decref_counted_command_line. */ - -static void -do_cleanup_counted_command_line (void *arg) -{ - decref_counted_command_line ((struct counted_command_line **) arg); -} - -/* Create a cleanup that calls decref_counted_command_line on the - argument. */ - -static struct cleanup * -make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) -{ - return make_cleanup (do_cleanup_counted_command_line, cmdp); -} - /* Return the breakpoint with the specified number, or NULL if the number does not refer to an existing breakpoint. */ @@ -1304,8 +1235,7 @@ breakpoint_set_commands (struct breakpoint *b, { validate_commands_for_breakpoint (b, commands.get ()); - decref_counted_command_line (&b->commands); - b->commands = alloc_counted_command_line (commands.release ()); + b->commands = std::move (commands); observer_notify_breakpoint_modified (b); } @@ -1361,12 +1291,7 @@ static void commands_command_1 (const char *arg, int from_tty, struct command_line *control) { - struct cleanup *cleanups; - struct counted_command_line *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 (&cmd); + counted_command_line cmd; std::string new_arg; @@ -1385,10 +1310,8 @@ commands_command_1 (const char *arg, int from_tty, { if (cmd == NULL) { - command_line_up l; - if (control != NULL) - l = copy_command_lines (control->body_list[0]); + cmd = copy_command_lines (control->body_list[0]); else { struct cleanup *old_chain; @@ -1400,25 +1323,21 @@ commands_command_1 (const char *arg, int from_tty, old_chain = make_cleanup (xfree, str); - l = read_command_lines (str, - from_tty, 1, - (is_tracepoint (b) - ? check_tracepoint_command : 0), - b); + cmd = 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); + validate_commands_for_breakpoint (b, cmd.get ()); b->commands = cmd; observer_notify_breakpoint_modified (b); } @@ -1426,8 +1345,6 @@ commands_command_1 (const char *arg, int from_tty, if (cmd == NULL) error (_("No breakpoints specified.")); - - do_cleanups (cleanups); } static void @@ -4428,7 +4345,6 @@ bpstats::~bpstats () { if (old_val != NULL) value_free (old_val); - decref_counted_command_line (&commands); if (bp_location_at != NULL) decref_bp_location (&bp_location_at); } @@ -4470,7 +4386,6 @@ bpstats::bpstats (const bpstats &other) release_value (old_val); } incref_bp_location (bp_location_at); - incref_counted_command_line (commands); } /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that @@ -4589,7 +4504,7 @@ bpstat_clear_actions (void) for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) { - decref_counted_command_line (&bs->commands); + bs->commands = NULL; if (bs->old_val != NULL) { @@ -4668,9 +4583,7 @@ bpstat_do_actions_1 (bpstat *bsp) breakpoint_proceeded = 0; for (; bs != NULL; bs = bs->next) { - struct counted_command_line *ccmd; - struct command_line *cmd; - struct cleanup *this_cmd_tree_chain; + struct command_line *cmd = NULL; /* Take ownership of the BSP's command tree, if it has one. @@ -4682,10 +4595,10 @@ bpstat_do_actions_1 (bpstat *bsp) commands are only executed once, we don't need to copy it; we can clear the pointer in the bpstat, and make sure we free the tree when we're done. */ - ccmd = bs->commands; + counted_command_line ccmd = bs->commands; bs->commands = NULL; - this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); - cmd = ccmd ? ccmd->commands : NULL; + if (ccmd != NULL) + cmd = ccmd.get (); if (command_line_is_silent (cmd)) { /* The action has been already done by bpstat_stop_status. */ @@ -4702,9 +4615,6 @@ bpstat_do_actions_1 (bpstat *bsp) cmd = cmd->next; } - /* We can free this command tree now. */ - do_cleanups (this_cmd_tree_chain); - if (breakpoint_proceeded) { if (current_ui->async) @@ -5240,7 +5150,7 @@ watchpoint_check (void *p) } /* Make sure the watchpoint's commands aren't executed. */ - decref_counted_command_line (&b->commands); + b->commands = NULL; watchpoint_del_at_next_stop (b); return WP_DELETED; @@ -5730,9 +5640,8 @@ bpstat_stop_status (struct address_space *aspace, if (b->silent) bs->print = 0; bs->commands = b->commands; - incref_counted_command_line (bs->commands); if (command_line_is_silent (bs->commands - ? bs->commands->commands : NULL)) + ? bs->commands.get () : NULL)) bs->print = 0; b->ops->after_condition_true (bs); @@ -6595,7 +6504,7 @@ print_one_breakpoint_location (struct breakpoint *b, } } - l = b->commands ? b->commands->commands : NULL; + l = b->commands ? b->commands.get () : NULL; if (!part_of_multiple && l) { annotate_field (9); @@ -12674,7 +12583,6 @@ static const struct bp_location_ops bp_location_ops = breakpoint::~breakpoint () { - decref_counted_command_line (&this->commands); xfree (this->cond_string); xfree (this->extra_string); xfree (this->filter); @@ -15454,7 +15362,7 @@ save_breakpoints (char *filename, int from_tty, current_uiout->redirect (&fp); TRY { - print_command_lines (current_uiout, tp->commands->commands, 2); + print_command_lines (current_uiout, tp->commands.get (), 2); } CATCH (ex, RETURN_MASK_ALL) { diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index f3c0961..ae7547e 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -655,10 +655,9 @@ enum watchpoint_triggered typedef struct bp_location *bp_location_p; DEF_VEC_P(bp_location_p); -/* A reference-counted struct command_line. This lets multiple - breakpoints share a single command list. This is an implementation +/* A reference-counted struct command_line. This is an implementation detail to the breakpoints module. */ -struct counted_command_line; +typedef std::shared_ptr counted_command_line; /* Some targets (e.g., embedded PowerPC) need two debug registers to set a watchpoint over a memory region. If this flag is true, GDB will use @@ -710,7 +709,7 @@ struct breakpoint /* Chain of command lines to execute when this breakpoint is hit. */ - counted_command_line *commands = NULL; + counted_command_line commands; /* Stack depth (address of frame). If nonzero, break only if fp equals this. */ struct frame_id frame_id = null_frame_id; @@ -1116,7 +1115,7 @@ struct bpstats struct breakpoint *breakpoint_at; /* The associated command list. */ - struct counted_command_line *commands; + counted_command_line commands; /* Old value associated with a watchpoint. */ struct value *old_val;