qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: minyihh@uci.edu, ma.mandourr@gmail.com, Luke.Craig@ll.mit.edu,
	cota@braap.org, aaron@os.amperecomputing.com,
	kuhn.chenqun@huawei.com, robhenry@microsoft.com,
	mahmoudabdalghany@outlook.com,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PATCH v1 02/10] disas: generalise plugin_printf and use for monitor_disas
Date: Wed, 21 Sep 2022 17:07:53 +0100	[thread overview]
Message-ID: <20220921160801.1490125-3-alex.bennee@linaro.org> (raw)
In-Reply-To: <20220921160801.1490125-1-alex.bennee@linaro.org>

Rather than assembling our output piecemeal lets use the same approach
as the plugin disas interface to build the disassembly string before
printing it.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/disas.c b/disas.c
index e31438f349..f07b6e760b 100644
--- a/disas.c
+++ b/disas.c
@@ -239,7 +239,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     }
 }
 
-static int plugin_printf(FILE *stream, const char *fmt, ...)
+static int gstring_printf(FILE *stream, const char *fmt, ...)
 {
     /* We abuse the FILE parameter to pass a GString. */
     GString *s = (GString *)stream;
@@ -270,7 +270,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
     GString *ds = g_string_new(NULL);
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = plugin_printf;
+    s.info.fprintf_func = gstring_printf;
     s.info.stream = (FILE *)ds;  /* abuse this slot */
     s.info.buffer_vma = addr;
     s.info.buffer_length = size;
@@ -358,15 +358,19 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 {
     int count, i;
     CPUDebug s;
+    g_autoptr(GString) ds = g_string_new("");
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = qemu_fprintf;
+    s.info.fprintf_func = gstring_printf;
+    s.info.stream = (FILE *)ds;  /* abuse this slot */
+
     if (is_physical) {
         s.info.read_memory_func = physical_read_memory;
     }
     s.info.buffer_vma = pc;
 
     if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
+        monitor_puts(mon, ds->str);
         return;
     }
 
@@ -376,13 +380,16 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
         return;
     }
 
-    for(i = 0; i < nb_insn; i++) {
-	monitor_printf(mon, "0x" TARGET_FMT_lx ":  ", pc);
+    for (i = 0; i < nb_insn; i++) {
+        g_string_append_printf(ds, "0x" TARGET_FMT_lx ":  ", pc);
         count = s.info.print_insn(pc, &s.info);
-	monitor_printf(mon, "\n");
-	if (count < 0)
-	    break;
+        g_string_append_c(ds, '\n');
+        if (count < 0) {
+            break;
+        }
         pc += count;
     }
+
+    monitor_puts(mon, ds->str);
 }
 #endif
-- 
2.34.1



  parent reply	other threads:[~2022-09-21 16:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
2022-09-21 17:34   ` Philippe Mathieu-Daudé via
2022-09-22  4:30   ` Markus Armbruster
2022-09-22 15:06   ` Kevin Wolf
2022-09-21 16:07 ` Alex Bennée [this message]
2022-09-21 16:07 ` [PATCH v1 03/10] disas: use result of ->read_memory_func Alex Bennée
2022-09-21 17:37   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64 Alex Bennée
2022-09-28 22:54   ` Richard Henderson
2022-09-21 16:07 ` [PATCH v1 05/10] plugins: extend execlog to filter matches Alex Bennée
2022-09-21 16:07 ` [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Alex Bennée
2022-09-21 17:40   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins Alex Bennée
2022-09-21 17:39   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst Alex Bennée
2022-09-21 17:39   ` Philippe Mathieu-Daudé via
2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
2022-09-21 17:38   ` Philippe Mathieu-Daudé via
2022-09-28 22:59   ` Richard Henderson
2022-09-21 16:08 ` [PATCH v1 10/10] docs/devel: document the test plugins Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220921160801.1490125-3-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=Luke.Craig@ll.mit.edu \
    --cc=aaron@os.amperecomputing.com \
    --cc=cota@braap.org \
    --cc=kuhn.chenqun@huawei.com \
    --cc=ma.mandourr@gmail.com \
    --cc=mahmoudabdalghany@outlook.com \
    --cc=minyihh@uci.edu \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=robhenry@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).