]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
target/loongarch/gdbstub: Fix gdbstub incorrectly handling some registers
authorBibo Mao <maobibo@loongson.cn>
Tue, 18 Feb 2025 03:20:27 +0000 (11:20 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Sat, 22 Mar 2025 07:52:51 +0000 (10:52 +0300)
Write operation with R32 (orig_a0) and R34 (CSR_BADV) is discarded on
gdbstub implementation for LoongArch system. And return value should
be register size rather than 0, since it is used to calculate offset of
next register such as R33 (PC) in function handle_write_all_regs().

Cc: qemu-stable@nongnu.org
Fixes: ca61e75071c6 ("target/loongarch: Add gdb support.")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
(cherry picked from commit 7bd4eaa847fcdbc4505d9ab95dafa21791d8302a)
(Mjt: context fix due to missing v9.1.0-913-g2a99b2af2c
 "target/loongarch: Use explicit little-endian LD/ST API")
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
target/loongarch/gdbstub.c

index 5fc2f19e965e101a269c923a101c9be05d2bd2ac..320a6f2fcc966d7a8dd5ffbe2b9044bcecc49830 100644 (file)
@@ -63,23 +63,24 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     LoongArchCPU *cpu = LOONGARCH_CPU(cs);
     CPULoongArchState *env = &cpu->env;
     target_ulong tmp;
-    int read_length;
     int length = 0;
 
+    if (n < 0 || n > 34) {
+        return 0;
+    }
+
     if (is_la64(env)) {
         tmp = ldq_p(mem_buf);
-        read_length = 8;
+        length = 8;
     } else {
         tmp = ldl_p(mem_buf);
-        read_length = 4;
+        length = 4;
     }
 
     if (0 <= n && n < 32) {
         env->gpr[n] = tmp;
-        length = read_length;
     } else if (n == 33) {
         set_pc(env, tmp);
-        length = read_length;
     }
     return length;
 }