rust-lang / rust-lang/backtrace-rs

Filter frames by __rust_end_short_backtrace and __rust_begin_short_backtrace

Open
#502 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
628
Forks
291
PR merge metrics
No merged PRs in 30d

Description

rustc inserts frames std::sys_common::backtrace::__rust_end_short_backtrace and std::sys_common::backtrace::__rust_begin_short_backtrace so that the internal backtrace implementation can filter out noise from backtrace capturing.

Can we make use of these in the backtrace crate in order to have equivalent noise removal?

I'm not sure if these frame names are stable but I figure that we can just fall back to the old filtering implementation if they are missing?

Edit:
Oh huh, I just realized even std::backtrace::Backtrace isnt filtering these out... I filed an issue for it here: https://github.com/rust-lang/rust/issues/105413

Example:

With the following program:

use backtrace::Backtrace;

fn setup() {
    std::panic::set_hook(Box::new(|panic| {
        println!("{:?}", Backtrace::new());
    }));
}

fn run() {
    panic!("OOPS");
}

fn main() {
    setup();
    run();
}

Currently the backtrace looks like this:

   0: foo::setup::{{closure}}
             at src/main.rs:4:26
   1: std::panicking::rust_panic_with_hook
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:702:17
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:586:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18
   4: rust_begin_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
   5: core::panicking::panic_fmt
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
   6: foo::run
             at src/main.rs:9:5
   7: foo::main
             at src/main.rs:14:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:122:18
  10: std::rt::lang_start::{{closure}}
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:166:18
  11: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283:13
      std::panicking::try::do_call
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
      std::panicking::try
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
      std::panic::catch_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
      std::panicking::try
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
      std::panic::catch_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
      std::rt::lang_start_internal
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:20
  12: std::rt::lang_start
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:165:17
  13: main
  14: <unknown>
  15: __libc_start_main
  16: _start
             at /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:115

With filtering it would look like:

   0: rust_begin_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
   2: foo::run
             at src/main.rs:9:5
   3: foo::main
             at src/main.rs:14:5
   4: core::ops::function::FnOnce::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5

We could keep the full unfiltered version available via "{:#?}" formatting.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the backtrace crate's existing frame-filtering implementation and reproduce the issue's example program. Check how the named __rust_end_short_backtrace and __rust_begin_short_backtrace frames are represented, preserve the old behavior when they are absent, and verify that normal formatting removes the noise while "{:#?}" retains the full backtrace.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.