From patchwork Sun Sep 24 02:46:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23119 Received: (qmail 42411 invoked by alias); 24 Sep 2017 02:46: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 42059 invoked by uid 89); 24 Sep 2017 02:46:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=arguably X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Sep 2017 02:46:16 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy7.mail.unifiedlayer.com (Postfix) with ESMTP id 69838215C52 for ; Sat, 23 Sep 2017 20:46:14 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id DEmB1w00B2f2jeq01EmEtr; Sat, 23 Sep 2017 20:46:14 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=I5KbSrPAXO36_qBKB2EA:9 a=kFx70eKZ4Mogz76B:21 a=TJpChfq8NNxwx1yn:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:56144 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dvwvr-001i9G-8H; Sat, 23 Sep 2017 20:46:11 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/5] Remove make_cleanup_regcache_xfree Date: Sat, 23 Sep 2017 20:46:06 -0600 Message-Id: <20170924024608.4346-4-tom@tromey.com> In-Reply-To: <20170924024608.4346-1-tom@tromey.com> References: <20170924024608.4346-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dvwvr-001i9G-8H X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:56144 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes make_cleanup_regcache_xfree in favor of using std::unique_ptr as the return type of frame_save_as_regcache. ChangeLog 2017-09-23 Tom Tromey * spu-tdep.c (spu2ppu_sniffer): Update. * regcache.h (make_cleanup_regcache_xfree): Don't declare. * regcache.c (do_regcache_xfree, make_cleanup_regcache_xfree): Remove. * ppc-linux-tdep.c (ppu2spu_sniffer): Update. * mi/mi-main.c (mi_cmd_data_list_changed_registers): Update. * frame.h (frame_save_as_regcache): Return std::unique_ptr. * frame.c (frame_save_as_regcache): Return std::unique_ptr. (frame_pop): Update. --- gdb/ChangeLog | 12 ++++++++++++ gdb/frame.c | 19 +++++++------------ gdb/frame.h | 3 ++- gdb/mi/mi-main.c | 17 ++++++++--------- gdb/ppc-linux-tdep.c | 9 ++++----- gdb/regcache.c | 12 ------------ gdb/regcache.h | 2 -- gdb/spu-tdep.c | 2 +- 8 files changed, 34 insertions(+), 42 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index ad0cb92..a74deef 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1017,16 +1017,14 @@ do_frame_register_read (void *src, int regnum, gdb_byte *buf) return REG_VALID; } -struct regcache * +std::unique_ptr frame_save_as_regcache (struct frame_info *this_frame) { struct address_space *aspace = get_frame_address_space (this_frame); - struct regcache *regcache = new regcache (get_frame_arch (this_frame), - aspace); - struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache); + std::unique_ptr regcache + (new struct regcache (get_frame_arch (this_frame), aspace)); - regcache_save (regcache, do_frame_register_read, this_frame); - discard_cleanups (cleanups); + regcache_save (regcache.get (), do_frame_register_read, this_frame); return regcache; } @@ -1034,8 +1032,6 @@ void frame_pop (struct frame_info *this_frame) { struct frame_info *prev_frame; - struct regcache *scratch; - struct cleanup *cleanups; if (get_frame_type (this_frame) == DUMMY_FRAME) { @@ -1062,8 +1058,8 @@ frame_pop (struct frame_info *this_frame) Save them in a scratch buffer so that there isn't a race between trying to extract the old values from the current regcache while at the same time writing new values into that same cache. */ - scratch = frame_save_as_regcache (prev_frame); - cleanups = make_cleanup_regcache_xfree (scratch); + std::unique_ptr scratch + = frame_save_as_regcache (prev_frame); /* FIXME: cagney/2003-03-16: It should be possible to tell the target's register cache that it is about to be hit with a burst @@ -1075,8 +1071,7 @@ frame_pop (struct frame_info *this_frame) (arguably a bug in the target code mind). */ /* Now copy those saved registers into the current regcache. Here, regcache_cpy() calls regcache_restore(). */ - regcache_cpy (get_current_regcache (), scratch); - do_cleanups (cleanups); + regcache_cpy (get_current_regcache (), scratch.get ()); /* We've made right mess of GDB's local state, just discard everything. */ diff --git a/gdb/frame.h b/gdb/frame.h index 3b00d36..0249857 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -679,7 +679,8 @@ extern void *frame_obstack_zalloc (unsigned long size); ((TYPE *) frame_obstack_zalloc ((NUMBER) * sizeof (TYPE))) /* Create a regcache, and copy the frame's registers into it. */ -struct regcache *frame_save_as_regcache (struct frame_info *this_frame); +std::unique_ptr frame_save_as_regcache + (struct frame_info *this_frame); extern const struct block *get_frame_block (struct frame_info *, CORE_ADDR *addr_in_block); diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index c06ef18..5e71949 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1031,22 +1031,20 @@ mi_cmd_data_list_register_names (const char *command, char **argv, int argc) void mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) { - static struct regcache *this_regs = NULL; + static std::unique_ptr this_regs; struct ui_out *uiout = current_uiout; - struct regcache *prev_regs; + std::unique_ptr prev_regs; struct gdbarch *gdbarch; int regnum, numregs, changed; int i; - struct cleanup *cleanup; /* The last time we visited this function, the current frame's register contents were saved in THIS_REGS. Move THIS_REGS over to PREV_REGS, and refresh THIS_REGS with the now-current register contents. */ - prev_regs = this_regs; + prev_regs = std::move (this_regs); this_regs = frame_save_as_regcache (get_selected_frame (NULL)); - cleanup = make_cleanup_regcache_xfree (prev_regs); /* Note that the test for a valid register must include checking the gdbarch_register_name because gdbarch_num_regs may be allocated @@ -1055,7 +1053,7 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) will change depending upon the particular processor being debugged. */ - gdbarch = get_regcache_arch (this_regs); + gdbarch = get_regcache_arch (this_regs.get ()); numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); ui_out_emit_list list_emitter (uiout, "changed-registers"); @@ -1070,7 +1068,8 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) if (gdbarch_register_name (gdbarch, regnum) == NULL || *(gdbarch_register_name (gdbarch, regnum)) == '\0') continue; - changed = register_changed_p (regnum, prev_regs, this_regs); + changed = register_changed_p (regnum, prev_regs.get (), + this_regs.get ()); if (changed < 0) error (_("-data-list-changed-registers: " "Unable to read register contents.")); @@ -1089,7 +1088,8 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) && gdbarch_register_name (gdbarch, regnum) != NULL && *gdbarch_register_name (gdbarch, regnum) != '\000') { - changed = register_changed_p (regnum, prev_regs, this_regs); + changed = register_changed_p (regnum, prev_regs.get (), + this_regs.get ()); if (changed < 0) error (_("-data-list-changed-registers: " "Unable to read register contents.")); @@ -1099,7 +1099,6 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) else error (_("bad register number")); } - do_cleanups (cleanup); } static int diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 2faee42..5f313f8 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1363,13 +1363,12 @@ ppu2spu_sniffer (const struct frame_unwind *self, = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); struct address_space *aspace = get_frame_address_space (this_frame); - struct regcache *regcache = new regcache (data.gdbarch, aspace); - struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache); - regcache_save (regcache, ppu2spu_unwind_register, &data); - discard_cleanups (cleanups); + std::unique_ptr regcache + (new struct regcache (data.gdbarch, aspace)); + regcache_save (regcache.get (), ppu2spu_unwind_register, &data); cache->frame_id = frame_id_build (base, func); - cache->regcache = regcache; + cache->regcache = regcache.release (); *this_prologue_cache = cache; return 1; } diff --git a/gdb/regcache.c b/gdb/regcache.c index 54aed6c..ab6a651 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -241,18 +241,6 @@ regcache_get_ptid (const struct regcache *regcache) return regcache->ptid (); } -static void -do_regcache_xfree (void *data) -{ - delete (struct regcache *) data; -} - -struct cleanup * -make_cleanup_regcache_xfree (struct regcache *regcache) -{ - return make_cleanup (do_regcache_xfree, regcache); -} - /* Cleanup routines for invalidating a register. */ struct register_to_invalidate diff --git a/gdb/regcache.h b/gdb/regcache.h index 4a430ae..3ecdb3b 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -35,8 +35,6 @@ extern struct regcache *get_thread_arch_aspace_regcache (ptid_t, struct gdbarch *, struct address_space *); -struct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache); - /* Return REGCACHE's ptid. */ extern ptid_t regcache_get_ptid (const struct regcache *regcache); diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c index f77e37f..6d7a35e 100644 --- a/gdb/spu-tdep.c +++ b/gdb/spu-tdep.c @@ -1267,7 +1267,7 @@ spu2ppu_sniffer (const struct frame_unwind *self, if (fi) { - cache->regcache = frame_save_as_regcache (fi); + cache->regcache = frame_save_as_regcache (fi).release (); *this_prologue_cache = cache; return 1; }