Skip to contentSkip to conversation

target/arm: Support SME2 in gdbstub

PATCH In review Peter Maydell 3 participants 10 messages Oct 17, 2025 – Oct 23, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover target/arm: Support SME2 in gdbstub

This patchseries adds SME2 support to the gdbstub. This is fairly straightforward as the only thing we need to do is expose the new ZT0 register in the XML in the way that gdb documents that we should.

Patch 2 adds the TLS section that we should in theory have been exposing already; this mostly will become relevant when gdb implements the SME lazy-state-handling that uses TPIDR2.

Patch 3 is a simple "check reads and writes" test case along the lines of our existing SME tests.

Changes v1->v2:
* use static XML for the sme2 section, not dynamic
* add patch 2 for the tls section
* tidy up some excessively cut-n-pasted stuff in the testcase script

thanks
-- PMM

Peter Maydell (3):
target/arm: Implement SME2 support in gdbstub
target/arm: Implement org.gnu.gdb.aarch64.tls XML feature in gdbstub tests/tcg/aarch64: Add test case for SME2 gdbstub registers

 configs/targets/aarch64-bsd-user.mak      |   2 +-
 configs/targets/aarch64-linux-user.mak    |   2 +-
 configs/targets/aarch64-softmmu.mak       |   2 +-
 configs/targets/aarch64_be-linux-user.mak |   2 +-
 target/arm/cpu.h                          |   1 +
 target/arm/internals.h                    |   5 +
 target/arm/gdbstub.c                      |  12 +++
 target/arm/gdbstub64.c                    | 115 ++++++++++++++++++++++
 gdb-xml/aarch64-sme2.xml                  |  14 +++
 tests/tcg/aarch64/Makefile.target         |   9 +-
 tests/tcg/aarch64/gdbstub/test-sme2.py    |  36 +++++++
 11 files changed, 195 insertions(+), 5 deletions(-)
 create mode 100644 gdb-xml/aarch64-sme2.xml
 create mode 100644 tests/tcg/aarch64/gdbstub/test-sme2.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 target/arm: Implement SME2 support in gdbstub

For SME2, we need to expose the new ZT0 register in the gdbstub XML. gdb documents that the requirements are:

Quoted 7 lines

The ‘org.gnu.gdb.aarch64.sme2’ feature is optional. If present, then the ‘org.gnu.gdb.aarch64.sme’ feature must also be present. The ‘org.gnu.gdb.aarch64.sme2’ feature should contain the following:

- ZT0 is a register of 512 bits (64 bytes). It is defined as a vector of bytes.

Implement this.

---
 configs/targets/aarch64-bsd-user.mak      |  2 +-
 configs/targets/aarch64-linux-user.mak    |  2 +-
 configs/targets/aarch64-softmmu.mak       |  2 +-
 configs/targets/aarch64_be-linux-user.mak |  2 +-
 target/arm/internals.h                    |  2 +
 target/arm/gdbstub.c                      |  6 +++
 target/arm/gdbstub64.c                    | 52 +++++++++++++++++++++++
 gdb-xml/aarch64-sme2.xml                  | 14 ++++++
 8 files changed, 78 insertions(+), 4 deletions(-)
 create mode 100644 gdb-xml/aarch64-sme2.xml
configs/targets/aarch64-bsd-user.mak +1 -1
index f99c73377a9..7f42e060477 100644
@@ -1,4 +1,4 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
-TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml
+TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-sme2.xml
 TARGET_LONG_BITS=64
configs/targets/aarch64-linux-user.mak +1 -1
index b779ac3b4a0..bf328b3b80c 100644
@@ -1,6 +1,6 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
-TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml
+TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml gdb-xml/aarch64-sme2.xml
 TARGET_HAS_BFLT=y
 CONFIG_SEMIHOSTING=y
 CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y
configs/targets/aarch64-softmmu.mak +1 -1
index 5dfeb35af90..d14bcfc4900 100644
@@ -1,7 +1,7 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
 TARGET_KVM_HAVE_GUEST_DEBUG=y
-TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml gdb-xml/aarch64-pauth.xml
+TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-sme2.xml
 # needed by boot.c
 TARGET_NEED_FDT=y
 TARGET_LONG_BITS=64
configs/targets/aarch64_be-linux-user.mak +1 -1
index ef9be02290f..284430add7b 100644
@@ -1,7 +1,7 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
 TARGET_BIG_ENDIAN=y
-TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml
+TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml gdb-xml/aarch64-sme2.xml
 TARGET_HAS_BFLT=y
 CONFIG_SEMIHOSTING=y
 CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y
target/arm/internals.h +2 -0
index f539bbe58e1..b8b07e6477c 100644
@@ -1719,6 +1719,8 @@ int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg);
+int aarch64_gdb_get_sme2_reg(CPUState *cs, GByteArray *buf, int reg);
+int aarch64_gdb_set_sme2_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_fpu_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_fpu_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg);
target/arm/gdbstub.c +6 -0
index 8d2229f5192..1ca3e647a84 100644
@@ -554,6 +554,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                 arm_gen_dynamic_smereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sme_reg,
                                      aarch64_gdb_set_sme_reg, sme_feature, 0);
+            if (isar_feature_aa64_sme2(&cpu->isar)) {
+                gdb_register_coprocessor(cs, aarch64_gdb_get_sme2_reg,
+                                         aarch64_gdb_set_sme2_reg,
+                                         gdb_find_static_feature("aarch64-sme2.xml"),
+                                         0);
+            }
         }
         /*
          * Note that we report pauth information via the feature name
target/arm/gdbstub64.c +52 -0

58 lines not on this page · raw message

gdb-xml/aarch64-sme2.xml new file +14 -0
new file mode 100644
index 00000000000..43911dae160
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2025 Linaro Ltd.
+
+     SPDX-License-Identifier: GPL-2.0-or-later
+
+     This is the SME2 ZT0 register. Upstream GDB dynamically generates
+     the XML for this feature, but because the vector is always 64 bytes
+     in size we prefer to use static XML for it.
+     -->
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.aarch64.sme2">
+  <vector id="sme2_bv" type="uint8" count="64"/>
+  <reg name="zt0" bitsize="512" type="sme2_bv"/>
+</feature>
Signature · 1 line
2.43.0
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] target/arm: Implement SME2 support in gdbstub

Quoted 23 lines · Peter Maydell

For SME2, we need to expose the new ZT0 register in the gdbstub XML. gdb documents that the requirements are:

Quoted 7 lines

The ‘org.gnu.gdb.aarch64.sme2’ feature is optional. If present, then the ‘org.gnu.gdb.aarch64.sme’ feature must also be present. The ‘org.gnu.gdb.aarch64.sme2’ feature should contain the following:

- ZT0 is a register of 512 bits (64 bytes). It is defined as a vector of bytes.

Implement this.

---
  configs/targets/aarch64-bsd-user.mak      |  2 +-
  configs/targets/aarch64-linux-user.mak    |  2 +-
  configs/targets/aarch64-softmmu.mak       |  2 +-
  configs/targets/aarch64_be-linux-user.mak |  2 +-
  target/arm/internals.h                    |  2 +
  target/arm/gdbstub.c                      |  6 +++
  target/arm/gdbstub64.c                    | 52 +++++++++++++++++++++++
  gdb-xml/aarch64-sme2.xml                  | 14 ++++++
  8 files changed, 78 insertions(+), 4 deletions(-)
Quoted 1 line

create mode 100644 gdb-xml/aarch64-sme2.xml

r~

Reviewed-by on v2 1/3
#3 lore raw

Re: [PATCH v2 1/3] target/arm: Implement SME2 support in gdbstub

In reply to Peter Maydell
Quoted 24 lines · Peter Maydell

For SME2, we need to expose the new ZT0 register in the gdbstub XML. gdb documents that the requirements are:

Quoted 7 lines

The ‘org.gnu.gdb.aarch64.sme2’ feature is optional. If present, then the ‘org.gnu.gdb.aarch64.sme’ feature must also be present. The ‘org.gnu.gdb.aarch64.sme2’ feature should contain the following:

- ZT0 is a register of 512 bits (64 bytes). It is defined as a vector of bytes.

Implement this.

---
  configs/targets/aarch64-bsd-user.mak      |  2 +-
  configs/targets/aarch64-linux-user.mak    |  2 +-
  configs/targets/aarch64-softmmu.mak       |  2 +-
  configs/targets/aarch64_be-linux-user.mak |  2 +-
  target/arm/internals.h                    |  2 +
  target/arm/gdbstub.c                      |  6 +++
  target/arm/gdbstub64.c                    | 52 +++++++++++++++++++++++
  gdb-xml/aarch64-sme2.xml                  | 14 ++++++
  8 files changed, 78 insertions(+), 4 deletions(-)
Quoted 1 line

create mode 100644 gdb-xml/aarch64-sme2.xml

#4 lore raw

PATCH v2 2/3 target/arm: Implement org.gnu.gdb.aarch64.tls XML feature in gdbstub

In reply to Peter Maydell

GDB expects the TLS registers to be exposed via org.gnu.gdb.aarch64.tls, which will contain either just "tpidr", or else "tpidr" and "tpidr2".

This will be important for SME in future, because the lazy state restoration scheme requires GDB to use the TPIDR2 information. GDB doesn't currently implement that, but we should provide the register via the XML so that we are ready when future GDB versions support it.

---
 target/arm/cpu.h       |  1 +
 target/arm/internals.h |  3 ++
 target/arm/gdbstub.c   |  6 ++++
 target/arm/gdbstub64.c | 63 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+)
target/arm/cpu.h +1 -0
index bf221e6f973..47be3076370 100644
@@ -941,6 +941,7 @@ struct ArchCPU {
     DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
+    DynamicGDBFeatureInfo dyn_tls_feature;
 
     /* Timers used by the generic (architected) timer */
     QEMUTimer *gt_timer[NUM_GTIMERS];
target/arm/internals.h +3 -0
index b8b07e6477c..97ff54896e6 100644
@@ -1715,6 +1715,7 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
 GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cpu, int base_reg);
+GDBFeature *arm_gen_dynamic_tls_feature(CPUState *cpu, int base_reg);
 int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg);
@@ -1727,6 +1728,8 @@ int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_pauth_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg);
+int aarch64_gdb_get_tls_reg(CPUState *cs, GByteArray *buf, int reg);
+int aarch64_gdb_set_tls_reg(CPUState *cs, uint8_t *buf, int reg);
 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp);
 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp);
 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp);
target/arm/gdbstub.c +6 -0
index 1ca3e647a84..8865f27089d 100644
@@ -583,6 +583,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                                      0);
         }
 #endif
+
+        /* All AArch64 CPUs have at least TPIDR */
+        gdb_register_coprocessor(cs, aarch64_gdb_get_tls_reg,
+                                 aarch64_gdb_set_tls_reg,
+                                 arm_gen_dynamic_tls_feature(cs, cs->gdb_num_regs),
+                                 0);
 #endif
     } else {
         if (arm_feature(env, ARM_FEATURE_NEON)) {
target/arm/gdbstub64.c +63 -0

75 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v2 2/3
#5 lore raw

Re: [PATCH v2 2/3] target/arm: Implement org.gnu.gdb.aarch64.tls XML feature in gdbstub

Quoted 9 lines · Peter Maydell

GDB expects the TLS registers to be exposed via org.gnu.gdb.aarch64.tls, which will contain either just "tpidr", or else "tpidr" and "tpidr2".

This will be important for SME in future, because the lazy state restoration scheme requires GDB to use the TPIDR2 information. GDB doesn't currently implement that, but we should provide the register via the XML so that we are ready when future GDB versions support it.

Quoted 7 lines
---
  target/arm/cpu.h       |  1 +
  target/arm/internals.h |  3 ++
  target/arm/gdbstub.c   |  6 ++++
  target/arm/gdbstub64.c | 63 ++++++++++++++++++++++++++++++++++++++++++
  4 files changed, 73 insertions(+)

r~

#6 lore raw

PATCH v2 3/3 tests/tcg/aarch64: Add test case for SME2 gdbstub registers

In reply to Peter Maydell

Test the SME2 register exposure over gdbstub, in the same way we already do for SME.

---
 tests/tcg/aarch64/Makefile.target      |  9 ++++++-
 tests/tcg/aarch64/gdbstub/test-sme2.py | 36 ++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/aarch64/gdbstub/test-sme2.py
tests/tcg/aarch64/Makefile.target +8 -1
index 55ce34e45ee..9fa86874534 100644
@@ -164,7 +164,14 @@ run-gdbstub-sysregs-sme-tile-slice: sysregs
 	"selected gdb ($(GDB)) does not support SME ZA tile slices")
 endif
 
-EXTRA_RUNS += run-gdbstub-sysregs-sme run-gdbstub-sysregs-sme-tile-slice
+run-gdbstub-sysregs-sme2: sysregs
+	$(call run-test, $@, $(GDB_SCRIPT) \
+		--gdb $(GDB) \
+		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+		--bin $< --test $(AARCH64_SRC)/gdbstub/test-sme2.py, \
+	gdbstub SME ZA tile slice support)
+
+EXTRA_RUNS += run-gdbstub-sysregs-sme run-gdbstub-sysregs-sme-tile-slice run-gdbstub-sysregs-sme2
 
 endif
 
tests/tcg/aarch64/gdbstub/test-sme2.py new file +36 -0
new file mode 100644
index 00000000000..a1663fac658
@@ -0,0 +1,36 @@
+#
+# Copyright (C) 2025 Linaro Ltd.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+#
+# Test the SME2 registers are visible and changeable via gdbstub
+#
+# This is launched via tests/guest-debug/run-test.py
+#
+
+import gdb
+from test_gdbstub import main, report
+
+
+def run_test():
+    """Test reads and writes of the SME2 registers"""
+    frame = gdb.selected_frame()
+    rname = "zt0"
+    zt0 = frame.read_register(rname)
+    report(True, "Reading %s" % rname)
+
+    # Writing to the ZT0 register, byte by byte.
+    for i in range(0, 64):
+        cmd = "set $zt0[%d] = 0x01" % (i)
+            gdb.execute(cmd)
+            report(True, "%s" % cmd)
+
+    # Reading from the ZT0 register, byte by byte.
+    for i in range(0, 64):
+        reg = "$zt0[%d]" % (i)
+        v = gdb.parse_and_eval(reg)
+        report(str(v.type) == "uint8_t", "size of %s" % (reg))
+        report(v == 0x1, "%s is 0x%x" % (reg, 0x1))
+
+main(run_test, expected_arch="aarch64")
Signature · 1 line
2.43.0
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] tests/tcg/aarch64: Add test case for SME2 gdbstub registers

Quoted 9 lines · Peter Maydell

Test the SME2 register exposure over gdbstub, in the same way we already do for SME.

---
  tests/tcg/aarch64/Makefile.target      |  9 ++++++-
  tests/tcg/aarch64/gdbstub/test-sme2.py | 36 ++++++++++++++++++++++++++
  2 files changed, 44 insertions(+), 1 deletion(-)

create mode 100644 tests/tcg/aarch64/gdbstub/test-sme2.py

r~

Reviewed-by on v2 3/3
#8 lore raw

Re: [PATCH v2 3/3] tests/tcg/aarch64: Add test case for SME2 gdbstub registers

In reply to Peter Maydell
Quoted 9 lines · Peter Maydell

Test the SME2 register exposure over gdbstub, in the same way we already do for SME.

---
  tests/tcg/aarch64/Makefile.target      |  9 ++++++-
  tests/tcg/aarch64/gdbstub/test-sme2.py | 36 ++++++++++++++++++++++++++
  2 files changed, 44 insertions(+), 1 deletion(-)

create mode 100644 tests/tcg/aarch64/gdbstub/test-sme2.py

#9 lore raw

Re: [PATCH v2 3/3] tests/tcg/aarch64: Add test case for SME2 gdbstub registers

In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

Test the SME2 register exposure over gdbstub, in the same way we already do for SME.

tests/tcg/aarch64/gdbstub/test-sme2.py new file +2 -0
+def run_test():
+    """Test reads and writes of the SME2 registers"""

tests/tcg/aarch64/gdbstub/test-sme2.py line 27

Quoted 10 lines
tests/tcg/aarch64/gdbstub/test-sme2.py new file +10 -0
+    frame = gdb.selected_frame()
+    rname = "zt0"
+    zt0 = frame.read_register(rname)
+    report(True, "Reading %s" % rname)
+
+    # Writing to the ZT0 register, byte by byte.
+    for i in range(0, 64):
+        cmd = "set $zt0[%d] = 0x01" % (i)
+            gdb.execute(cmd)
+            report(True, "%s" % cmd)

These two lines are wrongly indented, and Python will error out with "unexpected indent". I fixed this up in my local tree but clearly forgot to commit the change to git before sending. I'll fix this up in applying them to target-arm.next.

-- PMM