diff mbox series

[1/2] plugin: extend API with qemu_plugin_tb_get_insn_by_vaddr

Message ID 20250127201734.1769540-2-lacraig3@gmail.com (mailing list archive)
State New
Headers show
Series plugins: add tb convenience functions | expand

Commit Message

Luke Craig Jan. 27, 2025, 8:17 p.m. UTC
---
 include/qemu/qemu-plugin.h | 11 +++++++++++
 plugins/api.c              | 13 +++++++++++++
 2 files changed, 24 insertions(+)

Comments

Alex Bennée Jan. 28, 2025, 9:07 a.m. UTC | #1
Luke Craig <lacraig3@gmail.com> writes:

> ---
>  include/qemu/qemu-plugin.h | 11 +++++++++++
>  plugins/api.c              | 13 +++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
> index 3a850aa216..a1c478c54f 100644
> --- a/include/qemu/qemu-plugin.h
> +++ b/include/qemu/qemu-plugin.h
> @@ -500,6 +500,17 @@ QEMU_PLUGIN_API
>  struct qemu_plugin_insn *
>  qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx);
>  
> +/**
> + * qemu_plugin_tb_get_insn_by_vaddr() - lookup handle for instruction by vaddr
> + * @tb: opaque handle to TB passed to callback
> + * @vaddr: virtual address of instruction
> + *
> + * Returns: opaque handle to instruction
> + */
> +QEMU_PLUGIN_API
> +struct qemu_plugin_insn *
> +qemu_plugin_tb_get_insn_by_vaddr(const struct qemu_plugin_tb *tb, uint64_t vaddr);
> +
>  /**
>   * qemu_plugin_insn_data() - copy instruction data
>   * @insn: opaque instruction handle from qemu_plugin_tb_get_insn()
> diff --git a/plugins/api.c b/plugins/api.c
> index 4110cfaa23..7ff5e1c1bd 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -258,6 +258,19 @@ qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx)
>      return insn;
>  }
>  
> +struct qemu_plugin_insn *
> +qemu_plugin_tb_get_insn_by_vaddr(const struct qemu_plugin_tb *tb, uint64_t vaddr)
> +{
> +    struct qemu_plugin_insn *insn;
> +    for (size_t i = 0; i < tb->n; i++){
> +        insn = g_ptr_array_index(tb->insns, idx);
> +        if (insn != NULL && insn->vaddr == vaddr){
> +            return insn;
> +        }
> +    }
> +    return NULL;
> +}
> +

I don't have any fundamental objection to this. I would prefer it if the
new helper was used by either one of the test or contrib plugins to
ensure we don't bitrot it.

>  /*
>   * Instruction information
>   *
diff mbox series

Patch

diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 3a850aa216..a1c478c54f 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -500,6 +500,17 @@  QEMU_PLUGIN_API
 struct qemu_plugin_insn *
 qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx);
 
+/**
+ * qemu_plugin_tb_get_insn_by_vaddr() - lookup handle for instruction by vaddr
+ * @tb: opaque handle to TB passed to callback
+ * @vaddr: virtual address of instruction
+ *
+ * Returns: opaque handle to instruction
+ */
+QEMU_PLUGIN_API
+struct qemu_plugin_insn *
+qemu_plugin_tb_get_insn_by_vaddr(const struct qemu_plugin_tb *tb, uint64_t vaddr);
+
 /**
  * qemu_plugin_insn_data() - copy instruction data
  * @insn: opaque instruction handle from qemu_plugin_tb_get_insn()
diff --git a/plugins/api.c b/plugins/api.c
index 4110cfaa23..7ff5e1c1bd 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -258,6 +258,19 @@  qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx)
     return insn;
 }
 
+struct qemu_plugin_insn *
+qemu_plugin_tb_get_insn_by_vaddr(const struct qemu_plugin_tb *tb, uint64_t vaddr)
+{
+    struct qemu_plugin_insn *insn;
+    for (size_t i = 0; i < tb->n; i++){
+        insn = g_ptr_array_index(tb->insns, idx);
+        if (insn != NULL && insn->vaddr == vaddr){
+            return insn;
+        }
+    }
+    return NULL;
+}
+
 /*
  * Instruction information
  *