target/ppc: Fix GDB register indexing on secondary CPUs

The GDB server protocol assigns an arbitrary numbering of the SPRs.
We track this correspondence on each SPR with gdb_id, using it to
resolve any SPR requests GDB makes.

Early on we generate an XML representation of the SPRs to give GDB,
including this numbering. However the XML is cached globally, and we
skip setting the SPR gdb_id values on subsequent threads if we detect
it is cached. This causes QEMU to fail to resolve SPR requests against
secondary CPUs because it cannot find the matching gdb_id value on that
thread's SPRs.

This is a minimal fix to first assign the gdb_id values, then return
early if the XML is cached. Otherwise we generate the XML using the
now already initialised gdb_id values.

Fixes: 1b53948ff8 ("target/ppc: Use GDBFeature for dynamic XML")
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
This commit is contained in:
Benjamin Gray 2024-03-20 12:50:25 +11:00 committed by Nicholas Piggin
parent 978897a572
commit ed399ade3c

View File

@ -305,6 +305,25 @@ static void gdb_gen_spr_feature(CPUState *cs)
unsigned int num_regs = 0; unsigned int num_regs = 0;
int i; int i;
for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
ppc_spr_t *spr = &env->spr_cb[i];
if (!spr->name) {
continue;
}
/*
* GDB identifies registers based on the order they are
* presented in the XML. These ids will not match QEMU's
* representation (which follows the PowerISA).
*
* Store the position of the current register description so
* we can make the correspondence later.
*/
spr->gdb_id = num_regs;
num_regs++;
}
if (pcc->gdb_spr.xml) { if (pcc->gdb_spr.xml) {
return; return;
} }
@ -321,18 +340,8 @@ static void gdb_gen_spr_feature(CPUState *cs)
} }
gdb_feature_builder_append_reg(&builder, g_ascii_strdown(spr->name, -1), gdb_feature_builder_append_reg(&builder, g_ascii_strdown(spr->name, -1),
TARGET_LONG_BITS, num_regs, TARGET_LONG_BITS, spr->gdb_id,
"int", "spr"); "int", "spr");
/*
* GDB identifies registers based on the order they are
* presented in the XML. These ids will not match QEMU's
* representation (which follows the PowerISA).
*
* Store the position of the current register description so
* we can make the correspondence later.
*/
spr->gdb_id = num_regs;
num_regs++;
} }
gdb_feature_builder_end(&builder); gdb_feature_builder_end(&builder);