Open rukai opened 1 year ago
I would prefer if this crate does not try to be clever about stack traces and instead leaves this up to the user of the library. In particular due to the fact that the top of the stack requires different handling with regards to the instruction addr compared to all other frames makes it for some cases important to understand if the stack has been truncated or not.
Backtrace-rs already filters itself away, so the top of the printed backtrace is not the top of the actual stack. Also the libstd api allows you to choose if anything should be filtered or not.
I would prefer if this crate does not try to be clever about stack traces and instead leaves this up to the user of the library.
Surely it could just be something that can be toggled by the user? (and not impact existing users)
Also, something that came up while @Gankra and I were discussing such functionality: what if not just the filtering, but __rust_begin_short_backtrace
/__rust_end_short_backtrace
themselves were provided by backtrace
(as a "please hide these implementation details" bracketing system), and then libstd also used that?
That way, nothing would be hardcoding implementation details of anything else, and the backtrace
crate could even check for its specific full symbol names (e.g. backtrace::short::begin
/backtrace::short::end
etc.), instead of just .contains
with the function names.
I was considering proposing adding some alternatives to Backtrace::frames. Specifically:
Backtrace::short_frames_strict
: reproduces the current behaviour of std where it only uses the two delimiter framesBacktrace::short_frames
: as above, but also does "nice" cleanups like hiding rust_begin_unwind
and panic_fmt
which are still garbage frames as far as end users are concerned.These APIs should exist because without them people don't know how to properly use this library and are shipping broken things like just using a hardcoded .skip(N)
on the frames, absent any docs or APIs to guide them:
tbc I'm happy to implement this if it will be accepted. until then i'm just going to implement the same logic in the above libraries to fix the ecosystem
Also the libstd api allows you to choose if anything should be filtered or not.
Also I couldn't find any such API in std::backtrace? Are you just referring to env vars?
I've created the backtrace-ext crate with a short_frames_strict function as described above. miette now uses it.
rustc inserts frames
std::sys_common::backtrace::__rust_end_short_backtrace
andstd::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:
Currently the backtrace looks like this:
With filtering it would look like:
We could keep the full unfiltered version available via "{:#?}" formatting.