-
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
std: Depend on backtrace
crate from crates.io
#60852
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2cb5fcc
to
0d517eb
Compare
This comment has been minimized.
This comment has been minimized.
0d517eb
to
5015eef
Compare
This comment has been minimized.
This comment has been minimized.
5015eef
to
947642f
Compare
This comment has been minimized.
This comment has been minimized.
947642f
to
d64b071
Compare
This comment has been minimized.
This comment has been minimized.
@sfackler would you be up for doing a quick overview of the backtrace crate itself? That's where sort of the real meat of this PR is, especially in all the changes leading up to getting parity with libstd (msvc inlining support, libbacktrace on OSX/MinGW, etc) |
Sure - should I be looking at the change in the include-in-std branch? |
@sfackler there's currently only one commit in the branch used here, otherwise taking a look at the |
I took a look through the backtrace crate and have a few minor notes here and there: I don't think this ever panics: Cleanup should be done with a destructor in case the closure panics: unix cfg is a superset of target_os = "linux": ip_lo/ip_hi shenanigans could potentially be replaced by resolving the function information of the address and having more accurate bounds: Might be easier to use LoadLibraryA to avoid the [u16] stuff: This is intended to force an abort via a double panic? Seems like that should at least be documented, and maybe replaced by an explicit abort: |
Ok thanks for taking a look! I've attempted to address all that in these commits, and to clarify the intention is indeed to abort the process due to the usage of C callbacks and the inability to unwind through them, and I figured that |
d64b071
to
6ab0b72
Compare
Ok I've done the publication to crates.io and everything should be ready for an r+ here, although before doing so I wanted to make sure I called out the differences between today's backtraces and this PR. The only strategy that shows differences is libbacktrace, and today libstd does:
After this PR, the difference is that during each invocation fo Given a program like this: fn main() {
panic!();
} today this yields:
but with this PR we get
Take a look at Also of note is I'm honestly not entirely sure why the debuginfo names for each frame in libstd is so terse. I figure it has something to do with our debuginfo, but It may just be that in the long run this places more pressure on us to clean up the libstd backtraces perhaps? I'm not sure how others think about doing that now vs later. |
That seems pretty bad - is the theory that it's specifically limited to symbols in libstd? |
So I'm actually getting pretty confusing behavior and I don't really know why. If libstd is built with
If libstd is built with
however if I compile user code with
(note the lack of filename/line number) and with
So I seem to have concluded that:
... ... and on further digging things just seem to keep getting weirder. I'm just using the latest stable release for these tests in the
This means that the way my program is compiled apparently affects symbol resolution for upstream crates somehow. I have no idea how though! @michaelwoerister would you be able to help shed some light here perhaps? This all seems highly related to various bits and pieces of debuginfo that we're emitting. Could you maybe provide a bit of background to what we're specifying in debuginfo as the name of each function? Do you know why there might be such inconsistent results for a library like |
@alexcrichton maybe related #61007? |
This comment has been minimized.
This comment has been minimized.
std: Depend on `backtrace` crate from crates.io This commit removes all in-tree support for generating backtraces in favor of depending on the `backtrace` crate on crates.io. This resolves a very longstanding piece of duplication where the standard library has long contained the ability to generate a backtrace on panics, but the code was later extracted and duplicated on crates.io with the `backtrace` crate. Since that fork each implementation has seen various improvements one way or another, but typically `backtrace`-the-crate has lagged behind libstd in one way or another. The goal here is to remove this duplication of a fairly critical piece of code and ensure that there's only one source of truth for generating backtraces between the standard library and the crate on crates.io. Recently I've been working to bring the `backtrace` crate on crates.io up to speed with the support in the standard library which includes: * Support for `StackWalkEx` on MSVC to recover inline frames with debuginfo. * Using `libbacktrace` by default on MinGW targets. * Supporting `libbacktrace` on OSX as an option. * Ensuring all the requisite support in `backtrace`-the-crate compiles with `#![no_std]`. * Updating the `libbacktrace` implementation in `backtrace`-the-crate to initialize the global state with the correct filename where necessary. After reviewing the code in libstd the `backtrace` crate should be at exact feature parity with libstd today. The backtraces generated should have the same symbols and same number of frames in general, and there's not known divergence from libstd currently. Note that one major difference between libstd's backtrace support and the `backtrace` crate is that on OSX the crates.io crate enables the `coresymbolication` feature by default. This feature, however, uses private internal APIs that aren't published for OSX. While they provide more accurate backtraces this isn't appropriate for libstd distributed as a binary, so libstd's dependency on the `backtrace` crate explicitly disables this feature and forces OSX to use `libbacktrace` as a symbolication strategy. The long-term goal of this refactoring is to eventually move us towards a world where we can drop `libbacktrace` entirely and simply use Gimli and the surrounding crates for backtrace support. That's still aways off but hopefully will much more easily enabled by having the source of truth for backtraces live in crates.io! Procedurally if we go forward with this I'd like to transfer the `backtrace-rs` crate to the rust-lang GitHub organization as well, but I figured I'd hold off on that until we get closer to merging.
This comment has been minimized.
This comment has been minimized.
This commit removes all in-tree support for generating backtraces in favor of depending on the `backtrace` crate on crates.io. This resolves a very longstanding piece of duplication where the standard library has long contained the ability to generate a backtrace on panics, but the code was later extracted and duplicated on crates.io with the `backtrace` crate. Since that fork each implementation has seen various improvements one way or another, but typically `backtrace`-the-crate has lagged behind libstd in one way or another. The goal here is to remove this duplication of a fairly critical piece of code and ensure that there's only one source of truth for generating backtraces between the standard library and the crate on crates.io. Recently I've been working to bring the `backtrace` crate on crates.io up to speed with the support in the standard library which includes: * Support for `StackWalkEx` on MSVC to recover inline frames with debuginfo. * Using `libbacktrace` by default on MinGW targets. * Supporting `libbacktrace` on OSX as an option. * Ensuring all the requisite support in `backtrace`-the-crate compiles with `#![no_std]`. * Updating the `libbacktrace` implementation in `backtrace`-the-crate to initialize the global state with the correct filename where necessary. After reviewing the code in libstd the `backtrace` crate should be at exact feature parity with libstd today. The backtraces generated should have the same symbols and same number of frames in general, and there's not known divergence from libstd currently. Note that one major difference between libstd's backtrace support and the `backtrace` crate is that on OSX the crates.io crate enables the `coresymbolication` feature by default. This feature, however, uses private internal APIs that aren't published for OSX. While they provide more accurate backtraces this isn't appropriate for libstd distributed as a binary, so libstd's dependency on the `backtrace` crate explicitly disables this feature and forces OSX to use `libbacktrace` as a symbolication strategy. The long-term goal of this refactoring is to eventually move us towards a world where we can drop `libbacktrace` entirely and simply use Gimli and the surrounding crates for backtrace support. That's still aways off but hopefully will much more easily enabled by having the source of truth for backtraces live in crates.io! Procedurally if we go forward with this I'd like to transfer the `backtrace-rs` crate to the rust-lang GitHub organization as well, but I figured I'd hold off on that until we get closer to merging.
083cc82
to
d1040fe
Compare
@bors: r=sfackler |
📌 Commit d1040fe has been approved by |
std: Depend on `backtrace` crate from crates.io This commit removes all in-tree support for generating backtraces in favor of depending on the `backtrace` crate on crates.io. This resolves a very longstanding piece of duplication where the standard library has long contained the ability to generate a backtrace on panics, but the code was later extracted and duplicated on crates.io with the `backtrace` crate. Since that fork each implementation has seen various improvements one way or another, but typically `backtrace`-the-crate has lagged behind libstd in one way or another. The goal here is to remove this duplication of a fairly critical piece of code and ensure that there's only one source of truth for generating backtraces between the standard library and the crate on crates.io. Recently I've been working to bring the `backtrace` crate on crates.io up to speed with the support in the standard library which includes: * Support for `StackWalkEx` on MSVC to recover inline frames with debuginfo. * Using `libbacktrace` by default on MinGW targets. * Supporting `libbacktrace` on OSX as an option. * Ensuring all the requisite support in `backtrace`-the-crate compiles with `#![no_std]`. * Updating the `libbacktrace` implementation in `backtrace`-the-crate to initialize the global state with the correct filename where necessary. After reviewing the code in libstd the `backtrace` crate should be at exact feature parity with libstd today. The backtraces generated should have the same symbols and same number of frames in general, and there's not known divergence from libstd currently. Note that one major difference between libstd's backtrace support and the `backtrace` crate is that on OSX the crates.io crate enables the `coresymbolication` feature by default. This feature, however, uses private internal APIs that aren't published for OSX. While they provide more accurate backtraces this isn't appropriate for libstd distributed as a binary, so libstd's dependency on the `backtrace` crate explicitly disables this feature and forces OSX to use `libbacktrace` as a symbolication strategy. The long-term goal of this refactoring is to eventually move us towards a world where we can drop `libbacktrace` entirely and simply use Gimli and the surrounding crates for backtrace support. That's still aways off but hopefully will much more easily enabled by having the source of truth for backtraces live in crates.io! Procedurally if we go forward with this I'd like to transfer the `backtrace-rs` crate to the rust-lang GitHub organization as well, but I figured I'd hold off on that until we get closer to merging.
☀️ Test successful - checks-travis, status-appveyor |
I've now transferred the repository to live in rust-lang |
@alexcrichton could this change have caused backtraces under macosx to refer to each scope only as |
Yep that's probably this! Mind opening an issue and I can debug next week? |
Filed #61416. Thank you! |
This commit removes all in-tree support for generating backtraces in
favor of depending on the
backtrace
crate on crates.io. This resolvesa very longstanding piece of duplication where the standard library has
long contained the ability to generate a backtrace on panics, but the
code was later extracted and duplicated on crates.io with the
backtrace
crate. Since that fork each implementation has seen variousimprovements one way or another, but typically
backtrace
-the-crate haslagged behind libstd in one way or another.
The goal here is to remove this duplication of a fairly critical piece
of code and ensure that there's only one source of truth for generating
backtraces between the standard library and the crate on crates.io.
Recently I've been working to bring the
backtrace
crate on crates.ioup to speed with the support in the standard library which includes:
StackWalkEx
on MSVC to recover inline frames withdebuginfo.
libbacktrace
by default on MinGW targets.libbacktrace
on OSX as an option.backtrace
-the-crate compileswith
#![no_std]
.libbacktrace
implementation inbacktrace
-the-crate toinitialize the global state with the correct filename where necessary.
After reviewing the code in libstd the
backtrace
crate should be atexact feature parity with libstd today. The backtraces generated should
have the same symbols and same number of frames in general, and there's
not known divergence from libstd currently.
Note that one major difference between libstd's backtrace support and
the
backtrace
crate is that on OSX the crates.io crate enables thecoresymbolication
feature by default. This feature, however, usesprivate internal APIs that aren't published for OSX. While they provide
more accurate backtraces this isn't appropriate for libstd distributed
as a binary, so libstd's dependency on the
backtrace
crate explicitlydisables this feature and forces OSX to use
libbacktrace
as asymbolication strategy.
The long-term goal of this refactoring is to eventually move us towards
a world where we can drop
libbacktrace
entirely and simply use Gimliand the surrounding crates for backtrace support. That's still aways off
but hopefully will much more easily enabled by having the source of
truth for backtraces live in crates.io!
Procedurally if we go forward with this I'd like to transfer the
backtrace-rs
crate to the rust-lang GitHub organization as well, but Ifigured I'd hold off on that until we get closer to merging.