mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #12468 - asajeffrey:constellation-remove-panic-channel, r=emilio
Removed panic channel, replaced by integrated logging and issue reporting <!-- Please describe your changes on the following line: --> Remove the previous ad hoc panic channel, replace it by an integrated logging and panicking mechanism, including crash reporting. All thread panics are now reported, not just content threads. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11838 - [X] These changes do not require tests because we don't test error reporting <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12468) <!-- Reviewable:end -->
This commit is contained in:
commit
df1b00d43d
22 changed files with 85 additions and 251 deletions
|
@ -11,12 +11,11 @@ path = "lib.rs"
|
|||
|
||||
[features]
|
||||
# servo as opposed to geckolib
|
||||
servo = ["serde", "serde_macros", "backtrace", "ipc-channel", "app_units/plugins",
|
||||
servo = ["serde", "serde_macros", "ipc-channel", "app_units/plugins",
|
||||
"euclid/plugins", "euclid/unstable", "url/heap_size", "url/serde", "plugins"]
|
||||
|
||||
[dependencies]
|
||||
app_units = "0.2.5"
|
||||
backtrace = {version = "0.2.1", optional = true}
|
||||
bitflags = "0.7"
|
||||
euclid = "0.7.1"
|
||||
getopts = "0.2.11"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#![cfg_attr(feature = "servo", feature(custom_derive))]
|
||||
#![cfg_attr(feature = "servo", feature(fnbox))]
|
||||
#![cfg_attr(feature = "servo", feature(plugin))]
|
||||
#![cfg_attr(feature = "servo", feature(reflect_marker))]
|
||||
#![cfg_attr(feature = "servo", plugin(serde_macros))]
|
||||
|
@ -12,7 +11,6 @@
|
|||
#![deny(unsafe_code)]
|
||||
|
||||
extern crate app_units;
|
||||
#[cfg(feature = "servo")] extern crate backtrace;
|
||||
#[allow(unused_extern_crates)] #[macro_use] extern crate bitflags;
|
||||
extern crate euclid;
|
||||
extern crate getopts;
|
||||
|
@ -31,7 +29,6 @@ pub mod basedir;
|
|||
pub mod geometry;
|
||||
#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod ipc;
|
||||
#[allow(unsafe_code)] pub mod opts;
|
||||
#[cfg(feature = "servo")] pub mod panicking;
|
||||
pub mod prefs;
|
||||
pub mod resource_files;
|
||||
pub mod thread;
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::any::Any;
|
||||
use std::boxed::FnBox;
|
||||
use std::cell::RefCell;
|
||||
use std::panic::{PanicInfo, take_hook, set_hook};
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::thread;
|
||||
|
||||
// only set the panic hook once
|
||||
static HOOK_SET: Once = ONCE_INIT;
|
||||
|
||||
/// TLS data pertaining to how failures should be reported
|
||||
pub struct PanicHandlerLocal {
|
||||
/// failure handler passed through spawn_named_with_send_on_failure
|
||||
pub fail: Box<FnBox(&Any)>
|
||||
}
|
||||
|
||||
thread_local!(pub static LOCAL_INFO: RefCell<Option<PanicHandlerLocal>> = RefCell::new(None));
|
||||
|
||||
/// Set the thread-local panic hook
|
||||
pub fn set_thread_local_hook(local: Box<FnBox(&Any)>) {
|
||||
LOCAL_INFO.with(|i| *i.borrow_mut() = Some(PanicHandlerLocal { fail: local }));
|
||||
}
|
||||
|
||||
/// Initiates the custom panic hook
|
||||
/// Should be called in main() after arguments have been parsed
|
||||
pub fn initiate_panic_hook() {
|
||||
// Set the panic handler only once. It is global.
|
||||
HOOK_SET.call_once(|| {
|
||||
// The original backtrace-printing hook. We still want to call this
|
||||
let hook = take_hook();
|
||||
|
||||
let new_hook = move |info: &PanicInfo| {
|
||||
let payload = info.payload();
|
||||
let name = thread::current().name().unwrap_or("<unknown thread>").to_string();
|
||||
// Notify error handlers stored in LOCAL_INFO if any
|
||||
LOCAL_INFO.with(|i| {
|
||||
if let Some(local_info) = i.borrow_mut().take() {
|
||||
debug!("Thread `{}` failed, notifying error handlers", name);
|
||||
(local_info.fail).call_box((payload, ));
|
||||
} else {
|
||||
hook(&info);
|
||||
}
|
||||
});
|
||||
};
|
||||
set_hook(Box::new(new_hook));
|
||||
});
|
||||
|
||||
}
|
|
@ -2,12 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[cfg(feature = "servo")] use backtrace::Backtrace;
|
||||
#[cfg(feature = "servo")] use ipc_channel::ipc::IpcSender;
|
||||
#[cfg(feature = "servo")] use panicking;
|
||||
#[cfg(feature = "servo")] use serde::Serialize;
|
||||
#[cfg(feature = "servo")] use std::any::Any;
|
||||
#[cfg(feature = "servo")] use thread_state;
|
||||
use std::thread;
|
||||
|
||||
pub fn spawn_named<F>(name: String, f: F)
|
||||
|
@ -15,39 +9,3 @@ pub fn spawn_named<F>(name: String, f: F)
|
|||
{
|
||||
thread::Builder::new().name(name).spawn(f).expect("Thread spawn failed");
|
||||
}
|
||||
|
||||
/// Arrange to send a particular message to a channel if the thread fails.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn spawn_named_with_send_on_panic<F, Id>(name: String,
|
||||
state: thread_state::ThreadState,
|
||||
f: F,
|
||||
id: Id,
|
||||
panic_chan: IpcSender<(Id, String, String)>)
|
||||
where F: FnOnce() + Send + 'static,
|
||||
Id: Copy + Send + Serialize + 'static,
|
||||
{
|
||||
thread::Builder::new().name(name).spawn(move || {
|
||||
thread_state::initialize(state);
|
||||
panicking::set_thread_local_hook(Box::new(move |payload: &Any| {
|
||||
debug!("Thread failed, notifying constellation");
|
||||
let reason = payload.downcast_ref::<String>().map(|s| String::from(&**s))
|
||||
.or(payload.downcast_ref::<&'static str>().map(|s| String::from(*s)))
|
||||
.unwrap_or_else(|| String::from("<unknown reason>"));
|
||||
// FIXME(ajeffrey): Really we should send the backtrace itself,
|
||||
// not just a string representation. Unfortunately we can't, because
|
||||
// Servo won't compile backtrace with the serialize-serde feature:
|
||||
//
|
||||
// .../quasi_macros-0.9.0/src/lib.rs:19:29: 19:32 error: mismatched types:
|
||||
// expected `&mut syntex::Registry`,
|
||||
// found `&mut rustc_plugin::Registry<'_>`
|
||||
// (expected struct `syntex::Registry`,
|
||||
// found struct `rustc_plugin::Registry`) [E0308]
|
||||
// .../quasi_macros-0.9.0/src/lib.rs:19 quasi_codegen::register(reg);
|
||||
//
|
||||
// so for the moment we just send a debug string.
|
||||
let backtrace = format!("{:?}", Backtrace::new());
|
||||
let _ = panic_chan.send((id, reason, backtrace));
|
||||
}));
|
||||
f()
|
||||
}).expect("Thread spawn failed");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue