cgo panic stack trace with no proper line number for c code

569 views
Skip to first unread message

andy....@gmail.com

unread,
Jan 19, 2016, 8:34:30 AM1/19/16
to golang-nuts
I have recently come across a situation that when processing cgo. When i make a SIGBUS signal to the cgo program, the stack trace come to an error line number pointing to the c code. How does the line number with cgo to be interpreted correctly?

i.e. what is the meaning of "54" after " /home/demo/code/go/src/github.com/demo/a/".
[signal 0x7 code=0x2 addr=0x7f45fe055000 pc=0x36f5889131]

runtime stack:
runtime.gothrow(0x95b570, 0x2a)
        /usr/local/go/src/runtime/panic.go:503 +0x8e
runtime.sigpanic()
        /usr/local/go/src/runtime/sigpanic_unix.go:14 +0x5e

goroutine 13 [syscall, locked to thread]:
runtime.cgocall_errno(0x403aa0, 0xc65d0c1a60, 0x0)
        /usr/local/go/src/runtime/cgocall.go:130 +0xf5 fp=0xc65d0c1a40 sp=0xc65d0c1a18
github.com/demo/a._Cfunc_create(0x7f4614000ac0, 0x12c, 0x568c8d61, 0xc20000000e, 0xc2db7b82a0, 0x0)
        /home/demo/code/go/src/github.com/demo/a/:54 +0x44 fp=0xc65d0c1a60 sp=0xc65d0c1a40


Ian Lance Taylor

unread,
Jan 19, 2016, 1:18:42 PM1/19/16
to andy....@gmail.com, golang-nuts
On Tue, Jan 19, 2016 at 4:23 AM, <andy....@gmail.com> wrote:
> I have recently come across a situation that when processing cgo. When i
> make a SIGBUS signal to the cgo program, the stack trace come to an error
> line number pointing to the c code. How does the line number with cgo to be
> interpreted correctly?
>
> i.e. what is the meaning of "54" after "
> /home/demo/code/go/src/github.com/demo/a/".

That looks strange. I don't know why there is no file name there.

What I do know is that it doesn't matter, in that knowing the answer
won't help. That file is a file generated by cgo to implement the
call to C.create. The actual SIGBUS signal is coming from C code, and
the Go traceback is not showing that code. With Go 1.6 you will need
to run the program under a debugger, or use nm/objdump/readelf to
translate the PC address (0x36f5889131) back into a symbol.

If you feel like experimenting, and you are using amd64 GNU/Linux, you
could try using https://golang.org/cl/17761 in conjunction with the
github.com/ianlancetaylor/cgosymbolize package, to get a symbolic
backtrace of your cgo crash. That is strictly experimental, though,
and not for the unwary. I hope to include it in the 1.7 release.

Ian

andy.xning

unread,
Jan 19, 2016, 9:05:32 PM1/19/16
to Ian Lance Taylor, golang-nuts

> What I do know is that it doesn't matter, in that knowing the answer
> won't help. That file is a file generated by cgo to implement the
> call to C.create. The actual SIGBUS signal is coming from C code, and
> the Go traceback is not showing that code.


Does it mean that by default cgo stack trace will not show the exact line number and c file where the error occures? Or, it is only a special case in mine that the exact line number and c file name is losing.

Currently the debug is difficult for a cgo stack trace. :(

===
Ning Xie

 原始邮件 
发件人: Ian Lance Taylor<ia...@golang.org>
收件人: andy.xning<andy....@gmail.com>
抄送: golang-nuts<golan...@googlegroups.com>
发送时间: 2016年1月20日(周三) 02:18
主题: Re: [go-nuts] cgo panic stack trace with no proper line number for c code

Ian Lance Taylor

unread,
Jan 19, 2016, 9:08:17 PM1/19/16
to andy.xning, golang-nuts
On Tue, Jan 19, 2016 at 6:05 PM, andy.xning <andy....@gmail.com> wrote:
>> What I do know is that it doesn't matter, in that knowing the answer
>> won't help. That file is a file generated by cgo to implement the
>> call to C.create. The actual SIGBUS signal is coming from C code, and
>> the Go traceback is not showing that code.
>
>
> Does it mean that by default cgo stack trace will not show the exact line
> number and c file where the error occures? Or, it is only a special case in
> mine that the exact line number and c file name is losing.

The cgo stack trace is not being displayed at all. What is being
displayed is the Go stack trace up to the point of the call into C.
The stack trace of the code in C does not appear.


> Currently the debug is difficult for a cgo stack trace. :(

Yes. That is why I am working to make it better in 1.7, but that
won't help you today.

Ian

andy.xning

unread,
Jan 19, 2016, 9:09:30 PM1/19/16
to Ian Lance Taylor, golang-nuts

Thanks for the info about changing it in 1.7. :)



===
Ning Xie

 原始邮件 
发件人: Ian Lance Taylor<ia...@golang.org>
收件人: andy.xning<andy....@gmail.com>
抄送: golang-nuts<golan...@googlegroups.com>
发送时间: 2016年1月20日(周三) 10:08
主题: Re: [go-nuts] cgo panic stack trace with no proper line number for c code
Reply all
Reply to author
Forward
0 new messages