From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116742 invoked by alias); 30 Aug 2017 22:06:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 116558 invoked by uid 89); 30 Aug 2017 22:06:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 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= 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:17 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id 540631E0759 for ; Wed, 30 Aug 2017 16:06:16 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 3a6D1w0042f2jeq01a6GlE; Wed, 30 Aug 2017 16:06:16 -0600 X-Authority-Analysis: v=2.2 cv=fJ5J5dSe c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=6I5d2MoRAAAA:8 a=KDqz63Fc_M-E5tg7CIMA:9 a=hUFMwu3Guf8Zqy_q:21 a=zqX3L4xq_I9K_eYI:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=IjZwj45LgO3ly-622nXo: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-0P; Wed, 30 Aug 2017 16:06:13 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/3] Allocate bpstats with new Date: Wed, 30 Aug 2017 22:06:00 -0000 Message-Id: <20170830220610.19718-2-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-0P 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: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-08/txt/msg00536.txt.bz2 This changes struct bpstats to be allocated with new and freed with delete, adding constructors and a destructor in the process. This allows the removal of one cleanup and clears the way for more to follow. ChangeLog 2017-08-30 Tom Tromey * breakpoint.c (~bpstats): Rename from bpstat_free. Update. (bpstat_clear): Use delete. (bpstats): New constructors. (bpstat_copy, bpstat_stop_status): Use new. (dprintf_after_condition_true): Update. * breakpoint.h (bpstats::bpstats): Add constructors. (bpstats::~bpstats): Add destructor. --- gdb/ChangeLog | 10 +++++++ gdb/breakpoint.c | 91 +++++++++++++++++++++++++++++++++----------------------- gdb/breakpoint.h | 7 +++++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5559bc2..5baad20 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2017-08-30 Tom Tromey + + * breakpoint.c (~bpstats): Rename from bpstat_free. Update. + (bpstat_clear): Use delete. + (bpstats): New constructors. + (bpstat_copy, bpstat_stop_status): Use new. + (dprintf_after_condition_true): Update. + * breakpoint.h (bpstats::bpstats): Add constructors. + (bpstats::~bpstats): Add destructor. + 2017-08-29 John Baldwin * mips-fbsd-nat.c (getfpregs_supplies): Return true for FIR. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index ae09da4..57e8479 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4459,14 +4459,13 @@ is_catchpoint (struct breakpoint *ep) /* Frees any storage that is part of a bpstat. Does not walk the 'next' chain. */ -static void -bpstat_free (bpstat bs) +bpstats::~bpstats () { - if (bs->old_val != NULL) - value_free (bs->old_val); - decref_counted_command_line (&bs->commands); - decref_bp_location (&bs->bp_location_at); - xfree (bs); + if (old_val != NULL) + value_free (old_val); + decref_counted_command_line (&commands); + if (bp_location_at != NULL) + decref_bp_location (&bp_location_at); } /* Clear a bpstat so that it says we are not at any breakpoint. @@ -4484,12 +4483,31 @@ bpstat_clear (bpstat *bsp) while (p != NULL) { q = p->next; - bpstat_free (p); + delete p; p = q; } *bsp = NULL; } +bpstats::bpstats (const bpstats &other) + : next (NULL), + bp_location_at (other.bp_location_at), + breakpoint_at (other.breakpoint_at), + commands (other.commands), + old_val (other.old_val), + print (other.print), + stop (other.stop), + print_it (other.print_it) +{ + if (old_val != NULL) + { + old_val = value_copy (old_val); + 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 is part of the bpstat is copied as well. */ @@ -4505,15 +4523,7 @@ bpstat_copy (bpstat bs) for (; bs != NULL; bs = bs->next) { - tmp = (bpstat) xmalloc (sizeof (*tmp)); - memcpy (tmp, bs, sizeof (*tmp)); - incref_counted_command_line (tmp->commands); - incref_bp_location (tmp->bp_location_at); - if (bs->old_val != NULL) - { - tmp->old_val = value_copy (bs->old_val); - release_value (tmp->old_val); - } + tmp = new bpstats (*bs); if (p == NULL) /* This is the first thing in the chain. */ @@ -5002,23 +5012,31 @@ breakpoint_cond_eval (void *exp) /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ -static bpstat -bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) +bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) + : next (NULL), + bp_location_at (bl), + breakpoint_at (bl->owner), + commands (NULL), + old_val (NULL), + print (0), + stop (0), + print_it (print_it_normal) { - bpstat bs; - - bs = (bpstat) xmalloc (sizeof (*bs)); - bs->next = NULL; - **bs_link_pointer = bs; - *bs_link_pointer = &bs->next; - bs->breakpoint_at = bl->owner; - bs->bp_location_at = bl; incref_bp_location (bl); - /* If the condition is false, etc., don't do the commands. */ - bs->commands = NULL; - bs->old_val = NULL; - bs->print_it = print_it_normal; - return bs; + **bs_link_pointer = this; + *bs_link_pointer = &next; +} + +bpstats::bpstats () + : next (NULL), + bp_location_at (NULL), + breakpoint_at (NULL), + commands (NULL), + old_val (NULL), + print (0), + stop (0), + print_it (print_it_normal) +{ } /* The target has stopped with waitstatus WS. Check if any hardware @@ -5661,7 +5679,7 @@ bpstat_stop_status (struct address_space *aspace, /* Come here if it's a watchpoint, or if the break address matches. */ - bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to + bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to explain stop. */ /* Assume we stop. Should we find a watchpoint that is not @@ -5692,7 +5710,7 @@ bpstat_stop_status (struct address_space *aspace, if (breakpoint_location_address_match (loc, aspace, bp_addr) && need_moribund_for_location_type (loc)) { - bs = bpstat_alloc (loc, &bs_link); + bs = new bpstats (loc, &bs_link); /* For hits of moribund locations, we should just proceed. */ bs->stop = 0; bs->print = 0; @@ -13466,8 +13484,7 @@ dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) static void dprintf_after_condition_true (struct bpstats *bs) { - struct cleanup *old_chain; - struct bpstats tmp_bs = { NULL }; + struct bpstats tmp_bs; struct bpstats *tmp_bs_p = &tmp_bs; /* dprintf's never cause a stop. This wasn't set in the @@ -13482,14 +13499,12 @@ dprintf_after_condition_true (struct bpstats *bs) commands here throws. */ tmp_bs.commands = bs->commands; bs->commands = NULL; - old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); bpstat_do_actions_1 (&tmp_bs_p); /* 'tmp_bs.commands' will usually be NULL by now, but bpstat_do_actions_1 may return early without processing the whole list. */ - do_cleanups (old_chain); } /* The breakpoint_ops structure to be used on static tracepoints with diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index dc2b098..f3c0961 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1080,6 +1080,13 @@ enum bp_print_how struct bpstats { + bpstats (); + bpstats (struct bp_location *bl, bpstat **bs_link_pointer); + ~bpstats (); + + bpstats (const bpstats &); + bpstats &operator= (const bpstats &) = delete; + /* Linked list because there can be more than one breakpoint at the same place, and a bpstat reflects the fact that all have been hit. */ -- 2.9.4