-
Notifications
You must be signed in to change notification settings - Fork 14k
Show backtrace on allocation failures when possible #148020
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
Open
bjorn3
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
bjorn3:oom_backtrace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−23
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //@ run-pass | ||
| //@ ignore-android FIXME #17520 | ||
| //@ needs-subprocess | ||
| //@ ignore-openbsd no support for libbacktrace without filename | ||
| //@ ignore-fuchsia Backtraces not symbolized | ||
| //@ compile-flags:-g | ||
| //@ compile-flags:-Cstrip=none | ||
|
|
||
| use std::alloc::{Layout, handle_alloc_error}; | ||
| use std::process::Command; | ||
| use std::{env, str}; | ||
|
|
||
| fn main() { | ||
| if env::args().len() > 1 { | ||
| handle_alloc_error(Layout::new::<[u8; 42]>()) | ||
| } | ||
|
|
||
| let me = env::current_exe().unwrap(); | ||
| let output = Command::new(&me).env("RUST_BACKTRACE", "1").arg("next").output().unwrap(); | ||
| assert!(!output.status.success(), "{:?} is a success", output.status); | ||
|
|
||
| let mut stderr = str::from_utf8(&output.stderr).unwrap(); | ||
|
|
||
| // When running inside QEMU user-mode emulation, there will be an extra message printed by QEMU | ||
| // in the stderr whenever a core dump happens. Remove it before the check. | ||
| stderr = stderr | ||
| .strip_suffix("qemu: uncaught target signal 6 (Aborted) - core dumped\n") | ||
| .unwrap_or(stderr); | ||
|
|
||
| assert!(stderr.contains("memory allocation of 42 bytes failed"), "{}", stderr); | ||
| assert!(stderr.contains("alloc_error_backtrace::main"), "{}", stderr); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me what this safety comment is on - I don't see any unsafe code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the default panic hook. This comment originates from 1c8f9bb, which doesn't have unsafe code either. cc @jyn514
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BacktraceLock::printis incorrectly marked as safe. It and all callers should be marked unsafe. See 1c8f9bb?w=1#diff-1b221b9e32f6143fdd8a5505c8893377e8e9eb1ff47b988716343c7e70393b1bR40.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not safe? The mere fact that you have a
BacktraceLock(which you need to callprint) means that no other thread can be printing a backtrace, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, right. probably the safety comment should just be moved inside that function then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done