I am using Keil Micro Vision4 for ARM 9 Processor .the Local variables appears "Out of scope" How do i monitor the local variables
When debugging, make sure you set optimization level to minimum.
When you tell the compiler to optimize code, then the compiler really will optimize the code. So it will convert some local variables into registers. And it may reuse same register for multiple local variables. Or move the local variable between different registers for different parts of the code based on what produces most efficient code.
And it will detect local variables that are no longer used (even if there exists more assigns to them or following expressions makes use of them but don't produce any side effects later used) and then quickly reuse the registers for other things.
An automatic (ie, "local") variable only exists while it is in-scope - therefore, you cannot monitor such a variable when it is out of scope.
You do understand the concept of symbol scope in a block-structured language (such as 'C') - don't you...?
I myself also worry about of that "out of scope" I think -- well the copmpiler did just compiled my code and he really knows in which register variables resides. Why can he not tell that the debugger? In my distress I have always to open dissasemby window and look at the Register window. Furthermor ig I want to see a register value as an signed integer, i must this register add to the watch window -- just terrible.
Are we sure that this warning is actually produced by optimisation?
Is it not simply that the variable is out-of-scope?!
Just that depending on optimization level, there are no valid information that can be given to the debugger. Because the same register is sometimes one variable and sometimes another variable. All within the same function. Debuggers normally don't support scope rules line-by-line.
But then you haven't given us any information about your optimization levels...
Nor even any information about the situation(s) in which the message actually appears.
It appears that the OP is another one of those not interested to engage in the discussion.
:-(
Didn't want to start a new thread, but recently i am also facing the same problem.
Even when i am using simulator. The variables are local variables and i check the variables in the function itself, but in vain. also keil has stopped displaying the values of variables on 'mouse over'. The optimization level shows default and all check-boxes are unchecked.
uint8_t VSTIR_ProcessData() { uint8_t paddleno=0, i=0, rxdlrc=0, calclrc=0, err=0, mod=0; char tempbuf[5]={0}; >This> unsigned int temp=0; ... if(calclrc == rxdlrc) { err = SPI_ACK; if(gSPIRxBuf[11] < MAXSENSORS) { if(paddleno < gTotalPaddles) { temp = (gSPIRxBuf[8]<<8 | gSPIRxBuf[7]); // if((temp%10) > 5) { temp += (10 - mod); } sprintf(tempbuf, "%4d", temp); gCur_Temperature[paddleno][0] = tempbuf[0]; gCur_Temperature[paddleno][1] = tempbuf[1]; gCur_Temperature[paddleno][2] = '.'; gCur_Temperature[paddleno][3] = tempbuf[2]; } } } else { err = SPI_NACK; } ... return paddleno; }
I am unable to set a break-point on the line i have marked, but find a break point for all the other definition lines(Sic). I dont want to set the break point there, but only that variable cant be seen in the watch window. I am trying to round off the value in temp (last digit) but unable to watch the value.
And today, i even encountered an awkward situation. when i debugged code in simulator, i found that the code is not executed in a line-by-line manner. the execution jumps to lines randomly (in a function) and can't understand the pattern.
the variable also remains <not in scope> when in try to watch it in the Call stack + Locals window.
If you don't like the execution to process the lines in "random" order, you should start by turning off all optimization. The compiler can move around things quite a lot if allowed to.
Does it mean that the "Default" optimization level may not be "optimization level 0". Because my keil compiler optimization level is set to "Default".
If you find a setting named 'Default' and not '0', then it must be obvious that this 'Default' may be something different than '0'. Or it would have been bad to have two separate choices that are actually always identical.
But since this thread have already recommended to test with optimization at minimum, my question must be: Haven't you already tested to select optimization level zero (-O0)?
A little bit of Assumption made over here, that the Default optimization level may be '0' or Minimum or the Best suited (the way it happens while installing any software).
But now i have changed the optimization level to '0' and everything works fine. :)
Note that 'Best suited' is something different if: - you want easiest debug - you want smallest code - you want fastest code - you want quick code generation
Most compiler defaults to something in-between.
Got it. Default may not be "Best For Debugging".
Check the Compiler Control String
-c --cpu Cortex-M3 -D__RTX -g -O0 --apcs=interwork -I C:\Keil\ARM\RV31\Inc -I C:\Keil\ARM\CMSIS\Include -I C:\Keil\ARM\Inc\NXP\LPC17xx -o ".\obj\*.o" --omf_browse
the Highlighted 2digit number displays the Optimization level. may not be set to '00' for default settings. In my keil, it was set to '02'. :P