disas: generalise plugin_printf and use for monitor_disas
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>
This commit is contained in:
parent
bf0c50d4aa
commit
4332099f0e
23
disas.c
23
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. */
|
/* We abuse the FILE parameter to pass a GString. */
|
||||||
GString *s = (GString *)stream;
|
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);
|
GString *ds = g_string_new(NULL);
|
||||||
|
|
||||||
initialize_debug_target(&s, cpu);
|
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.stream = (FILE *)ds; /* abuse this slot */
|
||||||
s.info.buffer_vma = addr;
|
s.info.buffer_vma = addr;
|
||||||
s.info.buffer_length = size;
|
s.info.buffer_length = size;
|
||||||
@ -358,15 +358,19 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
|
|||||||
{
|
{
|
||||||
int count, i;
|
int count, i;
|
||||||
CPUDebug s;
|
CPUDebug s;
|
||||||
|
g_autoptr(GString) ds = g_string_new("");
|
||||||
|
|
||||||
initialize_debug_target(&s, cpu);
|
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) {
|
if (is_physical) {
|
||||||
s.info.read_memory_func = physical_read_memory;
|
s.info.read_memory_func = physical_read_memory;
|
||||||
}
|
}
|
||||||
s.info.buffer_vma = pc;
|
s.info.buffer_vma = pc;
|
||||||
|
|
||||||
if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
|
if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
|
||||||
|
monitor_puts(mon, ds->str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,13 +380,16 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < nb_insn; i++) {
|
for (i = 0; i < nb_insn; i++) {
|
||||||
monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);
|
g_string_append_printf(ds, "0x" TARGET_FMT_lx ": ", pc);
|
||||||
count = s.info.print_insn(pc, &s.info);
|
count = s.info.print_insn(pc, &s.info);
|
||||||
monitor_printf(mon, "\n");
|
g_string_append_c(ds, '\n');
|
||||||
if (count < 0)
|
if (count < 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
pc += count;
|
pc += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor_puts(mon, ds->str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user