From patchwork Mon Jul 9 17:10:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28281 Received: (qmail 116549 invoked by alias); 9 Jul 2018 17:10:54 -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 116449 invoked by uid 89); 9 Jul 2018 17:10:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=processes, U*simark, sk:simark@, simark@simark.ca X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.49.218) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jul 2018 17:10:37 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway23.websitewelcome.com (Postfix) with ESMTP id C58104D8 for ; Mon, 9 Jul 2018 12:10:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id cZgBf3IkGbXuJcZgEfCewc; Mon, 09 Jul 2018 12:10:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7wnvTX4skVAoqibwlTAkZxn/N+nUgyXxeJE3PdXfU1w=; b=HboWNeWc87ACVFlXU1hs040S3E AaDvTnVrhoW9ZLIfIK2Wrq0GPJGNfUhAdLL8X+EZBeFzD1kfZqdZ4tq7xPxTG7B72UfZFBrmd74Nl lDBwEg+SvVgzYFXZXhMZyRvdD; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:44814 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fcZgB-001ZBk-04; Mon, 09 Jul 2018 12:10:27 -0500 From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA] Use std::vector for moribund_locations References: <20180605192346.5509-1-tom@tromey.com> Date: Mon, 09 Jul 2018 11:10:26 -0600 In-Reply-To: (Simon Marchi's message of "Wed, 4 Jul 2018 00:51:38 -0400") Message-ID: <87sh4spc71.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 >>>>> "Simon" == Simon Marchi writes: Simon> Just a note that this changes an "unordered remove" to an "ordered remove". Simon> If we don't need to keep the relative order of the remaining elements, it Simon> might be good performance-wise to keep the original behavior. This could Simon> be done by keeping the original code structure (iterating by index) and Simon> calling undordered_remove. How's this? Tom commit ccb7af8e831bd703fda0fa87ea5bca951965faf0 Author: Tom Tromey Date: Tue Jun 5 10:35:38 2018 -0600 Use std::vector for moribund_locations This changes moribund_locations to use a std::vector rather than VEC. I also noticed that moribund_locations is only used in breakpoint.c, so now it is static as well. It might be possible to make this code a bit simpler by using a ref_ptr in moribund_locations; however, I have not done this. Tested by the buildbot. gdb/ChangeLog 2018-07-09 Tom Tromey * breakpoint.c (moribund_locations): Now static and a std::vector. (breakpoint_init_inferior, moribund_breakpoint_here_p) (build_bpstat_chain, update_global_location_list) (breakpoint_retire_moribund): Update. * breakpoint.h (bp_location_p): Remove typedef. Don't declare VEC. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 70b4d443d0d..fbe2f2be92b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2018-07-09 Tom Tromey + * breakpoint.c (moribund_locations): Now static and a + std::vector. + (breakpoint_init_inferior, moribund_breakpoint_here_p) + (build_bpstat_chain, update_global_location_list) + (breakpoint_retire_moribund): Update. + * breakpoint.h (bp_location_p): Remove typedef. Don't declare + VEC. + +2018-07-09 Tom Tromey + * Makefile.in (CDEPS): Don't mention XM_CDEPS. (CLIBS): Don't mention NAT_CLIBS. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 77c4638df83..b135db3db95 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -560,7 +560,7 @@ static CORE_ADDR bp_locations_shadow_len_after_address_max; /* The locations that no longer correspond to any breakpoint, unlinked from the bp_locations array, but for which a hit may still be reported by a target. */ -VEC(bp_location_p) *moribund_locations = NULL; +static std::vector moribund_locations; /* Number of last breakpoint made. */ @@ -3860,8 +3860,6 @@ void breakpoint_init_inferior (enum inf_context context) { struct breakpoint *b, *b_tmp; - struct bp_location *bl; - int ix; struct program_space *pspace = current_program_space; /* If breakpoint locations are shared across processes, then there's @@ -3951,9 +3949,9 @@ breakpoint_init_inferior (enum inf_context context) } /* Get rid of the moribund locations. */ - for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) + for (bp_location *bl : moribund_locations) decref_bp_location (&bl); - VEC_free (bp_location_p, moribund_locations); + moribund_locations.clear (); } /* These functions concern about actual breakpoints inserted in the @@ -4041,10 +4039,7 @@ breakpoint_in_range_p (const address_space *aspace, int moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) { - struct bp_location *loc; - int ix; - - for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) + for (bp_location *loc : moribund_locations) if (breakpoint_location_address_match (loc, aspace, pc)) return 1; @@ -5372,10 +5367,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, if (!target_supports_stopped_by_sw_breakpoint () || !target_supports_stopped_by_hw_breakpoint ()) { - bp_location *loc; - - for (int ix = 0; - VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) + for (bp_location *loc : moribund_locations) { if (breakpoint_location_address_match (loc, aspace, bp_addr) && need_moribund_for_location_type (loc)) @@ -12012,7 +12004,7 @@ update_global_location_list (enum ugll_insert_mode insert_mode) old_loc->events_till_retirement = 3 * (thread_count () + 1); old_loc->owner = NULL; - VEC_safe_push (bp_location_p, moribund_locations, old_loc); + moribund_locations.push_back (old_loc); } else { @@ -12115,16 +12107,16 @@ update_global_location_list (enum ugll_insert_mode insert_mode) void breakpoint_retire_moribund (void) { - struct bp_location *loc; - int ix; - - for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) - if (--(loc->events_till_retirement) == 0) - { - decref_bp_location (&loc); - VEC_unordered_remove (bp_location_p, moribund_locations, ix); - --ix; - } + for (int ix = 0; ix < moribund_locations.size (); ++ix) + { + struct bp_location *loc = moribund_locations[ix]; + if (--(loc->events_till_retirement) == 0) + { + decref_bp_location (&loc); + unordered_remove (moribund_locations, ix); + --ix; + } + } } static void diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 7da9452fd15..63cb5370c16 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -667,9 +667,6 @@ enum watchpoint_triggered watch_triggered_yes }; -typedef struct bp_location *bp_location_p; -DEF_VEC_P(bp_location_p); - /* 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 only one register per watchpoint, thus assuming that all acesses that