From patchwork Wed Feb 5 17:10:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 11366691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A81192A for ; Wed, 5 Feb 2020 17:22:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5133B20702 for ; Wed, 5 Feb 2020 17:22:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hJlscAK0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5133B20702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izONN-0006y9-Ed for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Feb 2020 12:22:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37984) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izOIX-0007jk-9Q for qemu-devel@nongnu.org; Wed, 05 Feb 2020 12:17:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izOIV-0006MC-VK for qemu-devel@nongnu.org; Wed, 05 Feb 2020 12:17:09 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:37476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izOIV-0006DA-NI for qemu-devel@nongnu.org; Wed, 05 Feb 2020 12:17:07 -0500 Received: by mail-wm1-x342.google.com with SMTP id f129so3766434wmf.2 for ; Wed, 05 Feb 2020 09:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aZuMW44fnQ04CL8/YhpNcDrPqDAquQNEa3kKCwxgJO4=; b=hJlscAK0cb1ygwmwvyDlLKaFbePQDRx5UXs6llfNmKr72lKOADg1lcYvADn6OQjU4L ZDusZGUNGzLPt91NtkGGSdrz7NZaQWrGtilGdRi8DnrbBrGRykvZFXo/PjEmc2/37EJo uRmacKG4AhkZyhlf2AWFG9hBs66794f+QB16f6/qkLFaeIhKliTuhcOudvQJFFE7TI11 HGXLkoMcIr39RDsHyn4PnG4nj/trFqrA2xFOaNHJ92fWMlUDEuqeGRi0l5ZcttnIUtdX FBARWiw8rgQtXbpHvhBp+oZ/NRQIPGcdF/QX+1SS/QQFxiuK1XMEPbzxVxXFdAn6ujAG Ra6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aZuMW44fnQ04CL8/YhpNcDrPqDAquQNEa3kKCwxgJO4=; b=M1S/gIy6PSxfwN4rmnx/4S7S+WoP84P2GZ973Ba1z1Ri59a3OzmLX+HWPNHtFT9ker 1H30nTCNhEnIDEURvd+vK0nzLUNi22TTjeisAYgfOQZE+qhJIj7EclsMh1xiZN+y0dBO cJ8cCaZ0CVSwzf5clc41hOQEkMDSzWWRwI3sB6hN1T4LNo1to0gZR3cFt1oXdoG6wZPZ vMH2eN1L0yK/d5HMBe9egDOeA0SnEa86v4Spvwxn5XCircakeG+HOn/Kh1GDL5G2TRUm +mfl6tz9ZuKdud/adpcd6RxzZ4lWRrXJPaCAyTxmM6IIgwtxbkPngYmWhpeexTHeETOe BPEQ== X-Gm-Message-State: APjAAAUuJg7MpZo+N66b9tWrbtuaa3R2EkJcozwKBFi3a79lrdU7RtCx rKDGkBJuFIiB91Xt2bpZsTJOLw== X-Google-Smtp-Source: APXvYqzRPVrzjOuU+2VKiiukxk6/r+PlMTlfriIj83tkEXrISLYJn41Tz3eDTbIP62dx0OnrsJ1HOw== X-Received: by 2002:a1c:a78b:: with SMTP id q133mr6570389wme.28.1580923026611; Wed, 05 Feb 2020 09:17:06 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w13sm589266wru.38.2020.02.05.09.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 09:17:02 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B672D1FFAC; Wed, 5 Feb 2020 17:10:33 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v6 21/22] gdbstub: change GDBState.last_packet to GByteArray Date: Wed, 5 Feb 2020 17:10:30 +0000 Message-Id: <20200205171031.22582-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200205171031.22582-1-alex.bennee@linaro.org> References: <20200205171031.22582-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philippe_?= =?utf-8?q?Mathieu-Daud=C3=A9?= , richard.henderson@linaro.org, alan.hayward@arm.com, =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Damien Hedde Remove the packet size upper limit by using a GByteArray instead of a statically allocated array for last_packet. Thus we can now send big packets. Also remove the last_packet_len field and use last_packet->len instead. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20191211160514.58373-2-damien.hedde@greensocs.com> Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index dcfa4f1dd75..b9fb8c0a95a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -351,8 +351,7 @@ typedef struct GDBState { int line_buf_index; int line_sum; /* running checksum */ int line_csum; /* checksum at the end of the packet */ - uint8_t last_packet[MAX_PACKET_LENGTH + 4]; - int last_packet_len; + GByteArray *last_packet; int signal; #ifdef CONFIG_USER_ONLY int fd; @@ -384,6 +383,7 @@ static void init_gdbserver_state(void) gdbserver_state.init = true; gdbserver_state.str_buf = g_string_new(NULL); gdbserver_state.mem_buf = g_byte_array_sized_new(MAX_PACKET_LENGTH); + gdbserver_state.last_packet = g_byte_array_sized_new(MAX_PACKET_LENGTH + 4); } #ifndef CONFIG_USER_ONLY @@ -626,28 +626,29 @@ static void hexdump(const char *buf, int len, static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; - uint8_t *p; - uint8_t *ps = &gdbserver_state.last_packet[0]; + uint8_t footer[3]; if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPLY)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } for(;;) { - p = ps; - *(p++) = '$'; - memcpy(p, buf, len); - p += len; + g_byte_array_set_size(gdbserver_state.last_packet, 0); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) "$", 1); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) buf, len); csum = 0; for(i = 0; i < len; i++) { csum += buf[i]; } - *(p++) = '#'; - *(p++) = tohex((csum >> 4) & 0xf); - *(p++) = tohex((csum) & 0xf); + footer[0] = '#'; + footer[1] = tohex((csum >> 4) & 0xf); + footer[2] = tohex((csum) & 0xf); + g_byte_array_append(gdbserver_state.last_packet, footer, 3); - gdbserver_state.last_packet_len = p - ps; - put_buffer(ps, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); #ifdef CONFIG_USER_ONLY i = get_char(); @@ -2812,20 +2813,22 @@ static void gdb_read_byte(uint8_t ch) uint8_t reply; #ifndef CONFIG_USER_ONLY - if (gdbserver_state.last_packet_len) { + if (gdbserver_state.last_packet->len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch == '-') { trace_gdbstub_err_got_nack(); - put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); } else if (ch == '+') { trace_gdbstub_io_got_ack(); } else { trace_gdbstub_io_got_unexpected(ch); } - if (ch == '+' || ch == '$') - gdbserver_state.last_packet_len = 0; + if (ch == '+' || ch == '$') { + g_byte_array_set_size(gdbserver_state.last_packet, 0); + } if (ch != '$') return; } @@ -3209,7 +3212,7 @@ static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) const char *p = (const char *)buf; int max_sz; - max_sz = (sizeof(gdbserver_state.last_packet) - 2) / 2; + max_sz = (MAX_PACKET_LENGTH / 2) + 1; for (;;) { if (len <= max_sz) { gdb_monitor_output(p, len);