Author Topic: Debugging with Floating Point Variables  (Read 9187 times)

Offline Richard

  • Newbie
  • *
  • Posts: 44
    • View Profile
Debugging with Floating Point Variables
« on: April 05, 2009, 04:15:57 AM »
Maybe I'm losing my mind...

If I write

double x;
void fn0(void) {
  x = ...;
}


where x is a global, I'll get expected results.  But if I write

void fn0(void) {
  double x;
  x = ...;
}


where x is a local variable, the debugger and the compiler disagree about where x is located, so the displayed value for x in the debugger has the wrong value.  I've single stepped through the assembly code and seen what location gets put into the registers that access the variable; it's not the same as the one attributed to the variable by the debugger.

A similar problem occurs with values passed as function arguments, e.g.,

void fn1(double t) {
  ... = t...;
}


My code is based on uTasker SP 7  -- in particular, in the ColdFire Processor configuration panel, Parameter Passing is set to Register, Integers are 4 bytes, A6 Stack Frames are turned off, the CPU is a 52233 (so Floating Point is automatically selected to be Software), both the Code and Data Models are set to Far (32 bit).  I believe all the other choices are the usual ColdFire ones.

I'm using CodeWarrior 7.1, build 14. I've made the recommended additions and changes to use floating point variables --
1) include (and link) the following files in my project:
    fp_coldfire.a in C:\Program Files\Freescale\CodeWarrior for ColdFire V7.1\ColdFire_Support\Libraries
    C_4i_CF_RegABI_Runtime.a in C:\Program Files\Freescale\CodeWarrior for ColdFire V7.1\ColdFire_Support\Runtime
    C_4i_CF_RegABI_SZ_MSL.a in C:\Program Files\Freescale\CodeWarrior for ColdFire V7.1\ColdFire_Support\msl\MSL_C\MSL_ColdFire\Lib

2) modify ansi_prefix.CF.size.h in C:\Program Files\Freescale\CodeWarrior for ColdFire V7.1\ColdFire_Support\msl\MSL_C\MSL_ColdFire\Include by changing a couple of #defines to give

#if !((__COLDFIRE__ == __MCF5475__ || __COLDFIRE__ == __MCF5485__) && !__option(fp_library))
#define _MSL_FLOATING_POINT 1  // was 0
#undef _MSL_NO_MATH_LIB         // was define
#endif

Unlike Neil's suggestion (topic 399, message 1646), I did not change _MSL_FLOATING_POINT_IO from 0 to 1, because I'm not trying to format or print floating point numbers.

With the exception of this debugging problem, floating point code seems to work just fine with this setup.

My questions are these:
    1) has anyone else observed this problem? and
    2) is there some setting I missed that would make the debugger correctly recognize the location of local variables of type double?
and, of course,
    3) am I losing my mind?

Cheers,
    Richard

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Debugging with Floating Point Variables
« Reply #1 on: April 05, 2009, 01:12:58 PM »
Hi Richard

Have you tried with optimisations disabled?

To be honest, I have often difficulties with CW debugging with normal variables (nothing to do with floating point). Usually because they are displayed as being unknown (although they are often in a register and so can be easily seen when working in assembler/mixed view). Sometimes the values that are displayed are also not correct, so have to be treated with some caution.

Global variables seem to be much easier for the debugger to deal with.

I suspect that also disabling the optimisation makes it easier for the debugger so you may like to give it a try (if the code doesn't grow too much) to see whether it then displays more reliably.

My suspicion is that this got worst with the CW V7 version since I don't remember having any real difficulties when using the CW6.3. But, I am not 100% sure since other tweaks have also been made in the meantime to increase code density performance and these may be making it more difficult for the debugger (?).

Regards

Mark

Offline Richard

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Debugging with Floating Point Variables
« Reply #2 on: April 05, 2009, 03:48:31 PM »
Thanks, Mark, for your prompt reply.

I should have said that I turned optimizations off to simplify tracing and to make sure that various variables introduced simply for checking their values were not removed. 

Along the way, I tried intermediate values of optimization, and a couple of them caused the compiler itself to fail: while compiling M5223X.c at optimization levels 1 and 2, it tries to write at 0x28 and cannot.  It has no difficulty with optimization levels 0, 3, and 4.  Somewhat scary!  But at least it can compile the project at the two extremes, and those are what most people need.

Cheers,
    Richard

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: Debugging with Floating Point Variables
« Reply #3 on: April 30, 2009, 01:22:55 PM »
Hi,
  Since I ran the patch so I can use the 52259 chip, I cant use floating point as described (and on my previous topic 399, message 1646). The strange thing I made a type error in ansi_prefix.CF.size.h, and didnt get a compile error (even when I typed in rubbish).

Do I have to rebuild the libraries? Or should floating point work as previously described?

Regards
Neil