From f8c43c69b23f53973f30962f04cdebdfcf67a7e7 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sat, 17 Feb 2018 17:29:57 -0500 Subject: [PATCH] target-arm: Fix gdb singlestep 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. Backports commit 5c629f4ff4dc9ae79cc732f59a8df15ede796ff7 from qemu --- qemu/target-arm/op_helper.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/qemu/target-arm/op_helper.c b/qemu/target-arm/op_helper.c index 839833bb..389a96bd 100644 --- a/qemu/target-arm/op_helper.c +++ b/qemu/target-arm/op_helper.c @@ -911,14 +911,18 @@ void arm_debug_excp_handler(CPUState *cs) } } } else { - // Unicorn: commented out - //uint64_t pc = is_a64(env) ? env->pc : env->regs[15]; + uint64_t pc = is_a64(env) ? env->pc : env->regs[15]; bool same_el = (arm_debug_target_el(env) == arm_current_el(env)); - // Unicorn: commented out - //if (cpu_breakpoint_test(cs, pc, BP_GDB)) { - // return; - //} + /* (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; + } if (extended_addresses_enabled(env)) { env->exception.fsr = (1 << 9) | 0x22;