Bug 1456350 - Forward webrender error log to gfxCriticalNote r=bholley

This commit is contained in:
sotaro 2018-04-27 16:48:39 +09:00
parent e8cda31517
commit 666719aa81
8 changed files with 85 additions and 17 deletions

4
Cargo.lock generated
View File

@ -786,7 +786,6 @@ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cstr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
@ -828,8 +827,9 @@ dependencies = [
"cubeb-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding_c 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding_glue 0.1.0",
"env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"geckoservo 0.0.1",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mozurl 0.0.1",
"mp4parse_capi 0.10.1",
"netwerk_helper 0.0.1",

View File

@ -17,7 +17,6 @@ gecko_debug = ["style/gecko_debug"]
atomic_refcell = "0.1"
cssparser = "0.23.0"
cstr = "0.1.2"
env_logger = {version = "0.5", default-features = false} # disable `regex` to reduce code size
libc = "0.2"
log = {version = "0.4", features = ["release_max_level_info"]}
malloc_size_of = {path = "../../components/malloc_size_of"}

View File

@ -4,7 +4,6 @@
use cssparser::{ParseErrorKind, Parser, ParserInput, SourceLocation};
use cssparser::ToCss as ParserToCss;
use env_logger::Builder;
use malloc_size_of::MallocSizeOfOps;
use nsstring::nsCString;
use selectors::{NthIndexCache, SelectorList};
@ -12,7 +11,6 @@ use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use smallvec::SmallVec;
use std::cell::RefCell;
use std::env;
use std::fmt::Write;
use std::iter;
use std::mem;
@ -184,14 +182,6 @@ static mut DUMMY_URL_DATA: *mut URLExtraData = 0 as *mut URLExtraData;
pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
use style::gecko_bindings::sugar::origin_flags;
// Initialize logging.
let mut builder = Builder::new();
let default_level = if cfg!(debug_assertions) { "warn" } else { "error" };
match env::var("RUST_LOG") {
Ok(v) => builder.parse(&v).init(),
_ => builder.parse(default_level).init(),
};
// Pretend that we're a Servo Layout thread, to make some assertions happy.
thread_state::initialize(thread_state::ThreadState::LAYOUT);

View File

@ -5,7 +5,6 @@
extern crate cssparser;
#[macro_use] extern crate cstr;
extern crate env_logger;
extern crate libc;
#[macro_use] extern crate log;
extern crate malloc_size_of;

View File

@ -14,7 +14,6 @@
extern crate atomic_refcell;
extern crate cssparser;
#[macro_use] extern crate cstr;
extern crate env_logger;
extern crate geckoservo;
#[macro_use] extern crate log;
extern crate malloc_size_of;

View File

@ -24,7 +24,8 @@ audioipc-server = { path = "../../../../media/audioipc/server", optional = true
u2fhid = { path = "../../../../dom/webauthn/u2f-hid-rs" }
rsdparsa_capi = { path = "../../../../media/webrtc/signaling/src/sdp/rsdparsa_capi" }
# We have these to enforce common feature sets for said crates.
log = {version = "0.3", features = ["release_max_level_info"]}
log = {version = "0.4", features = ["release_max_level_info"]}
env_logger = {version = "0.5", default-features = false} # disable `regex` to reduce code size
cose-c = { version = "0.1.5" }
[features]

View File

@ -22,17 +22,89 @@ extern crate encoding_glue;
extern crate audioipc_client;
#[cfg(feature = "cubeb-remoting")]
extern crate audioipc_server;
extern crate env_logger;
extern crate u2fhid;
extern crate log;
extern crate cosec;
extern crate rsdparsa_capi;
use std::boxed::Box;
use std::ffi::CStr;
use std::env;
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use std::panic;
extern "C" {
fn gfx_critical_note(msg: *const c_char);
}
struct GeckoLogger {
logger: env_logger::Logger
}
impl GeckoLogger {
fn new() -> GeckoLogger {
let mut builder = env_logger::Builder::new();
let default_level = if cfg!(debug_assertions) { "warn" } else { "error" };
let logger = match env::var("RUST_LOG") {
Ok(v) => builder.parse(&v).build(),
_ => builder.parse(default_level).build(),
};
GeckoLogger {
logger
}
}
fn init() -> Result<(), log::SetLoggerError> {
let gecko_logger = Self::new();
log::set_max_level(gecko_logger.logger.filter());
log::set_boxed_logger(Box::new(gecko_logger))
}
fn should_log_to_gfx_critical_note(record: &log::Record) -> bool {
if record.level() == log::Level::Error &&
record.target().contains("webrender") {
true
} else {
false
}
}
fn maybe_log_to_gfx_critical_note(&self, record: &log::Record) {
if Self::should_log_to_gfx_critical_note(record) {
let msg = CString::new(format!("{}", record.args())).unwrap();
unsafe {
gfx_critical_note(msg.as_ptr());
}
}
}
}
impl log::Log for GeckoLogger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
self.logger.enabled(metadata)
}
fn log(&self, record: &log::Record) {
// Forward log to gfxCriticalNote, if the log should be in gfx crash log.
self.maybe_log_to_gfx_critical_note(record);
self.logger.log(record);
}
fn flush(&self) { }
}
#[no_mangle]
pub extern "C" fn GkRust_Init() {
// Initialize logging.
let _ = GeckoLogger::init();
}
#[no_mangle]
pub extern "C" fn GkRust_Shutdown() {
}
/// Used to implement `nsIDebug2::RustPanic` for testing purposes.
#[no_mangle]

View File

@ -156,6 +156,10 @@ using namespace mozilla;
using base::AtExitManager;
using mozilla::ipc::BrowserProcessSubThread;
// From toolkit/library/rust/lib.rs
extern "C" void GkRust_Init();
extern "C" void GkRust_Shutdown();
namespace {
static AtExitManager* sExitManager;
@ -452,6 +456,8 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
// passed, passing (0, nullptr) is alright here.
mozilla::LogModule::Init(0, nullptr);
GkRust_Init();
nsresult rv = NS_OK;
// We are not shutting down
@ -999,6 +1005,8 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
// Shut down SystemGroup for main thread dispatching.
SystemGroup::Shutdown();
GkRust_Shutdown();
NS_ShutdownAtomTable();
NS_IF_RELEASE(gDebug);