[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen staging] tcg/cpu-exec: precise single-stepping after an exception



commit a7ba744f4082abbd3e36a9265dd1682ad0980477
Author:     Luc Michel <luc.michel@xxxxxxxxxxxxx>
AuthorDate: Thu Jul 16 21:39:47 2020 +0200
Commit:     Richard Henderson <richard.henderson@xxxxxxxxxx>
CommitDate: Thu Jul 16 14:08:29 2020 -0700

    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 <luc.michel@xxxxxxxxxxxxx>
    Message-Id: <20200716193947.3058389-1-luc.michel@xxxxxxxxxxxxx>
    Signed-off-by: Richard Henderson <richard.henderson@xxxxxxxxxx>
---
 accel/tcg/cpu-exec.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index d95c4848a4..6a3d3a3cfc 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -504,6 +504,17 @@ static inline bool cpu_handle_exception(CPUState *cpu, int 
*ret)
             cc->do_interrupt(cpu);
             qemu_mutex_unlock_iothread();
             cpu->exception_index = -1;
+
+            if (unlikely(cpu->singlestep_enabled)) {
+                /*
+                 * After processing the exception, ensure an EXCP_DEBUG is
+                 * raised when single-stepping so that GDB doesn't miss the
+                 * next instruction.
+                 */
+                *ret = EXCP_DEBUG;
+                cpu_handle_debug_exception(cpu);
+                return true;
+            }
         } else if (!replay_has_interrupt()) {
             /* give a chance to iothread in replay mode */
             *ret = EXCP_INTERRUPT;
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.