[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 33/51] disas: generalise plugin_printf and use for monitor_dis
From: |
Alex Bennée |
Subject: |
[PATCH v1 33/51] disas: generalise plugin_printf and use for monitor_disas |
Date: |
Thu, 29 Sep 2022 12:42:13 +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: <20220921160801.1490125-3-alex.bennee@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
- [PATCH v1 17/51] configure: return status code from probe_target_compiler, (continued)
- [PATCH v1 17/51] configure: return status code from probe_target_compiler, Alex Bennée, 2022/09/29
- [PATCH v1 21/51] tests/tcg: add distclean rule, Alex Bennée, 2022/09/29
- [PATCH v1 49/51] contrib/gitdm: add WANG Xuerui to individual contributers, Alex Bennée, 2022/09/29
- [PATCH v1 23/51] tests/tcg: clean up calls to run-test, Alex Bennée, 2022/09/29
- [PATCH v1 47/51] contrib/gitdm: add mapping for Loongson Technology, Alex Bennée, 2022/09/29
- [PATCH v1 18/51] configure: store container engine in config-host.mak, Alex Bennée, 2022/09/29
- [PATCH v1 20/51] tests/tcg: remove -f from Makefile invocation, Alex Bennée, 2022/09/29
- [PATCH v1 48/51] contrib/gitdm: add Paul to individual contributors, Alex Bennée, 2022/09/29
- [PATCH v1 50/51] contrib/gitdm: add ISCAS to the academics group, Alex Bennée, 2022/09/29
- [PATCH v1 44/51] gdbstub: move breakpoint logic to accel ops, Alex Bennée, 2022/09/29
- [PATCH v1 33/51] disas: generalise plugin_printf and use for monitor_disas,
Alex Bennée <=
- [PATCH v1 42/51] gdbstub: move into its own sub directory, Alex Bennée, 2022/09/29
- [PATCH v1 39/51] contrib/plugins: reset skip when matching in execlog, Alex Bennée, 2022/09/29
- [PATCH v1 35/51] plugins: extend execlog to filter matches, Alex Bennée, 2022/09/29
- [PATCH v1 26/51] configure: unify creation of cross-compilation Makefiles, Alex Bennée, 2022/09/29
- [PATCH v1 22/51] tests/tcg: unify ppc64 and ppc64le Makefiles, Alex Bennée, 2022/09/29
- [PATCH v1 32/51] monitor: expose monitor_puts to rest of code, Alex Bennée, 2022/09/29
- [PATCH v1 41/51] semihosting: update link to spec, Alex Bennée, 2022/09/29
- [PATCH v1 30/51] pc-bios/s390-ccw: Adopt meson style Make output, Alex Bennée, 2022/09/29
- [PATCH v1 51/51] contrib/gitdm: add China Telecom to the domain map, Alex Bennée, 2022/09/29
- [PATCH v1 40/51] docs/devel: document the test plugins, Alex Bennée, 2022/09/29