From patchwork Tue Apr 14 20:06:26 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: 185444 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1834812ilf; Tue, 14 Apr 2020 13:10:43 -0700 (PDT) X-Google-Smtp-Source: APiQypILOjg7w1u5N0ZtVgUEcKjNy7a3zhS0IvVIIgc1uKwGtwo0B2zvMlfGV3KQgFGBPyiK+/HB X-Received: by 2002:a37:a049:: with SMTP id j70mr7787740qke.193.1586895043549; Tue, 14 Apr 2020 13:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586895043; cv=none; d=google.com; s=arc-20160816; b=wCzwkTSXsY2iRs2se/28HSJkMAMd0jDhIQt/3XLxaa74kOXTYfS8ielDOy6uKzThqU SiAaCpDxisqE8pg3KBG0FId/KHjlCDw4/a1Cg1o3B2ZjtXDGhCndXTchHx4/kOkFDxZN +pliMphTd0fk1036IBPMFKfh2AjEt86SHN6hZAJFM5hhi93C62HFQaxSXmtTdZS78IjD lbzcpHmhEMLkTPcYt1xLj0C0XQR8FkYMzITBCO9uE0UcfGMgjCOEIpJIqMnLpD9vMbAN 6ujhWKaMCRvbTPnSR9zR52l04zPzMWIZBq5pHOfgBNN2PWf0KWrSqhrPwVwCqDNVIztB Nr0Q== 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=aZ6FKx87IIsaQ+fv9HHif36FthP5pDUoqk2AxtvgmQ8=; b=0+LLbynU8opkDX5b2qAlyS+SfP2FxUdXil4+2vKjPN9Qvtr0++I9NCPex+hZZb1M3x DWr84NsN8yVWYzqgk2BfX4Eos2VvCZWow+kEHAyhFX1XpYvTR0PosnKyd9nfLe6WtU6x EuhwfwQ1r2a1Qx32FtFTqw6dL9brjouc1vkK/lNjYu4TDrUUIpotD9F1gZlj18+L4+Xl iqAaSMEIYR5mJclwm0IpZfJAWJnSKDtQ2oyDcZQ4EnRY6wBqPDAIZHdCXzpj7mJBHsVV PK/r81Msay880ECRhYoEXNjFulZFEhbEq6UNVal9jLkt54OwgTpoj6DvPNJgLlKRF+92 3B3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eUXplBNY; 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 f11si8437279qtm.12.2020.04.14.13.10.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Apr 2020 13:10:43 -0700 (PDT) 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=eUXplBNY; 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]:38428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jORtL-0004eW-2W for patch@linaro.org; Tue, 14 Apr 2020 16:10:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44542) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jORpY-0006Ag-OG for qemu-devel@nongnu.org; Tue, 14 Apr 2020 16:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jORpX-0005yQ-JD for qemu-devel@nongnu.org; Tue, 14 Apr 2020 16:06:48 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:54470) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jORpX-0005xz-CK for qemu-devel@nongnu.org; Tue, 14 Apr 2020 16:06:47 -0400 Received: by mail-wm1-x332.google.com with SMTP id h2so14492110wmb.4 for ; Tue, 14 Apr 2020 13:06:47 -0700 (PDT) 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=aZ6FKx87IIsaQ+fv9HHif36FthP5pDUoqk2AxtvgmQ8=; b=eUXplBNYodG6JvFBONo8L2tEaI/kp6eZoywXUqbyebmAcDcuCDcAeR0YJYW95D5TaH 0RNJJwZpd3ggMQ/YHnfJGW72P1lZk0wVjw7RWju1wmk/LB2XZtag/CxNHYbBpDDcqYyq 1hlP7oX7jJxTMPnELJTdLeg3hkiyyFtsBeuttFJT5tuIk86jyxkVhgNjv4saKw+uRsfn F007fJBxomr6EKdpnxoRpIjjnAmQsOFKEaU3/lnOR8p3lGjven6DckXymUNTdqDz610z 8X35a5na7Rav/ANxVFULQgDnsw55VRFt6+KfllhSogx72uBa5fR3gbQT4JDnxlwfCOh9 t6bA== 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=aZ6FKx87IIsaQ+fv9HHif36FthP5pDUoqk2AxtvgmQ8=; b=b4NDhEZnHBO25iBElobheZm0ggRpAlM3SfUIc+cfwznOI3LrwRmqyPacr/z+TuZ3wO t8/eE304Ko2g4jyabb3bYna+AVHayChut/9+f75cARVYelQBnYv1hyf5JV8ee6PnGTvH bAp6OwVz+zDrMmRuLkXQeTkVWqFLbCl3egta08p0tYpE7UB9gOLSuQQXDjhCUU0W4DIZ P6GwhXLSutLcGstW13xPUR/u93H0hhkPRLitBMrfmQ6SXpnx66uK4q0dGjkouh8GV3/p sxebk5xG2aOlZS+wBwsaxMPb1GbFHIntt3J0+9fDjbrxWOp8kOwHEoGtXbkz2m9uvUrj 2K+Q== X-Gm-Message-State: AGi0PuZsTXPUut4DWGqYFi4Yd49f6TUlcejK1C/S9F+azTfQDkDU/6Rw mI1erRPgPfaUuce1sMuwc2PKOQ== X-Received: by 2002:a1c:4b0a:: with SMTP id y10mr1472289wma.24.1586894806418; Tue, 14 Apr 2020 13:06:46 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q17sm11836553wmj.45.2020.04.14.13.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 13:06:44 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 87CFB1FF9B; Tue, 14 Apr 2020 21:06:33 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 12/17] gdbstub: Do not use memset() on GByteArray Date: Tue, 14 Apr 2020 21:06:26 +0100 Message-Id: <20200414200631.12799-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414200631.12799-1-alex.bennee@linaro.org> References: <20200414200631.12799-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::332 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: Max Filippov , =?utf-8?q?Alex_Benn=C3=A9e?= , "open list:ARM TCG CPUs" , =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Introduce gdb_get_zeroes() to fill a GByteArray with zeroes. Fixes: a010bdbe719 ("extend GByteArray to read register helpers") Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20200414102427.7459-1-philmd@redhat.com> [AJB: used slightly more gliby set_size approach] Signed-off-by: Alex Bennée --- include/exec/gdbstub.h | 9 +++++++++ target/arm/gdbstub.c | 3 +-- target/xtensa/gdbstub.c | 6 ++---- 3 files changed, 12 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 30b909ebd27..3c452fc50c0 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -125,6 +125,15 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, return 16; } +static inline int gdb_get_zeroes(GByteArray *array, size_t len) +{ + guint oldlen = array->len; + g_byte_array_set_size(array, oldlen + len); + memset(array->data + oldlen, 0, len); + + return len; +} + /** * gdb_get_reg_ptr: get pointer to start of last element * @len: length of element diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 8efc535f2a0..063551df234 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -47,8 +47,7 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) if (gdb_has_xml) { return 0; } - memset(mem_buf, 0, 12); - return 12; + return gdb_get_zeroes(mem_buf, 12); } switch (n) { case 24: diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c index 0ee3feabe54..4d43f1340ae 100644 --- a/target/xtensa/gdbstub.c +++ b/target/xtensa/gdbstub.c @@ -105,8 +105,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) default: qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported size %d\n", __func__, n, reg->size); - memset(mem_buf, 0, reg->size); - return reg->size; + return gdb_get_zeroes(mem_buf, reg->size); } case xtRegisterTypeWindow: /*a*/ @@ -115,8 +114,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) default: qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported type %d\n", __func__, n, reg->type); - memset(mem_buf, 0, reg->size); - return reg->size; + return gdb_get_zeroes(mem_buf, reg->size); } }