Skip to contentSkip to conversation

tcg/cpu-exec: precise single-stepping after an interrupt

PATCH In review Richard Henderson 2 participants 2 messages Jul 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/cpu-exec: precise single-stepping after an interrupt

When single-stepping with a debugger attached to QEMU, and when an interrupt is raised, the debugger misses the first instruction after the interrupt.

---
 accel/tcg/cpu-exec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
accel/tcg/cpu-exec.c +7 -1
index 6a3d3a3cfc..66d38f9d85 100644
@@ -588,7 +588,13 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
         else {
             if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
                 replay_interrupt();
-                cpu->exception_index = -1;
+                /*
+                 * After processing the interrupt, ensure an EXCP_DEBUG is
+                 * raised when single-stepping so that GDB doesn't miss the
+                 * next instruction.
+                 */
+                cpu->exception_index =
+                    (cpu->singlestep_enabled ? EXCP_DEBUG : -1);
                 *last_tb = NULL;
             }
             /* The target hook may have updated the 'cpu->interrupt_request';
Signature · 1 line
2.25.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Richard Henderson

When single-stepping with a debugger attached to QEMU, and when an interrupt is raised, the debugger misses the first instruction after the interrupt.

Quoted 24 lines
---
  accel/tcg/cpu-exec.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
accel/tcg/cpu-exec.c +7 -1
index 6a3d3a3cfc..66d38f9d85 100644
@@ -588,7 +588,13 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
          else {
              if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
                  replay_interrupt();
-                cpu->exception_index = -1;
+                /*
+                 * After processing the interrupt, ensure an EXCP_DEBUG is
+                 * raised when single-stepping so that GDB doesn't miss the
+                 * next instruction.
+                 */
+                cpu->exception_index =
+                    (cpu->singlestep_enabled ? EXCP_DEBUG : -1);
                  *last_tb = NULL;
              }
              /* The target hook may have updated the 'cpu->interrupt_request';