plugins: add read-only property for registers
Some registers should be marked as read-only from a plugin API perspective, as writing to them via qemu_plugin_write_register has no effect. This includes the program counter, and we expose this fact to the plugins with this patch. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Signed-off-by: Florian Hofhammer <florian.hofhammer@epfl.ch> Link: https://lore.kernel.org/qemu-devel/20260305-setpc-v5-v7-6-4c3adba52403@epfl.ch Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Florian Hofhammer committed
Mar 5, 2026 at 11:06 UTC
3ebd871cbdaf044a4cc0dd255d482175524c13c4
2 files changed
+19
include/plugins/qemu-plugin.h
+3
@@ -979,11 +979,14 @@ struct qemu_plugin_register;
979
* writing value with qemu_plugin_write_register
980
* @name: register name
981
* @feature: optional feature descriptor, can be NULL
982
+ * @is_readonly: true if the register cannot be written via
983
+ * qemu_plugin_write_register
984
*/
985
typedef struct {
986
struct qemu_plugin_register *handle;
987
const char *name;
988
const char *feature;
989
+ bool is_readonly;
990
} qemu_plugin_reg_descriptor;
991
992
/**
plugins/api.c
+16
@@ -410,6 +410,12 @@ bool qemu_plugin_bool_parse(const char *name, const char *value, bool *ret)
410
* ancillary data the plugin might find useful.
411
*/
412
413
+static const char pc_str[] = "pc"; /* generic name for program counter */
414
+static const char eip_str[] = "eip"; /* x86-specific name for PC */
415
+static const char rip_str[] = "rip"; /* x86_64-specific name for PC */
416
+static const char pswa_str[] = "pswa"; /* s390x-specific name for PC */
417
+static const char iaoq_str[] = "iaoq"; /* HP/PA-specific name for PC */
418
+static const char rpc_str[] = "rpc"; /* microblaze-specific name for PC */
419
static GArray *create_register_handles(GArray *gdbstub_regs)
420
{
421
GArray *find_data = g_array_new(true, true,
@@ -427,6 +433,16 @@ static GArray *create_register_handles(GArray *gdbstub_regs)
433
/* Create a record for the plugin */
434
desc.handle = GINT_TO_POINTER(grd->gdb_reg + 1);
435
desc.name = g_intern_string(grd->name);
436
+ desc.is_readonly = false;
437
+ if (g_strcmp0(desc.name, pc_str) == 0
438
+ || g_strcmp0(desc.name, eip_str) == 0
439
+ || g_strcmp0(desc.name, rip_str) == 0
440
+ || g_strcmp0(desc.name, pswa_str) == 0
441
+ || g_strcmp0(desc.name, iaoq_str) == 0
442
+ || g_strcmp0(desc.name, rpc_str) == 0
443
+ ) {
444
+ desc.is_readonly = true;
445
+ }
446
desc.feature = g_intern_string(grd->feature_name);
447
g_array_append_val(find_data, desc);
448
}