[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 33/54] disas: generalise plugin_printf and use for monitor_disas
From: |
Alex Bennée |
Subject: |
[PULL 33/54] disas: generalise plugin_printf and use for monitor_disas |
Date: |
Tue, 4 Oct 2022 14:01:17 +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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220929114231.583801-34-alex.bennee@linaro.org>
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
- [PULL 44/54] gdbstub: move breakpoint logic to accel ops, (continued)
- [PULL 44/54] gdbstub: move breakpoint logic to accel ops, Alex Bennée, 2022/10/04
- [PULL 38/54] docs/devel: move API to end of tcg-plugins.rst, Alex Bennée, 2022/10/04
- [PULL 45/54] gdbstub: move guest debug support check to ops, Alex Bennée, 2022/10/04
- [PULL 26/54] configure: unify creation of cross-compilation Makefiles, Alex Bennée, 2022/10/04
- [PULL 53/54] contrib/gitdm: add Université Grenoble Alpes, Alex Bennée, 2022/10/04
- [PULL 36/54] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr, Alex Bennée, 2022/10/04
- [PULL 19/54] tests: simplify Makefile invocation for tests/tcg, Alex Bennée, 2022/10/04
- [PULL 34/54] disas: use result of ->read_memory_func, Alex Bennée, 2022/10/04
- [PULL 50/54] contrib/gitdm: add ISCAS to the academics group, Alex Bennée, 2022/10/04
- [PULL 33/54] disas: generalise plugin_printf and use for monitor_disas,
Alex Bennée <=
- [PULL 49/54] contrib/gitdm: add WANG Xuerui to individual contributers, Alex Bennée, 2022/10/04
- [PULL 40/54] docs/devel: document the test plugins, Alex Bennée, 2022/10/04
- [PULL 42/54] gdbstub: move into its own sub directory, Alex Bennée, 2022/10/04
- [PULL 15/54] vof: add distclean target, Alex Bennée, 2022/10/04
- [PULL 30/54] pc-bios/s390-ccw: Adopt meson style Make output, Alex Bennée, 2022/10/04
- [PULL 41/54] semihosting: update link to spec, Alex Bennée, 2022/10/04
- [PULL 18/54] configure: store container engine in config-host.mak, Alex Bennée, 2022/10/04
- [PULL 22/54] tests/tcg: unify ppc64 and ppc64le Makefiles, Alex Bennée, 2022/10/04
- [PULL 32/54] monitor: expose monitor_puts to rest of code, Alex Bennée, 2022/10/04
- [PULL 21/54] tests/tcg: add distclean rule, Alex Bennée, 2022/10/04