Enable Core Dumps
ulimit -S -c unlimited
Confirm or Change The Location of Core Dumps
sysctl -w kernel.core_pattern=/tmp/core.%e.%p
# Or
echo '/tmp/core.%e.%p' | tee /proc/sys/kernel/core_pattern
Set GOTRACEBACK
Environment Variable to Let Go Program Core Dumps when Panic
export GOTRACEBACK=crash
Run Go Program and Wait Segmentation Fault
Use GDB to Debug
gdb /path/to/goprogram /tmp/core-xx-xx
Then use thread apply all bt
to see all backtraces, include compiled C code.
Note: -g
option should be applied to the compiled C code to generate debug symbols.