From a247ff122380a6a6e14878b462785fc209f875b0 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Mon, 3 Nov 2025 11:07:31 +0100 Subject: [PATCH] target, breakpoints: report hit watchpoint in trivial case Some targets have no means to find out which watchpoint triggered the debug halt. Resolve properly the trivial and most used case when only one watchpoint is set. Change-Id: I683933ec43e6ca0fed84a08a2aa222ed8a6e277f Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/9210 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/target/breakpoints.c | 14 ++++++++++++++ src/target/target.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index d65e5594f..fa6b635f0 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -629,6 +629,20 @@ int watchpoint_hit(struct target *target, enum watchpoint_rw *rw, struct watchpoint *hit_watchpoint; retval = target_hit_watchpoint(target, &hit_watchpoint); + if (retval == ERROR_NOT_IMPLEMENTED + && target->debug_reason == DBG_REASON_WATCHPOINT) { + // Handle the trivial case: only one watchpoint is set + unsigned int cnt = 0; + struct watchpoint *wp = target->watchpoints; + while (wp) { + cnt++; + wp = wp->next; + } + if (cnt == 1) { + retval = ERROR_OK; + hit_watchpoint = target->watchpoints; + } + } if (retval != ERROR_OK) return ERROR_FAIL; diff --git a/src/target/target.c b/src/target/target.c index 3d807ba35..ababa57fb 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1360,9 +1360,9 @@ int target_hit_watchpoint(struct target *target, if (!target->type->hit_watchpoint) { /* For backward compatible, if hit_watchpoint is not implemented, - * return ERROR_FAIL such that gdb_server will not take the nonsense + * return error such that gdb_server will not take the nonsense * information. */ - return ERROR_FAIL; + return ERROR_NOT_IMPLEMENTED; } return target->type->hit_watchpoint(target, hit_watchpoint);