AnsweredAssumed Answered

The constant variable has been changed even before the program starts!

Question asked by gang han on Apr 3, 2012
Latest reply on Apr 4, 2012 by gang han

I never suffer such a weird thing.

 

Platform: MPC5668GKIT

IDE: CodeWarrior_MCU_10.2

 

In my source code, a constant array variable is defined as a initialized value of 0. Then, I compile it and download it to the RAM of MPC5668G in debug mode with the CodeWarrior debugger. And the code is set to stop at the entry point.

However, when I read the const variable, it turns out to be 0x 40009338!

 

Tom said that:

  • How does CodeWarrior initialise the DATA area? Some systems have a fixed slab of data, and others compress the data area, and run some code to fill it (or fill parts with repeated values). CW might be doing that. You should be able to find some documentation on that. Put a breakpoint further along and see if the data "comes good".

 

However, I just use the Compilor and debugger of CodeWarrior.  All my code is contained in another project (Eclipse of an RTOS Erika). I don't think it could uncompress the .elf file and fill in the data. Actually, even if the program stops at main(), the data in memory still don't match that in source code.

 

Besides, I checked the memory of target MCU and .elf file. The data in sbss2 and  sbss sections in memory do not match those in the source code, and these data take up no space in .elf file.

 

I know that all data in sbss2 and sbss are initialized to 0 or un-initialized, so it is reasonable to allocate no space for them in .elf file. And consequently, when downloaded into memory, the debuger should initialized all these data as 0

 

But I checked the corresponding address in memory, some are initialized to 0 while some are not.

why aren't they all initialized?

Outcomes