From nobody Sun Oct 5 19:42:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579015641; cv=none; d=zohomail.com; s=zohoarc; b=IeB9d9cy0wfOUZWDrVFg2IBV53xt7YEF+ugPkiUAnBNCcDOfhHqHnIxB6kK/r/TgQw3tg7Lk+PhbUGlQ5vFqcocu5ox/9PQHALWYd3PVXaFUCGvGerRzr+RXGd23CcwwI7uasTD20RzZbzEqKpgRtq61vGHnBhGj7UNPB8/NnWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015641; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=eWXzCVRGYWPxykrBZFdUXmt9SVTkmAdIw/qenKh8AG65P6dO+50I+lRU2/afUMhvbrMLnREiYtSoCGYVGl0/fLavlyvN1HkX8inou/9yTT6yv7+Ww3fYyzESaxSV7Ym3kF1yxq2InIoyoqd0LV+tkCfSEjDvyjSiiYx3MstYSKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579015641268820.4368123408395; Tue, 14 Jan 2020 07:27:21 -0800 (PST) Received: from localhost ([::1]:42056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO6C-00026a-76 for importer@patchew.org; Tue, 14 Jan 2020 10:27:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpm-0005Uu-7t for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpk-0007iN-JM for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:22 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:51042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpj-0007Zo-6u for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:20 -0500 Received: by mail-wm1-x343.google.com with SMTP id a5so14210057wmb.0 for ; Tue, 14 Jan 2020 07:10:12 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y6sm19661497wrl.17.2020.01.14.07.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B24B71FFA9; Tue, 14 Jan 2020 15:09:57 +0000 (GMT) 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=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=rP4mPkWWfOjtPv7lRbz3RJYmwDAnVsmCCYYDVva8UXUG7rbSBqmm2L+mITM1iIcxiP 87886LCapsDL1pZuhnCItDpQ2Lq3AjYObfk1q1JVFjBRYPrwUl+Vf1f0WUa0DKH2XXZb bbzZee86Oi7Ot8pRdb2EHSwyaM8NxlUntmqHUyNGujaQkVxaTwhXRth0ojKYg0NidfwP xb6brQ1tlML5FABsHTMu3DaoYVnMJ35JxHHkq0OUc0O37I7FZfNGMTTZQDEQae1mXPt/ 4HgJnEjUvuXaeY8u2NILROxCiOMDbOipG6E0nV9X3IQDU7c/JjW0MEg8+674MagOZTgL pWnw== 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=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=UzDrVIwsSSwbKUDSkuv17j57UTm6hehCRI2g+KftXJd9vCE0YSS3XRgpax4WCc3TAY GO7BUZoK3/Y8mofcc3H91WFUYM6YNixjLVRVsxvpPtWgj99asprVL5HzHgJ1atgWQgK3 yWP1zuuCWI6TSTGy+FRcLJxXRzrRRHy5BJrZ8jlRhJfcbvOFMFkSe7vRahH3c9L/mRB/ QKaIgzDHPEaLQTu+7nkJtGJx05XwUOZUQ0eYubribd50hwQQYgha3NjJXUXt9pz/Mjqd eZH5zYV+8Btx46uALpe2+eci3IYy2GgT/5tl+L+Tn2UGsuzlG4YDSSGxzjgrCUNMjsV5 jPew== X-Gm-Message-State: APjAAAVyWPUMvDYjaZ9KiFlQCW6hva3eW1MADEClXHtpKDLJ3WEi9ni3 udTV25r/DoubxF8imfTP7o4GXg== X-Google-Smtp-Source: APXvYqz+LpsChzstUjIprs1+gIZGbO/09Rj9rBC+/uDZi6zfmwLUZGKNjl9RsGmYOuac1/SDMGxMUg== X-Received: by 2002:a7b:ca4c:: with SMTP id m12mr26723126wml.176.1579014612025; Tue, 14 Jan 2020 07:10:12 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 21/22] gdbstub: change GDBState.last_packet to GByteArray Date: Tue, 14 Jan 2020 15:09:52 +0000 Message-Id: <20200114150953.27659-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 Message-Id: <20191211160514.58373-2-damien.hedde@greensocs.com> Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index dcfa4f1dd7..b9fb8c0a95 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 =3D true; gdbserver_state.str_buf =3D g_string_new(NULL); gdbserver_state.mem_buf =3D g_byte_array_sized_new(MAX_PACKET_LENGTH); + gdbserver_state.last_packet =3D g_byte_array_sized_new(MAX_PACKET_LENG= TH + 4); } =20 #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 =3D &gdbserver_state.last_packet[0]; + uint8_t footer[3]; =20 if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPL= Y)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } =20 for(;;) { - p =3D ps; - *(p++) =3D '$'; - memcpy(p, buf, len); - p +=3D 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 =3D 0; for(i =3D 0; i < len; i++) { csum +=3D buf[i]; } - *(p++) =3D '#'; - *(p++) =3D tohex((csum >> 4) & 0xf); - *(p++) =3D tohex((csum) & 0xf); + footer[0] =3D '#'; + footer[1] =3D tohex((csum >> 4) & 0xf); + footer[2] =3D tohex((csum) & 0xf); + g_byte_array_append(gdbserver_state.last_packet, footer, 3); =20 - gdbserver_state.last_packet_len =3D p - ps; - put_buffer(ps, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); =20 #ifdef CONFIG_USER_ONLY i =3D get_char(); @@ -2812,20 +2813,22 @@ static void gdb_read_byte(uint8_t ch) uint8_t reply; =20 #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 =3D=3D '-') { trace_gdbstub_err_got_nack(); - put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_s= tate.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); } else if (ch =3D=3D '+') { trace_gdbstub_io_got_ack(); } else { trace_gdbstub_io_got_unexpected(ch); } =20 - if (ch =3D=3D '+' || ch =3D=3D '$') - gdbserver_state.last_packet_len =3D 0; + if (ch =3D=3D '+' || ch =3D=3D '$') { + g_byte_array_set_size(gdbserver_state.last_packet, 0); + } if (ch !=3D '$') return; } @@ -3209,7 +3212,7 @@ static int gdb_monitor_write(Chardev *chr, const uint= 8_t *buf, int len) const char *p =3D (const char *)buf; int max_sz; =20 - max_sz =3D (sizeof(gdbserver_state.last_packet) - 2) / 2; + max_sz =3D (MAX_PACKET_LENGTH / 2) + 1; for (;;) { if (len <=3D max_sz) { gdb_monitor_output(p, len); --=20 2.20.1