From patchwork Mon Jun 11 04:11:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27732 Received: (qmail 82703 invoked by alias); 11 Jun 2018 04:11:23 -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 82690 invoked by uid 89); 11 Jun 2018 04:11:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Jun 2018 04:11:21 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 882F61532A for ; Sun, 10 Jun 2018 23:11:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id SEApfWRSKRPojSEApfBSic; Sun, 10 Jun 2018 23:11:19 -0500 X-Authority-Reason: nr=8 Received: from 75-166-51-220.hlrn.qwest.net ([75.166.51.220]:54770 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fSEAo-0027pz-Vw; Sun, 10 Jun 2018 23:11:19 -0500 From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA] Remove a VEC from record-full.c References: <20180608025636.14640-1-tom@tromey.com> <87o9gi7hyp.fsf@tromey.com> <1b1a05c47192dd4dde60bcf3f58d229a@polymtl.ca> <87muw2clw8.fsf@tromey.com> <87in6qch4e.fsf@tromey.com> Date: Sun, 10 Jun 2018 22:11:16 -0600 In-Reply-To: (Simon Marchi's message of "Sun, 10 Jun 2018 20:28:43 -0400") Message-ID: <87efhec68r.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fSEAo-0027pz-Vw X-Source-Sender: 75-166-51-220.hlrn.qwest.net (bapiya) [75.166.51.220]:54770 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes >>>>> "Simon" == Simon Marchi writes: Simon> Thanks, LGTM. You can get extra credits if you make the Simon> in_target_beneath field a bool :). Here's what I'm checking in. Tom commit 98fe1618e47c7850a50ac882f229ec527c1e1eb1 Author: Tom Tromey Date: Thu Jun 7 17:22:49 2018 -0600 Remove a VEC from record-full.c This replaces a VEC in record-full.c with a std::vector. This version of the patch also catches a memory leak in the original code noticed by Simon. Tested by the buildbot. gdb/ChangeLog 2018-06-10 Tom Tromey * record-full.c (record_full_breakpoint_p): Remove typedef. Don't declare VEC. Add constructor. : Now bool. (record_full_breakpoints): Now a std::vector, static. (record_full_sync_record_breakpoints) (record_full_init_record_breakpoints) (record_full_target::insert_breakpoint) (record_full_target::remove_breakpoint): Update. Don't use XNEW. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0e5c0685cc2..c00dc9817ef 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2018-06-10 Tom Tromey + * record-full.c (record_full_breakpoint_p): Remove typedef. Don't + declare VEC. Add constructor. + : Now bool. + (record_full_breakpoints): Now a std::vector, static. + (record_full_sync_record_breakpoints) + (record_full_init_record_breakpoints) + (record_full_target::insert_breakpoint) + (record_full_target::remove_breakpoint): Update. Don't use XNEW. + +2018-06-10 Tom Tromey + * procfs.c (procfs_target::xfer_partial): Use "beneath" as a method. * nto-procfs.c (nto_procfs_target::xfer_partial): Use "beneath" as diff --git a/gdb/record-full.c b/gdb/record-full.c index 87c77e06ea9..27c8065835c 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -1700,6 +1700,15 @@ record_full_target::xfer_partial (enum target_object object, struct record_full_breakpoint { + record_full_breakpoint (struct address_space *address_space_, + CORE_ADDR addr_, + bool in_target_beneath_) + : address_space (address_space_), + addr (addr_), + in_target_beneath (in_target_beneath_) + { + } + /* The address and address space the breakpoint was set at. */ struct address_space *address_space; CORE_ADDR addr; @@ -1707,15 +1716,12 @@ struct record_full_breakpoint /* True when the breakpoint has been also installed in the target beneath. This will be false for breakpoints set during replay or when recording. */ - int in_target_beneath; + bool in_target_beneath; }; -typedef struct record_full_breakpoint *record_full_breakpoint_p; -DEF_VEC_P(record_full_breakpoint_p); - /* The list of breakpoints inserted while the record target is active. */ -VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL; +static std::vector record_full_breakpoints; static void record_full_sync_record_breakpoints (struct bp_location *loc, void *data) @@ -1725,14 +1731,10 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data) if (loc->inserted) { - struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint); - - bp->addr = loc->target_info.placed_address; - bp->address_space = loc->target_info.placed_address_space; - - bp->in_target_beneath = 1; - - VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp); + record_full_breakpoints.emplace_back + (loc->target_info.placed_address_space, + loc->target_info.placed_address, + 1); } } @@ -1741,7 +1743,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data) static void record_full_init_record_breakpoints (void) { - VEC_free (record_full_breakpoint_p, record_full_breakpoints); + record_full_breakpoints.clear (); iterate_over_bp_locations (record_full_sync_record_breakpoints); } @@ -1754,9 +1756,7 @@ int record_full_target::insert_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { - struct record_full_breakpoint *bp; - int in_target_beneath = 0; - int ix; + bool in_target_beneath = false; if (!RECORD_FULL_IS_REPLAY) { @@ -1773,30 +1773,25 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch, if (ret != 0) return ret; - in_target_beneath = 1; + in_target_beneath = true; } /* Use the existing entries if found in order to avoid duplication in record_full_breakpoints. */ - for (ix = 0; - VEC_iterate (record_full_breakpoint_p, - record_full_breakpoints, ix, bp); - ++ix) + for (struct record_full_breakpoint &bp : record_full_breakpoints) { - if (bp->addr == bp_tgt->placed_address - && bp->address_space == bp_tgt->placed_address_space) + if (bp.addr == bp_tgt->placed_address + && bp.address_space == bp_tgt->placed_address_space) { - gdb_assert (bp->in_target_beneath == in_target_beneath); + gdb_assert (bp.in_target_beneath == in_target_beneath); return 0; } } - bp = XNEW (struct record_full_breakpoint); - bp->addr = bp_tgt->placed_address; - bp->address_space = bp_tgt->placed_address_space; - bp->in_target_beneath = in_target_beneath; - VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp); + record_full_breakpoints.emplace_back (bp_tgt->placed_address_space, + bp_tgt->placed_address, + in_target_beneath); return 0; } @@ -1807,18 +1802,16 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason) { - struct record_full_breakpoint *bp; - int ix; - - for (ix = 0; - VEC_iterate (record_full_breakpoint_p, - record_full_breakpoints, ix, bp); - ++ix) + for (auto iter = record_full_breakpoints.begin (); + iter != record_full_breakpoints.end (); + ++iter) { - if (bp->addr == bp_tgt->placed_address - && bp->address_space == bp_tgt->placed_address_space) + struct record_full_breakpoint &bp = *iter; + + if (bp.addr == bp_tgt->placed_address + && bp.address_space == bp_tgt->placed_address_space) { - if (bp->in_target_beneath) + if (bp.in_target_beneath) { scoped_restore restore_operation_disable = record_full_gdb_operation_disable_set (); @@ -1830,10 +1823,7 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch, } if (reason == REMOVE_BREAKPOINT) - { - VEC_unordered_remove (record_full_breakpoint_p, - record_full_breakpoints, ix); - } + unordered_remove (record_full_breakpoints, iter); return 0; } }