diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-30 07:18:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-30 07:18:11 +0200 |
| commit | 23f86255ef7cf044c50348d7fa937ca63f94896b (patch) | |
| tree | 4ca7d97204044ad670d0cad6203bd58365ca02b6 /src | |
| parent | 639116505a6c27a1fe4453aa6c108bc4e4976b2b (diff) | |
| parent | beeb2b13cc40a550d2bc60361d6fa77cfb02e698 (diff) | |
| download | rust-23f86255ef7cf044c50348d7fa937ca63f94896b.tar.gz rust-23f86255ef7cf044c50348d7fa937ca63f94896b.zip | |
Rollup merge of #115272 - RalfJung:miri-error-print, r=saethlin
miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors This should fix the missing output encountered [here](https://github.com/rust-lang/rust/issues/115145#issuecomment-1694334410). r? `@saethlin`
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/diagnostics.rs | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index f3285ccf917..799a9a8e4be 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -1,9 +1,8 @@ -use std::fmt; +use std::fmt::{self, Write}; use std::num::NonZeroU64; use log::trace; -use rustc_const_eval::ReportErrorExt; use rustc_errors::DiagnosticMessage; use rustc_span::{source_map::DUMMY_SP, SpanData, Symbol}; use rustc_target::abi::{Align, Size}; @@ -271,10 +270,13 @@ pub fn report_error<'tcx, 'mir>( }; (title, helps) } else { - #[rustfmt::skip] let title = match e.kind() { - UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(e)) if matches!(e.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) => - bug!("This validation error should be impossible in Miri: {:?}", e.kind), + UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(validation_err)) + if matches!(validation_err.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) => + { + ecx.handle_ice(); // print interpreter backtrace + bug!("This validation error should be impossible in Miri: {}", ecx.format_error(e)); + } UndefinedBehavior(_) => "Undefined Behavior", ResourceExhaustion(_) => @@ -290,8 +292,10 @@ pub fn report_error<'tcx, 'mir>( InvalidProgramInfo::Layout(..) ) => "post-monomorphization error", - kind => - bug!("This error should be impossible in Miri: {kind:?}"), + _ => { + ecx.handle_ice(); // print interpreter backtrace + bug!("This error should be impossible in Miri: {}", ecx.format_error(e)); + } }; #[rustfmt::skip] let helps = match e.kind() { @@ -333,30 +337,22 @@ pub fn report_error<'tcx, 'mir>( let stacktrace = ecx.generate_stacktrace(); let (stacktrace, was_pruned) = prune_stacktrace(stacktrace, &ecx.machine); - let (e, backtrace) = e.into_parts(); - backtrace.print_backtrace(); - - // We want to dump the allocation if this is `InvalidUninitBytes`. Since `add_args` consumes - // the `InterpError`, we extract the variables it before that. - let extra = match e { - UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) => - Some((alloc_id, access)), - _ => None, - }; - // FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the - // label and arguments from the InterpError. - let e = { - let handler = &ecx.tcx.sess.parse_sess.span_diagnostic; - let mut diag = ecx.tcx.sess.struct_allow(""); - let msg = e.diagnostic_message(); - e.add_args(handler, &mut diag); - let s = handler.eagerly_translate_to_string(msg, diag.args()); - diag.cancel(); - s - }; + // We want to dump the allocation if this is `InvalidUninitBytes`. Since `format_error` consumes `e`, we compute the outut early. + let mut extra = String::new(); + match e.kind() { + UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) => { + writeln!( + extra, + "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:", + range = access.bad, + ).unwrap(); + writeln!(extra, "{:?}", ecx.dump_alloc(*alloc_id)).unwrap(); + } + _ => {} + } - msg.insert(0, e); + msg.insert(0, ecx.format_error(e)); report_msg( DiagLevel::Error, @@ -375,6 +371,8 @@ pub fn report_error<'tcx, 'mir>( ); } + eprint!("{extra}"); // newlines are already in the string + // Debug-dump all locals. for (i, frame) in ecx.active_thread_stack().iter().enumerate() { trace!("-------------------"); @@ -385,15 +383,6 @@ pub fn report_error<'tcx, 'mir>( } } - // Extra output to help debug specific issues. - if let Some((alloc_id, access)) = extra { - eprintln!( - "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:", - range = access.bad, - ); - eprintln!("{:?}", ecx.dump_alloc(alloc_id)); - } - None } |
