I have a program which produces a fatal error with a testcase, and I can locate the problem by reading the log and the stack trace of the fatal. It turns out that there is a read operation upon a null pointer.
But when I try to attach GDB to it and set a breakpoint around the suspicious code, the null pointer just cannot be observed! The program works smoothly without any error.
This is a single-process, single-thread program, and I didn't experience this kind of thing before. Why is it?
Appended: I also tried to call the pause() system call before the fatal-trigger code, and expected to make the program sleep before the fatal point and then attach GDB on it on-the-fly, sadly, no fatal error occurred.
It's only guesswork without looking at the code, but debuggers sometimes do this:
I don't have a quote on GDB, but I do have one on valgrind (granted the two do wildly different things..)
My program crashes normally, but doesn't under Valgrind, or vice versa. What's happening?
When a program runs under Valgrind, its environment is slightly different to when it runs natively. For example, the memory layout is different, and the way that threads are scheduled is different.
Same would go for GDB.
Most of the time this doesn't make any difference, but it can, particularly if your program is buggy.
So the true problem is likely in your program.