[PATCH 3/4] gdbstub: Emit base_register index in GDBFeature entries

Philippe Mathieu-Daudé posted 4 patches 2 days, 11 hours ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Brian Cain <brian.cain@oss.qualcomm.com>, Paolo Bonzini <pbonzini@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Song Gao <gaosong@loongson.cn>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Thomas Huth <thuth@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>
[PATCH 3/4] gdbstub: Emit base_register index in GDBFeature entries
Posted by Philippe Mathieu-Daudé 2 days, 11 hours ago
Record the base register index in the generated C file.

Check at runtime that either @g_pos argument of
gdb_register_coprocessor() is zero, or it the base register
index.

This change pass 'make check-tcg' test suite, which runs the
tests/tcg/multiarch/gdbstub/registers.py test, itself calling
gdb_register_coprocessor() for each target tested.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/gdbstub.h  | 1 +
 gdbstub/gdbstub.c       | 2 ++
 scripts/feature_to_c.py | 1 +
 3 files changed, 4 insertions(+)

diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index bd7182c4d32..12e7b5b7282 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -6,6 +6,7 @@ typedef struct GDBFeature {
     const char *xml;
     const char *name;
     const char * const *regs;
+    int base_reg;
     int num_regs;
 } GDBFeature;
 
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 90f4b95135b..6eadae3804e 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -610,6 +610,8 @@ void gdb_register_coprocessor(CPUState *cpu,
     guint i;
     int base_reg = cpu->gdb_num_regs;
 
+    assert(!g_pos || g_pos == feature->base_reg);
+
     for (i = 0; i < cpu->gdb_regs->len; i++) {
         /* Check for duplicates.  */
         s = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py
index 1329695ad04..a52cd2e9ec6 100644
--- a/scripts/feature_to_c.py
+++ b/scripts/feature_to_c.py
@@ -102,6 +102,7 @@ def writeliteral(indent, bytes):
         sys.stdout.write(',\n')
 
     sys.stdout.write( '        },\n')
+    sys.stdout.write(f'        .base_reg = {base_reg},\n')
     sys.stdout.write(f'        .num_regs = {num_regs},\n')
     sys.stdout.write( '    },\n')
 
-- 
2.52.0


Re: [PATCH 3/4] gdbstub: Emit base_register index in GDBFeature entries
Posted by Pierrick Bouvier 2 days, 11 hours ago
On 2/27/26 1:39 PM, Philippe Mathieu-Daudé wrote:
> Record the base register index in the generated C file.
> 
> Check at runtime that either @g_pos argument of
> gdb_register_coprocessor() is zero, or it the base register
> index.
> 
> This change pass 'make check-tcg' test suite, which runs the
> tests/tcg/multiarch/gdbstub/registers.py test, itself calling
> gdb_register_coprocessor() for each target tested.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/exec/gdbstub.h  | 1 +
>   gdbstub/gdbstub.c       | 2 ++
>   scripts/feature_to_c.py | 1 +
>   3 files changed, 4 insertions(+)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>