New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime/cgo: add cgosymbolizer package to provide default Traceback #36596
Comments
The Go runtime does not have the machinery to read DWARF. That machinery is available in the debug/dwarf package, but debug/dwarf depends on a number of other packages, which are also not in the Go runtime. Bringing debug/dwarf into the runtime would not be trivial, and it would not be a relatively small addition. It would also increase the size of all Go programs, for the benefit of a much smaller number of programs. The |
We live in the time of containerized applications. In many cases, the only diagnostic operations can rely on for problem analysis is the stack trace. Now we have the following situation:
As to the binary size penalty, if can trivially be made conditional on actual cgo presence. No cgo - no penalty (plus tag to disable it if a particular developer feels lucky). |
A Go program that crashes during a cgo call should display a stack trace for the Go code that made the call. I agree that a Go program that crashes in a thread newly started by C code will not display anything useful. I would not be opposed to this change if someone can implement it without imposing any significant penalty on Go programs that do not use cgo. Unfortunately I think you are significantly underestimating the difficulty. I would be happy to be proven wrong. |
The Go call is of course there, on the stack. The usual problem, though, that when something like SIGSEGV happens several frames into the native code, the knowledge of the last go function is not of particular use. Your cgosymbolizer package is only a dozen of files. What's wrong with it being included by default? |
The cgosymbolizer package is written partly in C and using it requires using the external linker. It's important to us that people be able to write pure Go programs that do not require installing a compiler and libraries. That said I suppose we could consider adding cgosymbolizer to the runtime/cgo package. It would need to be ported to macOS. It won't work when using a C compiler other than GCC or clang. The cgosymbolizer implementation does not provide a context function, meaning that it does not support a traceback when Go calls C calls Go. Supporting that is difficult, as it requires an implementation of the unwinder. |
Go runtime has all the necessary machinery to resolve symbols from platform specific debug data (such as dwarf). It makes sense, therefore, to actually provide the default handlers for
SetCgoTraceback
out of the box, instead of forcing users to use somewhat under maintained and not always wieldy miniport of the GCC backtrace facility.This relatively small functionality addition on the Go runtime side (which already has a decent chunk of the machinery required) will make the life of Cgo users everywhere instantaneously better.
The text was updated successfully, but these errors were encountered: