Maybe a better title for this post would be “Eclipse Debugging with Strings Attached’? Digging a bit more into the domain of string debugging, things are not always the way I wish they are.
I’m using here CodeWarrior for MCU10.2, which is based on Eclipse 3.6. Let’s use the following piece of code with the ARM Cortex-M4 Kinetis K60 core and the Freescale ARM compiler:
char buf = "abcd"; char *p = &buf; unsigned char ubuf="ABCD"; unsigned char *up = &ubuf; signed char sbuf="1234"; signed char *sp = &sbuf;
So I have three arrays of bytes with pointers to it:
As shown in Eclipse Debugging with Strings, I have multiple ways to display the strings in a human readable form:
But it does not work for the other pointers:
Here, instead of the string, only the address of the first character is shown in the preview pane. Actually the same is happening for the ‘p’ pointer as well. Eclipse only shows strings for ‘unsigned char’ types. Or if plain char is unsigned.
To show the type of the variable, it is useful to enable the ‘type’ column. This can be done with selecting the small triangle in the view and to use Layout > Select Columns…:
Then I can select ‘Declared Type’ as an option:
This then will show me the type of the variables:
So what now? What if I cast the variable to ‘unsigned char*’? This is what I can do with a context menu:
And now it shows like this:
Better, but still not showing it as a string in the variable preview pane :-(.
So this is for Eclipse 3.6, and I tried the same thing with Eclipse 3.7, and here it works with casting the pointer to an unsigned one:
So it looks that bug is fixed in Eclipse 3.7 :-).
The other case is using the character arrays. And here unfortunately the preview pane fails: it does not show strings for any of my arrays: signed or unsigned:
The result is the same for Eclipse 3.6 and 3.7, and I have not found a way to cast the arrays neither. So this feature is definitely missing in Eclipse for me.
In Eclipse 3.6 (CodeWarrior for MCU10.2) only unsigned character pointers are shown as strings in the variable preview. Casting signed character pointers only works in the next Eclipse 3.7 version.
Unfortunately arrays are not displayed as strings, which in my view is a step back from the classic non-Eclipse CodeWarrior version. At least unsigned character arrays should be displayed as strings.
As a side comment, this adds to my rule of thumb to use ‘unsigned char’ for strings, and not to use plain char: depending on the architecture and the compiler, plain char might be handled differently. Using plain char makes porting more difficult, and not using unsigned char might impact debugging.
Happy (or unhappy) string casting 😉