cortex_m: implement hit_watchpoint function 81/6181/3
authorTarek BOCHKATI <tarek.bouchkati@gmail.com>
Thu, 22 Apr 2021 19:47:23 +0000 (20:47 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Sun, 2 May 2021 21:42:29 +0000 (22:42 +0100)
this change aims to provide a better gdb debugging experience,
by making gdb understand what's really happening.

before this change when hitting a watchpoint
 - openocd reports "T05" to gdb
 - gdb displays: Program received signal SIGTRAP, Trace/breakpoint trap.

after the change
 - openocd reports "T05watch:20000000;" to gdb
 - gdb displays:
   Hardware watchpoint 1: *0x20000000

   Old value = 16000000
   New value = 170000000
   ...

Change-Id: Iac3a85eadd86663617889001dd04513a4211ced9
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/6181
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/target/cortex_m.c

index 46b0e3c2a717a60bbb54fa3c4799df34f487cfd0..2b38b4a7fda9177d67236a8d18791611a4f8028d 100644 (file)
@@ -1596,6 +1596,35 @@ int cortex_m_remove_watchpoint(struct target *target, struct watchpoint *watchpo
        return ERROR_OK;
 }
 
+int cortex_m_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
+{
+       if (target->debug_reason != DBG_REASON_WATCHPOINT)
+               return ERROR_FAIL;
+
+       struct cortex_m_common *cortex_m = target_to_cm(target);
+
+       for (struct watchpoint *wp = target->watchpoints; wp; wp = wp->next) {
+               if (!wp->set)
+                       continue;
+
+               unsigned int dwt_num = wp->set - 1;
+               struct cortex_m_dwt_comparator *comparator = cortex_m->dwt_comparator_list + dwt_num;
+
+               uint32_t dwt_function;
+               int retval = target_read_u32(target, comparator->dwt_comparator_address + 8, &dwt_function);
+               if (retval != ERROR_OK)
+                       return ERROR_FAIL;
+
+               /* check the MATCHED bit */
+               if (dwt_function & BIT(24)) {
+                       *hit_watchpoint = wp;
+                       return ERROR_OK;
+               }
+       }
+
+       return ERROR_FAIL;
+}
+
 void cortex_m_enable_watchpoints(struct target *target)
 {
        struct watchpoint *watchpoint = target->watchpoints;
@@ -2523,6 +2552,7 @@ struct target_type cortexm_target = {
        .remove_breakpoint = cortex_m_remove_breakpoint,
        .add_watchpoint = cortex_m_add_watchpoint,
        .remove_watchpoint = cortex_m_remove_watchpoint,
+       .hit_watchpoint = cortex_m_hit_watchpoint,
 
        .commands = cortex_m_command_handlers,
        .target_create = cortex_m_target_create,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)