Stepping problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Stepping problem

649件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andrew24 on Fri Mar 26 09:15:42 MST 2010
HI. I've bought LPC1343 eval board recently, and already gained some experience writing projects including ADC, timers etc..
but can't undestand simple thing:
When i try to step through these lines using F5 or F6, the IDE freezes. Why? (If there is more complex code in the while loop, then everything's ok)

int main(void) {

volatile unsigned int i = 0 ;
while(1) {
  i++ ;
}
return 0 ;
}
0 件の賞賛
返信
2 返答(返信)

634件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andrew24 on Fri Mar 26 10:02:15 MST 2010
Thanks for the answer. I had the optimisations turned off when i tried this. 
This code, for example works perfectly while stepping,and i can see the variable changing:
[SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](1) [/SIZE]
[SIZE=2]{
i++ ;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]       if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (i==10)
       {
        i=0;
        }[/LEFT]
}
[/SIZE]
I undeststand ,that if there is a some kind of optimisations, the compiler probably will see i++ as unnecesarry action and will skip it, but with -O0 it's strange..
0 件の賞賛
返信

634件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Fri Mar 26 09:33:26 MST 2010

Quote: Andrew24
the IDE freezes. Why? (If there is more complex code in the while loop, then everything's ok)


Look at the generated Asm (I'll bet this ws built with something other than -O0). The compiler will have spotted that 'i' is never actually used for anything so won't have bothered to generate any code to modify it. (If you had assigned it to a volatile destination it would have had to modify it though the chances are it would optimize it into register only use and 'i' would never really exist even in that case). Without i the loop is simply "while(1)" - a statement that never ends - the generated code will simply be a "here: jump here" and the single step in the debugger will never come back from this because the statement never actually ends.

Welcome to the world of debugging optimised code. If this bothers you turn the optimiser off (-O0) and accept the truly awful code that the compiler then generates.
0 件の賞賛
返信