If you want to debug why your C/C++ application segfaults once in a while (daemon that segfaults once in few days) under Linux the obvious way is to tell your program to create core dump files on segfault. It took me few hours to make my program coredump - by default under Linux setuid programs do not dump core. To force a program to do so, you should execute this after setuid:

prctl(PR_SET_DUMPABLE, 1);

and include:

#include <sys/prctl.h>

Of course you should also enable core dump with setrlimit:

setrlimit(RLIMIT_CORE, &limit);

To tune where your core dumps are stored, search google for core_pattern or /proc/sys/kernel/core_pattern, I don’t feel like copy-pasting.

Hope this helps somebody.