This is an automated email from Gerrit. "Tomas Vanek <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9182
-- gerrit commit cbb5e05d9166ceaf8f327103f53afed00dbc9d10 Author: Tomas Vanek <[email protected]> Date: Thu Oct 23 16:09:57 2025 +0200 target/cortex_m: fix segfault on setting HW BP on not examined target Check cortex_m->fp_comparator_list and if NULL log and return error. Change-Id: Icf53f1bbc60de3486a285ef1f16bb98a5596913b Signed-off-by: Tomas Vanek <[email protected]> diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index e2fd8af6e0..b08d502133 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1892,7 +1892,6 @@ int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint int retval; unsigned int fp_num = 0; struct cortex_m_common *cortex_m = target_to_cm(target); - struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list; if (breakpoint->is_set) { LOG_TARGET_WARNING(target, "breakpoint (BPID: %" PRIu32 ") already set", breakpoint->unique_id); @@ -1901,6 +1900,12 @@ int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint if (breakpoint->type == BKPT_HARD) { uint32_t fpcr_value; + struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list; + if (!comparator_list) { + LOG_TARGET_ERROR(target, "No comparator list. Not examined?"); + return ERROR_FAIL; + } + while (comparator_list[fp_num].used && (fp_num < cortex_m->fp_num_code)) fp_num++; if (fp_num >= cortex_m->fp_num_code) { @@ -1989,7 +1994,6 @@ int cortex_m_unset_breakpoint(struct target *target, struct breakpoint *breakpoi { int retval; struct cortex_m_common *cortex_m = target_to_cm(target); - struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list; if (!breakpoint->is_set) { LOG_TARGET_WARNING(target, "breakpoint not set"); @@ -2009,6 +2013,13 @@ int cortex_m_unset_breakpoint(struct target *target, struct breakpoint *breakpoi LOG_TARGET_DEBUG(target, "Invalid FP Comparator number in breakpoint"); return ERROR_OK; } + + struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list; + if (!comparator_list) { + LOG_TARGET_ERROR(target, "No comparator list. Not examined?"); + return ERROR_FAIL; + } + comparator_list[fp_num].used = false; comparator_list[fp_num].fpcr_value = 0; target_write_u32(target, comparator_list[fp_num].fpcr_address, --
