I'm debugging C code running on a MSP430 microprocessor using GDB.
When I set a breakpoint on the line double average = sum / 10;
using break 172
, it confirms by responding Breakpoint 1 at 0xc01c: file main.c, line 172
, but when I continue with c
, the code runs until it hits Breakpoint 1, main () at main.c:184
.
I wasn't having issues debugging until recently, so I tried reverting everything to the previous version and I still have this issue. I have also tried:
#include <stdio.h>
.The code looks something like:
void main(void)
{
OtherMethod();
while(1)
{
int sum = 0;
for(int i = 0; i < 10; i++)
{
sum += i;
}
double average = sum / 10; // Line 172
}
}
void OtherMethod(void)
{
P1DIR |= LED1 + LED2; // Line 184
}
Other information that might be helpful is that I can successfully set a breakpoint on the line sum += i;
.
Any ideas are appreciated.
If you compile with optimization, several "strange" things might happen, see your compiler's documentation. This might lead to statements being removed or re-arranged, and when debugging, surprising behaviour.
To debug a program "by the line", compile without optimization.
Or live with the surprises; it's a source of delight, in any case.