CGO segmentation violation

688 views
Skip to first unread message

Luke Mauldin

unread,
Dec 27, 2013, 8:32:30 AM12/27/13
to golan...@googlegroups.com
All,

I have a Go program using CGO to access the libvnc library and I am getting this signal and stack trace below.  Even though the stack trace shows it is the C function rfbProcessEvents where the crash is occurring, how can I get more information about the C part of the stack trace?  The libvnc libraries are compiled with debug information and if I call them from a C program and the C program crashes then the crash output will tell me exactly what line is causing the crash but Go doesn't give me that information.  Can I configure the Go program to generate a core dump that would be examinable by GDB that would contain additional information about the crash?  Is there another method that I can use to obtain more information?


SIGSEGV: segmentation violation
PC=0x7f70308821e4
signal arrived during cgo execution

runtime.cgocall(0x402040, 0x7f702c064f68)
/opt/go/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x7f702c064f50
tf/vncmulticastserver/vncmulticast._Cfunc_rfbProcessEvents(0x7f6ffc000920, 0x1f4, 0x134397756a5b2c00)
tf/vncmulticastserver/vncmulticast/_obj/_cgo_defun.c:172 +0x31 fp=0x7f702c064f68
tf/vncmulticastserver/vncmulticast.(*MulticastSession).runServer(0xc2100634e0)
/opt/gopath/src/tf/vncmulticastserver/vncmulticast/multicastsession.go:316 +0xeb fp=0x7f702c064f98
runtime.goexit()
/opt/go/src/pkg/runtime/proc.c:1394 fp=0x7f702c064fa0
created by tf/vncmulticastserver/vncmulticast.(*MulticastSession).initializeServer
/opt/gopath/src/tf/vncmulticastserver/vncmulticast/multicastsession.go:295 +0x29c

Ian Lance Taylor

unread,
Dec 27, 2013, 9:24:15 AM12/27/13
to Luke Mauldin, golang-nuts
On Fri, Dec 27, 2013 at 5:32 AM, Luke Mauldin <lukem...@gmail.com> wrote:
>
> I have a Go program using CGO to access the libvnc library and I am getting
> this signal and stack trace below. Even though the stack trace shows it is
> the C function rfbProcessEvents where the crash is occurring, how can I get
> more information about the C part of the stack trace? The libvnc libraries
> are compiled with debug information and if I call them from a C program and
> the C program crashes then the crash output will tell me exactly what line
> is causing the crash but Go doesn't give me that information. Can I
> configure the Go program to generate a core dump that would be examinable by
> GDB that would contain additional information about the crash?

You should be able to get a core dump if you set the environment
variable GOTRACEBACK=crash. Unfortunately you may run into
http://golang.org/issue/6988 , which is fixed on tip but not in the
1.2 release.

> Is there
> another method that I can use to obtain more information?

Can you run the program under gdb?

Ian

Luke Mauldin

unread,
Dec 27, 2013, 9:38:39 AM12/27/13
to golan...@googlegroups.com, Luke Mauldin
Thank you for the helpful information.  If I apply the patch to fix issue 6988, and set the environment variables, then where will the Go program put the coredump files on Linux after the crash?

Ian Lance Taylor

unread,
Dec 27, 2013, 11:47:55 AM12/27/13
to Luke Mauldin, golang-nuts
On Fri, Dec 27, 2013 at 6:38 AM, Luke Mauldin <lukem...@gmail.com> wrote:
>
> Thank you for the helpful information. If I apply the patch to fix issue
> 6988, and set the environment variables, then where will the Go program put
> the coredump files on Linux after the crash?

The core dump is really generated by the kernel. I think it will go
into the program's current directory. So don't use "go run" to run
the program--unless you take extra steps, that will run it in a
temporary directory that will then be deleted. Instead, use "go
build" and then run the program.

Ian

Ken Allen

unread,
Dec 27, 2013, 12:50:21 PM12/27/13
to golan...@googlegroups.com, Luke Mauldin
You can change kernel.core_pattern with sysctl to change where the core file goes if you need to.

Luke Mauldin

unread,
Dec 30, 2013, 7:58:04 AM12/30/13
to golan...@googlegroups.com, Luke Mauldin
I applied the patch for issue 6988 and Go did generate a core dump.  However, when I am using GDB to inspect it I am not getting the expected results.  When I load the core dump file in GDB I get the stack trace below but as you can see from the crash output the program is crashing in the C function "rfbScreenCleanup".  That C function comes from the libvnc library and the library is compiled with debugging information and I would like to use GDB to see exactly what line in the rfbScreenCleanup function caused the crash.  Is that possible?

Luke


GDB output:

(gdb) bt

#0  runtime.raise (sig=void) at /opt/go/src/pkg/runtime/sys_linux_amd64.s:86

#1  0x000000000041e526 in runtime.crash ()

#2  0x000000000041e15f in runtime.sighandler (sig=void, info=void, ctxt=void, gp=void) at /opt/go/src/pkg/runtime/signal_amd64.c:132

#3  0x0000000000428956 in runtime.sigtramp () at /opt/go/src/pkg/runtime/sys_linux_amd64.s:209

#4  0x0000000000428970 in ?? () at /opt/go/src/pkg/runtime/sys_linux_amd64.s:215

#5  0x0000000000000001 in ?? ()

#6  0x0000000000000000 in ?? ()


Crash output:

SIGSEGV: segmentation violation

PC=0x7f4644056460

signal arrived during cgo execution


runtime.cgocall(0x4020a0, 0x7f46645a4ec8)

/opt/go/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x7f46645a4eb0

tf/vncmulticastserver/vncmulticast._Cfunc_rfbScreenCleanup(0x7f46500008c0)

tf/vncmulticastserver/vncmulticast/_obj/_cgo_defun.c:181 +0x31 fp=0x7f46645a4ec8

tf/vncmulticastserver/vncmulticast.(*MulticastSession).Close(0xc2100d79c0, 0x1)

/opt/gopath/src/tf/vncmulticastserver/vncmulticast/multicastsession.go:86 +0x103 fp=0x7f46645a4f28

tf/vncmulticastserver/vncmulticast.(*MulticastSession).listenShutdown(0xc2100d79c0)

/opt/gopath/src/tf/vncmulticastserver/vncmulticast/multicastsession.go:334 +0x14e fp=0x7f46645a4f98

runtime.goexit()

/opt/go/src/pkg/runtime/proc.c:1394 fp=0x7f46645a4fa0

created by tf/vncmulticastserver/vncmulticast.NewMulticastSession

/opt/gopath/src/tf/vncmulticastserver/vncmulticast/multicastsession.go:349 +0xe8

andrey mirtchovski

unread,
Dec 30, 2013, 4:01:06 PM12/30/13
to Luke Mauldin, golang-nuts
try "thread apply all bt"
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages