From patchwork Sun Nov 4 16:06:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30021 Received: (qmail 109513 invoked by alias); 4 Nov 2018 16:06:56 -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 109497 invoked by uid 89); 4 Nov 2018 16:06:54 -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:obstack, obstack, replacing X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Nov 2018 16:06:53 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway23.websitewelcome.com (Postfix) with ESMTP id EB08913923 for ; Sun, 4 Nov 2018 10:06:51 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id JKvLgAeZtBcCXJKvLgMFZS; Sun, 04 Nov 2018 10:06:51 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Oa6jeGquidgRoNv0ltv6sVBEpYT8PSClNrfjZGnIiPw=; b=HdZqoxfIkgBgLS4FSUNqOWKl5y /uULf8CwUxhqjbMORTMmcvEpnE1k3FHRDFR7SSkPv/+gjkU4uMRYPv5XTv1Lf+ilnalnHcUWJDd38 hZPE5or4qD3qDOqUGTh66FtsC; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:34122 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gJKvL-000t71-Ne; Sun, 04 Nov 2018 10:06:51 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove a VEC from remote.c Date: Sun, 4 Nov 2018 09:06:49 -0700 Message-Id: <20181104160649.8292-1-tom@tromey.com> This removes the VEC from remote_g_packet_data, replacing it with a std::vector. This is a bit odd in that this object is never destroyed, and is obstack-allocated. I believe a gdbarch is never destroyed, so this seemed ok. Tested by the buildbot. gdb/ChangeLog 2018-11-04 Tom Tromey * remote.c (remote_g_packet_guess_s): Remove typedef and DEF_VEC. (struct remote_g_packet_data): Derive from allocate_on_obstack. : Now a std::vector. (remote_g_packet_data_init, register_remote_g_packet_guess): Update. (remote_read_description_p): Update. Return bool. (remote_target::read_description): Update. --- gdb/ChangeLog | 10 ++++++++++ gdb/remote.c | 44 ++++++++++++++++---------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index c53553af5b..f7a398ec95 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1030,7 +1030,7 @@ static ptid_t read_ptid (const char *buf, const char **obuf); static void remote_async_inferior_event_handler (gdb_client_data); -static int remote_read_description_p (struct target_ops *target); +static bool remote_read_description_p (struct target_ops *target); static void remote_console_output (char *msg); @@ -11620,12 +11620,10 @@ struct remote_g_packet_guess int bytes; const struct target_desc *tdesc; }; -typedef struct remote_g_packet_guess remote_g_packet_guess_s; -DEF_VEC_O(remote_g_packet_guess_s); -struct remote_g_packet_data +struct remote_g_packet_data : public allocate_on_obstack { - VEC(remote_g_packet_guess_s) *guesses; + std::vector guesses; }; static struct gdbarch_data *remote_g_packet_data_handle; @@ -11633,7 +11631,7 @@ static struct gdbarch_data *remote_g_packet_data_handle; static void * remote_g_packet_data_init (struct obstack *obstack) { - return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data); + return new (obstack) remote_g_packet_data; } void @@ -11643,38 +11641,32 @@ register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes, struct remote_g_packet_data *data = ((struct remote_g_packet_data *) gdbarch_data (gdbarch, remote_g_packet_data_handle)); - struct remote_g_packet_guess new_guess, *guess; - int ix; + struct remote_g_packet_guess new_guess; gdb_assert (tdesc != NULL); - for (ix = 0; - VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess); - ix++) - if (guess->bytes == bytes) + for (const remote_g_packet_guess &guess : data->guesses) + if (guess.bytes == bytes) internal_error (__FILE__, __LINE__, _("Duplicate g packet description added for size %d"), bytes); new_guess.bytes = bytes; new_guess.tdesc = tdesc; - VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess); + data->guesses.push_back (new_guess); } -/* Return 1 if remote_read_description would do anything on this target - and architecture, 0 otherwise. */ +/* Return true if remote_read_description would do anything on this target + and architecture, false otherwise. */ -static int +static bool remote_read_description_p (struct target_ops *target) { struct remote_g_packet_data *data = ((struct remote_g_packet_data *) gdbarch_data (target_gdbarch (), remote_g_packet_data_handle)); - if (!VEC_empty (remote_g_packet_guess_s, data->guesses)) - return 1; - - return 0; + return !data->guesses.empty (); } const struct target_desc * @@ -11689,17 +11681,13 @@ remote_target::read_description () if (!target_has_execution || inferior_ptid == null_ptid) return beneath ()->read_description (); - if (!VEC_empty (remote_g_packet_guess_s, data->guesses)) + if (!data->guesses.empty ()) { - struct remote_g_packet_guess *guess; - int ix; int bytes = send_g_packet (); - for (ix = 0; - VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess); - ix++) - if (guess->bytes == bytes) - return guess->tdesc; + for (const remote_g_packet_guess &guess : data->guesses) + if (guess.bytes == bytes) + return guess.tdesc; /* We discard the g packet. A minor optimization would be to hold on to it, and fill the register cache once we have selected