Skip to contentSkip to conversation

target-arm: Fix non-CPU breakpoint handling in arm_debug_excp_handler()

PATCH In review Sergey Fedorov 2 participants 3 messages Nov 5, 2015 – Nov 6, 2015

v2 of 3 In review Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target-arm: Fix non-CPU breakpoint handling in arm_debug_excp_handler()

Do not raise a CPU exception if no CPU breakpoint has fired, since singlestep is also done by generating a debug internal exception. This fixes a bug with singlestepping in gdbstub.

---
This is a v2 of 'target-arm: Fix arm_debug_excp_handler() for singlestep enabled.'

Changes in v2:
* Commit subject and body changed
* Instead of checking for singlestep enabled, CPU breakpoint match checked

 target-arm/op_helper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
target-arm/op_helper.c +7 -1
index b5db345..6cd54c8 100644
@@ -917,7 +917,13 @@ void arm_debug_excp_handler(CPUState *cs)
         uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
         bool same_el = (arm_debug_target_el(env) == arm_current_el(env));
 
-        if (cpu_breakpoint_test(cs, pc, BP_GDB)) {
+        /* (1) GDB breakpoints should be handled first.
+         * (2) Do not raise a CPU exception if no CPU breakpoint has fired,
+         * since singlestep is also done by generating a debug internal
+         * exception.
+         */
+        if (cpu_breakpoint_test(cs, pc, BP_GDB)
+            || !cpu_breakpoint_test(cs, pc, BP_CPU)) {
             return;
         }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 4 lines · Sergey Fedorov

Do not raise a CPU exception if no CPU breakpoint has fired, since singlestep is also done by generating a debug internal exception. This fixes a bug with singlestepping in gdbstub.

Quoted 8 lines

---
This is a v2 of 'target-arm: Fix arm_debug_excp_handler() for singlestep enabled.'

Changes in v2:
* Commit subject and body changed
* Instead of checking for singlestep enabled, CPU breakpoint match checked

Isn't this fixing singlestep, not non-CPU breakpoints? (GDB breakpoints were already being checked for and early-returned.)

I'll tweak the commit subject line and apply to target-arm.next.

Incidentally, this only affects gdbstub singlestep for aarch64 in practice, because gdb for 32-bit ARM uses set-breakpoint-and-continue rather than the singlestep gdbstub protocol command.

Quoted 23 lines
 target-arm/op_helper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
target-arm/op_helper.c +7 -2
index b5db345..6cd54c8 100644
@@ -917,7 +917,13 @@ void arm_debug_excp_handler(CPUState *cs)
         uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
         bool same_el = (arm_debug_target_el(env) == arm_current_el(env));
 
-        if (cpu_breakpoint_test(cs, pc, BP_GDB)) {
+        /* (1) GDB breakpoints should be handled first.
+         * (2) Do not raise a CPU exception if no CPU breakpoint has fired,
+         * since singlestep is also done by generating a debug internal
+         * exception.
+         */
+        if (cpu_breakpoint_test(cs, pc, BP_GDB)
+            || !cpu_breakpoint_test(cs, pc, BP_CPU)) {
             return;
         }
 
--
Quoted 2 lines

1.9.1

thanks
-- PMM

#2 lore raw
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Sergey Fedorov

Do not raise a CPU exception if no CPU breakpoint has fired, since singlestep is also done by generating a debug internal exception. This fixes a bug with singlestepping in gdbstub.

---
This is a v2 of 'target-arm: Fix arm_debug_excp_handler() for singlestep enabled.'

Quoted 5 lines
Quoted 3 lines

Changes in v2:
* Commit subject and body changed
* Instead of checking for singlestep enabled, CPU breakpoint match checked

Isn't this fixing singlestep, not non-CPU breakpoints? (GDB breakpoints were already being checked for and early-returned.)

Sorry for the confusing commit subject, actually, I meant "fix handling of EXCP_DEBUG in case of no CPU breakpoint fired" :)

Quoted 29 lines

I'll tweak the commit subject line and apply to target-arm.next.

Incidentally, this only affects gdbstub singlestep for aarch64 in practice, because gdb for 32-bit ARM uses set-breakpoint-and-continue rather than the singlestep gdbstub protocol command.

Quoted 22 lines
 target-arm/op_helper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
target-arm/op_helper.c +7 -1
index b5db345..6cd54c8 100644
@@ -917,7 +917,13 @@ void arm_debug_excp_handler(CPUState *cs)
         uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
         bool same_el = (arm_debug_target_el(env) == arm_current_el(env));
 
-        if (cpu_breakpoint_test(cs, pc, BP_GDB)) {
+        /* (1) GDB breakpoints should be handled first.
+         * (2) Do not raise a CPU exception if no CPU breakpoint has fired,
+         * since singlestep is also done by generating a debug internal
+         * exception.
+         */
+        if (cpu_breakpoint_test(cs, pc, BP_GDB)
+            || !cpu_breakpoint_test(cs, pc, BP_CPU)) {
             return;
         }
 
Quoted 4 lines
Quoted 3 lines

--
1.9.1

Thanks,
Sergey