From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89314 invoked by alias); 5 Jun 2018 19:23:53 -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 89190 invoked by uid 89); 5 Jun 2018 19:23:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.64.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Jun 2018 19:23:50 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 01B15400C488F for ; Tue, 5 Jun 2018 14:23:49 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id QHYafChSXRPojQHYafseAT; Tue, 05 Jun 2018 14:23:48 -0500 X-Authority-Reason: nr=8 Received: from 75-166-37-59.hlrn.qwest.net ([75.166.37.59]:38518 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fQHYa-0003Rh-PT; Tue, 05 Jun 2018 14:23:48 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Use std::vector for moribund_locations Date: Tue, 05 Jun 2018 19:23:00 -0000 Message-Id: <20180605192346.5509-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fQHYa-0003Rh-PT X-Source-Sender: 75-166-37-59.hlrn.qwest.net (bapiya.Home) [75.166.37.59]:38518 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-06/txt/msg00113.txt.bz2 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-06-05 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. --- gdb/ChangeLog | 10 ++++++++++ gdb/breakpoint.c | 42 ++++++++++++++++++------------------------ gdb/breakpoint.h | 3 --- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 00c538e989e..36d1a6735e6 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; @@ -5362,10 +5357,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)) @@ -12009,7 +12001,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 { @@ -12112,16 +12104,18 @@ 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; - } + auto it = std::remove_if (moribund_locations.begin (), + moribund_locations.end (), + [] (bp_location *loc) + { + if (--(loc->events_till_retirement) == 0) + { + decref_bp_location (&loc); + return true; + } + return false; + }); + moribund_locations.erase (it, moribund_locations.end ()); } static void diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 4223158fbc0..6c9326fb8a9 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -666,9 +666,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 -- 2.13.6