Code: Select all
if(...) {
...
} else {
...
// if(FATAL_NODE) printf("OK\n"), fflush(stdout), exit(0);
}
// if(FATAL_NODE) printf("OK2\n"), fflush(stdout), exit(0);
So I have been moving around a print statement + exit() combination to figure out where in this node the crash happens. When I only uncommentize the printing of "OK" above, the program prints "OK", and then of course exits. When I only uncomment the printing of OK2, nothing is printed. So one can deduce that the crash is caused by what it is doing between the two print statements. Except of course that it isn't doing anything there...
When I uncomment both (clipping the exit() call off the first) it prints both OK and OK2. When I then comment out the OK2 printing again, it crashes only in iteration 8 rather than iteration 5 (presumably in another node).
To test the hypothesis that this is because I use some unintialized variable altered by printf, I made routines Save() and Restore() that copy their stack frame (of 4KB) to a static memory area, or copy it back from there, and put those around the printf/fflush. That still shifts the crash to another place. If I only call Save/Restore in that place (i.e. remove the printf for "OK", and leave the OK2 stuff commented out), it shifts the crash to yet another iteration.
What on earth could I be doing wrong to get such sick behavior? This is with gcc under Linux. Any ideas? Is it possible that the code is modified during execution? I though that under Linux the code segment was write-protected?
Oh, and when I compile with the -m32 flag, the crash seems to have gone away completely...