Skip to contentSkip to conversation

target/arm: Added support for SME register exposure to GDB

PATCH Superseded Vacha Bhavsar 4 participants 16 messages Jul 22, 2025 – Aug 11, 2025

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover target/arm: Added support for SME register exposure to GDB

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

Furthermore, this patch series increases the value of MAX_PACKET_LENGTH to allow for remote GDB debugging of the ZA register when the vector length is maximal.

Vacha Bhavsar (2):
target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging target/arm: Added support for SME register exposure to GDB

Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/2 target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +1 -1
index bf5a5c6302..b58a66c201 100644
@@ -11,7 +11,7 @@
 
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100
 
 /*
  * Shared structures and definitions
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Quoted 20 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644

gdbstub/internals.h line 14

Quoted 5 lines
gdbstub/internals.h +1 -1
@@ -11,7 +11,7 @@
 
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a static at:

    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make line_buf a dynamically re-sizeable buffer along the lines of str_buf and mem_buf. In fact make it a GString and we can get rid of line_buf_index as well.

Quoted 3 lines
gdbstub/internals.h +0 -0
 /*
  * Shared structures and definitions
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#3 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Quoted 31 lines · Alex Bennée
Quoted 20 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644

gdbstub/internals.h line 14

Quoted 5 lines
gdbstub/internals.h +1 -1
@@ -11,7 +11,7 @@
 
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a static at:

Quoted 5 lines
    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make line_buf a dynamically re-sizeable buffer along the lines of str_buf and mem_buf. In fact make it a GString and we can get rid of line_buf_index as well.

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

In general I thought the gdbstub protocol was supposed to handle a fixed packet length (e.g. in handle_query_xfer_features() the response packet indicates truncation via "l" vs "m" so the gdb end knows it needs to send another request to get the rest of the data). So if we run into something which seems to be fixed by raising MAX_PACKET_LENGTH I would first want to look at whether the underlying problem is that we're not indicating to gdb "this data is incomplete, you'll need to ask for more of it" or something of that nature.

thanks
-- PMM

#4 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Quoted 32 lines · Peter Maydell
Quoted 31 lines · Alex Bennée
Quoted 20 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644

gdbstub/internals.h line 14

Quoted 5 lines
gdbstub/internals.h +1 -1
@@ -11,7 +11,7 @@
 
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a static at:

Quoted 8 lines
Quoted 5 lines
    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make line_buf a dynamically re-sizeable buffer along the lines of str_buf and mem_buf. In fact make it a GString and we can get rid of line_buf_index as well.

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

I assume it would be the g/G or p/P packets. The docs don't seem to say anything about them splitting them across multiple packets.

Quoted 8 lines

In general I thought the gdbstub protocol was supposed to handle a fixed packet length (e.g. in handle_query_xfer_features() the response packet indicates truncation via "l" vs "m" so the gdb end knows it needs to send another request to get the rest of the data). So if we run into something which seems to be fixed by raising MAX_PACKET_LENGTH I would first want to look at whether the underlying problem is that we're not indicating to gdb "this data is incomplete, you'll need to ask for more of it" or something of that nature.

The docs reference "bulk transfers":

‘PacketSize=bytes’

The remote stub can accept packets up to at least bytes in length. GDB will send packets up to this size for bulk transfers, and will never send larger packets. This is a limit on the data characters in the packet, not including the frame and checksum. There is no trailing NUL byte in a remote protocol packet; if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL. If this stub feature is not supported, GDB guesses based on the size of the ‘g’ packet response.

Quoted 3 lines

thanks
-- PMM

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#5 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Quoted 41 lines · Alex Bennée
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Alex Bennée
Quoted 20 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644

gdbstub/internals.h line 14

Quoted 5 lines
gdbstub/internals.h +1 -1
@@ -11,7 +11,7 @@
 
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a static at:

    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make line_buf a dynamically re-sizeable buffer along the lines of str_buf and mem_buf. In fact make it a GString and we can get rid of line_buf_index as well.

Quoted 5 lines
Quoted 2 lines

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

I assume it would be the g/G or p/P packets. The docs don't seem to say anything about them splitting them across multiple packets.

Probably because nobody thought about the possibility of enormous registers. This sounds like something to query with the gdb devs about what they expect the handling of the SME ZA storage should be.

Quoted 13 lines
Quoted 8 lines

In general I thought the gdbstub protocol was supposed to handle a fixed packet length (e.g. in handle_query_xfer_features() the response packet indicates truncation via "l" vs "m" so the gdb end knows it needs to send another request to get the rest of the data). So if we run into something which seems to be fixed by raising MAX_PACKET_LENGTH I would first want to look at whether the underlying problem is that we're not indicating to gdb "this data is incomplete, you'll need to ask for more of it" or something of that nature.

The docs reference "bulk transfers":

‘PacketSize=bytes’

Quoted 8 lines

The remote stub can accept packets up to at least bytes in length. GDB will send packets up to this size for bulk transfers, and will never send larger packets. This is a limit on the data characters in the packet, not including the frame and checksum. There is no trailing NUL byte in a remote protocol packet; if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL. If this stub feature is not supported, GDB guesses based on the size of the ‘g’ packet response.

We do advertise this.

-- PMM

#6 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Hi,

Thank you for your comments!

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

The issue is that when we run something like set $za[0][0] = 0x01 in the gdb client, the client sends the entire contents on the new expected za register value, at which point the client side gets stuck and does not return the gdb prompt. The issue is found to be the following code (line 2396 of gdbstub/gdbstub.c):

else if (gdbserver_state.line_buf_index >= sizeof(gdbserver_state.line_buf)

- 1) {
                trace_gdbstub_err_overrun();
                gdbserver_state.state = RS_IDLE;

Since the current value of sizeof(gdbserver_state.line_buf) is 4096 whereas the
entire contents of the P packet coming in from the gdb client is at least 131072
(twice the number of bytes in the za storage at max svl), the above statement
eventually evaluates to true, causing the state machine to reset to RS_IDLE and
treat the rest of the packet as if it's looking for a new command. This is why
the client side gets stuck until there is a timeout and then debugging continues
as usual.

For this reason, the MAX_PACKET_LENGTH value was increased in an effort to increase
the size of gdbserver_state.line_buf and avoid entering the above mentioned clause.

This sounds like something to query with the gdb devs about what they expect the handling of the SME ZA storage should be.

Will do!

Thanks,
Vacha

Quoted 83 lines · Peter Maydell
Quoted 4 lines · Alex Bennée
Quoted 1 line · Peter Maydell

On Mon, 4 Aug 2025 at 16:34, Alex Bennée <[email protected]>

Quoted 24 lines · wrote:
Quoted 24 lines
Quoted 24 lines
Quoted 21 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644
@@ -11,7 +11,7 @@
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

gdbstub/internals.h line 14

Quoted 4 lines
gdbstub/internals.h +1 -1
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a

static at:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make

line_buf a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

dynamically re-sizeable buffer along the lines of str_buf and mem_buf. In fact make it a GString and we can get rid of line_buf_index as

well.

Quoted 6 lines
Quoted 3 lines

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

I assume it would be the g/G or p/P packets. The docs don't seem to say anything about them splitting them across multiple packets.

Probably because nobody thought about the possibility of enormous registers. This sounds like something to query with the gdb devs about what they expect the handling of the SME ZA storage should be.

Quoted 3 lines
Quoted 3 lines

In general I thought the gdbstub protocol was supposed to handle a fixed packet length (e.g. in handle_query_xfer_features() the response packet indicates truncation via "l" vs "m" so the gdb end knows it

needs

Quoted 10 lines
Quoted 5 lines

to send another request to get the rest of the data). So if we run into something which seems to be fixed by raising MAX_PACKET_LENGTH I would first want to look at whether the underlying problem is that we're not indicating to gdb "this data is incomplete, you'll need to ask for more of it" or something of that nature.

The docs reference "bulk transfers":

‘PacketSize=bytes’

Quoted 8 lines

The remote stub can accept packets up to at least bytes in length. GDB will send packets up to this size for bulk transfers, and will never send larger packets. This is a limit on the data characters in the packet, not including the frame and checksum. There is no trailing NUL byte in a remote protocol packet; if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL. If this stub feature is not supported, GDB guesses based on the size of the ‘g’ packet response.

We do advertise this.

-- PMM

#7 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Hi,

I reached out to the gdb dev team regarding these questions on how to correctly handle the SME za storage. This discussion can be found here:

https://sourceware.org/pipermail/gdb/2025-August/051858.html
https://sourceware.org/pipermail/gdb/2025-August/051860.html

It seems this approach of increasing the buffer size to above 131100 has also been applied to gdbserver as there currently isn't support for partial data transfers.

Thanks,

Vacha

Quoted 153 lines · Vacha Bhavsar

Hi,

Thank you for your comments!

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

The issue is that when we run something like set $za[0][0] = 0x01 in the gdb client, the client sends the entire contents on the new expected za register value, at which point the client side gets stuck and does not return the gdb prompt. The issue is found to be the following code (line 2396 of gdbstub/gdbstub.c):

else if (gdbserver_state.line_buf_index >=

sizeof(gdbserver_state.line_buf) - 1) {
                trace_gdbstub_err_overrun();
                gdbserver_state.state = RS_IDLE;

Since the current value of sizeof(gdbserver_state.line_buf) is 4096 whereas the
entire contents of the P packet coming in from the gdb client is at least 131072
(twice the number of bytes in the za storage at max svl), the above statement
eventually evaluates to true, causing the state machine to reset to RS_IDLE and
treat the rest of the packet as if it's looking for a new command. This is why
the client side gets stuck until there is a timeout and then debugging continues
as usual.

For this reason, the MAX_PACKET_LENGTH value was increased in an effort to increase
the size of gdbserver_state.line_buf and avoid entering the above mentioned clause.

This sounds like something to query with the gdb devs about what they expect the handling of the SME ZA storage should be.

Will do!

Thanks,
Vacha

Quoted 84 lines · Peter Maydell
Quoted 4 lines · Alex Bennée
Quoted 1 line · Peter Maydell

On Mon, 4 Aug 2025 at 16:34, Alex Bennée <[email protected]>

Quoted 24 lines · wrote:
Quoted 24 lines
Quoted 24 lines
Quoted 21 lines · Vacha Bhavsar

This patch increases the value of the MAX_PACKET_LEGNTH to 131100 from 4096 to allow the GDBState.line_buf to be large enough to accommodate the full contents of the SME ZA storage when the vector length is maximal. This is in preparation for a related patch that allows SME register visibility through remote GDB debugging.

---
Changes since v3:
- this patch was not present in version 3

 gdbstub/internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/internals.h +0 -0
index bf5a5c6302..b58a66c201 100644
@@ -11,7 +11,7 @@
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

gdbstub/internals.h line 14

Quoted 4 lines
gdbstub/internals.h +1 -1
 #include "exec/cpu-common.h"
 
-#define MAX_PACKET_LENGTH 4096
+#define MAX_PACKET_LENGTH 131100

This is a rather large expansion for something that ends up in a

static at:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
    char line_buf[MAX_PACKET_LENGTH];

I think maybe its time to get rid of this hardcoded define and make

line_buf a

Quoted 1 line
Quoted 1 line
Quoted 1 line

dynamically re-sizeable buffer along the lines of str_buf and

mem_buf.

Quoted 1 line
Quoted 1 line
Quoted 1 line

In fact make it a GString and we can get rid of line_buf_index as

well.

Quoted 6 lines
Quoted 3 lines

What exactly is the packet/response where MAX_PACKET_LENGTH is causing problems? The commit message doesn't say.

I assume it would be the g/G or p/P packets. The docs don't seem to say anything about them splitting them across multiple packets.

Probably because nobody thought about the possibility of enormous registers. This sounds like something to query with the gdb devs about what they expect the handling of the SME ZA storage should be.

Quoted 3 lines
Quoted 3 lines

In general I thought the gdbstub protocol was supposed to handle a fixed packet length (e.g. in handle_query_xfer_features() the response packet indicates truncation via "l" vs "m" so the gdb end knows it

needs

Quoted 10 lines
Quoted 5 lines

to send another request to get the rest of the data). So if we run into something which seems to be fixed by raising MAX_PACKET_LENGTH I would first want to look at whether the underlying problem is that we're not indicating to gdb "this data is incomplete, you'll need to ask for more of it" or something of that nature.

The docs reference "bulk transfers":

‘PacketSize=bytes’

Quoted 8 lines

The remote stub can accept packets up to at least bytes in length. GDB will send packets up to this size for bulk transfers, and will never send larger packets. This is a limit on the data characters in the packet, not including the frame and checksum. There is no trailing NUL byte in a remote protocol packet; if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL. If this stub feature is not supported, GDB guesses based on the size of the ‘g’ packet response.

We do advertise this.

-- PMM

#8 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Quoted 7 lines · Vacha Bhavsar

Hi,

I reached out to the gdb dev team regarding these questions on how to correctly handle the SME za storage. This discussion can be found here:

Quoted 6 lines

https://sourceware.org/pipermail/gdb/2025-August/051858.html
https://sourceware.org/pipermail/gdb/2025-August/051860.html

It seems this approach of increasing the buffer size to above 131100 has also been applied to gdbserver as there currently isn't support for partial data transfers.

Thanks for chasing that up.

(1) I note that gdb bumped this to 131104, and we only have 131100. We should check what the worst-case is and make sure our number is big enough (maybe we count different things in our buffer size than gdbstub does?)

(2) We should add a comment to MAX_PACKET_LENGTH, something like:

/*
* Most "large" transfers (e.g. memory reads, feature XML
* transfer) have mechanisms in the gdb protocol for splitting
* them. However, register values in particular cannot currently
* be split. This packet size must therefore be at least big enough
* for the worst-case register size. Currently that is Arm SME
* ZA storage with a 256x256 byte value. We also must account
* for the conversion from raw data to hex in gdb_memtohex(),
* which writes 2*size + 1 bytes, and for other overhead like
* the command itself or the checksum.
*/

(but ideally check the figures and be a bit less vague about the "other overhead" :-))

-- PMM

#9 lore raw

Re: [PATCH v4 1/2] target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging

Hi,

From testing with a max vector length, the minimum size the buffer needs to be is 131077 to survive the worst case of a P packet with the ZA register. This is enough to fit the whole ZA register plus the overhead for the P packet (command + register number, the checksum is not stored in line_buf) and the null terminator. I had overshot and rounded it safely to 131100, and it seems gdbserver has done the same thing but they specifically counted 32 bytes for overhead, it's not specified why. So the 131100 is large enough, however I have changed it to 131104 just to stay consistent with gdbserver and have added this note to the comment you've suggested to be placed above MAX_PACKET_LENGTH. I've also changed line_buf to be a GString as Alex suggested.

I have sent a new version with these changes. Looking forward to your feedback!

Thanks,
Vacha

#10 lore raw

PATCH v4 2/2 target/arm: Added support for SME register exposure to GDB

In reply to Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

---
Changes since v3:
- added changes to aarch64_gdb_set_sme_reg() to address the concerns brought up in review regarding endianness

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 ++
 target/arm/gdbstub64.c | 122 +++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h |   3 +
 4 files changed, 132 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
target/arm/gdbstub.c +6 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg, feature, 0);
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature = 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);
+            }
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +122 -0

134 lines not on this page · raw message

target/arm/internals.h +3 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ 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);
 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_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);
Signature · 1 line
2.34.1
#11 lore raw
Quoted 198 lines · Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

---
Changes since v3:
- added changes to aarch64_gdb_set_sme_reg() to address the concerns brought up in review regarding endianness

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 ++
 target/arm/gdbstub64.c | 122 +++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h |   3 +
 4 files changed, 132 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
target/arm/gdbstub.c +6 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg, feature, 0);
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature = 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);
+            }
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +122 -0
index 64ee9b3b56..3d86980bc9 100644
@@ -228,6 +228,91 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)
     return 0;
 }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    /* Svg register */
+    case 0:
+    {
+        int vq = 0;
+        if (FIELD_EX64(env->svcr, SVCR, SM)) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     FIELD_EX64(env->svcr, SVCR, SM)) + 1;
+        }
+        /* svg = vector granules (2 * vector quardwords) in streaming mode */
+        return gdb_get_reg64(buf, vq * 2);
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                len += gdb_get_reg128(buf,
+                           env->za_state.za[i].d[q * 2 + 1],
+                           env->za_state.za[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d", __func__, reg);
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 8;
+    }
+    case 1:
+        aarch64_set_svcr(env, ldq_le_p(buf),
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                if (target_big_endian()){
+                    env->za_state.za[i].d[q * 2 + 1] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za[i].d[q * 2] = ldq_p(buf);
+                } else{
+                    env->za_state.za[i].d[q * 2] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za[i].d[q * 2 + 1] = ldq_p(buf);
+                }
+                buf += 8;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
+
+    return 0;
+}
+
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -392,6 +477,43 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)
     return &cpu->dyn_svereg_feature.desc;
 }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int base_reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sme_max_vq;
+    int svl = vq * 16;
+    GDBFeatureBuilder builder;
+    int reg = 0;
+
+    gdb_feature_builder_init(&builder, &cpu->dyn_smereg_feature.desc,
+        "org.gnu.gdb.aarch64.sme", "sme-registers.xml", base_reg);
+
+
+    /* Create the sme_bv vector type. */
+    gdb_feature_builder_append_tag(&builder,
+        "<vector id=\"sme_bv\" type=\"uint8\" count=\"%d\"/>",
+        svl);
+
+    /* Create the sme_bvv vector type. */
+    gdb_feature_builder_append_tag(
+        &builder, "<vector id=\"sme_bvv\" type=\"sme_bv\" count=\"%d\"/>",
+        svl);
+
+    /* Define the svg, svcr, and za registers. */
+
+    /* fpscr & status registers */
+    gdb_feature_builder_append_reg(&builder, "svg", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "svcr", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "za", svl * svl * 8, reg++,
+        "sme_bvv", NULL);
+
+    gdb_feature_builder_end(&builder);
+
+    return &cpu->dyn_smereg_feature.desc;
+}
+
 #ifdef CONFIG_USER_ONLY
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg)
 {
target/arm/internals.h +0 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)
 }

target/arm/internals.h static inline uint64_t pmu_counter_mask(CPUARMState *env) · line 1818

Quoted 10 lines
target/arm/internals.h +3 -0
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
+GDBFeature *arm_gen_dynamic_smereg_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);
+int aarch64_gdb_set_sme_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);

It would also be nice to add a test for this, see tests/tcg/aarch64/gdbstub/test-sve.py

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#12 lore raw

Hi,

I've built a testcase for this similar to the one you suggested. This test

checks both reading and writing the za register via $za and via the tiles

and tiles slices that gdb produces (i.e., za0hb0). However, these tiles and

slices are generated from the gdb side, they're not made available by any

of the changes that I have implemented. But this feature of gdb's kicks in

when using gdb14.1 or newer. Due to this, the testcase works correctly when

used with gdb14.1 and above, and fails on any gdb version older than that

as the tiles/slices are not made available by gdb.

I was wondering if there is any way to set a requirement on this testcase

which specifies it needs to be run with minimum of gdb version 14.1

which has the functionality to break down the ZA storage into tiles and

slices?

Thanks,

Vacha

Quoted 231 lines · Alex Bennée
Quoted 2 lines · Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug

SME

Quoted 1 line

code. To provide this functionality in Aarch64 target, this patch

registers the

Quoted 5 lines

SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports

SME.

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU

Quoted 32 lines

Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

---
Changes since v3:
- added changes to aarch64_gdb_set_sme_reg() to address the concerns brought up in review regarding endianness

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 ++
 target/arm/gdbstub64.c | 122 +++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h |   3 +
 4 files changed, 132 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
target/arm/gdbstub.c +0 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU

*cpu)

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU · line 531

Quoted 1 line
target/arm/gdbstub.c +0 -0
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs,

cs->gdb_num_regs);

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU · line 533

Quoted 2 lines
target/arm/gdbstub.c +0 -0
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg, feature,

0);

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU · line 535

Quoted 2 lines
target/arm/gdbstub.c +2 -0
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature =

arm_gen_dynamic_smereg_feature(cs,

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t

Quoted 12 lines
target/arm/gdbstub.c +4 -0
+                                             cs->gdb_num_regs);
+                gdb_register_coprocessor(cs, aarch64_gdb_get_sme_reg,
+                    aarch64_gdb_set_sme_reg, sme_feature, 0);
+            }
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +0 -0
index 64ee9b3b56..3d86980bc9 100644
@@ -228,6 +228,91 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t

*buf, int reg)

Quoted 8 lines
target/arm/gdbstub64.c +5 -0
     return 0;
 }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+    switch (reg) {
+    /* Svg register */
+    case 0:
+    {
+        int vq = 0;
+        if (FIELD_EX64(env->svcr, SVCR, SM)) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     FIELD_EX64(env->svcr, SVCR, SM)) + 1;
+        }
+        /* svg = vector granules (2 * vector quardwords) in streaming

mode */

Quoted 11 lines
target/arm/gdbstub64.c +11 -0
+        return gdb_get_reg64(buf, vq * 2);
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+                len += gdb_get_reg128(buf,
+                           env->za_state.za[i].d[q * 2 + 1],
+                           env->za_state.za[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d",

__func__, reg);

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState

Quoted 53 lines
target/arm/gdbstub64.c +49 -0
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 8;
+    }
+    case 1:
+        aarch64_set_svcr(env, ldq_le_p(buf),
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                if (target_big_endian()){
+                    env->za_state.za[i].d[q * 2 + 1] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za[i].d[q * 2] = ldq_p(buf);
+                } else{
+                    env->za_state.za[i].d[q * 2] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za[i].d[q * 2 + 1] = ldq_p(buf);
+                }
+                buf += 8;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
+
+    return 0;
+}
+
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -392,6 +477,43 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState

*cs, int base_reg)

Quoted 13 lines
target/arm/gdbstub64.c +10 -0
     return &cpu->dyn_svereg_feature.desc;
 }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int base_reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sme_max_vq;
+    int svl = vq * 16;
+    GDBFeatureBuilder builder;
+    int reg = 0;
+
+    gdb_feature_builder_init(&builder, &cpu->dyn_smereg_feature.desc,
+        "org.gnu.gdb.aarch64.sme", "sme-registers.xml", base_reg);

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+
+
+    /* Create the sme_bv vector type. */
+    gdb_feature_builder_append_tag(&builder,
+        "<vector id=\"sme_bv\" type=\"uint8\" count=\"%d\"/>",
+        svl);
+
+    /* Create the sme_bvv vector type. */
+    gdb_feature_builder_append_tag(
+        &builder, "<vector id=\"sme_bvv\" type=\"sme_bv\"

count=\"%d\"/>",

target/arm/internals.h static inline uint64_t

Quoted 25 lines
target/arm/gdbstub64.c +17 -0
+        svl);
+
+    /* Define the svg, svcr, and za registers. */
+
+    /* fpscr & status registers */
+    gdb_feature_builder_append_reg(&builder, "svg", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "svcr", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "za", svl * svl * 8, reg++,
+        "sme_bvv", NULL);
+
+    gdb_feature_builder_end(&builder);
+
+    return &cpu->dyn_smereg_feature.desc;
+}
+
 #ifdef CONFIG_USER_ONLY
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg)
 {
target/arm/internals.h +0 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ static inline uint64_t

pmu_counter_mask(CPUARMState *env)

target/arm/internals.h static inline uint64_t pmu_counter_mask(CPUARMState *env) · line 1818

Quoted 11 lines
target/arm/internals.h +3 -0
 }
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
+GDBFeature *arm_gen_dynamic_smereg_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);
+int aarch64_gdb_set_sme_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);

It would also be nice to add a test for this, see
tests/tcg/aarch64/gdbstub/test-sve.py

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

#13 lore raw
Quoted 22 lines · Vacha Bhavsar

Hi,

I've built a testcase for this similar to the one you suggested. This test

checks both reading and writing the za register via $za and via the tiles

and tiles slices that gdb produces (i.e., za0hb0). However, these tiles and

slices are generated from the gdb side, they're not made available by any

of the changes that I have implemented. But this feature of gdb's kicks in

when using gdb14.1 or newer. Due to this, the testcase works correctly when

used with gdb14.1 and above, and fails on any gdb version older than that

as the tiles/slices are not made available by gdb.

Quoted 7 lines

I was wondering if there is any way to set a requirement on this testcase

which specifies it needs to be run with minimum of gdb version 14.1

which has the functionality to break down the ZA storage into tiles and

slices?

We have tests in configure to probe the gdbversion, e.g:

  if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
      echo "GDB_HAS_MTE=y" >> $config_target_mak
  fi

which can then wrap the test in the Makefile, e.g.:

  ifeq ($(GDB_HAS_MTE),y)
  run-gdbstub-mte: mte-8
          $(call run-test, $@, $(GDB_SCRIPT) \
                  --gdb $(GDB) \
                  --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
                  --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py \
                  -- --mode=user, \
          gdbstub MTE support)

EXTRA_RUNS += run-gdbstub-mte
endif

Quoted 227 lines

Thanks,

Vacha

On Mon, Aug 4, 2025 at 11:35 AM Alex Bennée <[email protected]> wrote:

Quoted 198 lines · Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

---
Changes since v3:
- added changes to aarch64_gdb_set_sme_reg() to address the concerns brought up in review regarding endianness

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 ++
 target/arm/gdbstub64.c | 122 +++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h |   3 +
 4 files changed, 132 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
target/arm/gdbstub.c +6 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg, feature, 0);
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature = 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);
+            }
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +122 -0
index 64ee9b3b56..3d86980bc9 100644
@@ -228,6 +228,91 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)
     return 0;
 }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    /* Svg register */
+    case 0:
+    {
+        int vq = 0;
+        if (FIELD_EX64(env->svcr, SVCR, SM)) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     FIELD_EX64(env->svcr, SVCR, SM)) + 1;
+        }
+        /* svg = vector granules (2 * vector quardwords) in streaming mode */
+        return gdb_get_reg64(buf, vq * 2);
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                len += gdb_get_reg128(buf,
+                           env->za_state.za⚠️[i].d[q * 2 + 1],
+                           env->za_state.za⚠️[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d", __func__, reg);
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 8;
+    }
+    case 1:
+        aarch64_set_svcr(env, ldq_le_p(buf),
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                if (target_big_endian()){
+                    env->za_state.za⚠️[i].d[q * 2 + 1] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za⚠️[i].d[q * 2] = ldq_p(buf);
+                } else{
+                    env->za_state.za⚠️[i].d[q * 2] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za⚠️[i].d[q * 2 + 1] = ldq_p(buf);
+                }
+                buf += 8;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
+
+    return 0;
+}
+
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -392,6 +477,43 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)
     return &cpu->dyn_svereg_feature.desc;
 }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int base_reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sme_max_vq;
+    int svl = vq * 16;
+    GDBFeatureBuilder builder;
+    int reg = 0;
+
+    gdb_feature_builder_init(&builder, &cpu->dyn_smereg_feature.desc,
+        "org.gnu.gdb.aarch64.sme", "sme-registers.xml", base_reg);
+
+
+    /* Create the sme_bv vector type. */
+    gdb_feature_builder_append_tag(&builder,
+        "<vector id=\"sme_bv\" type=\"uint8\" count=\"%d\"/>",
+        svl);
+
+    /* Create the sme_bvv vector type. */
+    gdb_feature_builder_append_tag(
+        &builder, "<vector id=\"sme_bvv\" type=\"sme_bv\" count=\"%d\"/>",
+        svl);
+
+    /* Define the svg, svcr, and za registers. */
+
+    /* fpscr & status registers */
+    gdb_feature_builder_append_reg(&builder, "svg", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "svcr", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "za", svl * svl * 8, reg++,
+        "sme_bvv", NULL);
+
+    gdb_feature_builder_end(&builder);
+
+    return &cpu->dyn_smereg_feature.desc;
+}
+
 #ifdef CONFIG_USER_ONLY
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg)
 {
target/arm/internals.h +0 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)
 }

target/arm/internals.h static inline uint64_t pmu_counter_mask(CPUARMState *env) · line 1818

Quoted 10 lines
target/arm/internals.h +3 -0
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
+GDBFeature *arm_gen_dynamic_smereg_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);
+int aarch64_gdb_set_sme_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);

It would also be nice to add a test for this, see tests/tcg/aarch64/gdbstub/test-sve.py

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#14 lore raw

Got it, thank you!

Quoted 315 lines · Alex Bennée
Quoted 5 lines · Vacha Bhavsar

Hi,

I've built a testcase for this similar to the one you suggested. This

test

Quoted 4 lines

checks both reading and writing the za register via $za and via the tiles

and tiles slices that gdb produces (i.e., za0hb0). However, these tiles

and

Quoted 4 lines

slices are generated from the gdb side, they're not made available by any

of the changes that I have implemented. But this feature of gdb's kicks

in

Quoted 2 lines

when using gdb14.1 or newer. Due to this, the testcase works correctly

when

Quoted 7 lines

used with gdb14.1 and above, and fails on any gdb version older than that

as the tiles/slices are not made available by gdb.

Quoted 7 lines

I was wondering if there is any way to set a requirement on this testcase

which specifies it needs to be run with minimum of gdb version 14.1

which has the functionality to break down the ZA storage into tiles and

slices?

We have tests in configure to probe the gdbversion, e.g:

if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge
$gdb_version 15.1; then
echo "GDB_HAS_MTE=y" >> $config_target_mak
fi

which can then wrap the test in the Makefile, e.g.:

  ifeq ($(GDB_HAS_MTE),y)
  run-gdbstub-mte: mte-8
          $(call run-test, $@, $(GDB_SCRIPT) \
                  --gdb $(GDB) \
                  --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
                  --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py \
                  -- --mode=user, \
          gdbstub MTE support)

EXTRA_RUNS += run-gdbstub-mte
endif

Quoted 10 lines

Thanks,

Vacha

On Mon, Aug 4, 2025 at 11:35 AM Alex Bennée <[email protected]>

Quoted 4 lines · wrote:
Quoted 1 line · Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB

via

Quoted 1 line
Quoted 1 line

the remote serial protocol, which can be a useful functionality to

debug SME

Quoted 1 line
Quoted 1 line

code. To provide this functionality in Aarch64 target, this patch

registers the

Quoted 1 line
Quoted 1 line

SME register set with the GDB stub. To do so, this patch implements

the

Quoted 4 lines
Quoted 4 lines

aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture

supports SME.

Quoted 1 line
Quoted 1 line

Finally, this patch includes a dyn_smereg_feature structure to hold

this

Quoted 11 lines
Quoted 11 lines

GDB XML description of the SME registers for each CPU.

---
Changes since v3:
- added changes to aarch64_gdb_set_sme_reg() to address the concerns brought up in review regarding endianness

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 ++
 target/arm/gdbstub64.c | 122

+++++++++++++++++++++++++++++++++++++++++

Quoted 15 lines
Quoted 15 lines
 target/arm/internals.h |   3 +
 4 files changed, 132 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
Quoted 5 lines

target/arm/gdbstub.c void

Quoted 5 lines
target/arm/gdbstub.c +0 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void

arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)

Quoted 1 line

target/arm/gdbstub.c void · line 531

Quoted 1 line
target/arm/gdbstub.c +0 -0
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs,

cs->gdb_num_regs);

Quoted 2 lines

target/arm/gdbstub.c void · line 533

Quoted 2 lines
target/arm/gdbstub.c +0 -0
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg,

feature, 0);

Quoted 2 lines

target/arm/gdbstub.c void · line 535

Quoted 2 lines
target/arm/gdbstub.c +2 -0
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature =

arm_gen_dynamic_smereg_feature(cs,

Quoted 4 lines
Quoted 4 lines
target/arm/gdbstub.c +4 -0
+                                             cs->gdb_num_regs);
+                gdb_register_coprocessor(cs, aarch64_gdb_get_sme_reg,
+                    aarch64_gdb_set_sme_reg, sme_feature, 0);
+            }
Quoted 8 lines

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs,

Quoted 8 lines
target/arm/gdbstub.c +0 -0
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +0 -0
index 64ee9b3b56..3d86980bc9 100644
@@ -228,6 +228,91 @@ int aarch64_gdb_set_sve_reg(CPUState *cs,

uint8_t *buf, int reg)

Quoted 18 lines
Quoted 8 lines
target/arm/gdbstub64.c +5 -0
     return 0;
 }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+    switch (reg) {
+    /* Svg register */
+    case 0:
+    {
+        int vq = 0;
+        if (FIELD_EX64(env->svcr, SVCR, SM)) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     FIELD_EX64(env->svcr, SVCR, SM)) + 1;
+        }
+        /* svg = vector granules (2 * vector quardwords) in

streaming mode */

Quoted 13 lines
Quoted 13 lines
target/arm/gdbstub64.c +13 -0
+        return gdb_get_reg64(buf, vq * 2);
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                len += gdb_get_reg128(buf,
+                           env->za_state.za⚠️[i].d[q * 2 + 1],
Quoted 8 lines

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 8 lines
target/arm/gdbstub64.c +8 -0
+                           env->za_state.za⚠️[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d",

__func__, reg);

Quoted 45 lines
Quoted 45 lines
target/arm/gdbstub64.c +45 -0
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 8;
+    }
+    case 1:
+        aarch64_set_svcr(env, ldq_le_p(buf),
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int len = 0;
+        int vq = cpu->sme_max_vq;
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (int q = 0; q < vq; q++) {
+                if (target_big_endian()){
+                    env->za_state.za⚠️[i].d[q * 2 + 1] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za⚠️[i].d[q * 2] = ldq_p(buf);
+                } else{
+                    env->za_state.za⚠️[i].d[q * 2] = ldq_p(buf);
+                    buf += 8;
+                    env->za_state.za⚠️[i].d[q * 2 + 1] = ldq_p(buf);
+                }
+                buf += 8;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
Quoted 8 lines

target/arm/gdbstub64.c GDBFeature

Quoted 8 lines
target/arm/gdbstub64.c +4 -0
+
+    return 0;
+}
+
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -392,6 +477,43 @@ GDBFeature

*arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 4 lines

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 4 lines
target/arm/gdbstub64.c +1 -0
     return &cpu->dyn_svereg_feature.desc;
 }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int

base_reg)

Quoted 11 lines
Quoted 11 lines
target/arm/gdbstub64.c +11 -0
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sme_max_vq;
+    int svl = vq * 16;
+    GDBFeatureBuilder builder;
+    int reg = 0;
+
+    gdb_feature_builder_init(&builder, &cpu->dyn_smereg_feature.desc,
+        "org.gnu.gdb.aarch64.sme", "sme-registers.xml", base_reg);
+
+
Quoted 8 lines

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 8 lines
target/arm/gdbstub64.c +8 -0
+    /* Create the sme_bv vector type. */
+    gdb_feature_builder_append_tag(&builder,
+        "<vector id=\"sme_bv\" type=\"uint8\" count=\"%d\"/>",
+        svl);
+
+    /* Create the sme_bvv vector type. */
+    gdb_feature_builder_append_tag(
+        &builder, "<vector id=\"sme_bvv\" type=\"sme_bv\"

count=\"%d\"/>",

Quoted 10 lines

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+        svl);
+
+    /* Define the svg, svcr, and za registers. */
+
+    /* fpscr & status registers */
+    gdb_feature_builder_append_reg(&builder, "svg", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "svcr", 64, reg++,
+        "int", NULL);
+    gdb_feature_builder_append_reg(&builder, "za", svl * svl * 8,

reg++,

Quoted 9 lines

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)

Quoted 9 lines
target/arm/gdbstub64.c +7 -0
+        "sme_bvv", NULL);
+
+    gdb_feature_builder_end(&builder);
+
+    return &cpu->dyn_smereg_feature.desc;
+}
+
 #ifdef CONFIG_USER_ONLY
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int

reg)

Quoted 6 lines

target/arm/internals.h static inline uint64_t

Quoted 6 lines
target/arm/gdbstub64.c +0 -0
 {
target/arm/internals.h +0 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ static inline uint64_t

pmu_counter_mask(CPUARMState *env)

Quoted 3 lines

target/arm/internals.h static inline uint64_t · line 1810

Quoted 3 lines
target/arm/internals.h +0 -0
 }
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int

base_reg);

Quoted 1 line

target/arm/internals.h static inline uint64_t · line 1811

Quoted 1 line
target/arm/internals.h +1 -0
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cpu, int

base_reg);

Quoted 7 lines

target/arm/internals.h static inline uint64_t pmu_counter_mask(CPUARMState *env)

Quoted 7 lines
target/arm/internals.h +2 -0
 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_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);

Quoted 2 lines

It would also be nice to add a test for this, see

tests/tcg/aarch64/gdbstub/test-sve.py

Quoted 4 lines

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

#15 lore raw
In reply to Vacha Bhavsar

Cc'ing Gustavo.

Quoted 21 lines · Vacha Bhavsar

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

Furthermore, this patch series increases the value of MAX_PACKET_LENGTH to allow for remote GDB debugging of the ZA register when the vector length is maximal.

Vacha Bhavsar (2):
target/arm: Increase MAX_PACKET_LENGTH for SME ZA remote gdb debugging target/arm: Added support for SME register exposure to GDB