We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi
I found a bug in my code, a for was out of range and overwriting the variables after the wanted one.
i.e. uint8_t xdata globalMyVar[4];
for ( ii = 0; ii < 20; ii++ ) { globalMyVar[ii] = 0; }
So I wanted to look which were these overwritten variables. For that I checked the file generated by the linker (.M51) with the symbols information My application has several modules. The symbol(s) table(s) produced is not well adapted for a quick look on how variables are piled up in memory.
What I did was to cut and paste all the modules symbols information in excel, with fixed columns for the address value, type and name then sort by address value.
I couldn't find a switch for the linker to obtain this kind of sorted list. Btw I noted that the memory pile-up is not as declared in the source code, nor alphabetic (some internal hash used for optimization?).
Is there a better way to get the sorted list of variables as they are defined in memory? (than sorting via excel)
Regards Daniel
So I wanted to look which were these overwritten variables. just curious why?". what does it matter which were ovewritten
yes, in my case matters. Really I found the bug in an already deployed embedded application (about 1000 devices). That part of the code is used at the initialization and in some rare cases of partial setup. Several variables are "refreshed"/restored with the correct values later during execution, this is why it passed unnoticed. To evaluate if it worth the cost and effort to reprogram all the devices I needed to evaluate how dangerous was the bug, to analyze this impact I needed to check which were the variables affected.
But anyway, apart from this case, normally I work with mission critical systems, redundant and under radiation so memory locations and its uses is highly important for me.
If you are still curious I can explain more details by regular mail.
I work with mission critical systems
If it's mission critical, how the heck did a bug like that manage to get through in the first place?
It's situations like this that give software a bad name!
oh, how wondeefulit is to use plain numbers
uint8_t xdata globalMyVar[4]; for ( ii = 0; ii < 20; ii++ ) { globalMyVar[ii] = 0; } using correct methodology would never have let this pass #define SIZE_OF RALPH 4 uint8_t xdata globalMyVar[SIZE_OF RALPH]; for ( ii = 0; ii < SIZE_OF RALPH; ii++ ) { globalMyVar[ii] = 0; }
and, of course, crappy little variable names such as 'i' and 'ii' makes it even more error prone
To make a long explanation short, I wrote my first program 36 years ago (yes, 1982) and along all of these years I found myself bugs even in compilers, in the hardware (processors, coprocessors, logic, fpga, cplds, etc..) also after doing several reviews I'm never 100% sure there is something like bug free. Your statement sounds strong for me, may be with time you'll learn that the only thing we can do is to reduce the risk the better we can but not to eliminate it ...
I think that there are other things that give software/firmware/hardware a bad name but this is to discuss with another cup of coffee...
Sorry but I'm not in the mood to discuss about C coding today and is a bit off topic of what I asked in 1st place.
How to get a list of the variables sorted by address with C51 toolset.
Just let you know that the piece of code posted is not the real code and was a fast 4 line code to show a very simplified even understandable example.