From patchwork Wed May 16 14:18:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 27286 Received: (qmail 9511 invoked by alias); 16 May 2018 14:18:41 -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 9383 invoked by uid 89); 16 May 2018 14:18:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 May 2018 14:18:38 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 504D681663C0 for ; Wed, 16 May 2018 14:18:37 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 019D01002948 for ; Wed, 16 May 2018 14:18:36 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 09/10] remote: Make vcont_builder a class Date: Wed, 16 May 2018 15:18:29 +0100 Message-Id: <20180516141830.16859-10-palves@redhat.com> In-Reply-To: <20180516141830.16859-1-palves@redhat.com> References: <20180516141830.16859-1-palves@redhat.com> gdb/ChangeLog: yyyy-mm-dd Pedro Alves * remote.c (vcont_builder): Now a class. Make all data members private. (vcont_builder) : Declare methods. (vcont_builder_restart): Rename to ... (vcont_builder::restart): ... this. (vcont_builder_flush): Rename to ... (vcont_builder::flush): ... this. (vcont_builder_push_action): Rename to ... (vcont_builder::push_action): ... this. (remote_target::commit_resume): Adjust. --- gdb/remote.c | 79 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 7ec8d24a3b..4166598750 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -6091,41 +6091,50 @@ get_remote_inferior (inferior *inf) outgoing packet buffer. This is used to send multiple vCont packets if we have more actions than would fit a single packet. */ -struct vcont_builder +class vcont_builder { +public: + vcont_builder () + {} + + void restart (); + void flush (); + void push_action (ptid_t ptid, bool step, gdb_signal siggnal); + +private: /* Pointer to the first action. P points here if no action has been appended yet. */ - char *first_action; + char *m_first_action; /* Where the next action will be appended. */ - char *p; + char *m_p; /* The end of the buffer. Must never write past this. */ - char *endp; + char *m_endp; }; /* Prepare the outgoing buffer for a new vCont packet. */ -static void -vcont_builder_restart (struct vcont_builder *builder) +void +vcont_builder::restart () { struct remote_state *rs = get_remote_state (); - builder->p = rs->buf; - builder->endp = rs->buf + get_remote_packet_size (); - builder->p += xsnprintf (builder->p, builder->endp - builder->p, "vCont"); - builder->first_action = builder->p; + m_p = rs->buf; + m_endp = rs->buf + get_remote_packet_size (); + m_p += xsnprintf (m_p, m_endp - m_p, "vCont"); + m_first_action = m_p; } /* If the vCont packet being built has any action, send it to the remote end. */ -static void -vcont_builder_flush (struct vcont_builder *builder) +void +vcont_builder::flush () { struct remote_state *rs; - if (builder->p == builder->first_action) + if (m_p == m_first_action) return; rs = get_remote_state (); @@ -6146,33 +6155,30 @@ vcont_builder_flush (struct vcont_builder *builder) what we've got so far to the remote end and start over a new vCont packet (with the new action). */ -static void -vcont_builder_push_action (struct vcont_builder *builder, - ptid_t ptid, int step, enum gdb_signal siggnal) +void +vcont_builder::push_action (ptid_t ptid, bool step, gdb_signal siggnal) { char buf[MAX_ACTION_SIZE + 1]; - char *endp; - size_t rsize; - endp = append_resumption (buf, buf + sizeof (buf), - ptid, step, siggnal); + char *endp = append_resumption (buf, buf + sizeof (buf), + ptid, step, siggnal); /* Check whether this new action would fit in the vCont packet along with previous actions. If not, send what we've got so far and start a new vCont packet. */ - rsize = endp - buf; - if (rsize > builder->endp - builder->p) + size_t rsize = endp - buf; + if (rsize > m_endp - m_p) { - vcont_builder_flush (builder); - vcont_builder_restart (builder); + flush (); + restart (); /* Should now fit. */ - gdb_assert (rsize <= builder->endp - builder->p); + gdb_assert (rsize <= m_endp - m_p); } - memcpy (builder->p, buf, rsize); - builder->p += rsize; - *builder->p = '\0'; + memcpy (m_p, buf, rsize); + m_p += rsize; + *m_p = '\0'; } /* to_commit_resume implementation. */ @@ -6184,7 +6190,6 @@ remote_target::commit_resume () struct thread_info *tp; int any_process_wildcard; int may_global_wildcard_vcont; - struct vcont_builder vcont_builder; /* If connected in all-stop mode, we'd send the remote resume request directly from remote_resume. Likewise if @@ -6282,7 +6287,8 @@ remote_target::commit_resume () we end up with too many actions for a single packet vcont_builder flushes the current vCont packet to the remote side and starts a new one. */ - vcont_builder_restart (&vcont_builder); + struct vcont_builder vcont_builder; + vcont_builder.restart (); /* Threads first. */ ALL_NON_EXITED_THREADS (tp) @@ -6303,7 +6309,7 @@ remote_target::commit_resume () continue; } - vcont_builder_push_action (&vcont_builder, tp->ptid, + vcont_builder.push_action (tp->ptid, remote_thr->last_resume_step, remote_thr->last_resume_sig); remote_thr->vcont_resumed = 1; @@ -6330,8 +6336,8 @@ remote_target::commit_resume () continue action for each running process, if any. */ if (may_global_wildcard_vcont) { - vcont_builder_push_action (&vcont_builder, minus_one_ptid, - 0, GDB_SIGNAL_0); + vcont_builder.push_action (minus_one_ptid, + false, GDB_SIGNAL_0); } else { @@ -6339,15 +6345,14 @@ remote_target::commit_resume () { if (get_remote_inferior (inf)->may_wildcard_vcont) { - vcont_builder_push_action (&vcont_builder, - pid_to_ptid (inf->pid), - 0, GDB_SIGNAL_0); + vcont_builder.push_action (pid_to_ptid (inf->pid), + false, GDB_SIGNAL_0); } } } } - vcont_builder_flush (&vcont_builder); + vcont_builder.flush (); }