plugins: add tb convenience functions
v2 cover plugins: add tb convenience functions
This PR extends the plugin API with two functions which allow convenient access around tbs.
The first, qemu_plugin_tb_size, provides a mechanism for determining the total size of a translation block.
The second, qemu_plugin_tb_get_insn_by_vaddr, allows users to get a reference to an instruction by its virtual address rather than just its index.
In response to feedback from Pierrick I have updated the implementation of qemu_plugin_tb_size.
Additionally, I have added these functions to the insn.c test plugin in response to Alex's feedback.
Lastly, I'll provide a reply to Alex's feeback (repeated below):
Quoted 3 lines
But the general comment is this is an example of tying the plugin API too deeply with the internals of the translator. Why does a plugin need to know what is an implementation detail?
Finding the line between implementation detail and relevant to plugins is challenging, but I submitted this change because I found myself implementing these functions in plugins. If you'd like for me to enumerate examples where knowing the tb_size is relevant to analysis I'd be happy to submit some.
Luke Craig (3):
plugin: extend API with qemu_plugin_tb_get_insn_by_vaddr
plugin: extend API with qemu_plugin_tb_size
plugins: extend insn test for new convenience functions
include/qemu/qemu-plugin.h | 21 +++++++++++++++++++++ plugins/api.c | 20 ++++++++++++++++++++ tests/tcg/plugins/insn.c | 10 ++++++++++ 3 files changed, 51 insertions(+)
Signature · 1 line
2.34.1
PATCH v2 1/3 plugin: extend API with qemu_plugin_tb_get_insn_by_vaddr
--- include/qemu/qemu-plugin.h | 11 +++++++++++ plugins/api.c | 13 +++++++++++++ 2 files changed, 24 insertions(+)
include/qemu/qemu-plugin.h +11 -0
@@ -500,6 +500,17 @@ QEMU_PLUGIN_APIstruct 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()
plugins/api.c +13 -0
@@ -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, i); +if (insn !=NULL && insn->vaddr == vaddr){ +return insn; + } + } +return NULL ; +} +/* * Instruction information *
Signature · 1 line
2.34.1
PATCH v2 2/3 plugin: extend API with qemu_plugin_tb_size
In reply to Luke Craig--- include/qemu/qemu-plugin.h | 10 ++++++++++ plugins/api.c | 7 +++++++ 2 files changed, 17 insertions(+)
include/qemu/qemu-plugin.h +10 -0
@@ -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
plugins/api.c +7 -0
@@ -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;
Signature · 1 line
2.34.1
PATCH v2 3/3 plugins: extend insn test for new convenience functions
In reply to Luke CraigFrom: Luke Craig <[email protected]>
--- tests/tcg/plugins/insn.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tests/tcg/plugins/insn.c +10 -0
@@ -142,6 +142,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {size_t n =qemu_plugin_tb_n_insns (tb);size_t i; +size_t tb_size =0 ; +struct qemu_plugin_insn *last;for (i =0 ; i < n; i++) {struct qemu_plugin_insn *insn =qemu_plugin_tb_get_insn (tb, i);
@@ -156,6 +158,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)if (do_size) {size_t sz =qemu_plugin_insn_size (insn); + tb_size += sz;if (sz > sizes->len) {g_array_set_size (sizes, sz); }
@@ -188,6 +191,13 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)g_free (insn_disas); } } + + last =qemu_plugin_tb_get_insn (tb, n -1 ); +g_assert (qemu_plugin_tb_get_insn_by_vaddr (tb,qemu_plugin_insn_vaddr (last)) == last); + +if (do_size){ +g_assert (tb_size ==qemu_plugin_tb_size (tb)); + } }static void plugin_exit (qemu_plugin_id_t id,void *p)
Signature · 1 line
2.34.1
Hi Luke,
Quoted 16 lines · Luke Craig
This PR extends the plugin API with two functions which allow convenient access around tbs.
The first,
qemu_plugin_tb_size, provides a mechanism for determining the total size of a translation block.The second,
qemu_plugin_tb_get_insn_by_vaddr, allows users to get a reference to an instruction by its virtual address rather than just its index.In response to feedback from Pierrick I have updated the implementation of
qemu_plugin_tb_size.Additionally, I have added these functions to the
insn.ctest plugin in response to Alex's feedback.Lastly, I'll provide a reply to Alex's feeback (repeated below):
Quoted 3 lines
But the general comment is this is an example of tying the plugin API too deeply with the internals of the translator. Why does a plugin need to know what is an implementation detail?
Quoted 7 lines
Finding the line between implementation detail and relevant to plugins is challenging, but I submitted this change because I found myself implementing these functions in plugins. If you'd like for me to enumerate examples where knowing the
tb_sizeis relevant to analysis I'd be happy to submit some.Luke Craig (3):
plugin: extend API withqemu_plugin_tb_get_insn_by_vaddr
plugin: extend API withqemu_plugin_tb_size
plugins: extend insn test for new convenience functions
For all the series,
Quoted 5 lines
include/qemu/qemu-plugin.h | 21 +++++++++++++++++++++ plugins/api.c | 20 ++++++++++++++++++++ tests/tcg/plugins/insn.c | 10 ++++++++++ 3 files changed, 51 insertions(+)
To accept this series, commits should be signed off [1].
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#patch-emails-must-include-a-signed-off-by-line
Thanks,
Pierrick
Hi Pierrick,
Thank you for your reply.
I have submitted a new patch series with commits signed off.
Thanks!
-Luke
Quoted 53 lines · Pierrick Bouvier
Hi Luke,
Quoted 1 line · Luke Craig
This PR extends the plugin API with two functions which allow convenient
access around tbs.
Quoted 2 lines
The first,
qemu_plugin_tb_size, provides a mechanism for determining thetotal size of a translation block.
Quoted 2 lines
The second,
qemu_plugin_tb_get_insn_by_vaddr, allows users to get areference to an instruction by its virtual address rather than just its index.
Quoted 2 lines
In response to feedback from Pierrick I have updated the implementation
of
qemu_plugin_tb_size.Quoted 2 lines
Additionally, I have added these functions to the
insn.ctest plugin inresponse to Alex's feedback.
Quoted 8 lines
Lastly, I'll provide a reply to Alex's feeback (repeated below):
Quoted 3 lines
But the general comment is this is an example of tying the plugin API too deeply with the internals of the translator. Why does a plugin need to know what is an implementation detail?
Finding the line between implementation detail and relevant to plugins
is challenging, but I submitted this change because I found myself implementing these functions in plugins. If you'd like for me to enumerate examples where knowing the
tb_sizeis relevant to analysis I'd be happy to submit some.Quoted 6 lines
Luke Craig (3):
plugin: extend API withqemu_plugin_tb_get_insn_by_vaddr
plugin: extend API withqemu_plugin_tb_size
plugins: extend insn test for new convenience functionsFor all the series,
Reviewed-by Pierrick Bouvier <[email protected]>Quoted 5 lines
include/qemu/qemu-plugin.h | 21 +++++++++++++++++++++ plugins/api.c | 20 ++++++++++++++++++++ tests/tcg/plugins/insn.c | 10 ++++++++++ 3 files changed, 51 insertions(+)To accept this series, commits should be signed off [1].
Thanks,
Pierrick