diff mbox series

[RFC] plugins/api: expose symbol lookup to plugins

Message ID 20210601145824.3849-1-alex.bennee@linaro.org
State New
Headers show
Series [RFC] plugins/api: expose symbol lookup to plugins | expand

Commit Message

Alex Bennée June 1, 2021, 2:58 p.m. UTC
This is a quality of life helper for plugins so they don't need to
re-implement symbol lookup when dumping an address. The strings are
constant so don't need to be duplicated. One minor tweak is to return
NULL instead of a zero length string to show lookup failed.

Based-on: 20210530063712.6832-4-ma.mandourr@gmail.com
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 include/qemu/qemu-plugin.h |  9 +++++++++
 contrib/plugins/cache.c    | 10 ++++++++--
 plugins/api.c              |  6 ++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

-- 
2.20.1

Comments

Mahmoud Mandour June 2, 2021, 6:19 a.m. UTC | #1
On Tue, Jun 1, 2021 at 4:58 PM Alex Bennée <alex.bennee@linaro.org> wrote:

> This is a quality of life helper for plugins so they don't need to

> re-implement symbol lookup when dumping an address. The strings are

> constant so don't need to be duplicated. One minor tweak is to return

> NULL instead of a zero length string to show lookup failed.

>

Thank you for implementing this, I found it a really easy addition since you
already told me how this is done in the kick-off meeting and I implemented
it
but I'm glad you already posted it :D

>

> Based-on: 20210530063712.6832-4-ma.mandourr@gmail.com

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  include/qemu/qemu-plugin.h |  9 +++++++++

>  contrib/plugins/cache.c    | 10 ++++++++--

>  plugins/api.c              |  6 ++++++

>  3 files changed, 23 insertions(+), 2 deletions(-)

>

> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h

> index 97cdfd7761..dc3496f36c 100644

> --- a/include/qemu/qemu-plugin.h

> +++ b/include/qemu/qemu-plugin.h

> @@ -525,6 +525,15 @@

> qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,

>

>  char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);

>

> +/**

> + * qemu_plugin_insn_symbol() - best effort symbol lookup

> + * @insn: instruction reference

> + *

> + * Return a static string referring to the symbol. This is dependent

> + * on the binary QEMU is running having provided a symbol table.

> + */

> +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);

> +

>  /**

>   * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU

>   * @id: plugin ID

> diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c

> index 1e323494bf..afaa3d9db5 100644

> --- a/contrib/plugins/cache.c

> +++ b/contrib/plugins/cache.c

> @@ -46,6 +46,7 @@ enum AccessResult {

>

>  struct InsnData {

>      char *disas_str;

> +    const char *symbol;

>      uint64_t addr;

>      uint64_t misses;

>  };

> @@ -377,10 +378,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id,

> struct qemu_plugin_tb *tb)

>          struct InsnData *idata = g_new(struct InsnData, 1);

>

>          ddata->disas_str = qemu_plugin_insn_disas(insn);

> +        ddata->symbol = qemu_plugin_insn_symbol(insn);

>          ddata->misses = 0;

>          ddata->addr = effective_addr;

>

>          idata->disas_str = g_strdup(ddata->disas_str);

> +        idata->symbol = qemu_plugin_insn_symbol(insn);

>          idata->misses = 0;

>          idata->addr = effective_addr;

>

> @@ -397,8 +400,11 @@ static void print_entry(gpointer data)

>  {

>      struct InsnData *insn = (struct InsnData *) data;

>      g_autoptr(GString) xx = g_string_new("");

> -    g_string_append_printf(xx, "0x%" PRIx64 ": %s - misses: %lu\n",

> -            insn->addr, insn->disas_str, insn->misses);

> +    g_string_append_printf(xx, "0x%" PRIx64, insn->addr);

> +    if (insn->symbol) {

> +        g_string_append_printf(xx, " (%s)", insn->symbol);

> +    }

> +    g_string_append_printf(xx, ", %lu, %s\n", insn->misses,

> insn->disas_str);

>      qemu_plugin_outs(xx->str);

>  }



> diff --git a/plugins/api.c b/plugins/api.c

> index 817c9b6b69..332e2c60e2 100644

> --- a/plugins/api.c

> +++ b/plugins/api.c

> @@ -233,6 +233,12 @@ char *qemu_plugin_insn_disas(const struct

> qemu_plugin_insn *insn)

>      return plugin_disas(cpu, insn->vaddr, insn->data->len);

>  }

>

+const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)
> +{

> +    const char *sym = lookup_symbol(insn->vaddr);

> +    return sym[0] != 0 ? sym : NULL;

> +}

> +

>  /*

>   * The memory queries allow the plugin to query information about a

>   * memory access.

> --

> 2.20.1

>

>

How can I address such an addition? Should I add it to my next RFC series
under your name using your Signed-off-by line? Also, I think that somethings
in my series that you're basing your patch on will be changed, such as
having
two duplicated entries of InsnData and the stupid name "xx" of the report
string
How can I base your patch after my edits?

Thanks,
Mahmoud
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 1, 2021 at 4:58 PM Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org">alex.bennee@linaro.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This is a quality of life helper for plugins so they don&#39;t need to<br>
re-implement symbol lookup when dumping an address. The strings are<br>
constant so don&#39;t need to be duplicated. One minor tweak is to return<br>
NULL instead of a zero length string to show lookup failed.<br></blockquote><div>Thank you for implementing this, I found it a really easy addition since you<br></div><div>already told me how this is done in the kick-off meeting and I implemented it</div><div>but I&#39;m glad you already posted it :D</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Based-on: <a href="mailto:20210530063712.6832-4-ma.mandourr@gmail.com" target="_blank">20210530063712.6832-4-ma.mandourr@gmail.com</a><br>
Signed-off-by: Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org" target="_blank">alex.bennee@linaro.org</a>&gt;<br>

---<br>
 include/qemu/qemu-plugin.h |  9 +++++++++<br>
 contrib/plugins/cache.c    | 10 ++++++++--<br>
 plugins/api.c              |  6 ++++++<br>
 3 files changed, 23 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h<br>
index 97cdfd7761..dc3496f36c 100644<br>
--- a/include/qemu/qemu-plugin.h<br>
+++ b/include/qemu/qemu-plugin.h<br>
@@ -525,6 +525,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,<br>
<br>
 char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);<br>
<br>
+/**<br>
+ * qemu_plugin_insn_symbol() - best effort symbol lookup<br>
+ * @insn: instruction reference<br>
+ *<br>
+ * Return a static string referring to the symbol. This is dependent<br>
+ * on the binary QEMU is running having provided a symbol table.<br>
+ */<br>
+const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);<br>
+<br>
 /**<br>
  * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU<br>
  * @id: plugin ID<br>
diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c<br>
index 1e323494bf..afaa3d9db5 100644<br>
--- a/contrib/plugins/cache.c<br>
+++ b/contrib/plugins/cache.c<br>
@@ -46,6 +46,7 @@ enum AccessResult {<br>
<br>
 struct InsnData {<br>
     char *disas_str;<br>
+    const char *symbol;<br>
     uint64_t addr;<br>
     uint64_t misses;<br>
 };<br>
@@ -377,10 +378,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)<br>
         struct InsnData *idata = g_new(struct InsnData, 1);<br>
<br>
         ddata-&gt;disas_str = qemu_plugin_insn_disas(insn);<br>
+        ddata-&gt;symbol = qemu_plugin_insn_symbol(insn);<br>
         ddata-&gt;misses = 0;<br>
         ddata-&gt;addr = effective_addr;<br>
<br>
         idata-&gt;disas_str = g_strdup(ddata-&gt;disas_str);<br>
+        idata-&gt;symbol = qemu_plugin_insn_symbol(insn);<br>
         idata-&gt;misses = 0;<br>
         idata-&gt;addr = effective_addr;<br>
<br>
@@ -397,8 +400,11 @@ static void print_entry(gpointer data)<br>
 {<br>
     struct InsnData *insn = (struct InsnData *) data;<br>
     g_autoptr(GString) xx = g_string_new(&quot;&quot;);<br>
-    g_string_append_printf(xx, &quot;0x%&quot; PRIx64 &quot;: %s - misses: %lu\n&quot;,<br>
-            insn-&gt;addr, insn-&gt;disas_str, insn-&gt;misses);<br>
+    g_string_append_printf(xx, &quot;0x%&quot; PRIx64, insn-&gt;addr);<br>
+    if (insn-&gt;symbol) {<br>
+        g_string_append_printf(xx, &quot; (%s)&quot;, insn-&gt;symbol);<br>
+    }<br>
+    g_string_append_printf(xx, &quot;, %lu, %s\n&quot;, insn-&gt;misses, insn-&gt;disas_str);<br>
     qemu_plugin_outs(xx-&gt;str);<br>
 }</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
diff --git a/plugins/api.c b/plugins/api.c<br>
index 817c9b6b69..332e2c60e2 100644<br>
--- a/plugins/api.c<br>
+++ b/plugins/api.c<br>
@@ -233,6 +233,12 @@ char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)<br>
     return plugin_disas(cpu, insn-&gt;vaddr, insn-&gt;data-&gt;len);<br>
 } <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)<br>
+{<br>
+    const char *sym = lookup_symbol(insn-&gt;vaddr);<br>
+    return sym[0] != 0 ? sym : NULL;<br>
+}<br>
+<br>
 /*<br>
  * The memory queries allow the plugin to query information about a<br>
  * memory access.<br>
-- <br>
2.20.1<br>
<br></blockquote><div><br></div><div>How can I address such an addition? Should I add it to my next RFC series</div><div>under your name using your Signed-off-by line? Also, I think that somethings</div><div>in my series that you&#39;re basing your patch on will be changed, such as having</div><div>two duplicated entries of InsnData and the stupid name &quot;xx&quot; of the report string</div><div>How can I base your patch after my edits?</div><div><br></div><div>Thanks,</div><div>Mahmoud</div></div></div>
Alex Bennée June 2, 2021, 8:43 a.m. UTC | #2
Mahmoud Mandour <ma.mandourr@gmail.com> writes:

> On Tue, Jun 1, 2021 at 4:58 PM Alex Bennée <alex.bennee@linaro.org> wrote:

>

>  This is a quality of life helper for plugins so they don't need to

>  re-implement symbol lookup when dumping an address. The strings are

>  constant so don't need to be duplicated. One minor tweak is to return

>  NULL instead of a zero length string to show lookup failed.

>

> Thank you for implementing this, I found it a really easy addition since you

> already told me how this is done in the kick-off meeting and I implemented it

> but I'm glad you already posted it :D

>

>  Based-on: 20210530063712.6832-4-ma.mandourr@gmail.com

>  Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>  ---

>   include/qemu/qemu-plugin.h |  9 +++++++++

>   contrib/plugins/cache.c    | 10 ++++++++--

>   plugins/api.c              |  6 ++++++

>   3 files changed, 23 insertions(+), 2 deletions(-)

>

>  diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h

>  index 97cdfd7761..dc3496f36c 100644

>  --- a/include/qemu/qemu-plugin.h

>  +++ b/include/qemu/qemu-plugin.h

>  @@ -525,6 +525,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,

>

>   char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);

>

>  +/**

>  + * qemu_plugin_insn_symbol() - best effort symbol lookup

>  + * @insn: instruction reference

>  + *

>  + * Return a static string referring to the symbol. This is dependent

>  + * on the binary QEMU is running having provided a symbol table.

>  + */

>  +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);

>  +

>   /**

>    * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU

>    * @id: plugin ID

>  diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c

>  index 1e323494bf..afaa3d9db5 100644

>  --- a/contrib/plugins/cache.c

>  +++ b/contrib/plugins/cache.c

>  @@ -46,6 +46,7 @@ enum AccessResult {

>

>   struct InsnData {

>       char *disas_str;

>  +    const char *symbol;

>       uint64_t addr;

>       uint64_t misses;

>   };

>  @@ -377,10 +378,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)

>           struct InsnData *idata = g_new(struct InsnData, 1);

>

>           ddata->disas_str = qemu_plugin_insn_disas(insn);

>  +        ddata->symbol = qemu_plugin_insn_symbol(insn);

>           ddata->misses = 0;

>           ddata->addr = effective_addr;

>

>           idata->disas_str = g_strdup(ddata->disas_str);

>  +        idata->symbol = qemu_plugin_insn_symbol(insn);

>           idata->misses = 0;

>           idata->addr = effective_addr;

>

>  @@ -397,8 +400,11 @@ static void print_entry(gpointer data)

>   {

>       struct InsnData *insn = (struct InsnData *) data;

>       g_autoptr(GString) xx = g_string_new("");

>  -    g_string_append_printf(xx, "0x%" PRIx64 ": %s - misses: %lu\n",

>  -            insn->addr, insn->disas_str, insn->misses);

>  +    g_string_append_printf(xx, "0x%" PRIx64, insn->addr);

>  +    if (insn->symbol) {

>  +        g_string_append_printf(xx, " (%s)", insn->symbol);

>  +    }

>  +    g_string_append_printf(xx, ", %lu, %s\n", insn->misses, insn->disas_str);

>       qemu_plugin_outs(xx->str);

>   }

>

>  diff --git a/plugins/api.c b/plugins/api.c

>  index 817c9b6b69..332e2c60e2 100644

>  --- a/plugins/api.c

>  +++ b/plugins/api.c

>  @@ -233,6 +233,12 @@ char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)

>       return plugin_disas(cpu, insn->vaddr, insn->data->len);

>   } 

>

>  +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)

>  +{

>  +    const char *sym = lookup_symbol(insn->vaddr);

>  +    return sym[0] != 0 ? sym : NULL;

>  +}

>  +

>   /*

>    * The memory queries allow the plugin to query information about a

>    * memory access.

>  -- 

>  2.20.1

>

> How can I address such an addition? Should I add it to my next RFC series

> under your name using your Signed-off-by line?


Yes, if you git am the patch to your series it will keep my authorship
and also copy the message-id of the post it came from. When you re-base
you can add your s-o-b tag to indicate that to the best of your
knowledge it is code that can be included in the tree (which it is, I
posted it to qemu-devel ;-).

> Also, I think that somethings

> in my series that you're basing your patch on will be changed, such as having

> two duplicated entries of InsnData and the stupid name "xx" of the report string

> How can I base your patch after my edits?


You have two choices. Move the patch to the start of your series and
drop the actual plugin tweaks and make it API only or keep it at the end
of the series and fix it up when you re-base. Generally you make a note
"under the line" of the changes so the commit message would look like:

  plugins/api: expose symbol lookup to plugins

  This is a quality of life helper for plugins so they don't need to
  re-implement symbol lookup when dumping an address. The strings are
  constant so don't need to be duplicated. One minor tweak is to return
  NULL instead of a zero length string to show lookup failed.

  Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

  Message-Id: <20210601145824.3849-1-alex.bennee@linaro.org>
  Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>


  ---
  v3
    - included in my tree, fixed up rebase conflicts

This is a useful reference for people reading the patches on the list to
see what changed. The tooling will drop everything under --- when it is
applied to a tree.

-- 
Alex Bennée
Philippe Mathieu-Daudé June 2, 2021, 10:44 a.m. UTC | #3
On 6/2/21 10:43 AM, Alex Bennée wrote:
> 

> Mahmoud Mandour <ma.mandourr@gmail.com> writes:

> 

>> On Tue, Jun 1, 2021 at 4:58 PM Alex Bennée <alex.bennee@linaro.org> wrote:

>>

>>  This is a quality of life helper for plugins so they don't need to

>>  re-implement symbol lookup when dumping an address. The strings are

>>  constant so don't need to be duplicated. One minor tweak is to return

>>  NULL instead of a zero length string to show lookup failed.

>>

>> Thank you for implementing this, I found it a really easy addition since you

>> already told me how this is done in the kick-off meeting and I implemented it

>> but I'm glad you already posted it :D

>>

>>  Based-on: 20210530063712.6832-4-ma.mandourr@gmail.com

>>  Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>>  ---

>>   include/qemu/qemu-plugin.h |  9 +++++++++

>>   contrib/plugins/cache.c    | 10 ++++++++--

>>   plugins/api.c              |  6 ++++++

>>   3 files changed, 23 insertions(+), 2 deletions(-)

>>

>>  diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h

>>  index 97cdfd7761..dc3496f36c 100644

>>  --- a/include/qemu/qemu-plugin.h

>>  +++ b/include/qemu/qemu-plugin.h

>>  @@ -525,6 +525,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,

>>

>>   char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);

>>

>>  +/**

>>  + * qemu_plugin_insn_symbol() - best effort symbol lookup

>>  + * @insn: instruction reference

>>  + *

>>  + * Return a static string referring to the symbol. This is dependent

>>  + * on the binary QEMU is running having provided a symbol table.

>>  + */

>>  +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);

>>  +

>>   /**

>>    * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU

>>    * @id: plugin ID

>>  diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c

>>  index 1e323494bf..afaa3d9db5 100644

>>  --- a/contrib/plugins/cache.c

>>  +++ b/contrib/plugins/cache.c

>>  @@ -46,6 +46,7 @@ enum AccessResult {

>>

>>   struct InsnData {

>>       char *disas_str;

>>  +    const char *symbol;

>>       uint64_t addr;

>>       uint64_t misses;

>>   };

>>  @@ -377,10 +378,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)

>>           struct InsnData *idata = g_new(struct InsnData, 1);

>>

>>           ddata->disas_str = qemu_plugin_insn_disas(insn);

>>  +        ddata->symbol = qemu_plugin_insn_symbol(insn);

>>           ddata->misses = 0;

>>           ddata->addr = effective_addr;

>>

>>           idata->disas_str = g_strdup(ddata->disas_str);

>>  +        idata->symbol = qemu_plugin_insn_symbol(insn);

>>           idata->misses = 0;

>>           idata->addr = effective_addr;

>>

>>  @@ -397,8 +400,11 @@ static void print_entry(gpointer data)

>>   {

>>       struct InsnData *insn = (struct InsnData *) data;

>>       g_autoptr(GString) xx = g_string_new("");

>>  -    g_string_append_printf(xx, "0x%" PRIx64 ": %s - misses: %lu\n",

>>  -            insn->addr, insn->disas_str, insn->misses);

>>  +    g_string_append_printf(xx, "0x%" PRIx64, insn->addr);

>>  +    if (insn->symbol) {

>>  +        g_string_append_printf(xx, " (%s)", insn->symbol);

>>  +    }

>>  +    g_string_append_printf(xx, ", %lu, %s\n", insn->misses, insn->disas_str);

>>       qemu_plugin_outs(xx->str);

>>   }

>>

>>  diff --git a/plugins/api.c b/plugins/api.c

>>  index 817c9b6b69..332e2c60e2 100644

>>  --- a/plugins/api.c

>>  +++ b/plugins/api.c

>>  @@ -233,6 +233,12 @@ char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)

>>       return plugin_disas(cpu, insn->vaddr, insn->data->len);

>>   } 

>>

>>  +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)

>>  +{

>>  +    const char *sym = lookup_symbol(insn->vaddr);

>>  +    return sym[0] != 0 ? sym : NULL;

>>  +}

>>  +

>>   /*

>>    * The memory queries allow the plugin to query information about a

>>    * memory access.

>>  -- 

>>  2.20.1

>>

>> How can I address such an addition? Should I add it to my next RFC series

>> under your name using your Signed-off-by line?

> 

> Yes, if you git am the patch to your series it will keep my authorship

> and also copy the message-id of the post it came from. When you re-base

> you can add your s-o-b tag to indicate that to the best of your

> knowledge it is code that can be included in the tree (which it is, I

> posted it to qemu-devel ;-).

> 

>> Also, I think that somethings

>> in my series that you're basing your patch on will be changed, such as having

>> two duplicated entries of InsnData and the stupid name "xx" of the report string

>> How can I base your patch after my edits?

> 

> You have two choices. Move the patch to the start of your series and

> drop the actual plugin tweaks and make it API only or keep it at the end

> of the series and fix it up when you re-base. Generally you make a note

> "under the line" of the changes so the commit message would look like:

> 

>   plugins/api: expose symbol lookup to plugins

> 

>   This is a quality of life helper for plugins so they don't need to

>   re-implement symbol lookup when dumping an address. The strings are

>   constant so don't need to be duplicated. One minor tweak is to return

>   NULL instead of a zero length string to show lookup failed.

> 

>   Signed-off-by: Alex Bennée <alex.bennee@linaro.org>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


>   Message-Id: <20210601145824.3849-1-alex.bennee@linaro.org>

>   Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>

> 

>   ---

>   v3

>     - included in my tree, fixed up rebase conflicts

> 

> This is a useful reference for people reading the patches on the list to

> see what changed. The tooling will drop everything under --- when it is

> applied to a tree.

>
diff mbox series

Patch

diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 97cdfd7761..dc3496f36c 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -525,6 +525,15 @@  qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,
 
 char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);
 
+/**
+ * qemu_plugin_insn_symbol() - best effort symbol lookup
+ * @insn: instruction reference
+ *
+ * Return a static string referring to the symbol. This is dependent
+ * on the binary QEMU is running having provided a symbol table.
+ */
+const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);
+
 /**
  * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU
  * @id: plugin ID
diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c
index 1e323494bf..afaa3d9db5 100644
--- a/contrib/plugins/cache.c
+++ b/contrib/plugins/cache.c
@@ -46,6 +46,7 @@  enum AccessResult {
 
 struct InsnData {
     char *disas_str;
+    const char *symbol;
     uint64_t addr;
     uint64_t misses;
 };
@@ -377,10 +378,12 @@  static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
         struct InsnData *idata = g_new(struct InsnData, 1);
 
         ddata->disas_str = qemu_plugin_insn_disas(insn);
+        ddata->symbol = qemu_plugin_insn_symbol(insn);
         ddata->misses = 0;
         ddata->addr = effective_addr;
 
         idata->disas_str = g_strdup(ddata->disas_str);
+        idata->symbol = qemu_plugin_insn_symbol(insn);
         idata->misses = 0;
         idata->addr = effective_addr;
 
@@ -397,8 +400,11 @@  static void print_entry(gpointer data)
 {
     struct InsnData *insn = (struct InsnData *) data;
     g_autoptr(GString) xx = g_string_new("");
-    g_string_append_printf(xx, "0x%" PRIx64 ": %s - misses: %lu\n",
-            insn->addr, insn->disas_str, insn->misses);
+    g_string_append_printf(xx, "0x%" PRIx64, insn->addr);
+    if (insn->symbol) {
+        g_string_append_printf(xx, " (%s)", insn->symbol);
+    }
+    g_string_append_printf(xx, ", %lu, %s\n", insn->misses, insn->disas_str);
     qemu_plugin_outs(xx->str);
 }
 
diff --git a/plugins/api.c b/plugins/api.c
index 817c9b6b69..332e2c60e2 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -233,6 +233,12 @@  char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)
     return plugin_disas(cpu, insn->vaddr, insn->data->len);
 }
 
+const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)
+{
+    const char *sym = lookup_symbol(insn->vaddr);
+    return sym[0] != 0 ? sym : NULL;
+}
+
 /*
  * The memory queries allow the plugin to query information about a
  * memory access.