forked from auracaster/openocd
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 <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/9182 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
+13
-2
@@ -1900,7 +1900,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);
|
||||
@@ -1909,6 +1908,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) {
|
||||
@@ -1997,7 +2002,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");
|
||||
@@ -2017,6 +2021,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,
|
||||
|
||||
Reference in New Issue
Block a user