This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 5fff29778e3fb6d652f4665807b6d4d7a8487681 Author: zhangyu117 <[email protected]> AuthorDate: Sat Oct 25 00:30:05 2025 +0800 system/debugpoint: prevent optimizations to ensure debugpoints are triggered test_function() and test_data() run the access that should hit the breakpoint or the watchpoint and then check the triggered flag, which the debug exception handler sets. Nothing stops the compiler from moving the check ahead of a plain memory access. Put UP_DSB(), a memory barrier that is also a compiler barrier, around each access that should fire. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: zhangyu117 <[email protected]> --- system/debugpoint/debug.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/system/debugpoint/debug.c b/system/debugpoint/debug.c index da4178fbb..e29fff1a5 100644 --- a/system/debugpoint/debug.c +++ b/system/debugpoint/debug.c @@ -100,6 +100,7 @@ nooptimiziation_function static void test_function(void (*func)(void)) { int ret = 0; bool triggered; + printf("==== Calling test_function ====\n"); printf("Add breakpoint at %p\n", func); @@ -115,6 +116,9 @@ nooptimiziation_function static void test_function(void (*func)(void)) /* Trigger the breakpoint */ triggered = false; + + UP_DSB(); + func(); if (triggered) @@ -177,6 +181,9 @@ nooptimiziation_function static void test_data(uint8_t *addr, /* Trigger the watchpoint by reading the address */ triggered = false; + + UP_DSB(); + if (addr[0] == 0x55) { /* Do something to avoid compiler removing the read */ @@ -188,6 +195,8 @@ nooptimiziation_function static void test_data(uint8_t *addr, tmp = 0x55; } + UP_DSB(); + if (triggered) { printf("Pass: Read watchpoint at %p triggered\n", addr); @@ -212,8 +221,13 @@ nooptimiziation_function static void test_data(uint8_t *addr, /* Trigger the watchpoint by writing to the address */ triggered = false; + + UP_DSB(); + addr[0] = tmp; + UP_DSB(); + if (triggered) { printf("Pass: Write watchpoint at %p triggered\n", addr); @@ -229,6 +243,9 @@ nooptimiziation_function static void test_data(uint8_t *addr, /* Trigger the watchpoint by reading the address */ triggered = false; + + UP_DSB(); + if (addr[0] == 0x55) { /* Do something to avoid compiler removing the read */ @@ -236,6 +253,8 @@ nooptimiziation_function static void test_data(uint8_t *addr, printf("Reading %p\n", addr); } + UP_DSB(); + if (triggered) { printf("Pass: Read watchpoint at %p triggered\n", addr); @@ -251,8 +270,13 @@ nooptimiziation_function static void test_data(uint8_t *addr, /** Trigger the watchpoint by writing to the address */ triggered = false; + + UP_DSB(); + addr[0] = 0x55; + UP_DSB(); + if (triggered) { printf("Pass: Write watchpoint at %p triggered\n", addr);
