Skip to content

Commit a7ba744

Browse files
Luc Michelrth7680
authored andcommitted
tcg/cpu-exec: precise single-stepping after an exception
When single-stepping with a debugger attached to QEMU, and when an exception is raised, the debugger misses the first instruction after the exception: $ qemu-system-aarch64 -M virt -display none -cpu cortex-a53 -s -S $ aarch64-linux-gnu-gdb GNU gdb (GDB) 9.2 [...] (gdb) tar rem :1234 Remote debugging using :1234 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x0000000000000000 in ?? () (gdb) # writing nop insns to 0x200 and 0x204 (gdb) set *0x200 = 0xd503201f (gdb) set *0x204 = 0xd503201f (gdb) # 0x0 address contains 0 which is an invalid opcode. (gdb) # The CPU should raise an exception and jump to 0x200 (gdb) si 0x0000000000000204 in ?? () With this commit, the same run steps correctly on the first instruction of the exception vector: (gdb) si 0x0000000000000200 in ?? () Buglink: https://bugs.launchpad.net/qemu/+bug/757702 Signed-off-by: Luc Michel <[email protected]> Message-Id: <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 69c918d commit a7ba744

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

accel/tcg/cpu-exec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,17 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
504504
cc->do_interrupt(cpu);
505505
qemu_mutex_unlock_iothread();
506506
cpu->exception_index = -1;
507+
508+
if (unlikely(cpu->singlestep_enabled)) {
509+
/*
510+
* After processing the exception, ensure an EXCP_DEBUG is
511+
* raised when single-stepping so that GDB doesn't miss the
512+
* next instruction.
513+
*/
514+
*ret = EXCP_DEBUG;
515+
cpu_handle_debug_exception(cpu);
516+
return true;
517+
}
507518
} else if (!replay_has_interrupt()) {
508519
/* give a chance to iothread in replay mode */
509520
*ret = EXCP_INTERRUPT;

0 commit comments

Comments
 (0)