From patchwork Wed Jan 22 09:30:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 859140 Delivered-To: patch@linaro.org Received: by 2002:adf:f78a:0:b0:385:e875:8a9e with SMTP id q10csp244619wrp; Wed, 22 Jan 2025 01:32:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXg89ZtICWI/8Ze32/lFaOysLcdOXV0gzMKm6vTcqbZXHAtE2hmSOKvPBoQuZD/83V8+lXfKw==@linaro.org X-Google-Smtp-Source: AGHT+IGJ28JoGD5lQTbaRplhTIabzbI9nu4V9VR3ojE4823RXP4QS2NNNnpcKLU7RYphcIDYpCO6 X-Received: by 2002:a05:620a:44d4:b0:7b6:d237:abe5 with SMTP id af79cd13be357-7be631f305emr2951175285a.20.1737538369263; Wed, 22 Jan 2025 01:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1737538369; cv=none; d=google.com; s=arc-20240605; b=XripsB94fWvgFnF8v20/XbWOIIrAKJvC8Zx+TOACSTx9JI71hMaES5XFCPEWgw+XT/ iuKRmQ4aY5puXGCg14eCbjPWrhRkn0yyHjEcC33mwdURf9rGt5MH1K1TdhYNjUGri+7c Ffmvnv1DkgVxa21s1W9/Bvo8Dth4TnWOkVyTSSu19D1ONOaBfHfMQ2/vJfyD9Ms2bl+y 0IskX9VZqanNvoePkhi1kZyXNPV6hFWYWJOvwE1J2sgZPbJrQ5aLzzbO5orRwx2K/4Sw 1Rma2Nu9eqBZQ0JS5K9U6IUcO5xXU4UaRqsyWB12jipQJ9sFVH8/fK0FUv7/bOxkK6YR akbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=Exwv2SUshKwTjHy8msyqoapLFQlZN2ZYaumIRAoksx4=; fh=Brec4ZYd5wGCfOwL/9Q1OxqxWlcx8jJnKse3UD0zpBM=; b=OTYLYu1d7qE4jeQCRVn46MwB10tWk1jf0BdhDFLBUeJMpPgbf7np2Eh39Od5iF10rp ByrhNP5JpKFckJPbzWwD/dKRwL79ZjpzfH3hE1KDvX1o8Y6b1Cka+EjxSbJn8oLsJ1z8 3rHoFw8XH4jaU9UdwADy8LO3l0M43MlcKrDFkmy3JMamCq0y9amQC5Pp0LpcXZNE84IX xUWnqSf6cZw5TuXngJwsEs1L1tLC/eoSqb2ToG8SEpFOgTFgq/JlEDYXsLsQ9wGY5xYj Bq6xQbuumUbT+XyhdS3q/x7pDloye/+WJMBHAyvHjKWMpv5LX5qrikMzfl+TgbNSUMyK lJfA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1uWhsUU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7be614bfe0csi1429638385a.226.2025.01.22.01.32.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Jan 2025 01:32:49 -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=pass header.i=@linaro.org header.s=google header.b=B1uWhsUU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1taX4Z-0001JO-HO; Wed, 22 Jan 2025 04:30:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1taX4S-0001DO-9d for qemu-devel@nongnu.org; Wed, 22 Jan 2025 04:30:49 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1taX4L-0003Cn-R7 for qemu-devel@nongnu.org; Wed, 22 Jan 2025 04:30:43 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4361b0ec57aso68496625e9.0 for ; Wed, 22 Jan 2025 01:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737538240; x=1738143040; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Exwv2SUshKwTjHy8msyqoapLFQlZN2ZYaumIRAoksx4=; b=B1uWhsUUirJqiJilOepJQOlg7boSiweOkSghn3oQgmW9JtU97oDI1cItnVqnQETQDk I3A76BEv19VAc/qvdzpu3ktDh2psEaXAdfsDB5LgTblxJgQSHmfe2vNs2tOu60v7mV0R gUbs2VppR2m+l7S7XvapLgWCbFlEQRFy5ZV9v5Qd3JxsQzUP8AWcZ4669YUs1YK3VRnO 9yQ98+471ewyNTmFqHf447h+7AkuP63rirubYaHuHMZVbKfeszDCQrNivCbBWx+EukX4 VsFqxi4olRm/zdNQYoIIJeo78NEFVlcg6vhhvMF3aKKCKNAKA+iW1mDcSjqFf08/D7PL z50w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737538240; x=1738143040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Exwv2SUshKwTjHy8msyqoapLFQlZN2ZYaumIRAoksx4=; b=Cn27QaeE2TyF4kPPEWDZ0oT+N/zLI15cOnzH1OD+PNnyRvFS2DDEYDFUTzK4zF3Udd j/lhKPTMVsQNnflPypfMu0yMWS4ysLinLLUojNJdM8eQgp55+IyaP5sAlCz91f2RY8UM vtym9qP4pZNdYvEWh+SO2O8qYi4yblaV6vV18lnrguXUBfYhur6qheiClGwmynXt49mv 3gEebzz6AEnCgOsffdEmIeEUZUO9uVXKOptPEbA699bxcK7yWbe3OixHvCykNpIoctp+ uSE/ta7j8461YjBwfpd3PaKyngTwTSLp7/zAcTtTZ4qrIEJaJtcugvjme6vWH7DMx0OL ilRg== X-Gm-Message-State: AOJu0Yx5+Bs5wPVKRLrrqbUpdhXdA38FUBoAko0mZoT+hkkcaxVpVgJC 3WBZhbdKPdFaH8cTvItt6IAIHV8XZ7lP5JrJOw2MUzYwMp+RkmjHHAw4W1GSu2WavaNNAs7saYf ocZI= X-Gm-Gg: ASbGnct2+b34Ok4VYqbiRkHWYACL1YzoNYh/n5k7bLDVgupW2fCCj6TqFozgcsX2di+ x7/Y9nwtwO4SdtdBvbw+2OUXPftYFywE2Ta87lFcl6xlKYE8LHVPwI0X/87n7HVrM5wmplUBz1c 8jLZ3grN2AYyjJiXJ75mOD8x8QMJJUGQKjRmqBtXcS6B+LcO+9qCCl4EtYiRIX5B0l2+xuEAzwN 2IZklNHfPHBDWEjlB1HG4/srWgqZLRGQdqfYEsbD2psI5kFDy1YN5FOQYqAI4wUxfQ7GedQkhYs nxO1q9xiCrSd7lyc07jz7k3jO4mVzsUqpQebzx58kCYj X-Received: by 2002:a05:600c:ccc:b0:436:1bbe:f686 with SMTP id 5b1f17b1804b1-4389141c073mr153240065e9.21.1737538239766; Wed, 22 Jan 2025 01:30:39 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438b31afb70sm17224715e9.19.2025.01.22.01.30.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 22 Jan 2025 01:30:39 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PATCH v2 02/10] gdbstub: Clarify no more than @gdb_num_core_regs can be accessed Date: Wed, 22 Jan 2025 10:30:20 +0100 Message-ID: <20250122093028.52416-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250122093028.52416-1-philmd@linaro.org> References: <20250122093028.52416-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Both CPUClass::gdb_read_register() and CPUClass::gdb_write_register() handlers are called from common gdbstub code, and won't be called with register index over CPUClass::gdb_num_core_regs: int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc = CPU_GET_CLASS(cpu); if (reg < cc->gdb_num_core_regs) { return cc->gdb_read_register(cpu, buf, reg); } ... } static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) { CPUClass *cc = CPU_GET_CLASS(cpu); if (reg < cc->gdb_num_core_regs) { return cc->gdb_write_register(cpu, mem_buf, reg); } ... } Clarify that in CPUClass docstring, and remove unreachable code on the microblaze and tricore implementations. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 2 ++ target/microblaze/gdbstub.c | 5 ----- target/openrisc/gdbstub.c | 5 ----- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index fb397cdfc53..7b6b22c431b 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -124,7 +124,9 @@ struct SysemuCPUOps; * @get_pc: Callback for getting the Program Counter register. * As above, with the semantics of the target architecture. * @gdb_read_register: Callback for letting GDB read a register. + * No more than @gdb_num_core_regs registers can be read. * @gdb_write_register: Callback for letting GDB write a register. + * No more than @gdb_num_core_regs registers can be written. * @gdb_adjust_breakpoint: Callback for adjusting the address of a * breakpoint. Used by AVR to handle a gdb mis-feature with * its Harvard architecture split code and data. diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c index 09d74e164d0..d493681d38d 100644 --- a/target/microblaze/gdbstub.c +++ b/target/microblaze/gdbstub.c @@ -110,14 +110,9 @@ int mb_cpu_gdb_read_stack_protect(CPUState *cs, GByteArray *mem_buf, int n) int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { - CPUClass *cc = CPU_GET_CLASS(cs); CPUMBState *env = cpu_env(cs); uint32_t tmp; - if (n > cc->gdb_num_core_regs) { - return 0; - } - tmp = ldl_p(mem_buf); switch (n) { diff --git a/target/openrisc/gdbstub.c b/target/openrisc/gdbstub.c index c2a77d5d4d5..45bba80d878 100644 --- a/target/openrisc/gdbstub.c +++ b/target/openrisc/gdbstub.c @@ -47,14 +47,9 @@ int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { - CPUClass *cc = CPU_GET_CLASS(cs); CPUOpenRISCState *env = cpu_env(cs); uint32_t tmp; - if (n > cc->gdb_num_core_regs) { - return 0; - } - tmp = ldl_p(mem_buf); if (n < 32) {