aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2024-02-27 14:43:29 +0000
committerAlex Bennée <alex.bennee@linaro.org>2024-02-28 09:11:42 +0000
commit8df5e27cf71c727a3e1bc9172819ec69eca32ff4 (patch)
tree23f698e53feb070896f86812e03d3c9050dfd44f /plugins
parentc006147122dede4440c027142ce3025f64e199c0 (diff)
downloadqemu-8df5e27cf71c727a3e1bc9172819ec69eca32ff4.zip
qemu-8df5e27cf71c727a3e1bc9172819ec69eca32ff4.tar.gz
qemu-8df5e27cf71c727a3e1bc9172819ec69eca32ff4.tar.bz2
plugins: add an API to read registers
We can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase. We don't expose the reg number to the plugin instead hiding it behind an opaque handle. For now this is just the gdb_regnum encapsulated in an anonymous GPOINTER but in future as we add more state for plugins to track we can expand it. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706 Based-on: <20231025093128.33116-18-akihiko.odaki@daynix.com> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20240227144335.1196131-24-alex.bennee@linaro.org>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/api.c55
-rw-r--r--plugins/qemu-plugins.symbols2
2 files changed, 57 insertions, 0 deletions
diff --git a/plugins/api.c b/plugins/api.c
index 54df72c..81f43c9 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -8,6 +8,7 @@
*
* qemu_plugin_tb
* qemu_plugin_insn
+ * qemu_plugin_register
*
* Which can then be passed back into the API to do additional things.
* As such all the public functions in here are exported in
@@ -35,10 +36,12 @@
*/
#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
#include "qemu/plugin.h"
#include "qemu/log.h"
#include "tcg/tcg.h"
#include "exec/exec-all.h"
+#include "exec/gdbstub.h"
#include "exec/ram_addr.h"
#include "disas/disas.h"
#include "plugin.h"
@@ -410,3 +413,55 @@ uint64_t qemu_plugin_entry_code(void)
#endif
return entry;
}
+
+/*
+ * Create register handles.
+ *
+ * We need to create a handle for each register so the plugin
+ * infrastructure can call gdbstub to read a register. They are
+ * currently just a pointer encapsulation of the gdb_reg but in
+ * future may hold internal plugin state so its important plugin
+ * authors are not tempted to treat them as numbers.
+ *
+ * We also construct a result array with those handles and some
+ * ancillary data the plugin might find useful.
+ */
+
+static GArray *create_register_handles(GArray *gdbstub_regs)
+{
+ GArray *find_data = g_array_new(true, true,
+ sizeof(qemu_plugin_reg_descriptor));
+
+ for (int i = 0; i < gdbstub_regs->len; i++) {
+ GDBRegDesc *grd = &g_array_index(gdbstub_regs, GDBRegDesc, i);
+ qemu_plugin_reg_descriptor desc;
+
+ /* skip "un-named" regs */
+ if (!grd->name) {
+ continue;
+ }
+
+ /* Create a record for the plugin */
+ desc.handle = GINT_TO_POINTER(grd->gdb_reg);
+ desc.name = g_intern_string(grd->name);
+ desc.feature = g_intern_string(grd->feature_name);
+ g_array_append_val(find_data, desc);
+ }
+
+ return find_data;
+}
+
+GArray *qemu_plugin_get_registers(void)
+{
+ g_assert(current_cpu);
+
+ g_autoptr(GArray) regs = gdb_get_register_list(current_cpu);
+ return create_register_handles(regs);
+}
+
+int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray *buf)
+{
+ g_assert(current_cpu);
+
+ return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg));
+}
diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols
index adb6760..27fe972 100644
--- a/plugins/qemu-plugins.symbols
+++ b/plugins/qemu-plugins.symbols
@@ -3,6 +3,7 @@
qemu_plugin_end_code;
qemu_plugin_entry_code;
qemu_plugin_get_hwaddr;
+ qemu_plugin_get_registers;
qemu_plugin_hwaddr_device_name;
qemu_plugin_hwaddr_is_io;
qemu_plugin_hwaddr_phys_addr;
@@ -19,6 +20,7 @@
qemu_plugin_num_vcpus;
qemu_plugin_outs;
qemu_plugin_path_to_binary;
+ qemu_plugin_read_register;
qemu_plugin_register_atexit_cb;
qemu_plugin_register_flush_cb;
qemu_plugin_register_vcpu_exit_cb;