Debugging a running daemon using gdb

前端 未结 3 1550
萌比男神i
萌比男神i 2021-01-02 10:36

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

3条回答
  •  迷失自我
    2021-01-02 11:05

    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.

提交回复
热议问题