Unfortunately the GNU tools are not the best, and my experience is that the dynamic linker muddies the waters enormously. If you can get Apache to link statically with your module that will enable gdb especially to perform more reliably. I don't know how easy that is; a lot depends on the Apache build system.
It's worrisome but not shocking that you can't easily reproduce the bug with valgrind.
Regarding compiling with the right flags, both valgrind and gdb will give you much better information if you compile everything in sight with -g -O0
. Don't believe the claims on the gcc man page that gcc -g -O
is good enough; it isn't---even -O
will cause variables in the source code to be eliminated by the optimizer.