I am developing a high traffic network C server application that runs as a daemon. Under some circumstances, the app crashes (always without core). How I can debug the runni
Another method to debug your application is to use the core file for debugging with GDB.
To generate a core file when segmentation occurs you can follow the below steps:
1) Copy the below parameters to your script which runs the daemon.
ulimit -c unlimited
mkdir -p , eg : /etc/user/ankit/corefiles
chmod 777 /etc/user/ankit/corefiles
echo "/etc/user/ankit/corefiles/%e.%s.core" > /proc/sys/kernel/core_pattern
2) Run your application using the script and wait for the core dump file to be created. Once you get the core dump you can debug with gdb following the below steps as mentioned.
3) Getting backtrace using GDB
gdb -c , where core_file is the file generated after segmentation fault
4) Backtrace
Next, we want to know what the stack was when the program crashed. Running bt at the gdb prompt will give you a backtrace. If gdb hadn’t loaded symbols for the binary, so it will throw an error with the question mark similarly to this "??????". To fix this you will have to load symbols.
Here’s how to load debugging symbols.
symbol-file /path/to/binary
sharedlibrary
5) Get backTrace for all the threads
thread apply all bt full
NOTE: Make sure the binary is compiled with debugging symbols.