mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #10824 - asajeffrey:communicate-backtrace-on-panic, r=Manishearth
Communicate a backtrace to the constellation when panicking. Send a representation of the backtrace from a pipeline thread to the constellation in the case of panic. This is the next step in communicating the backtrace to the browser chrome (#10334). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10824) <!-- Reviewable:end -->
This commit is contained in:
commit
f773dc182b
10 changed files with 197 additions and 70 deletions
|
@ -29,6 +29,7 @@ git = "https://github.com/servo/ipc-channel"
|
|||
|
||||
[dependencies]
|
||||
app_units = {version = "0.2.3", features = ["plugins"]}
|
||||
backtrace = "0.2.1"
|
||||
bitflags = "0.3"
|
||||
deque = "0.3.1"
|
||||
euclid = {version = "0.6.4", features = ["unstable", "plugins"]}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#![deny(unsafe_code)]
|
||||
|
||||
extern crate app_units;
|
||||
extern crate backtrace;
|
||||
#[allow(unused_extern_crates)]
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
* 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 opts;
|
||||
use std::any::Any;
|
||||
use std::boxed::FnBox;
|
||||
use std::cell::RefCell;
|
||||
use std::io::{Write, stderr};
|
||||
use std::panic::{PanicInfo, take_hook, set_hook};
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::thread;
|
||||
|
@ -31,9 +29,6 @@ pub fn set_thread_local_hook(local: Box<FnBox(&Any)>) {
|
|||
/// Should be called in main() after arguments have been parsed
|
||||
pub fn initiate_panic_hook() {
|
||||
|
||||
// store it locally, we can't trust that opts::get() will work whilst panicking
|
||||
let full_backtraces = opts::get().full_backtraces;
|
||||
|
||||
// Set the panic handler only once. It is global.
|
||||
HOOK_SET.call_once(|| {
|
||||
// The original backtrace-printing hook. We still want to call this
|
||||
|
@ -44,34 +39,15 @@ pub fn initiate_panic_hook() {
|
|||
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(info) = i.borrow_mut().take() {
|
||||
if let Some(local_info) = i.borrow_mut().take() {
|
||||
debug!("Thread `{}` failed, notifying error handlers", name);
|
||||
(info.fail).call_box((payload, ));
|
||||
(local_info.fail).call_box((payload, ));
|
||||
} else {
|
||||
hook(&info);
|
||||
}
|
||||
});
|
||||
|
||||
// Skip cascading SendError/RecvError backtraces if allowed
|
||||
if !full_backtraces {
|
||||
if let Some(s) = payload.downcast_ref::<String>() {
|
||||
if s.contains("SendError") {
|
||||
let err = stderr();
|
||||
let _ = write!(err.lock(), "Thread \"{}\" panicked with an unwrap of \
|
||||
`SendError` (backtrace skipped)\n", name);
|
||||
return;
|
||||
} else if s.contains("RecvError") {
|
||||
let err = stderr();
|
||||
let _ = write!(err.lock(), "Thread \"{}\" panicked with an unwrap of \
|
||||
`RecvError` (backtrace skipped)\n", name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call the old hook to get the backtrace
|
||||
hook(&info);
|
||||
};
|
||||
set_hook(Box::new(new_hook));
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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 backtrace::Backtrace;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use panicking;
|
||||
use serde::Serialize;
|
||||
|
@ -20,7 +21,7 @@ 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)>)
|
||||
panic_chan: IpcSender<(Id, String, String)>)
|
||||
where F: FnOnce() + Send + 'static,
|
||||
Id: Copy + Send + Serialize + 'static,
|
||||
{
|
||||
|
@ -31,7 +32,20 @@ pub fn spawn_named_with_send_on_panic<F, Id>(name: String,
|
|||
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>"));
|
||||
let _ = panic_chan.send((id, 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