Communicate a backtrace to the constellation when panicking.

This commit is contained in:
Alan Jeffrey 2016-04-22 16:26:13 -05:00
parent 47efbea666
commit 9153333f62
10 changed files with 197 additions and 70 deletions

View file

@ -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");