Add log_raise_exception(), a common helper cpu_loop_*() can call to log a raised exception when '-d int' is used, and qemu_excp_name() to resolve QEMU-internal exceptions to names.
Use it in cpu_loop_exit_atomic() to log the EXCP_ATOMIC reason. Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Pierrick Bouvier <[email protected]> --- accel/tcg/cpu-exec-common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index 68077c8fd9d..bd2cb9d6311 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "exec/log.h" #include "system/tcg.h" #include "qemu/plugin.h" @@ -89,6 +90,34 @@ void tcg_update_all_cflags(void) } } +#define EXCP_QEMU_INTERNAL 0x10000 + +static const char *qemu_excp_name(int excp) +{ + static const char *excp_name[] = { + [EXCP_INTERRUPT - EXCP_QEMU_INTERNAL] = "async interruption", + [EXCP_HLT - EXCP_QEMU_INTERNAL] = "hlt instruction", + [EXCP_DEBUG - EXCP_QEMU_INTERNAL] = "debug", + [EXCP_HALTED - EXCP_QEMU_INTERNAL] = "halted", + [EXCP_YIELD - EXCP_QEMU_INTERNAL] = "yield", + [EXCP_ATOMIC - EXCP_QEMU_INTERNAL] = "emulate atomic", + }; + assert(excp >= EXCP_QEMU_INTERNAL); + excp -= EXCP_QEMU_INTERNAL; + return STR_ARRAY_ELEM_OR_NULL(excp_name, excp) ?: "unknown"; +} + +static void log_raise_exception(const CPUState *cpu, int excp) +{ + if (!qemu_loglevel_mask(CPU_LOG_INT)) { + return; + } + if (excp >= EXCP_QEMU_INTERNAL) { + qemu_log_mask(CPU_LOG_INT, "raise exception: 0x%x (internal: %s)\n", + excp, qemu_excp_name(excp)); + } +} + /* exit the current TB, but without causing any exception to be raised */ void cpu_loop_exit_noexc(CPUState *cpu) { @@ -118,5 +147,6 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) /* Prevent looping if already executing in a serial context. */ g_assert(!cpu_in_serial_context(cpu)); cpu->exception_index = EXCP_ATOMIC; + log_raise_exception(cpu, EXCP_ATOMIC); cpu_loop_exit_restore(cpu, pc); } -- 2.55.0
