From patchwork Wed Jun 20 21:08:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pedromfc X-Patchwork-Id: 27952 Received: (qmail 17282 invoked by alias); 20 Jun 2018 21:09:26 -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 17166 invoked by uid 89); 20 Jun 2018 21:09:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Jun 2018 21:09:21 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5KKs2iJ087686 for ; Wed, 20 Jun 2018 17:09:20 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jqx6a0ue3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 20 Jun 2018 17:09:19 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Jun 2018 15:09:19 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 20 Jun 2018 15:09:16 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5KL9Df98716548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 20 Jun 2018 14:09:14 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE1FBBE054; Wed, 20 Jun 2018 15:09:13 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A42DFBE058; Wed, 20 Jun 2018 15:09:13 -0600 (MDT) Received: from pedro.localdomain (unknown [9.18.235.95]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 20 Jun 2018 15:09:13 -0600 (MDT) Received: by pedro.localdomain (Postfix, from userid 1000) id 01AAB3C042B; Wed, 20 Jun 2018 18:09:11 -0300 (-03) From: Pedro Franco de Carvalho To: gdb-patches@sourceware.org Cc: uweigand@de.ibm.com Subject: [PATCH 3/4] Use get_remote_packet_size in download_tracepoint Date: Wed, 20 Jun 2018 18:08:54 -0300 In-Reply-To: <20180620210855.6385-1-pedromfc@linux.vnet.ibm.com> References: <20180620210855.6385-1-pedromfc@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18062021-0020-0000-0000-00000E32E69C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009229; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01049878; UDB=6.00537991; IPR=6.00828851; MB=3.00021765; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-20 21:09:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062021-0021-0000-0000-000062027EF1 Message-Id: <20180620210855.6385-4-pedromfc@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-20_09:, , signatures=0 X-IsSubscribed: yes This patch changes the remote target to use the remote packet size to build QTDP packets. The char array used to build the packets is changed to a gdb::char_vector and sized with the result from get_remote_packet_size. All writes to the buffer are changed to use xsnprintf, so that no assumptions on the size of the action strings are needed. gdb/ChangeLog: YYYY-MM-DD Pedro Franco de Carvalho * remote.c (remote_target::download_tracepoint): Remove BUF_SIZE and pkt. Replace array buf with gdb::char_vector buf, of size get_remote_packet_size (). Replace references to buf and BUF_SIZE to buf.data () and buf.size (). Replace strcpy, strcat and pack_hex_byte with xsnprintf. --- gdb/remote.c | 68 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 04dc67fdc0..f5fbb7e7ce 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12793,23 +12793,24 @@ remote_target::remote_download_command_source (int num, ULONGEST addr, void remote_target::download_tracepoint (struct bp_location *loc) { -#define BUF_SIZE 2048 - CORE_ADDR tpaddr; char addrbuf[40]; - char buf[BUF_SIZE]; std::vector tdp_actions; std::vector stepping_actions; - char *pkt; struct breakpoint *b = loc->owner; struct tracepoint *t = (struct tracepoint *) b; struct remote_state *rs = get_remote_state (); + /* We use a buffer other than rs->buf because we'll build strings + across multiple statements, and other statements in between could + modify rs->buf. */ + gdb::char_vector buf (get_remote_packet_size ()); + encode_actions_rsp (loc, &tdp_actions, &stepping_actions); tpaddr = loc->address; sprintf_vma (addrbuf, tpaddr); - xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number, + xsnprintf (buf.data (), buf.size (), "QTDP:%x:%s:%c:%lx:%x", b->number, addrbuf, /* address */ (b->enable_state == bp_enabled ? 'E' : 'D'), t->step_count, t->pass_count); @@ -12824,8 +12825,9 @@ remote_target::download_tracepoint (struct bp_location *loc) { if (gdbarch_fast_tracepoint_valid_at (loc->gdbarch, tpaddr, NULL)) - xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x", - gdb_insn_length (loc->gdbarch, tpaddr)); + xsnprintf (buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ()), + ":F%x", gdb_insn_length (loc->gdbarch, tpaddr)); else /* If it passed validation at definition but fails now, something is very wrong. */ @@ -12849,7 +12851,8 @@ remote_target::download_tracepoint (struct bp_location *loc) struct static_tracepoint_marker marker; if (target_static_tracepoint_marker_at (tpaddr, &marker)) - strcat (buf, ":S"); + xsnprintf (buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ()), ":S"); else error (_("Static tracepoint not valid during download")); } @@ -12868,12 +12871,23 @@ remote_target::download_tracepoint (struct bp_location *loc) if (remote_supports_cond_tracepoints ()) { agent_expr_up aexpr = gen_eval_for_expr (tpaddr, loc->cond.get ()); - xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,", + xsnprintf (buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ()), ":X%x,", aexpr->len); - pkt = buf + strlen (buf); + + char *end = buf.data () + strlen (buf.data ()); + long size_left = buf.size () - strlen (buf.data ()); + char hex_byte[3]; + hex_byte[2] = '\0'; + for (int ndx = 0; ndx < aexpr->len; ++ndx) - pkt = pack_hex_byte (pkt, aexpr->buf[ndx]); - *pkt = '\0'; + { + pack_hex_byte (hex_byte, aexpr->buf[ndx]); + xsnprintf (end, size_left, hex_byte); + + size_left -= strlen (end); + end += strlen (end); + } } else warning (_("Target does not support conditional tracepoints, " @@ -12881,8 +12895,10 @@ remote_target::download_tracepoint (struct bp_location *loc) } if (b->commands || *default_collect) - strcat (buf, "-"); - putpkt (buf); + xsnprintf (buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ()), "-"); + + putpkt (buf.data ()); remote_get_noisy_reply (); if (strcmp (rs->buf, "OK")) error (_("Target does not support tracepoints.")); @@ -12896,11 +12912,11 @@ remote_target::download_tracepoint (struct bp_location *loc) bool has_more = ((action_it + 1) != tdp_actions.end () || !stepping_actions.empty ()); - xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c", + xsnprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%c", b->number, addrbuf, /* address */ action_it->c_str (), has_more ? '-' : 0); - putpkt (buf); + putpkt (buf.data ()); remote_get_noisy_reply (); if (strcmp (rs->buf, "OK")) error (_("Error on target while setting tracepoints.")); @@ -12914,12 +12930,12 @@ remote_target::download_tracepoint (struct bp_location *loc) bool is_first = action_it == stepping_actions.begin (); bool has_more = (action_it + 1) != stepping_actions.end (); - xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s", + xsnprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%s%s", b->number, addrbuf, /* address */ is_first ? "S" : "", action_it->c_str (), has_more ? "-" : ""); - putpkt (buf); + putpkt (buf.data ()); remote_get_noisy_reply (); if (strcmp (rs->buf, "OK")) error (_("Error on target while setting tracepoints.")); @@ -12929,22 +12945,24 @@ remote_target::download_tracepoint (struct bp_location *loc) { if (b->location != NULL) { - strcpy (buf, "QTDPsrc:"); + xsnprintf (buf.data (), buf.size (), "QTDPsrc:"); encode_source_string (b->number, loc->address, "at", event_location_to_string (b->location.get ()), - buf + strlen (buf), 2048 - strlen (buf)); - putpkt (buf); + buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ())); + putpkt (buf.data ()); remote_get_noisy_reply (); if (strcmp (rs->buf, "OK")) warning (_("Target does not support source download.")); } if (b->cond_string) { - strcpy (buf, "QTDPsrc:"); + xsnprintf (buf.data (), buf.size (), "QTDPsrc:"); encode_source_string (b->number, loc->address, - "cond", b->cond_string, buf + strlen (buf), - 2048 - strlen (buf)); - putpkt (buf); + "cond", b->cond_string, + buf.data () + strlen (buf.data ()), + buf.size () - strlen (buf.data ())); + putpkt (buf.data ()); remote_get_noisy_reply (); if (strcmp (rs->buf, "OK")) warning (_("Target does not support source download."));