提交 e296ed32 编写于 作者: J Jonas Schievink

Move librustc panic handler into the new one

上级 a8926a5e
......@@ -15,7 +15,6 @@ bitflags = "1.0"
fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
jobserver = "0.1"
lazy_static = "1.0.0"
num_cpus = "1.0"
scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
......
......@@ -68,7 +68,6 @@
#[macro_use] extern crate bitflags;
extern crate getopts;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate scoped_tls;
#[cfg(windows)]
extern crate libc;
......
......@@ -5,17 +5,13 @@
use std::cell::{RefCell, Cell};
use std::fmt::Debug;
use std::hash::Hash;
use std::panic;
use std::env;
use std::time::{Duration, Instant};
use std::sync::mpsc::{Sender};
use syntax_pos::{SpanData};
use syntax::symbol::{Symbol, sym};
use rustc_macros::HashStable;
use crate::ty::TyCtxt;
use crate::dep_graph::{DepNode};
use lazy_static;
use crate::session::Session;
#[cfg(test)]
......@@ -31,39 +27,6 @@
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
lazy_static! {
static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
let hook = panic::take_hook();
panic::set_hook(Box::new(panic_hook));
hook
};
}
fn panic_hook(info: &panic::PanicInfo<'_>) {
(*DEFAULT_HOOK)(info);
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
if backtrace {
TyCtxt::try_print_query_stack();
}
#[cfg(windows)]
unsafe {
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
extern "system" {
fn DebugBreak();
}
// Trigger a debugger if we crashed during bootstrap.
DebugBreak();
}
}
}
pub fn install_panic_hook() {
lazy_static::initialize(&DEFAULT_HOOK);
}
/// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
#[derive(Clone,Debug)]
pub struct ProfQDumpParams {
......
......@@ -38,8 +38,8 @@
use rustc::lint::Lint;
use rustc::lint;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::util::common::{ErrorReported, install_panic_hook, print_time_passes_entry};
use rustc::util::common::{set_time_depth, time};
use rustc::ty::TyCtxt;
use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
use rustc_metadata::locator;
use rustc_metadata::cstore::CStore;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
......@@ -164,8 +164,6 @@ pub fn run_compiler(
None => return Ok(()),
};
install_panic_hook();
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
let mut dummy_config = |sopts, cfg, diagnostic_output| {
......@@ -1169,9 +1167,10 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
}
pub fn report_ice(info: &panic::PanicInfo<'_>) {
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
(*DEFAULT_HOOK)(info);
// Thread panicked without emitting a fatal diagnostic
// Print the infamous ICE message
eprintln!();
let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
......@@ -1212,6 +1211,24 @@ pub fn report_ice(info: &panic::PanicInfo<'_>) {
note,
errors::Level::Note);
}
// If backtraces are enabled, also print the query stack
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
if backtrace {
TyCtxt::try_print_query_stack();
}
#[cfg(windows)]
unsafe {
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
extern "system" {
fn DebugBreak();
}
// Trigger a debugger if we crashed during bootstrap
DebugBreak();
}
}
}
pub fn install_ice_hook() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册