Add a signal handler for SIGSEGV that reports the current thread name and backtrace.

This commit is contained in:
Josh Matthews 2016-05-31 17:13:15 -04:00
parent a5778fb5da
commit d4a5b45242
4 changed files with 50 additions and 1 deletions

View file

@ -3,6 +3,7 @@ name = "servo"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"browserhtml 0.1.7 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)", "browserhtml 0.1.7 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
@ -35,6 +36,7 @@ dependencies = [
"script 0.0.1", "script 0.0.1",
"script_tests 0.0.1", "script_tests 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"style_tests 0.0.1", "style_tests 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2112,6 +2114,11 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "sig"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "simd" name = "simd"
version = "0.1.0" version = "0.1.0"

View file

@ -73,6 +73,10 @@ euclid = "0.6.4"
libc = "0.2" libc = "0.2"
url = "1.0.0" url = "1.0.0"
[target.'cfg(not(target_os = "android"))'.dependencies]
sig = "0.1"
backtrace = "0.2"
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
log = "0.3" log = "0.3"
android_glue = "0.1.3" android_glue = "0.1.3"

View file

@ -15,11 +15,13 @@
//! //!
//! [glutin]: https://github.com/tomaka/glutin //! [glutin]: https://github.com/tomaka/glutin
#![feature(start)] #![feature(start, core_intrinsics)]
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
#[macro_use] #[macro_use]
extern crate android_glue; extern crate android_glue;
#[cfg(not(target_os = "android"))]
extern crate backtrace;
extern crate env_logger; extern crate env_logger;
// The window backed by glutin // The window backed by glutin
extern crate glutin_app as app; extern crate glutin_app as app;
@ -30,6 +32,9 @@ extern crate libc;
extern crate log; extern crate log;
// The Servo engine // The Servo engine
extern crate servo; extern crate servo;
#[cfg(not(target_os = "android"))]
#[macro_use]
extern crate sig;
use servo::Browser; use servo::Browser;
use servo::compositing::windowing::WindowEvent; use servo::compositing::windowing::WindowEvent;
@ -48,7 +53,33 @@ pub mod platform {
pub fn deinit() {} pub fn deinit() {}
} }
#[cfg(not(target_os = "android"))]
fn install_crash_handler() {
use backtrace::Backtrace;
use sig::ffi::Sig;
use std::intrinsics::abort;
use std::thread;
fn handler(_sig: i32) {
let name = thread::current().name()
.map(|n| format!(" for thread \"{}\"", n))
.unwrap_or("".to_owned());
println!("Stack trace{}\n{:?}", name, Backtrace::new());
unsafe {
abort();
}
}
signal!(Sig::SEGV, handler);
}
#[cfg(target_os = "android")]
fn install_crash_handler() {
}
fn main() { fn main() {
install_crash_handler();
// Parse the command line options and store them globally // Parse the command line options and store them globally
let opts_result = opts::from_cmdline_args(&*args()); let opts_result = opts::from_cmdline_args(&*args());

7
ports/cef/Cargo.lock generated
View file

@ -1864,6 +1864,7 @@ name = "servo"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"browserhtml 0.1.7 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)", "browserhtml 0.1.7 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
@ -1888,6 +1889,7 @@ dependencies = [
"profile_traits 0.0.1", "profile_traits 0.0.1",
"script 0.0.1", "script 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1", "util 0.0.1",
@ -1997,6 +1999,11 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "sig"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "simd" name = "simd"
version = "0.1.0" version = "0.1.0"