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/+/9240
-- gerrit commit 6efda869614d51c91c19ed273b07cac83b44a73c Author: Kulyatskaya Alexandra <[email protected]> Date: Mon Nov 17 15:55:17 2025 +0300 target.c: add warn about overwriting a breakpoint Call function 'is_breakpoint_in_range()' in handler_load_image_command for detecting breakpoint memory overwriting. Change-Id: I8fb6c9811dc7322d78ec9cbba0e4641d619b7e03 Signed-off-by: Kulyatskaya Alexandra <[email protected]> diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index 7254eac7dc..f319c10a9e 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -16,6 +16,7 @@ #include <helper/log.h> #include "breakpoints.h" #include "smp.h" +#include "helper/util.h" enum breakpoint_watchpoint { BREAKPOINT, @@ -36,6 +37,18 @@ static const char * const watchpoint_rw_strings[] = { /* monotonic counter/id-number for breakpoints and watch points */ static int bpwp_unique_id; +struct breakpoint *find_breakpoint_in_range(struct target *target, + struct breakpoint *breakpoint, target_addr_t start, uint32_t length) +{ + breakpoint = breakpoint ? breakpoint->next : target->breakpoints; + for(; breakpoint; breakpoint = breakpoint->next) { + if (is_memory_regions_overlap(start, length, breakpoint->address, + breakpoint->length)) + return breakpoint; + } + return breakpoint; +} + static int breakpoint_add_internal(struct target *target, target_addr_t address, unsigned int length, diff --git a/src/target/breakpoints.h b/src/target/breakpoints.h index d547a687fd..80be495da2 100644 --- a/src/target/breakpoints.h +++ b/src/target/breakpoints.h @@ -68,6 +68,9 @@ static inline void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int breakpoint->number = hw_number; } +struct breakpoint *find_breakpoint_in_range(struct target *target, + struct breakpoint *breakpoint, target_addr_t start, uint32_t length); + int watchpoint_add(struct target *target, target_addr_t address, unsigned int length, enum watchpoint_rw rw, uint64_t value, uint64_t mask); diff --git a/src/target/target.c b/src/target/target.c index bdf0ff244d..a8d15e68c0 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3646,6 +3646,16 @@ COMMAND_HANDLER(handle_load_image_command) break; } + for (struct breakpoint *breakpoint = find_breakpoint_in_range(target, + NULL, image.sections[i].base_address, image.sections[i].size); + breakpoint; + breakpoint = find_breakpoint_in_range(target, breakpoint, + image.sections[i].base_address, + image.sections[i].size)) { + LOG_WARNING("overwriting a breakpoint at the address: " + TARGET_ADDR_FMT, breakpoint->address); + } + retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt); if (retval != ERROR_OK) { free(buffer); --
