From patchwork Fri Dec 20 12:04:37 2019 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: 182266 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp469809ilf; Fri, 20 Dec 2019 04:35:48 -0800 (PST) X-Google-Smtp-Source: APXvYqy8ucUwdR10DjWsk1Rfmcld/XzGno32biQ4SULttoJPYm0HmIf6OCrQ69sM275POWxEm2z7 X-Received: by 2002:aca:4ec5:: with SMTP id c188mr74676oib.1.1576845348693; Fri, 20 Dec 2019 04:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576845348; cv=none; d=google.com; s=arc-20160816; b=leH9SL9py96XktGmpYFLiiEYDfbNIfPTq4YedGHem6UBWwOHKh2kHEyhIKYvJioo6Q BXduiEh1IAj/HshfpJ40zWBhEMDMpsioSe47PQa3zxCFxpo/fz4VMMADVRf0RXoHz5Rb Xx2EF+BcYdnIEvX68OdFxmKHh72uMJYBF7GZv7cKyW3PqoIlFb/lAz8yjLJHoEgixeqa GoalUwSZxMZ3w0tWrabEW090yHc82ODUf3gpFy1Wk/uJO7WLzYKGpjayHLP2xTq+/XJq tgUBM9Qq4OtN8ZjTjznlKqi/5K2/uFSDG5nNs6NKxMN5HRG5GwSdLtvdesJeC+8npdeU D6IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=HYTs7VdnIgn/2DYwqX0gFyzRy+yVJG3yPznnADafXQvEoOUHhyXqKXAC4FEj/6Gx0z FZMDxqdNOKEkdnhSfVZwcgcX2k61smxyrBbFFqR6AKIMA00iGfIspnLonOfB/XMt61Ly 0mvsR+UY7jUMjDkCSGxEWyMICU4wz2rDmU7SymUiqBdOmfTeA3ChGU6amnIVN7YjSTEa /rUf/EWbXg711ZmQexPjDfe/igSg0pW7LAMIEWhYaWVB/rI6XQhjaeHJh7uI+UCV38gf lqUq64Ldv2y+QDxIpw4/KuhNap1C4BUnnCgzcUDsBIl1K1LA/j7iJvpKSttyslf02M+m Yjpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qA2Nbbnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x142si2364989oia.220.2019.12.20.04.35.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:35:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qA2Nbbnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHVT-0001oq-TZ for patch@linaro.org; Fri, 20 Dec 2019 07:35:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36706) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAu-0000jj-RM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAt-0001Q9-39 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAs-0001M9-Oa for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:30 -0500 Received: by mail-wm1-x343.google.com with SMTP id c127so1632092wme.1 for ; Fri, 20 Dec 2019 04:14:30 -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=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=qA2Nbbnkf7t7LSKkmijtFigfij9EhBRtlf6+zLdSkH420XupqFUbMgVl9WcotKQEir fQYZXiwOwqXHl89D5VpT2YUiZK23e1DYjanfr7ZN4N2+JIOLltDI2tEx+Hel7HmfOakt ngHiiPj1zFQx5T8UFC9WvVXxphsrCHps0FzUznXpSsTf2DUPXut5jBeQQoZMB4i9ELGh rDLF6ELs8bZObKdDbNrU21jjHbV0Bkwjm2Vn36a1zANq2zbvk2xcbraG4XxL5GHhGZyQ Hv1ZiF3c2ReAx3O/Gbi9duUuFjpeaEFKa+ccTVpAPzWlM14mh7zUFzU3ak5iQEW7icOI kNtg== 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=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=hXMRQuLQ3FOCB5cdbII9D2bV4o41R+MUwV/L7ZRWLapFUbNrrUkQpZHAsvYv5g+vcy 8buCAuNLLbx4Z6Ql/JlHKYJzcChiqOWMz+s2bZJYZh4ScnEDb7xSkMV4wNoet55GDnDZ oKgvgu/QiotzTqSsgoFuXKG7M+iOfdELz3nHjYgQJLukv8kmwM4Od4w3iwqal7b8Cgtn emk6DeQdePYYYnTcgtqJi8Uadgx2CsOt2KwhIKPMWPWgcyybWnezNgnd6NYUGC4M/QVG pJrFa+aZqCV5BPGA/XdNPz3Yv8O7f8lyEiNDHdi7ppop4Cu2s65Mqrsbaj3T2n8LQYHF b8Vw== X-Gm-Message-State: APjAAAW7tfzy1CtDDcVN1XRtbAvruNf8xvAlsE3uY3DrxDAC/4od7Bo7 I7ZLqQW9nVmfWhWsR7B4z/opaA== X-Received: by 2002:a7b:cd0a:: with SMTP id f10mr16703426wmj.56.1576844069376; Fri, 20 Dec 2019 04:14:29 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s10sm9517124wrw.12.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 00A021FFAA; Fri, 20 Dec 2019 12:04:41 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 20/21] gdbstub: change GDBState.last_packet to GByteArray Date: Fri, 20 Dec 2019 12:04:37 +0000 Message-Id: <20191220120438.16114-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-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::343 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, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+patch=linaro.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 --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 287d0535b12..49e760283db 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);