about summary refs log tree commit diff
path: root/src/libstd/backtrace.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-493/+0
2020-07-23Auto merge of #74613 - Mark-Simulacrum:revert-gimli, r=nnethercotebors-10/+11
Revert libbacktrace -> gimli This reverts 4cbd265c119cb1a5eb92e98d2bb93466f05efa46 028f8d7b85898683b99e05564cd2976c7e0d5b43 13db3cc1e8d2fd4b8e7c74d91002274d7b62801b d7a36d8964c927863faef5d3b42da08f37e5896c (and technically 79673d300915f846726c27b9e1974dc451013ee9 but it's made empty by previous reverts). The current plan is to land this PR as a temporary change, so that we can get a better handle on the regressions introduced by it. Trying to fix/examine them in master is difficult, and we want to be better able to evaluate them without impact to other PRs being landed in the mean time. That said, it is currently *my* belief that gimli, in one form or another, will need to land sometime soon. I think it's quite likely that it may slip a week or two, but I would personally push for re-landing it then "regardless" of the regressions. We should try to focus efforts on understanding and removing as much of the performance impact as possible, as everyone pretty much agrees that it should be quite minimal (and entirely in the linker, basically). r? @nnethercote
2020-07-22Update src/libstd/backtrace.rsJane Lusby-1/+1
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-07-22Revert "std: Switch from libbacktrace to gimli"Mark Rousskov-10/+11
This reverts commit 13db3cc1e8d2fd4b8e7c74d91002274d7b62801b.
2020-07-18remove trailing semiJane Lusby-1/+1
2020-07-18add a Backtrace::disabled functionJane Lusby-0/+6
2020-07-17std: Switch from libbacktrace to gimliAlex Crichton-11/+10
This commit is a proof-of-concept for switching the standard library's backtrace symbolication mechanism on most platforms from libbacktrace to gimli. The standard library's support for `RUST_BACKTRACE=1` requires in-process parsing of object files and DWARF debug information to interpret it and print the filename/line number of stack frames as part of a backtrace. Historically this support in the standard library has come from a library called "libbacktrace". The libbacktrace library seems to have been extracted from gcc at some point and is written in C. We've had a lot of issues with libbacktrace over time, unfortunately, though. The library does not appear to be actively maintained since we've had patches sit for months-to-years without comments. We have discovered a good number of soundness issues with the library itself, both when parsing valid DWARF as well as invalid DWARF. This is enough of an issue that the libs team has previously decided that we cannot feed untrusted inputs to libbacktrace. This also doesn't take into account the portability of libbacktrace which has been difficult to manage and maintain over time. While possible there are lots of exceptions and it's the main C dependency of the standard library right now. For years it's been the desire to switch over to a Rust-based solution for symbolicating backtraces. It's been assumed that we'll be using the Gimli family of crates for this purpose, which are targeted at safely and efficiently parsing DWARF debug information. I've been working recently to shore up the Gimli support in the `backtrace` crate. As of a few weeks ago the `backtrace` crate, by default, uses Gimli when loaded from crates.io. This transition has gone well enough that I figured it was time to start talking seriously about this change to the standard library. This commit is a preview of what's probably the best way to integrate the `backtrace` crate into the standard library with the Gimli feature turned on. While today it's used as a crates.io dependency, this commit switches the `backtrace` crate to a submodule of this repository which will need to be updated manually. This is not done lightly, but is thought to be the best solution. The primary reason for this is that the `backtrace` crate needs to do some pretty nontrivial filesystem interactions to locate debug information. Working without `std::fs` is not an option, and while it might be possible to do some sort of trait-based solution when prototyped it was found to be too unergonomic. Using a submodule allows the `backtrace` crate to build as a submodule of the `std` crate itself, enabling it to use `std::fs` and such. Otherwise this adds new dependencies to the standard library. This step requires extra attention because this means that these crates are now going to be included with all Rust programs by default. It's important to note, however, that we're already shipping libbacktrace with all Rust programs by default and it has a bunch of C code implementing all of this internally anyway, so we're basically already switching already-shipping functionality to Rust from C. * `object` - this crate is used to parse object file headers and contents. Very low-level support is used from this crate and almost all of it is disabled. Largely we're just using struct definitions as well as convenience methods internally to read bytes and such. * `addr2line` - this is the main meat of the implementation for symbolication. This crate depends on `gimli` for DWARF parsing and then provides interfaces needed by the `backtrace` crate to turn an address into a filename / line number. This crate is actually pretty small (fits in a single file almost!) and mirrors most of what `dwarf.c` does for libbacktrace. * `miniz_oxide` - the libbacktrace crate transparently handles compressed debug information which is compressed with zlib. This crate is used to decompress compressed debug sections. * `gimli` - not actually used directly, but a dependency of `addr2line`. * `adler32`- not used directly either, but a dependency of `miniz_oxide`. The goal of this change is to improve the safety of backtrace symbolication in the standard library, especially in the face of possibly malformed DWARF debug information. Even to this day we're still seeing segfaults in libbacktrace which could possibly become security vulnerabilities. This change should almost entirely eliminate this possibility whilc also paving the way forward to adding more features like split debug information. Some references for those interested are: * Original addition of libbacktrace - #12602 * OOM with libbacktrace - #24231 * Backtrace failure due to use of uninitialized value - #28447 * Possibility to feed untrusted data to libbacktrace - #21889 * Soundness fix for libbacktrace - #33729 * Crash in libbacktrace - #39468 * Support for macOS, never merged - ianlancetaylor/libbacktrace#2 * Performance issues with libbacktrace - #29293, #37477 * Update procedure is quite complicated due to how many patches we need to carry - #50955 * Libbacktrace doesn't work on MinGW with dynamic libs - #71060 * Segfault in libbacktrace on macOS - #71397 Switching to Rust will not make us immune to all of these issues. The crashes are expected to go away, but correctness and performance may still have bugs arise. The gimli and `backtrace` crates, however, are actively maintained unlike libbacktrace, so this should enable us to at least efficiently apply fixes as situations come up.
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-1/+1
2020-03-09Write backtrace fmt test using relative pathsDavid Tolnay-5/+5
For some reason the absolute paths were formatted differently on the armhf-gnu target. thread '<unnamed>' panicked at 'assertion failed: `(left == right)` left: `"Backtrace [\n { fn: \"__rust_maybe_catch_panic\" },\n { fn: \"std::rt::lang_start_internal\", file: \"./rust/rt.rs\", line: 300 },\n { fn: \"std::rt::lang_start\", file: \"./rust/rt.rs\", line: 400 },\n]"`, right: `"Backtrace [\n { fn: \"__rust_maybe_catch_panic\" },\n { fn: \"std::rt::lang_start_internal\", file: \"/rust/rt.rs\", line: 300 },\n { fn: \"std::rt::lang_start\", file: \"/rust/rt.rs\", line: 400 },\n]"`', src/libstd/backtrace.rs:486:5
2020-03-09Add test of Debug representation of BacktraceDavid Tolnay-0/+52
2020-03-09Make it possible to instantiate hardcoded Backtrace from testDavid Tolnay-3/+28
2020-03-09Change disabled and unsupported backtraces to print using placeholder styleDavid Tolnay-2/+2
2020-03-09Add quotes around filename in Backtrace debugDavid Tolnay-1/+1
2020-03-09Remove quotes around unknown fn placeholder in backtraceDavid Tolnay-1/+1
2020-02-28use is_empty() instead of len() == x to determine if structs are empty.Matthias Krüger-1/+1
2020-02-11remove intentionally failing testJane Lusby-18/+0
2020-02-10backwards again, god damnitJane Lusby-1/+1
2020-02-10rule over the code in libstd with an iron fistJane Lusby-9/+4
2020-02-10maximum alternative consistency!Jane Lusby-2/+9
2020-02-10make symbol printing consistent with backtrace_rsJane Lusby-2/+3
2020-02-10add nice alt fmt for debugJane Lusby-6/+6
2020-02-10use debug_map and skip empty framesJane Lusby-5/+10
2020-02-10remove Some from fn nameJane Lusby-1/+1
2020-02-10final format cleanupsJane Lusby-1/+8
2020-02-10make it compileJane Lusby-1/+1
2020-02-10remove unnecessary Debug impl for BacktraceFrameJane Lusby-6/+0
2020-02-10remove unnecessary derivesJane Lusby-2/+0
2020-02-10less noisy formatJane Lusby-7/+37
2020-02-10Get vaguely working with a test for checking outputJane Lusby-1/+26
2020-02-10Add initial debug fmt for BacktraceJane Lusby-6/+19
2019-11-29Format libstd with rustfmtDavid Tolnay-2/+2
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-10-02BacktraceStatus: add Eq implBen Boeckel-1/+1
See discussion on #53487.
2019-09-14rename the crate, not the featureRalf Jung-0/+1
2019-09-09std: Add a `backtrace` moduleAlex Crichton-0/+352
This commit adds a `backtrace` module to the standard library, as designed in [RFC 2504]. The `Backtrace` type is intentionally very conservative, effectively only allowing capturing it and printing it. Additionally this commit also adds a `backtrace` method to the `Error` trait which defaults to returning `None`, as specified in [RFC 2504]. More information about the design here can be found in [RFC 2504] and in the [tracking issue]. Implementation-wise this is all based on the `backtrace` crate and very closely mirrors the `backtrace::Backtrace` type on crates.io. Otherwise it's pretty standard in how it handles everything internally. [RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md [tracking issue]: https://github.com/rust-lang/rust/issues/53487 cc #53487