Skip to content

[WIP Do not merge] Helpful stack overflow messages. #51514

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

Conversation

gilescope
Copy link
Contributor

@gilescope gilescope commented Jun 12, 2018

This is using libunwind, though the library is called this, it does't
actually unwind the stack in our case (which is good as this preserves
panic safety).

Discussion here: #51405

Keen to see how the test fairs on the various OSes that bors uses.
(We could also do this functionality with libbacktrace or more likely move to a pure rust
implementation: #51408 once ready. )

This is using libunwind, though the library is called this, it does't
actually unwind the stack in our case (which is good as this preserves
panic safety).
@rust-highfive
Copy link
Contributor

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 12, 2018

if let Some(format) = log_backtrace {
if let Ok(mut stderr) = Stderr::new() {
let _ = backtrace::print(&mut stderr, format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please print thread '{}' has overflowed its stack here too, because the backtrace is likely to be very big, which makes it easy to miss the first time it is printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea.

@gilescope
Copy link
Contributor Author

gilescope commented Jun 12, 2018

@kennytm would you mind running a @bors try for me please? I want to see this change on all the OSes we build on.

@rust-lang rust-lang deleted a comment from bors Jun 12, 2018
@rust-lang rust-lang deleted a comment from bors Jun 12, 2018
@kennytm
Copy link
Member

kennytm commented Jun 12, 2018

@gilescope try build will only produce an x86_64 Linux artifact, is this enough for you?

@gilescope
Copy link
Contributor Author

I think we need the full monty to see if there's any OS that's complaining. I.e. auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-cargotest, auto-linux-64-cross-freebsd, auto-linux-64-debug-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-opt-rustbuild, auto-linux-64-x-android-t, auto-linux-cross-opt, auto-linux-musl-64-opt, auto-mac-32-opt, auto-mac-64-opt, auto-mac-64-opt-rustbuild, auto-mac-cross-ios-opt, auto-win-gnu-32-opt, auto-win-gnu-32-opt-rustbuild, auto-win-gnu-64-opt, auto-win-msvc-32-opt, auto-win-msvc-64-cargotest, auto-win-msvc-64-opt, auto-win-msvc-64-opt-rustbuild

Maybe that's only possible by merging in the PR? If so let me add @bjorn3
suggestion in before we go further...

@kennytm
Copy link
Member

kennytm commented Jun 12, 2018

Yeah a try build can at most support Linux and macOS only at the moment.

@jonas-schievink
Copy link
Contributor

The backtrace implementation acquires a lock to print to stderr, so this is likely deadlock-prone (possibly only when a stack overflow occurs while a backtrace is printed). I think there are more signal safety problems in the actual backtrace implementation, too (at the very least, no regular allocations can be performed, which is why you need to enable the libbacktrace mmap allocator - this was mentioned in #51405).

@pietroalbini
Copy link
Member

Ping from triage @kennytm! How should we move forward with this?

@kennytm
Copy link
Member

kennytm commented Jun 18, 2018

Unfortunately, with the current setup we can't dist from Windows without merging it. If we decide to merge it, OP needs to fix #51514 (review) and reply to #51514 (comment).

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2018
@gilescope
Copy link
Contributor Author

Am still working on this. The PR as stands seems to work if the alternative stack is not triggered (at least that's what I think is happening: the stack probe test on my machine gives a great stack overflow message if you don't allocate much memory during the recursion - in my case < 256 produced a full stack trace, where as above that the stack trace ended at the signal handler.)

The signal handler's third parameter is a u_context which contains the data required to unwind while being on an alternative stack. I just need to invoke backtrace while giving it the u_context rather than it calling getcontext() itself. Alas I haven't figured out how to do this. Any hints gratefully appreciated.

@stokhos
Copy link

stokhos commented Jun 29, 2018

ping from triage @gilescope @kennytm what's the story with this PR?

@gilescope
Copy link
Contributor Author

gilescope commented Jul 1, 2018 via email

@pietroalbini
Copy link
Member

Great, I'm closing this to keep the PR queue clean. When you're ready you can reopen this PR, so we can review it again.

@pietroalbini pietroalbini added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 9, 2018
@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 27, 2018

any progress with pursuing something like this?

@gilescope
Copy link
Contributor Author

Using unwind-rs and with findshlibs section support I did manage to get unwind working on OSX.
The pause was on finding a nice way for section support to be exposed in findshlibs given that OSX and Elf do things a little differently. (Though if there's a better crate that reads sections from in-memory rather than on-disk let me know.)

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 29, 2018

FWIW I don't think an initial PR needs to necessarily provide better stack overflow error messages on all platforms. A PR that does so on Linux or MacOSX only would already be valuable, and things can be improved incrementally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants