
C programming – Seg fault not in GDB?
I’ve written a program in standard C. The program crashes upon sending it what should be the correct input, Seg Faulting and exiting. That’s fine… normally I’d just fire it up in gdb, give it the same input, let it Seg Fault, backtrace the execution and see what went wrong…
But for some reason, the program does not Seg Fault in GDB… as a matter of fact it works perfectly fine. Without going into extreme depth of my program (its pretty basic, but does go as far as Sockets and Threads…), what could cause a program to Seg Fault when ran normally, yet run fine in GDB or a debugging mode ??
When a bug doesn’t show up in a debugger, I start thinking it’s a timing problem between the program and something it’s communicating with, and the stepping through in the debugger is resolving the problem.
A second possibility is that the debugger is subtly altering the executable code so the seg fault doesn’t happen.
Third, if you have to compile differently for using or not using the debugger, the compiler itself may be altering the code it generates.
Finally, the code itself may be being overwritten by data.
Try a different strategy: Using printf() calls at strategic points in the code to narrow down where the problem is happening. (But I’ve seen instances where even the addition of a simple output statement “fixed” the problem by moving where an overwrite hit.)
Good luck with this one! These can be real hair-pullers.
Valgrind, GDB, and friends – Part 8 / 15
|
|
The Linux Programming Interface: A Linux and UNIX System Programming Handbook $79.95 The Linux Programming Interface is the definitive guide to the Linux and UNIX programming interface—the interface employed by nearly every application that runs on a Linux or UNIX system.In this authoritative work, Linux programming expert Michael Kerrisk provides detailed descriptions of the system calls and library functions that you need in order to master the craft of system programming, and… |
