-
Notifications
You must be signed in to change notification settings - Fork 352
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
Support generating backtraces in emulated code #1033
Comments
So far our strategy has been to implement the platform specific logic, but just looking at https://github.com/rust-lang/backtrace-rs/blob/master/src/windows.rs makes me shiver. For things like this where there's no use in having miri run the platform specific logic to find UB, I think it would be fine to add |
Supporting the full The main problem is Of course, Miri doesn't have a flat address space. I think the best approach would be to cast This approach avoids allocating any additional memory, so repeatedly calling |
Neat trick, but how do we do the inverse? Creating a |
Maybe return |
How so? We can check if it's in the valid range for a Span - it may be a nonsensical span, but we can easily handle that case. |
I assumed that rustc would simply panic on out of bounds spans I like the function pointer idea |
Using function pointers would make us lose precise line number information, which seems like a really unfortunate limitation. |
You can use the offset part of the pointer to encode an additional 32bit |
@oli-obk: I'm not sure what you mean, or how that could work on 32-bit platforms. Using the lower |
I guess. It just feels a bit hacky that we'd expose a compiler internal integer. Especially since they can change arbitrarily between runs |
Doesn't that apply to Miri function pointers as well? |
You can't get at that information. It's not exposed to the program. in https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=96c11f4863d9816868d9a09b0198a26b you will not see a rustc specific integer, but just the integer that you get from the ptr2int conversion which is a program-specific counter |
This was implemented in several PRs (the last one was #1589) |
Once rust-lang/rust#60026 is merged, Miri will have support for panicking via unwinding.
However, we will still lack support for printing backtraces from the panic hook (currently, Miri builds
libstd
without thebacktrace
feature, so nothing is printed).Unlike the implementation of panicking, getting this to work will require modifying a third party-crate. Specifically, we will need to modify backtrace-rs, which is used by
libstd
to generate backtraces.This will require Miri to expose some sort of API to the outside world for the first time. At a minimum,
backtrace-rs
needs a way to get a list ofFrame
s from Miri (the definition ofFrame
is up to us).This bring up an interesting question: do we ever want to stabilize this API? For printing panic backtraces, it's sufficient for this API to be unstable - Miri builds libstd using nightly Rust, so we can just enable some internal feature. However, it seems reasonable for third-party crates using
backtrace-rs
to 'just work' under Miri. This means that whatever mechanismbacktrace-rs
uses to communicate with Miri will (eventually) need to be stable as well.One way to go about this would be to have Miri define some special foreign function (e.g.
__rust_miri_magic_get_backtrace
), rather than an intrinsic. Conceptually, this would make Miri just another target platform, which happens to guarantee the existence of some foreign function.The text was updated successfully, but these errors were encountered: