Skip to contentSkip to conversation

target/alpha: Add TCG plugin register tracking support

PATCH Applied Yodel Eldar 2 participants 5 messages Jun 30, 2025 – Jul 8, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover target/alpha: Add TCG plugin register tracking support

This patch adds TCG plugin register tracking support for the Alpha target and resolves gitlab issue #2569:

https://gitlab.com/qemu-project/qemu/-/issues/2569

As mentioned in the bug report by Alex Bennée, the register list is built using the target's corresponding GDB XML feature file, but the Alpha target does not have one. The second patch introduces the missing feature file and the necessary plumbing for it.

While testing the second patch, I noticed the following error:

qemu-alpha: GLib: g_strrstr: assertion 'haystack != NULL' failed

when running:

  ./qemu-alpha -d plugin \
  -plugin ./contrib/plugins/libexeclog.so,reg=*,rdisas=on \
  ./tests/tcg/alpha-linux-user/linux-test

and discovered an issue with execlog.c that the first patch resolves:
a missing null check after execlog searches a disassembled instruction for a space separator between the mnemonic and the operands. Execlog assumes that disassembled instructions will contain a space, but some disassemblers use tabs (like Alpha).

Besides adding the null check, the execlog patch also adds tab to the separator search by replacing the g_strstr_len call with a call to g_strsplit_set, so that the plugin would operate as intended for Alpha.

A pointer in the immediate area of the changed code is converted to a const pointer in keeping with the QEMU Coding Style. Also, as a trivial optimization, I took the liberty of adding a break statement to the register search loop that immediately follows the separator search, so that it breaks out of the loop as soon as a relevant register is found in the instruction.

Patch Series History:
v1 -> v2:
- As suggested by Alex Bennée, replaced strpbrk with g_strsplit_set

Yodel Eldar (2):
contrib/plugins/execlog: Add tab to the separator search of insn_disas target/alpha: Add GDB XML feature file

 configs/targets/alpha-linux-user.mak |   1 +
 configs/targets/alpha-softmmu.mak    |   1 +
 contrib/plugins/execlog.c            |  15 +--
 gdb-xml/alpha-core.xml               | 136 +++++++++++++++++++++++++++
 target/alpha/cpu.c                   |   1 +
 5 files changed, 148 insertions(+), 6 deletions(-)
 create mode 100644 gdb-xml/alpha-core.xml
Signature · 1 line
2.50.0
#1 lore raw

PATCH v2 1/2 contrib/plugins/execlog: Add tab to the separator search of insn_disas

Currently, execlog searches for a space separator between the instruction mnemonic and operands, but some disassemblers, e.g. Alpha's, use a tab separator instead; this results in a null pointer being passed as the haystack in g_strstr during a subsequent register search, i.e. undefined behavior, because of a missing null check.

This patch adds tab to the separator search and a null check on the result.

Also, an affected pointer is changed to const.

Lastly, a break statement was added to immediately terminate the register search when a user-requested register is found in the current instruction as a trivial optimization, because searching for the remaining requested registers is unnecessary once one is found.

---
 contrib/plugins/execlog.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
contrib/plugins/execlog.c +9 -6
index d67d010761..06ec76d6e9 100644
@@ -232,12 +232,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
          */
         if (disas_assist && rmatches) {
             check_regs_next = false;
-            gchar *args = g_strstr_len(insn_disas, -1, " ");
-            for (int n = 0; n < all_reg_names->len; n++) {
-                gchar *reg = g_ptr_array_index(all_reg_names, n);
-                if (g_strrstr(args, reg)) {
-                    check_regs_next = true;
-                    skip = false;
+            g_auto(GStrv) args = g_strsplit_set(insn_disas, " \t", 2);
+            if (args && args[1]) {
+                for (int n = 0; n < all_reg_names->len; n++) {
+                    const gchar *reg = g_ptr_array_index(all_reg_names, n);
+                    if (g_strrstr(args[1], reg)) {
+                        check_regs_next = true;
+                        skip = false;
+                        break;
+                    }
                 }
             }
         }
Signature · 1 line
2.50.0
#2 lore raw

PATCH v2 2/2 target/alpha: Add GDB XML feature file

In reply to Yodel Eldar

This patch adds the GDB XML feature file that describes Alpha's core registers.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2569

---
 configs/targets/alpha-linux-user.mak |   1 +
 configs/targets/alpha-softmmu.mak    |   1 +
 gdb-xml/alpha-core.xml               | 136 +++++++++++++++++++++++++++
 target/alpha/cpu.c                   |   1 +
 4 files changed, 139 insertions(+)
 create mode 100644 gdb-xml/alpha-core.xml
configs/targets/alpha-linux-user.mak +1 -0
index ef8e365b09..aa25766236 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=alpha
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= gdb-xml/alpha-core.xml
configs/targets/alpha-softmmu.mak +1 -0
index 5275076e50..e31f059a52 100644
@@ -1,2 +1,3 @@
 TARGET_ARCH=alpha
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= gdb-xml/alpha-core.xml
gdb-xml/alpha-core.xml new file +136 -0

136 lines not on this page · raw message

target/alpha/cpu.c +1 -0
index 2082db45ea..bf1787a69d 100644
@@ -286,6 +286,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, const void *data)
     cc->get_pc = alpha_cpu_get_pc;
     cc->gdb_read_register = alpha_cpu_gdb_read_register;
     cc->gdb_write_register = alpha_cpu_gdb_write_register;
+    cc->gdb_core_xml_file = "alpha-core.xml";
 #ifndef CONFIG_USER_ONLY
     dc->vmsd = &vmstate_alpha_cpu;
     cc->sysemu_ops = &alpha_sysemu_ops;
Signature · 1 line
2.50.0
Applied
#3 lore raw
In reply to Yodel Eldar
Quoted 9 lines · Yodel Eldar

This patch adds TCG plugin register tracking support for the Alpha target and resolves gitlab issue #2569:

https://gitlab.com/qemu-project/qemu/-/issues/2569

As mentioned in the bug report by Alex Bennée, the register list is built using the target's corresponding GDB XML feature file, but the Alpha target does not have one. The second patch introduces the missing feature file and the necessary plumbing for it.

Queued to plugins/next, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#4 lore raw
Quoted 5 lines · Alex Bennée
Quoted 3 lines · Yodel Eldar

This patch adds TCG plugin register tracking support for the Alpha target and resolves gitlab issue #2569:

Quoted 8 lines
Quoted 6 lines
   https://gitlab.com/qemu-project/qemu/-/issues/2569

As mentioned in the bug report by Alex Bennée, the register list is built using the target's corresponding GDB XML feature file, but the Alpha target does not have one. The second patch introduces the missing feature file and the necessary plumbing for it.

Queued to plugins/next, thanks.

Excellent, thanks for the update!