I am working on RP2040 Pico, and gdb connected via openocd and Picoprobe (note that the RP2040 has two cores, which gdb recognizes as two "threads").
I have previously tried gdb watch on global uint8_t variables and such on this platform, and it seems to break fine.
Now, I've got a problem, that a (global) string that I write with with:
snprintf(stringbuf, sizeof(stringbuf), "val: %3d", the_value)
... and I can confirm the_value does not change from value 100 in gdb - I can see that the character buffer of size 9 (i.e. string of size 8) at a certain point in time unexpectedly changes from val: 100 to val: 0.
So, not having other things to debug by (again, the_value does not change from 100) - I tried to add a watchpoint on the 6-th (1-based, so index 5 zero-based) character, expecting it will break when the character changes from 1 to , and the backtrace will reveal what has changes this character, and therefore string.
So, just to make sure I do not mess up with syntax, I tried to set a watchpoint directly on the address of the 6th character in this string, interpreted as a char:
(gdb) p stringbuf
$1 = "val: 0"
(gdb) p &stringbuf
$2 = (char (*)[9]) 0x20000618 <stringbuf>
(gdb) p &stringbuf[5]
$3 = 0x2000061d <stringbuf+4> " 0"
(gdb) p *(char*)0x2000061d
$4 = 32 ' '
(gdb) watch *(char*)0x2000061d
Hardware watchpoint 4: *(char*)0x2000061d
(gdb) info br
Num Type Disp Enb Address What
4 hw watchpoint keep y *(char*)0x2000061d
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: ...
The messages from gdb look all good - except that, the watchpoint NEVER breaks; even though I can do:
...
(Ctrl-C)
Thread 1 received signal SIGINT, Interrupt.
0x10009588 in ...
(gdb) p *(char*)0x2000061d
$19 = 49 '1'
(gdb) c
Continuing.
( ... Ctrl-C)
Thread 1 received signal SIGINT, Interrupt.
0x10008238 in ...
(gdb) p *(char*)0x2000061d
$20 = 32 ' '
... and I can see, that obiously the character at address 0x2000061d has indeed changed its value.
Am I doing anything wrong - and how can I add a watchpoint correctly on this memory address, so gdb breaks whenever this memory location changes value? Or maybe gdb, or the platform I use, does not support watchpoints on char variables, or something similar?