From cd41947febbeb908e2c0dbf6c3c0e74d799da6c0 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Mon, 3 Nov 2025 17:33:12 +0100 Subject: [PATCH] target/cortex_a: fix HW breakpoint length for gdb kind 3 Gdb uses length 3 to set breakpoint on a 4 byte Thumb-2 instruction. Without this patch a breakpoint on down aligned word address was set. If the requested address was not word aligned, the breakpoint triggered at previous instruction and was not recognised properly by gdb. Set breakpoint on whole word if aligns with requested address, otherwise use length 2 and set byte mask. Change-Id: I12d1c57b7154e64abdf23dd7cd31714f9d8ec6f0 Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/9211 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/cortex_a.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 016ea175c..a9c034b55 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -54,6 +54,7 @@ #include #include #include +#include static int cortex_a_poll(struct target *target); static int cortex_a_debug_entry(struct target *target); @@ -1341,6 +1342,14 @@ static int cortex_a_set_breakpoint(struct target *target, return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } breakpoint_hw_set(breakpoint, brp_i); + if (breakpoint->length == 3) { + /* Thumb-2 breakpoint: fixup to length 4 if word aligned, + * set byte mask for length 2 if unaligned */ + if (IS_ALIGNED(breakpoint->address, 4)) + breakpoint->length = 4; + else + breakpoint->length = 2; + } if (breakpoint->length == 2) byte_addr_select = (3 << (breakpoint->address & 0x02)); control = ((matchmode & 0x7) << 20)