Eclipse Debugging with Strings – Part 2

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[0];

unsigned char ubuf[]="ABCD";
unsigned char *up = &ubuf[0];

signed char sbuf[]="1234";
signed char *sp = &sbuf[0];

So I have three arrays of bytes with pointers to it:

  1. plain char
  2. unsigned char
  3. signed char

Character Pointers

As shown in Eclipse Debugging with Strings, I have multiple ways to display the strings in a human readable form:

Variables View

Variables View

But it does not work for the other pointers:

Char pointer showing address of first element

Char pointer showing address of first element

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…:

Select Columns in Variable View

Select Columns in Variable View

Then I can select ‘Declared Type’ as an option:

Enabling Declared Type for Variables View

Enabling Declared Type for Variables View

This then will show me the type of the variables:

Variables View with Declared Type Column

Variables View with Declared Type Column

So what now? What if I cast the variable to ‘unsigned char*’? This is what I can do with a context menu:

Cast to Type

Cast to Type

And now it shows like this:

Variables View with Casted Type

Variables View with Casted Type

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:

Eclipse 3.8 with Casted Character Pointer

Eclipse 3.8 with Casted Character Pointer

So it looks that bug is fixed in Eclipse 3.7 :-).

Character Arrays

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:

Variables View with Arrays

Variables View with Arrays

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.

Summary

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 😉

Advertisements

3 thoughts on “Eclipse Debugging with Strings – Part 2

  1. Thanks SO much for this! It’s been driving me crazy.
    If you find a way of display as a hex dump (instead of view memory, which is quite laborious and bleugh), please post.
    🙂

    Like

  2. Pingback: Eclipse Debugging with Pointers and Arrays | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.