mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-26 20:03:54 -06:00
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>
This commit is contained in:
parent
c006147122
commit
8df5e27cf7
3 changed files with 105 additions and 2 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue