-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Expose Frames Iterator for the Backtrace Type #78299
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
372ba21
Expose BacktraceFrame as public
seanchen1991 9b8e4fc
Add empty `frames` method to Backtrace type
seanchen1991 e07b25d
Fill in `frames` function
seanchen1991 277a2a4
Add `Frames` struct
seanchen1991 b4e21e6
Add `as_ref` method for `Frames` type
seanchen1991 43f2774
Remove `Backtrace::frames` method
seanchen1991 7331efe
Remove unnecessary newlines
seanchen1991 b43bcb6
Merge branch 'master' of github.com:rust-lang/rust
seanchen1991 6df53a1
Add `frames` method that doesn't borrow from lock
seanchen1991 37f4f13
Add private clone methods to Frame and BacktraceFrame
seanchen1991 747bb91
Add additional unstable feature flags
seanchen1991 c5d5912
Fix a type in Frames::clone
seanchen1991 30c5494
Add tracking issue
seanchen1991 4e6d2ef
Fix ownership issues
seanchen1991 e7df885
Add doc comments to `Frames` and `BacktraceFrame`
seanchen1991 61b198f
Derive Debug on `Frames`, `BacktraceFrame`, and `RawFrame`
seanchen1991 b4175b1
Tie `Frames` to `Backtrace` via PhantomData
seanchen1991 b30f662
Add `generate_fake_backtrace` fn to backtrace/tests.rs
seanchen1991 c624d22
Add test for empty frames iterator
seanchen1991 de98734
Impl `Iterator` for Frames
seanchen1991 da2e4a9
Fix IntoIter type
seanchen1991 0199300
Get empty iterator test passing
seanchen1991 48e6a38
Add test to check frames iterator count
seanchen1991 ff81eb1
Remove iterator impl on Backtrace Frame
seanchen1991 43b9783
Merge upstream changes
seanchen1991 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
Submodule backtrace
updated
24 files
+6 −17 | .github/workflows/main.yml | |
+4 −4 | Cargo.toml | |
+9 −0 | ci/android-sdk.sh | |
+0 −17 | ci/docker/s390x-unknown-linux-gnu/Dockerfile | |
+0 −1 | ci/run-docker.sh | |
+3 −3 | crates/as-if-std/Cargo.toml | |
+1 −0 | crates/cpp_smoke_test/tests/smoke.rs | |
+0 −2 | crates/dylib-dep/src/lib.rs | |
+10 −0 | src/backtrace/dbghelp.rs | |
+11 −13 | src/backtrace/libunwind.rs | |
+0 −1 | src/backtrace/mod.rs | |
+5 −3 | src/capture.rs | |
+2 −4 | src/lib.rs | |
+2 −2 | src/print.rs | |
+10 −2 | src/symbolize/dbghelp.rs | |
+48 −68 | src/symbolize/gimli.rs | |
+5 −7 | src/symbolize/gimli/coff.rs | |
+4 −6 | src/symbolize/gimli/elf.rs | |
+28 −145 | src/symbolize/gimli/macho.rs | |
+10 −2 | src/symbolize/libbacktrace.rs | |
+0 −2 | src/symbolize/miri.rs | |
+22 −11 | src/symbolize/mod.rs | |
+0 −2 | src/symbolize/noop.rs | |
+1 −6 | tests/concurrent-panics.rs |
This file contains 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 |
---|---|---|
|
@@ -103,6 +103,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; | |
use crate::sync::Once; | ||
use crate::sys_common::backtrace::{lock, output_filename}; | ||
use crate::vec::Vec; | ||
use crate::marker::PhantomData; | ||
|
||
/// A captured OS thread stack backtrace. | ||
/// | ||
|
@@ -147,24 +148,39 @@ fn _assert_send_sync() { | |
_assert::<Backtrace>(); | ||
} | ||
|
||
struct BacktraceFrame { | ||
/// A single frame of a backtrace. | ||
#[derive(Debug)] | ||
#[unstable(feature = "backtrace_frames", issue = "79676")] | ||
pub struct BacktraceFrame { | ||
frame: RawFrame, | ||
symbols: Vec<BacktraceSymbol>, | ||
} | ||
|
||
/// An iterator over the frames of a backtrace, created | ||
/// by the [`frames`] method on [`Backtrace`]. | ||
#[derive(Debug)] | ||
#[unstable(feature = "backtrace_frames", issue = "79676")] | ||
pub struct Frames<'a> { | ||
inner: Vec<BacktraceFrame>, | ||
_backtrace: PhantomData<&'a Backtrace> | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum RawFrame { | ||
Actual(backtrace_rs::Frame), | ||
#[cfg(test)] | ||
Fake, | ||
} | ||
|
||
#[derive(Clone)] | ||
struct BacktraceSymbol { | ||
name: Option<Vec<u8>>, | ||
filename: Option<BytesOrWide>, | ||
lineno: Option<u32>, | ||
colno: Option<u32>, | ||
} | ||
|
||
#[derive(Clone)] | ||
enum BytesOrWide { | ||
Bytes(Vec<u8>), | ||
Wide(Vec<u16>), | ||
|
@@ -353,6 +369,25 @@ impl Backtrace { | |
} | ||
} | ||
|
||
impl<'a> Backtrace { | ||
/// Returns an iterator over the backtrace frames. | ||
#[unstable(feature = "backtrace_frames", issue = "79676")] | ||
pub fn frames(&self) -> Frames<'a> { | ||
if let Inner::Captured(captured) = &self.inner { | ||
let frames = &captured.lock().unwrap().frames; | ||
Frames { | ||
inner: frames.iter().map(|frame| frame.clone()).collect::<Vec<BacktraceFrame>>(), | ||
_backtrace: PhantomData | ||
} | ||
} else { | ||
Frames { | ||
inner: vec![], | ||
_backtrace: PhantomData | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Backtrace { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let capture = match &self.inner { | ||
|
@@ -476,3 +511,24 @@ impl RawFrame { | |
} | ||
} | ||
} | ||
|
||
#[unstable(feature = "backtrace_frames", issue = "79676")] | ||
impl<'a> AsRef<[BacktraceFrame]> for Frames<'a> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be incompatible with lazy resolving of backtraces. Only an Iterator would be compatible. |
||
fn as_ref(&self) -> &[BacktraceFrame] { | ||
&self.inner | ||
} | ||
} | ||
|
||
|
||
#[unstable(feature = "backtrace_frames", issue = "79676")] | ||
impl BacktraceFrame { | ||
// Private clone method so that we don't expose a | ||
// public BacktraceFrame.clone() by deriving Clone | ||
fn clone(&self) -> Self { | ||
BacktraceFrame { | ||
frame: self.frame.clone(), | ||
symbols: self.symbols.clone(), | ||
} | ||
} | ||
} | ||
|
This file contains 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
Submodule stdarch
updated
57 files
Submodule nomicon
updated
4 files
+1 −1 | src/atomics.md | |
+8 −8 | src/destructors.md | |
+4 −4 | src/repr-rust.md | |
+3 −3 | src/vec-final.md |
Submodule reference
updated
8 files
+0 −1 | .gitignore | |
+1 −1 | src/expressions/call-expr.md | |
+4 −14 | src/introduction.md | |
+4 −4 | src/items/functions.md | |
+9 −14 | src/items/unions.md | |
+4 −4 | src/patterns.md | |
+6 −6 | src/type-layout.md | |
+3 −5 | src/types/union.md |
Submodule rust-by-example
updated
14 files
+2 −1 | CODE_OF_CONDUCT.md | |
+1 −0 | CONTRIBUTING.md | |
+6 −6 | README.md | |
+1 −1 | book.toml | |
+2 −1 | src/cargo/deps.md | |
+2 −4 | src/custom_types/structs.md | |
+2 −1 | src/error/iter_result.md | |
+1 −1 | src/error/option_unwrap/map.md | |
+1 −7 | src/flow_control/for.md | |
+1 −4 | src/flow_control/match.md | |
+0 −4 | src/flow_control/match/destructuring/destructure_pointers.md | |
+1 −1 | src/flow_control/match/destructuring/destructure_structures.md | |
+1 −1 | src/hello/print/print_debug.md | |
+4 −2 | src/scope/lifetime/static_lifetime.md |
Submodule llvm-project
updated
195 files
Submodule rls
updated
14 files
+0 −88 | .github/workflows/ci.yml | |
+105 −125 | Cargo.lock | |
+2 −2 | Cargo.toml | |
+5 −1 | README.md | |
+47 −0 | azure-pipelines.yml | |
+33 −0 | ci/azure-install-rust.yml | |
+18 −0 | ci/azure-rustfmt.yml | |
+29 −0 | ci/azure-test.yml | |
+0 −37 | ci/setup-toolchain.sh | |
+0 −11 | rls/src/build/cargo.rs | |
+0 −1 | rust-toolchain | |
+1 −0 | rustfmt.toml | |
+8 −36 | tests/client.rs | |
+2 −2 | tests/fixtures/hover/save_data/test_tooltip_std.rs.0008_027.json |
Submodule rust-installer
updated
11 files
+0 −23 | .github/workflows/ci.yml | |
+9 −0 | .travis.yml | |
+13 −25 | src/combiner.rs | |
+0 −154 | src/compression.rs | |
+2 −7 | src/generator.rs | |
+0 −1 | src/lib.rs | |
+1 −9 | src/main.rs | |
+0 −15 | src/main.yml | |
+57 −19 | src/tarballer.rs | |
+2 −2 | src/util.rs | |
+0 −173 | test.sh |
Submodule rustfmt
updated
74 files
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.
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.
So with this change, what's the way to access the type inside of the
SyncLazy
? Before with theMutex
we hadWhat would we need to change the
let frames
line into to access the underlyingframes
?