Sorry I forgot to tell you that after a couple of steps, it is returning to the main routine and then keeps executing the rest of the code

--------------------------------------------------
From: "Andreas Fritiofson" <andreas.fritiof...@gmail.com>
Sent: Saturday, December 18, 2010 8:18 PM
To: "Kenan Özdemir" <gla...@hotmail.de>
Cc: <openocd-development@lists.berlios.de>
Subject: Re: [Openocd-development] Help needed for SAM3S4C

On Fri, Dec 17, 2010 at 6:27 PM, Kenan Özdemir <gla...@hotmail.de> 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
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to