PlatformIO Community

How do you observe arrays and buffers in the debugger?

Afternoon.

I am trying to use the debugger to observe a buffer (array) filling up using the debugger. Specifically I’m looking to observe the data captured into the String InputString from a UART. The program works but I cannot see how to view the buffer in the debugger IDE, can someone help please. I have expanded out the InputString buffer in the watch window, but I cannot see the contents. BTW the screen shot (below) shows the code creating a NULL empty buffer “” but I’ve tried initialising with a string (that gets transmitted) but I cannot see the string in the watch variable?

UART Watch Window 2020-05-28 150214

Thanks

Greg

First of, the debugger is having problems heer because String is a C++ class and so it can’t directly translate it to a string. You need to look at the implementation of String for your specific Arduino core to understand where the data actually lies.

However, you are already looking at the correct attributes of the object-- there’s a buff pointer with capacity and length information.

What you’re hovering over is the sso object – standing for short-string-optimization. This also indicates to me that you’re probably using the ESP32 Arduino core (support for SSO was added here), although you didn’t say so explicitly.

The string you’re looking at definitely seems empty now, because len is 0. Refer to the source code here. You maybe hit the breakpoint before it was able to write anything to the string?

Generally for viewing the string’s content you’d first try and open the buff: 0x3ff.: object on the left side and it hopefully gives you the data in its full form. You can also use direct gdb commands in the console to examine ( x) the memory, with commands like

x/1s *0x3ffb843c

“examine 1 zero-terminated string at address 0x3ffb843c” (docs). Or, more readably with variable names,

x/1s inputString._ptr.buff

(might need an * before the variable name). That assumes the string is null-terminated – if it isn’t, only print len many bytes with e.g. x/20c inputString._ptr.buff for examining 20 characters.