From patchwork Thu Aug 17 08:47:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 22177 Received: (qmail 112640 invoked by alias); 17 Aug 2017 08:48:03 -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 108800 invoked by uid 89); 17 Aug 2017 08:48:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy= X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50084.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Aug 2017 08:47:58 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) by AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1341.17; Thu, 17 Aug 2017 08:47:54 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::b8e2:8809:e2b2:ae37]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::b8e2:8809:e2b2:ae37%14]) with mapi id 15.01.1341.024; Thu, 17 Aug 2017 08:47:54 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH 3/7]: Regcache: Remove xmalloc/xfree methods Date: Thu, 17 Aug 2017 08:47:54 +0000 Message-ID: <08C93960-8ED8-431A-B786-3455FF149B77@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM3PR08MB0101; 6:MGc4AY1zlxJ1yGS6lq51CGQ8yuGHT9z6rHfgknL7ntC7bpDPfzr8W09rmMYR/pHa8yILFoBDIvKS0FrAR98iBCxS9xSHYwkJvHfL0G53HH0+e3UW1EDogKVAN5P/uzP7jZiEepJx4E/+Bk5zFtoTrEHamQ6Ui0PG+0G0cdEzSR12A7y4nU8s6e+D2pDE4Mf/eUSBHf/sjD7HuBYC7EJLKIqEyJ7nr8QKZdDgptgQVeanCJT+D2FH343xU1mzj6I63hZGH0rCd/QyoMCbBXcuwrKqFP6mpNNEXKRSnvw0T22tprqyVfVancgei0KqY5Pa/E8ruiJHfsDbFkm1fhroiA==; 5:UFNvQ4Rh+YslP8nH41nHM3n9UpRlVtFaWC4NGKxkN7Sznh9bew7A4H9QAHP0Pn86GZ5scIzPka2oH+r7mavfiDQaFHFwP6AUiLiNgtmytkaqVK89oSoiegTgCXMlcU9xV9tRJqakAiz87WaTVNdNRA==; 24:AV+VywJsENvHdu5Roke6m6bwgMAdyXWubBAuHPXfTSoOmY495OMallCpbg9/plkz2VCYTR/l/mhQu3+W5HQr3DnhCkOlopDprTRpA50HPck=; 7:egDrnwghTtBYO07lSoqR40fR6lmVqBERO5xyS72K2o+Bc27gSbQarQBPBkXqgtuqePZ7tXKMteDfcNVRU4mQOJgLB02ETowU8PJ6Ojf+ntO2YV9OoZgLOXwztfSBpvZCjpc2EqYytP15h1UF2bjeL2WseMk1rNqxaKXS1wNWqH8xsg08RWU6mGjmEkrBSYOEbWe1VAec1Pk50MyZeSpn9GDVevghWpZWJ4wxikGf8qU= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: bb4400b8-99a4-41cf-2237-08d4e54ca709 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM3PR08MB0101; x-ms-traffictypediagnostic: AM3PR08MB0101: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM3PR08MB0101; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM3PR08MB0101; x-forefront-prvs: 0402872DA1 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(199003)(377424004)(189002)(81166006)(68736007)(86362001)(3280700002)(575784001)(478600001)(189998001)(2501003)(5640700003)(99286003)(5660300001)(2906002)(6436002)(25786009)(7736002)(53936002)(3660700001)(33656002)(3846002)(305945005)(6512007)(36756003)(102836003)(101416001)(97736004)(8936002)(6116002)(66066001)(14454004)(50986999)(6916009)(2900100001)(8676002)(54356999)(6486002)(106356001)(105586002)(72206003)(6506006)(81156014)(2351001)(82746002)(83716003)(4326008)(110136004)(5250100002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0101; H:AM3PR08MB0101.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <5D63B5A27E876543A9695F59986678A6@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2017 08:47:54.7345 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0101 X-IsSubscribed: yes Regcache is a class. There is no need for explicit xmalloc and xfree methods, it is much simpler to use new and delete. Tested on a --enable-targets=all build with board files unix, native-gdbserver and unittest.exp. 2017-08-16 Alan Hayward * frame.c (frame_save_as_regcache): Use new. (frame_pop): Update name. * infrun.c (discard_infcall_suspend_state): Use delete. * jit.c (jit_dealloc_cache): Use delete. (jit_frame_sniffer): Use new. * linux-fork.c (free_fork): Use delete. (fork_save_infrun_state): Likewise. * mi/mi-main.c (mi_cmd_data_list_changed_registers): Update name. * ppc-linux-tdep.c (ppu2spu_sniffer): Use new. (ppu2spu_dealloc_cache): Use delete. * regcache.c (regcache_xmalloc): Remove. (regcache_xfree): Remove. (do_regcache_delete): Update name. (make_cleanup_regcache_delete): Likewise. * regcache.h: Remove functions and rename. * spu-tdep.c (spu2ppu_dealloc_cache): Use delete. diff --git a/gdb/frame.c b/gdb/frame.c index 30e4aeab7e2901074c289ac4d96ebda885805a29..7fd4b07a2e95f28b2eb6a18dea4d2071f0ece4e2 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1021,13 +1021,12 @@ struct regcache * frame_save_as_regcache (struct frame_info *this_frame) { struct address_space *aspace = get_frame_address_space (this_frame); - struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame), - aspace); - struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache); + regcache *backup = new regcache (get_frame_arch (this_frame), aspace); + struct cleanup *cleanups = make_cleanup_regcache_delete (backup); - regcache_save (regcache, do_frame_register_read, this_frame); + regcache_save (backup, do_frame_register_read, this_frame); discard_cleanups (cleanups); - return regcache; + return backup; } void @@ -1063,7 +1062,7 @@ frame_pop (struct frame_info *this_frame) 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); + cleanups = make_cleanup_regcache_delete (scratch); /* 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 diff --git a/gdb/infrun.c b/gdb/infrun.c index d6723fde85c90bce2a93d1ab308332f9387c3f15..6510aec548f6495ca64f5b566ff3628734698113 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8963,7 +8963,7 @@ make_cleanup_restore_infcall_suspend_state void discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) { - regcache_xfree (inf_state->registers); + delete inf_state->registers; xfree (inf_state->siginfo_data); xfree (inf_state); } diff --git a/gdb/jit.c b/gdb/jit.c index 725d41ef0a5b01a22d5994bdd4b7b336fd3c10a9..e96572a8d1d7fe16561be7ba8a61b56d6bb1e85d 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -1168,7 +1168,7 @@ jit_dealloc_cache (struct frame_info *this_frame, void *cache) struct jit_unwind_private *priv_data = (struct jit_unwind_private *) cache; gdb_assert (priv_data->regcache != NULL); - regcache_xfree (priv_data->regcache); + delete priv_data->regcache; xfree (priv_data); } @@ -1206,7 +1206,7 @@ jit_frame_sniffer (const struct frame_unwind *self, *cache = XCNEW (struct jit_unwind_private); priv_data = (struct jit_unwind_private *) *cache; - priv_data->regcache = regcache_xmalloc (gdbarch, aspace); + priv_data->regcache = new regcache (gdbarch, aspace); priv_data->this_frame = this_frame; callbacks.priv_data = priv_data; diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 573a3e9ecf040bb77b3f116e60289ba60266ffd0..032ff62807b728be336bf0e5daf59e47615d4799 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -129,7 +129,7 @@ free_fork (struct fork_info *fp) if (fp) { if (fp->savedregs) - regcache_xfree (fp->savedregs); + delete fp->savedregs; if (fp->filepos) xfree (fp->filepos); xfree (fp); @@ -295,7 +295,7 @@ fork_save_infrun_state (struct fork_info *fp, int clobber_regs) DIR *d; if (fp->savedregs) - regcache_xfree (fp->savedregs); + delete fp->savedregs; fp->savedregs = regcache_dup (get_current_regcache ()); fp->clobber_regs = clobber_regs; diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 0bf587ffe702c68f538fe2877cce6114e64ee1bd..1edcf752c82230fc65669f675e10735ac8e4f654 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1051,7 +1051,7 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) prev_regs = this_regs; this_regs = frame_save_as_regcache (get_selected_frame (NULL)); - cleanup = make_cleanup_regcache_xfree (prev_regs); + cleanup = make_cleanup_regcache_delete (prev_regs); /* Note that the test for a valid register must include checking the gdbarch_register_name because gdbarch_num_regs may be allocated diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 324b29d90c1266a73f172da20a6015174189625f..42aff2cd1bf3834268b0b58dcf00dac1c52add96 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1364,13 +1364,13 @@ 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 = regcache_xmalloc (data.gdbarch, aspace); - struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache); - regcache_save (regcache, ppu2spu_unwind_register, &data); + regcache *backup = new regcache (data.gdbarch, aspace); + struct cleanup *cleanups = make_cleanup_regcache_delete (backup); + regcache_save (backup, ppu2spu_unwind_register, &data); discard_cleanups (cleanups); cache->frame_id = frame_id_build (base, func); - cache->regcache = regcache; + cache->regcache = backup; *this_prologue_cache = cache; return 1; } @@ -1383,7 +1383,7 @@ static void ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache) { struct ppu2spu_cache *cache = (struct ppu2spu_cache *) this_cache; - regcache_xfree (cache->regcache); + delete cache->regcache; } static const struct frame_unwind ppu2spu_unwind = { diff --git a/gdb/regcache.h b/gdb/regcache.h index aeac54e8d7b91e2bcf6a3e1ce8e781c3f994306b..00b87db7d145205b74859c08ca5a9d852441a4aa 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -36,10 +36,7 @@ extern target_regcache *get_thread_arch_aspace_regcache (ptid_t, struct gdbarch *, struct address_space *); -void regcache_xfree (struct regcache *regcache); -struct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache); -struct regcache *regcache_xmalloc (struct gdbarch *gdbarch, - struct address_space *aspace); +struct cleanup *make_cleanup_regcache_delete (regcache *regcache); /* Return REGCACHE's ptid. */ @@ -261,12 +258,7 @@ public: regcache (const regcache &) = delete; void operator= (const regcache &) = delete; - /* class regcache is only extended in unit test, so only mark it - virtual when selftest is enabled. */ -#if GDB_SELF_TEST - virtual -#endif - ~regcache () + virtual ~regcache () { xfree (m_registers); xfree (m_register_status); diff --git a/gdb/regcache.c b/gdb/regcache.c index 524ac5754f6d2c1b00097b15a40b928845e45a59..e7da5a622e861e1e6a1938f91a0dd9a39942a050 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -249,31 +249,18 @@ regcache_get_ptid (const struct regcache *regcache) return regcache->ptid (); } -struct regcache * -regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace) -{ - return new regcache (gdbarch, aspace); -} - -void -regcache_xfree (struct regcache *regcache) -{ - if (regcache == NULL) - return; - - delete regcache; -} - static void -do_regcache_xfree (void *data) +do_regcache_delete (void *data) { - regcache_xfree ((struct regcache *) data); + if (data == NULL) + return; + delete (regcache *) data; } struct cleanup * -make_cleanup_regcache_xfree (struct regcache *regcache) +make_cleanup_regcache_delete (struct regcache *regcache) { - return make_cleanup (do_regcache_xfree, regcache); + return make_cleanup (do_regcache_delete, regcache); } /* Cleanup routines for invalidating a register. */ diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c index ca1a3fc99f99a506446925a20bd3598631930a53..1ac763da7ede9d4b9f4bff1e8d71551b0c776fa1 100644 --- a/gdb/spu-tdep.c +++ b/gdb/spu-tdep.c @@ -1288,7 +1288,7 @@ static void spu2ppu_dealloc_cache (struct frame_info *self, void *this_cache) { struct spu2ppu_cache *cache = (struct spu2ppu_cache *) this_cache; - regcache_xfree (cache->regcache); + delete cache->regcache; } static const struct frame_unwind spu2ppu_unwind = {