Cannot insert hardware breakpoint 1. when setting breakpoint in template class

Hi pio-team,

I created a (hopefully) highly efficient driver (using DMA) for the well known ST7789-240-240 display modules and a small test/debug application around it.

As long as I set breakpoints in my main.cpp file, debugging works as expected. But when I set a a single breakpoint in my (templated) driver class I get

Cannot insert hardware breakpoint 1.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

I did:

I searched for lines with “cortex_m_set_breakpoint()” in the openocd.logfle (copied relevant lines only):

Debug: 3971 44621 breakpoints.c:101 breakpoint_add_internal(): added hardware breakpoint at 0x08003236 of length 0x00000002, (BPID: 0)
Debug: 3978 44636 breakpoints.c:101 breakpoint_add_internal(): added hardware breakpoint at 0x08003554 of length 0x00000002, (BPID: 1)
Debug: 3985 44651 breakpoints.c:101 breakpoint_add_internal(): added hardware breakpoint at 0x08003b60 of length 0x00000002, (BPID: 2)
Debug: 3992 44667 breakpoints.c:101 breakpoint_add_internal(): added hardware breakpoint at 0x08003ec6 of length 0x00000002, (BPID: 3)
Error: 3996 44680 breakpoints.c:94 breakpoint_add_internal(): can't add breakpoint: resource not available

I investigated further and checked which code is at these addresses using PIO–>Inspect–>Symbols

  • 0x08003236: somewhere in the fillRect method
  • 0x08003554: somewhere in the printString method
  • 0x08003b60: somewhere in the drawItem method <–imho the only correct breakpoint
  • 0x08003ec6: sowewhere in the program’s main method

Why is openocd requested to set four breakpoints if I set only one? What can I do?

Thank you so much!

Regards,
Klaus

Per Espressif-documented quirks you only have a few breakpoints (2 or 4). Can you remove all other breakpoints before attempting to place one in that method? If the template is screwing with it, maybe you can spealize the template function for the class or types you’re interested in so that it’s only being used by one class where you can breakpoint in?

Thank you, maxgerhardt, for your post!

  • As declared with the “ststm32” tag, I am not working with espressiv32, but with ststm32 (v 12.0.0; did pio update yesterday). The cpu is STM32F072RB.
  • As written in my post, I’ve set ONE SINGLE breakpoint. I even removed the default breakpoint at main() with the "debug_init_break = ". According to the reference manual, the CPU should provide four hardware breakpoints.
  • I use template parameters to define buffer lengths and GPIOs. I use them as a modern and type safe replacement for lines like “#define PIN_RST… #define BUFLEN…”. Imho, specialization is not a proper way to go here. Btw, I use only one single instance of the template and one single instance of the class in my code.

Regards,

Klaus

My bad, seeing “Connot insert hardware breakpoint” my mind was immediately on Espressif32 as that’s where it’s mainly occuring.

Try and start debugging again with the normal initial breakpoint. In the “Debug Console” you should be able to type in GDB commands. Per debug c++ template with gdb - Stack Overflow there are break and rbreak commands available. I’m not sure about the syntax, but you can try

rbreak SPILCD16<.*>::drawItem
break SPILCD16::drawItem

to try and break in the function you want.

Maybe one of these work or gives more sensible output on why 4 breakpoints are attempted.

No problem :slight_smile:

First debugging session:

break SPILCD16::drawItem

–>success; works as expected (hmm)

Next debugging session
I tried to set the breakpoint to the same location by clicking with the on it in the IDE
—>success; works as expected!

Next debugging session:

break spilcd16.hpp:330

Breakpoint 2 at 0x800338a: spilcd16.hpp:330. (6 locations)
{"token":21,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
Warning:
Cannot insert hardware breakpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

The line with “6 locations” seems strange to me…

Regards, Klaus

Most interestingly there are 6 files where spilcd16.hpp is referenced (or it is the file itself), see here.

I’m not 100% what the VSCode debugger is trying to do here, of if this is really PlatformIO specific. Please file a bug at Issues · platformio/platformio-vscode-ide · GitHub to let the devs know, along with the full firmware (sensact/firmware/sensactHsIO3 at master · klaus-liebler/sensact · GitHub).

Thank you, maxgerhardt, for your great support! I filed a bug here https://github.com/platformio/platformio-vscode-ide/issues/2421