On 4/3/26 07:33, Philippe Mathieu-Daudé wrote:
On 27/2/26 22:39, Philippe Mathieu-Daudé wrote:
gdb_register_coprocessor()'s @g_pos argument is always '0',
meaning it is inferred from cpu->gdb_num_regs. Use instead
feature->base_reg, but check we don't overwrite other indexed
registers.

This fixes a bug with the "power-fpu.xml" file [*] which was
loaded at index 70 while the base register is 71. This latent
bug was exposed by commit 1ec0fbe2dda ("target/ppc: Fix
CPUClass::gdb_num_core_regs value").

[*] https://lore.kernel.org/qemu-devel/e44df309- [email protected]/

Reported-by: Florian Hofhammer <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
  include/exec/gdbstub.h     |  3 +--
  gdbstub/gdbstub.c          | 16 +++++-----------
  target/arm/gdbstub.c       | 21 ++++++++-------------
  target/arm/gdbstub64.c     | 19 +++++++------------
  target/hexagon/cpu.c       |  2 +-
  target/i386/gdbstub.c      |  8 +++-----
  target/loongarch/gdbstub.c |  6 +++---
  target/m68k/helper.c       |  4 ++--
  target/microblaze/cpu.c    |  3 +--
  target/ppc/gdbstub.c       | 11 +++++------
  target/riscv/gdbstub.c     | 18 ++++++------------
  target/s390x/gdbstub.c     | 15 +++++++--------
  target/sparc/gdbstub.c     | 12 ++++--------
  13 files changed, 53 insertions(+), 85 deletions(-)

diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 12e7b5b7282..75eb4d9c365 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -35,11 +35,10 @@ void gdb_init_cpu(CPUState *cpu);
   * @set_reg - set function (gdb modifying)
   * @num_regs - number of registers in set
   * @xml - xml name of set
- * @gpos - non-zero to append to "general" register set at @gpos
   */
  void gdb_register_coprocessor(CPUState *cpu,
                                gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
-                              const GDBFeature *feature, int g_pos);
+                              const GDBFeature *feature);
  /**
   * gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 6eadae3804e..882bc67e182 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -604,13 +604,14 @@ void gdb_init_cpu(CPUState *cpu)
  void gdb_register_coprocessor(CPUState *cpu,
                                gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
-                              const GDBFeature *feature, int g_pos)
+                              const GDBFeature *feature)
  {
      GDBRegisterState *s;
      guint i;
-    int base_reg = cpu->gdb_num_regs;
+    int base_reg;
-    assert(!g_pos || g_pos == feature->base_reg);
+    assert(feature->base_reg >= cpu->gdb_num_regs);

This should be:

  +    assert(!feature->base_reg || feature->base_reg >= cpu- >gdb_num_regs);

But still not enough:

https://github.com/philmd/qemu/actions/runs/22658072426/job/65672033735

:(

Reply via email to