Hi Luke,

On 1/27/25 12:17, Luke Craig wrote:
---
  include/qemu/qemu-plugin.h | 10 ++++++++++
  plugins/api.c              |  5 +++++
  2 files changed, 15 insertions(+)

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 7ff5e1c1bd..177f0ac9b6 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -241,6 +241,11 @@ 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){
+    const DisasContextBase *db = tcg_ctx->plugin_db;
+    return db->size;
+}
+
  uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb)
  {
      const DisasContextBase *db = tcg_ctx->plugin_db;

by tb size, do you mean the size, in bytes, of all (original) instructions of the tb?

If yes, you can get it by fetching first and last instruction, and compute the difference between last->vaddr + last->len - first->vaddr.

Regards,
Pierrick

Reply via email to