Skip to content

runtime: include panic/throw logs in core dumps #16893

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

Closed
rhysh opened this issue Aug 26, 2016 · 6 comments
Closed

runtime: include panic/throw logs in core dumps #16893

rhysh opened this issue Aug 26, 2016 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Proposal-Accepted
Milestone

Comments

@rhysh
Copy link
Contributor

rhysh commented Aug 26, 2016

When a Go program crashes with GOTRACEBACK=crash, the OS creates a core dump. I'd like that core dump to include the human-readable "panic" or "fatal error" messages and stack traces—or at least the first N kB of them.

This could be done by writing the first ~64kB of errors and stack traces to a pre-allocated global slice in the runtime package in addition to writing to stderr.

No user code would be involved, so this is distinct from e.g. #16340. I'm particularly interested in being able to reliably collect not only "panic" crashes (from runtime.gopanic), but also "fatal error" crashes (from runtime.throw).

There are more tools being built around core dumps (#16410), so it would be good to collect all information relevant to crashes in that one place (#16410 (comment))

Alternatives include:

  1. Adding an API that allows user code to set the fd that's used for panic/throw logs (Proposal: a sane, simple, Goish way to handle uncaught panics #16340 (comment)). This could end being a small change, though it would not catch problems with init functions in all packages.
  2. Consult a new environment variable (like GORACE's log_path option) which would provide a prefix for the name of a file where the runtime would write out the crash report. The cost of adding a new environment variable is high, and it looks like this problem can be resolved without it.
@quentinmit quentinmit added this to the Proposal milestone Sep 6, 2016
@adg
Copy link
Contributor

adg commented Oct 3, 2016

Seems fine to me. Anyone want to take a stab at implementing it?

@quentinmit quentinmit modified the milestones: Go1.8, Proposal Oct 4, 2016
@quentinmit quentinmit changed the title proposal: include panic/throw logs in core dumps runtime: include panic/throw logs in core dumps Oct 4, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2016
@rhysh
Copy link
Contributor Author

rhysh commented Oct 25, 2016

I've made an attempt at this which I'll mail momentarily. I can't say it's a good solution, but it's at least a starting point for discussion.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/32013 mentions this issue.

gopherbot pushed a commit that referenced this issue Nov 11, 2016
When a Go program crashes with GOTRACEBACK=crash, the OS creates a
core dump. Include the text-formatted output of some of the cause of
that crash in the core dump.

Output printed by the runtime before crashing is maintained in a
circular buffer to allow access to messages that may be printed
immediately before calling runtime.throw.

The stack traces printed by the runtime as it crashes are not stored.
The information required to recreate them should be included in the
core file.

Updates #16893

There are no tests covering the generation of core dumps; this change
has not added any.

This adds (reentrant) locking to runtime.gwrite, which may have an
undesired performance impact.

Change-Id: Ia2463be3c12429354d290bdec5f3c8d565d1a2c3
Reviewed-on: https://go-review.googlesource.com/32013
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@ianlancetaylor
Copy link
Contributor

What else is there to do this for this issue now that https://golang.org/cl/32013 has been committed?

@rhysh
Copy link
Contributor Author

rhysh commented Nov 17, 2016

Core dumps will now include text-formatted runtime messages from immediately before a crash; they don't include any text-formatted messages on the crashes themselves. We discussed in the CL how that could be recreated from the runtime package's datastructures in the core dump.

If that can become a requirement of the work for #16410, then this issue is ready to be closed since there won't be any more runtime changes required. Where should that request be tracked?

Thanks @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

Closing in favor of #16410. Thanks.

@golang golang locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Proposal-Accepted
Projects
None yet
Development

No branches or pull requests

5 participants