[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 07/15] disas: generalise plugin_printf and use for monitor_dis
From: |
Alex Bennée |
Subject: |
[PATCH v1 07/15] disas: generalise plugin_printf and use for monitor_disas |
Date: |
Fri, 8 Apr 2022 17:47:34 +0100 |
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>
---
disas.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/disas.c b/disas.c
index 3dab4482d1..9b52b2fa93 100644
--- a/disas.c
+++ b/disas.c
@@ -248,7 +248,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;
@@ -279,7 +279,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;
@@ -367,15 +367,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;
}
@@ -385,13 +389,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.30.2
- [PATCH v1 00/15] testing, docs, tracepoints and cputlb hacks, Alex Bennée, 2022/04/08
- [PATCH v1 02/15] docs/devel: add some notes on the binfmt-image-debian targets, Alex Bennée, 2022/04/08
- [PATCH v1 04/15] accel/tcg: move trace events to correct location, Alex Bennée, 2022/04/08
- [PATCH v1 09/15] cputlb: add tracepoints for the protect/unprotect helpers, Alex Bennée, 2022/04/08
- [PATCH v1 07/15] disas: generalise plugin_printf and use for monitor_disas,
Alex Bennée <=
- [PATCH v1 01/15] tests/avocado: update aarch64_virt test to exercise -cpu max, Alex Bennée, 2022/04/08
- [PATCH v1 03/15] docs/devel: drop :hidden: and :includehidden: tags, Alex Bennée, 2022/04/08
- [PATCH v1 06/15] monitor: expose monitor_puts to rest of code, Alex Bennée, 2022/04/08
- [PATCH v1 05/15] accel/tcg: add tb_invalidate_phy_pages_fast tracepoint, Alex Bennée, 2022/04/08
- [PATCH v1 12/15] tests/tcg: add memory-sve test for aarch64, Alex Bennée, 2022/04/08
- [PATCH v1 08/15] disas: use result of ->read_memory_func, Alex Bennée, 2022/04/08