about summary refs log tree commit diff
path: root/library/std/src/sys/windows/stack_overflow_uwp.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-02-02 22:03:23 +0000
committerbors <bors@rust-lang.org>2022-02-02 22:03:23 +0000
commitb3800860e123443ffada615538926beed6bc4f85 (patch)
tree4c666bc883ba940757f1f63ee612d8f8edc5bfc2 /library/std/src/sys/windows/stack_overflow_uwp.rs
parent27f5d830eb11cd7bdc834d6f0d78120976f75443 (diff)
parent85930c8f444e1ece1c92a0f9e39814f72d867e43 (diff)
downloadrust-b3800860e123443ffada615538926beed6bc4f85.tar.gz
rust-b3800860e123443ffada615538926beed6bc4f85.zip
Auto merge of #93101 - Mark-Simulacrum:library-backtrace, r=yaahc
Support configuring whether to capture backtraces at runtime

Tracking issue: https://github.com/rust-lang/rust/issues/93346

This adds a new API to the `std::panic` module which configures whether and how the default panic hook will emit a backtrace when a panic occurs.

After discussion with `@yaahc` on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/backtrace.20lib.20vs.2E.20panic), this PR chooses to avoid adjusting or seeking to provide a similar API for the (currently unstable) std::backtrace API. It seems likely that the users of that API may wish to expose more specific settings rather than just a global one (e.g., emulating the `env_logger`, `tracing` per-module configuration) to avoid the cost of capture in hot code. The API added here could plausibly be copied and/or re-exported directly from std::backtrace relatively easily, but I don't think that's the right call as of now.

```rust
mod panic {
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    #[non_exhaustive]
    pub enum BacktraceStyle {
        Short,
        Full,
        Off,
    }
    fn set_backtrace_style(BacktraceStyle);
    fn get_backtrace_style() -> Option<BacktraceStyle>;
}
```

Several unresolved questions:

* Do we need to move to a thread-local or otherwise more customizable strategy for whether to capture backtraces? See [this comment](https://github.com/rust-lang/rust/pull/79085#issuecomment-727845826) for some potential use cases for this.
   * Proposed answer: no, leave this for third-party hooks.
* Bikeshed on naming of all the options, as usual.
* Should BacktraceStyle be moved into `std::backtrace`?
   * It's already somewhat annoying to import and/or re-type the `std::panic::` prefix necessary to use these APIs, probably adding a second module to the mix isn't worth it.

Note that PR #79085 proposed a much simpler API, but particularly in light of the desire to fully replace setting environment variables via `env::set_var` to control the backtrace API, a more complete API seems preferable. This PR likely subsumes that one.
Diffstat (limited to 'library/std/src/sys/windows/stack_overflow_uwp.rs')
0 files changed, 0 insertions, 0 deletions