HW data watchpoints

vvb333007
Posts: 79
Joined: Wed Jul 31, 2024 5:53 am
Location: Thailand
Contact:

HW data watchpoints

Postby vvb333007 » Thu Feb 06, 2025 11:33 am

Hello!

Xtensa ISA reference mention data breakpoint registers, and ESP-IDF even has the code (xt_utils, set_watchpoint).

But how can these be used?

I mean, after I write the data address/length in a corresponding DBREAKA, DBREAKC registers, what would happen on data access?

An interrupt? Which on? How to hook on it?

I went with the gdbstub code, but quickly get lost. Is there any documentation on xtensa arch component of esp-idf? I mean, examples, docs, with these xt_... functions.

Thanks!

PS: Oh I forgot to mention what it is all about. I would like to get a control, wwhen one of FreeRTOS tasks accesses memory region of interest. After taking control and performing some job, control must be returned to the task which triggered the watchpoint.
Thanks!
Slava.

Sprite
Espressif staff
Espressif staff
Posts: 10650
Joined: Thu Nov 26, 2015 4:08 am

Re: HW data watchpoints

Postby Sprite » Fri Feb 07, 2025 2:29 am

The breakpoints trigger a debug interrupt, which by default triggers the panic handler.

The most compatible way to insert code in here may be to wrap the panic handler to do your own thing. Example code is e.g. here. To wrap the panic handler, you need to put these lines into your projects CMakeLists.txt. Note that you need to have gdbstub disabled, otherwise that takes precedence.

vvb333007
Posts: 79
Joined: Wed Jul 31, 2024 5:53 am
Location: Thailand
Contact:

Re: HW data watchpoints

Postby vvb333007 » Sat May 09, 2026 11:18 am

The breakpoints trigger a debug interrupt, which by default triggers the panic handler.

The most compatible way to insert code in here may be to wrap the panic handler to do your own thing. Example code is e.g. here. To wrap the panic handler, you need to put these lines into your projects CMakeLists.txt. Note that you need to have gdbstub disabled, otherwise that takes precedence.
Oh.. Thanks for the reply.

Finally I had achieved what I wanted, by intercepting debug interrupt vector.

I am trying to make a memory logger. It uses HW watchpoint #0 to catch memory access and then, in the interrupt handler I reset watchpoint and setup a HW breakpoint on the next instruction and then return from an interrupt (thus retrying instruction again). When breakpoint hits, I just rearm my watchpoint and disable a breakpoint.


I tried your approach (wrapping around panic() call) didn't not work, because _xt_debugexception calls panic handler via callx0, and this call does not return.

In the same handler function the gdb stub is called via "j" instruction. So I decided to replace (thanks god it is weak declaration) whole xt_debugexception with my own handler - made up from gdbstub panic handler and _xt_debugexception handler.

And it worked. Memory logger catches access to certain MMIOs of interest and logs access attempts and then let the instruction (load or store) to proceed.


May be someone can find it useful.
Thanks!
Slava.

Who is online

Users browsing this forum: No registered users and 1 guest