diff mbox series

[v2,2/3] plugin: extend API with qemu_plugin_tb_size

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

Commit Message

Luke Craig Jan. 31, 2025, 5:57 p.m. UTC
---
 include/qemu/qemu-plugin.h | 10 ++++++++++
 plugins/api.c              |  7 +++++++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index a1c478c54f..1fa656da82 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -476,6 +476,16 @@  void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
 QEMU_PLUGIN_API
 size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb);
 
+/**
+ * qemu_plugin_tb_size() - query helper for size of TB
+ * @tb: opaque handle to TB passed to callback
+ * 
+ * Returns: size of block in bytes
+ */
+
+QEMU_PLUGIN_API
+size_t qemu_plugin_tb_size(const struct qemu_plugin_tb *tb);
+
 /**
  * qemu_plugin_tb_vaddr() - query helper for vaddr of TB start
  * @tb: opaque handle to TB passed to callback
diff --git a/plugins/api.c b/plugins/api.c
index a6bd912c56..ae74668c2e 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -241,6 +241,13 @@  size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb)
     return tb->n;
 }
 
+size_t qemu_plugin_tb_size(const struct qemu_plugin_tb *tb)
+{
+    struct qemu_plugin_insn *last;
+    last = g_ptr_array_index(tb->insns, tb->n - 1);
+    return qemu_plugin_insn_vaddr(last) + qemu_plugin_insn_size(last) - qemu_plugin_tb_vaddr(tb);
+}
+
 uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb)
 {
     const DisasContextBase *db = tcg_ctx->plugin_db;