How to catch the exception when cgo code got a SIGSEGV signal?

535 views
Skip to first unread message

Jerry He

unread,
Jan 19, 2016, 12:32:49 AM1/19/16
to golang-nuts
How to catch the exception when cgo code got a SIGSEGV signal?
 I tried singal & recover method, both did not work,the program exit & print stack.

What I want to do is catching thoes things and log to file.
Anyone who can help me?

Ian Lance Taylor

unread,
Jan 19, 2016, 1:13:00 AM1/19/16
to Jerry He, golang-nuts
To catch a SIGSEGV in code running in C, you need to install a signal
handler on the C side. The Go signal handler can't generate a panic,
because it doesn't know how to unwind the C stack. If you install a C
signal handler before the Go code starts, such as by using a global
constructor, then the right thing should happen, at least when using
Go 1.6.

Ian
Reply all
Reply to author
Forward
0 new messages