This is an automated email from Gerrit. "Alexandra Kulyatskaya <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9146
-- gerrit commit ed9a5df85dab8b9ee59f659484983a50bf5a4397 Author: Kulyatskaya Alexandra <[email protected]> Date: Tue Jun 24 15:37:48 2025 +0300 target/breakpoints.c: add breakpoint intersection detection Modify the breakpoint insertion logic to include intersection detection between breakpoints. Change-Id: I294bea83b18335c2f304ddd99361872eadaaa684 Signed-off-by: Kulyatskaya Alexandra <[email protected]> diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index 54a6145caa..784d46b40f 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -36,6 +36,29 @@ static const char * const watchpoint_rw_strings[] = { /* monotonic counter/id-number for breakpoints and watch points */ static int bpwp_unique_id; +static bool is_memory_regions_intersect(target_addr_t start1, + unsigned int size1, + target_addr_t start2, + unsigned int size2) +{ + /* Two memory regions: [S1,E1] and [S2,E2] where: + * E1 = S1 + size1 - 1, E2 = S2 + size2 - 1 + * + * After normalization: + * Region 1: [0, size1 - 1] + * Region 2: [start2 - start1, (start2 - start1) + size2 - 1] + * + * Intersection cases: + * 1. Normalized region 2 wraps around 0 (unsigned overflow) + * 2. Start of normalized region 2 is within region 1 + */ + start2 -= start1; + target_addr_t end1 = size1 - 1; + target_addr_t end2 = start2 + size2 - 1; + + return start2 > end2 || start2 <= end1; +} + static int breakpoint_add_internal(struct target *target, target_addr_t address, unsigned int length, @@ -56,6 +79,13 @@ static int breakpoint_add_internal(struct target *target, address, breakpoint->unique_id); return ERROR_TARGET_DUPLICATE_BREAKPOINT; } + if (is_memory_regions_intersect(address, length, breakpoint->address, + breakpoint->length)) { + LOG_TARGET_ERROR(target, "Breakpoint intersects with another one at " TARGET_ADDR_FMT + " of length %u (BP %" PRIu32 ")", breakpoint->address, + breakpoint->length, breakpoint->unique_id); + return ERROR_TARGET_INTERSECT_BREAKPOINT; + } breakpoint_p = &breakpoint->next; breakpoint = breakpoint->next; } diff --git a/src/target/target.h b/src/target/target.h index b850b49cf3..84f9f88532 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -796,6 +796,7 @@ int target_profiling_default(struct target *target, uint32_t *samples, uint32_t #define ERROR_TARGET_SIZE_NOT_SUPPORTED (-314) #define ERROR_TARGET_PACKING_NOT_SUPPORTED (-315) #define ERROR_TARGET_HALTED_DO_RESUME (-316) /* used to workaround incorrect debug halt */ +#define ERROR_TARGET_INTERSECT_BREAKPOINT (-317) extern bool get_target_reset_nag(void); --
