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 <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/9211
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek
2025-11-03 17:33:12 +01:00
committed by Antonio Borneo
parent a247ff1223
commit cd41947feb

View File

@@ -54,6 +54,7 @@
#include <helper/bits.h>
#include <helper/nvp.h>
#include <helper/time_support.h>
#include <helper/align.h>
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)