Debugger - variables not properly traced

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debugger - variables not properly traced

Jump to solution
1,528 Views
admin
Specialist II
Hi everybody,
 
Im fresh with freescale and codewarrior so I hope there is a quick method to fix my problem.
During debugging C code (tested with different examples) some variables in Data:2 window are heaving wrong content. Especially those which are passed as input parameters in fuctions usually have strange values. For example if I pass two parameters in a function :
 InitTMR(word k=5, word l=1) then during debugging this function inside the k and l variables ussually having values like 0xE206, 0xE103 ... or so (looking more as a memory address and not a value anymore).
What I expect this effect is caused by the fact that some variables are passed to the fuctions by using index register H:X and then these variables are not tracable enymore by Data window. I can imagine that they can be as well somehow optimized by compiler and that could appear as well as a strange behaviour of the debugger. Anyway I tried to turn off all optimization options in the compiler but that did not help at all. Do you have any solution for that problem or is there any other way to trace the value of variables ? (I tried as well Inspect component but effect was the same)
 
(by the way Im using version 6.1 build 7285 of CW with freescale HCS08)
 
BR/Pawel
Labels (1)
Tags (1)
0 Kudos
1 Solution
405 Views
admin
Specialist II

Thanks for the hint. At the moment I’m trying that method. For testing little part of code it is ok but for a whole project I will need to find better solution. Anyway It is hard to believe that there is no other way to make debugger working fine .... I would expect that there is somewhere an option allowing to select between debug/release version ... as normally is done in professional environments. It looks like I will have to look for another environment option ... hopefully IAR debugger is dealing with that in a better way.

View solution in original post

0 Kudos
3 Replies
405 Views
Lundin
Senior Contributor IV
This is indeed caused by the compiler's optimizer. The CW debugger is too crappy to understand code optimized by the CW compiler...

If it doesn't work to disable all optimization, you could write a debug version for the code like this:

void func(int x, int y)
{
  volatile int debug_x = x;
  volatile int debug_y = y;
}


That will make the debug versions of the variables visible.

Another option is to look at the assembler code rather than the C code and single-step the assembler window while watching the accumulators and index registers.
0 Kudos
406 Views
admin
Specialist II

Thanks for the hint. At the moment I’m trying that method. For testing little part of code it is ok but for a whole project I will need to find better solution. Anyway It is hard to believe that there is no other way to make debugger working fine .... I would expect that there is somewhere an option allowing to select between debug/release version ... as normally is done in professional environments. It looks like I will have to look for another environment option ... hopefully IAR debugger is dealing with that in a better way.

0 Kudos
405 Views
Lundin
Senior Contributor IV
Yes, as a programmer comming from another environment you find it incredibly strange that CW has no option to remove all optimizations. I don't know how many times I have asked both old Metrowerks and recently Freescale to include such an option.

It seems there is one compiler option in the latest compiler called "Disable all optimization" (-Ms O0). Whether it disables all optimization or just some, I don't know.

Another option is to buy a 3rd party debugger. The CW compiler is a good one, but the CW debugger is so-so.
0 Kudos