From ffaef5809c68d81359de5573d3971a4b6bb521c3 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 29 Apr 2021 09:22:00 +0200 Subject: [PATCH] target/cortex_a: fix number of watchpoints Decrement the available watchpoints only when succeed setting it. Initialize the available watchpoint with the correct value. Change-Id: I0f93b347300b8ebedbcd9e718d4ba32b26cf6846 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6196 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/cortex_a.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 9e8248a74..78daed398 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -1802,8 +1802,12 @@ static int cortex_a_add_watchpoint(struct target *target, struct watchpoint *wat return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } + int retval = cortex_a_set_watchpoint(target, watchpoint); + if (retval != ERROR_OK) + return retval; + cortex_a->wrp_num_available--; - return cortex_a_set_watchpoint(target, watchpoint); + return ERROR_OK; } /** @@ -3007,7 +3011,7 @@ static int cortex_a_examine_first(struct target *target) /* Setup Watchpoint Register Pairs */ cortex_a->wrp_num = ((didr >> 28) & 0x0F) + 1; - cortex_a->wrp_num_available = cortex_a->brp_num; + cortex_a->wrp_num_available = cortex_a->wrp_num; free(cortex_a->wrp_list); cortex_a->wrp_list = calloc(cortex_a->wrp_num, sizeof(struct cortex_a_wrp)); for (i = 0; i < cortex_a->wrp_num; i++) {