On Fri, Dec 17, 2010 at 6:27 PM, Kenan Özdemir <[email protected]> wrote:
> Hi,
>
> i start working with the SAM3S4C, but having trouble with openOCD. When I
> start debugging, the very first instructions are working fine, but after the
> 3rd instruction, its jumping acrross the code.
>
> This is my main.cpp
>
>
> int
> main(void) {
> int a, i = 0;
> a = 5;
>
> for(i = 0; i <10; i++)
> a = a+5;
>
> }
>
> the first instructions (int a, i = 0; and a = 5;) are working. At the
> begining when the curser is at int a... the PC is pointing to 400107 (the
> next instruction a = 5).
>
> When I press step into, the curser goes to a = 5 and the PC is pointing to
> the next instruction (for(i...)), but when i press step into again, it jumps
> into the adress 400d50.
>
I suspect that you're wrongly assuming that the execution flow follows
line-by-line in source code order. That's not the case for any but
possibly the lowest compiler optimization settings. The compiler will
reorder and remove your statements at will, as long as semantics,
according to the C standard, are unchanged. In your case the entire
loop will be removed since it doesn't DO anything. The jump to 400d50
is probably where your main() returns to. In fact, your main() is
semantically equivalent to
int
main(void)
{
}
It's sometimes very hard to debug strongly optimized code, so you
might want to turn optimization off if you need to step around a lot.
/Andreas
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development