From patchwork Mon Sep 3 19:02:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29173 Received: (qmail 64793 invoked by alias); 3 Sep 2018 19:03:18 -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 64690 invoked by uid 89); 3 Sep 2018 19:03:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 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=sk:destroy, sk:tempora X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.119) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Sep 2018 19:03:16 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 302A81533EF for ; Mon, 3 Sep 2018 14:03:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id wu7gfhHLebXuJwu7tf1hC4; Mon, 03 Sep 2018 14:03:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type: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=pvLJtpv1iCDLhAdeQm6IWf+6afoppCGHx16SUeLKV28=; b=DRCuaF0AO3QPG+4qP9EsnRo+nw xr9T83GCtYYVDW4P3jsLhBQFXudTBxZXPXpDA14teC742LibILnPoEBfiwOxpxTeP9r773KDRDhE+ S2++QdPndfNhaNr1mUIeM8rnC; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:58120 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fwu7g-002juS-Gh; Mon, 03 Sep 2018 14:02:52 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/4] Remove cleanup from procfs.c Date: Mon, 3 Sep 2018 13:02:48 -0600 Message-Id: <20180903190250.11599-3-tom@tromey.com> In-Reply-To: <20180903190250.11599-1-tom@tromey.com> References: <20180903190250.11599-1-tom@tromey.com> This removes the last remaining cleanup from procfs.c, replacing it with a unique_ptr specialization. gdb/ChangeLog 2018-09-03 Tom Tromey * procfs.c (struct procinfo_deleter): New. (procinfo_up): New typedef. (do_destroy_procinfo_cleanup): Remove. (procfs_target::info_proc): Use procinfo_up. Remove cleanups. --- gdb/ChangeLog | 7 +++++++ gdb/procfs.c | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gdb/procfs.c b/gdb/procfs.c index ec346503487..7d41907c4aa 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -549,11 +549,16 @@ destroy_procinfo (procinfo *pi) } } -static void -do_destroy_procinfo_cleanup (void *pi) +/* A deleter that calls destroy_procinfo. */ +struct procinfo_deleter { - destroy_procinfo ((procinfo *) pi); -} + void operator() (procinfo *pi) const + { + destroy_procinfo (pi); + } +}; + +typedef std::unique_ptr procinfo_up; enum { NOKILL, KILL }; @@ -3545,7 +3550,6 @@ info_proc_mappings (procinfo *pi, int summary) bool procfs_target::info_proc (const char *args, enum info_proc_what what) { - struct cleanup *old_chain; procinfo *process = NULL; procinfo *thread = NULL; char *tmp = NULL; @@ -3567,7 +3571,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) error (_("Not supported on this target.")); } - old_chain = make_cleanup (null_cleanup, 0); gdb_argv built_argv (args); for (char *arg : built_argv) { @@ -3582,6 +3585,8 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) tid = strtoul (arg + 1, NULL, 10); } } + + procinfo_up temporary_procinfo; if (pid == 0) pid = inferior_ptid.pid (); if (pid == 0) @@ -3596,7 +3601,7 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) /* No. So open a procinfo for it, but remember to close it again when finished. */ process = create_procinfo (pid, 0); - make_cleanup (do_destroy_procinfo_cleanup, process); + temporary_procinfo.reset (process); if (!open_procinfo_files (process, FD_CTL)) proc_error (process, "info proc, open_procinfo_files", __LINE__); } @@ -3627,8 +3632,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) info_proc_mappings (process, 0); } - do_cleanups (old_chain); - return true; }