Force logging of panic messages

This commit is contained in:
Fabian 2018-08-20 17:38:27 -05:00
parent d67b91b895
commit d9282afec5
4 changed files with 53 additions and 12 deletions

View file

@ -258,6 +258,10 @@ function V86Starter(options)
const str = v86util.read_sized_string_from_mem(v86oxide.exports.memory, offset, len);
dbg_log(str, LOG_CPU);
},
"console_log_from_wasm": function(offset, len) {
const str = v86util.read_sized_string_from_mem(v86oxide.exports.memory, offset, len);
console.error(str);
},
"codegen_finalize": (wasm_table_index, start, end, first_opcode, state_flags) => cpu.codegen_finalize(wasm_table_index, start, end, first_opcode, state_flags),
"__indirect_function_table": wasm_table,
"floor": Math.floor,

View file

@ -22,14 +22,14 @@ pub fn rust_setup() {
panic::set_hook(Box::new(|panic_info| {
if let Some(location) = panic_info.location() {
dbg_log!(
console_log!(
"panic occurred in file '{}' at line {}",
location.file(),
location.line()
);
}
else {
dbg_log!("panic occurred but can't get location information...");
console_log!("panic occurred but can't get location information...");
}
}));
}

View file

@ -8,6 +8,16 @@ macro_rules! dbg_log {
}
}
#[allow(unused_macros)]
macro_rules! console_log {
($fmt:expr) => {
println!($fmt);
};
($fmt:expr, $($arg:tt)*) => {
println!($fmt, $($arg)*);
}
}
#[allow(unused_macros)]
macro_rules! dbg_assert {
($($arg:tt)*) => {
@ -17,17 +27,34 @@ macro_rules! dbg_assert {
#[cfg(target_arch = "wasm32")]
#[allow(unused_macros)]
macro_rules! dbg_log {
macro_rules! console_log {
($fmt:expr) => {
{
use ::util::{ DEBUG, _log_to_js_console };
if DEBUG { _log_to_js_console($fmt); }
use ::util::{ console_log_to_js_console };
console_log_to_js_console($fmt);
}
};
($fmt:expr, $($arg:tt)*) => {
{
use ::util::{ DEBUG, _log_to_js_console };
if DEBUG { _log_to_js_console(format!($fmt, $($arg)*)); }
use ::util::{ console_log_to_js_console };
console_log_to_js_console(format!($fmt, $($arg)*));
}
};
}
#[cfg(target_arch = "wasm32")]
#[allow(unused_macros)]
macro_rules! dbg_log {
($fmt:expr) => {
{
use ::util::{ DEBUG, log_to_js_console };
if DEBUG { log_to_js_console($fmt); }
}
};
($fmt:expr, $($arg:tt)*) => {
{
use ::util::{ DEBUG, log_to_js_console };
if DEBUG { log_to_js_console(format!($fmt, $($arg)*)); }
}
};
}
@ -36,9 +63,9 @@ macro_rules! dbg_log {
#[allow(unused_macros)]
macro_rules! dbg_assert {
($cond:expr) => {{
use util::{_log_to_js_console, abort, DEBUG};
use util::{abort, log_to_js_console, DEBUG};
if DEBUG && !$cond {
_log_to_js_console(format!(
log_to_js_console(format!(
"Assertion failed at {}:{}:{}: '{}'",
file!(),
line!(),
@ -52,9 +79,9 @@ macro_rules! dbg_assert {
}
}};
($cond:expr, $desc:expr) => {{
use util::{_log_to_js_console, abort, DEBUG};
use util::{abort, log_to_js_console, DEBUG};
if DEBUG && !$cond {
_log_to_js_console(format!(
log_to_js_console(format!(
"Assertion failed at {}:{}:{}: '{}' - '{}'",
file!(),
line!(),

View file

@ -77,6 +77,7 @@ pub const DEBUG: bool = cfg!(debug_assertions);
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn log_from_wasm(ptr: *const u8, len: usize);
pub fn console_log_from_wasm(ptr: *const u8, len: usize);
pub fn abort();
}
@ -84,10 +85,19 @@ extern "C" {
use std::string::ToString;
#[cfg(target_arch = "wasm32")]
pub fn _log_to_js_console<T: ToString>(s: T) {
pub fn log_to_js_console<T: ToString>(s: T) {
let s: String = s.to_string();
let len = s.len();
unsafe {
log_from_wasm(s.as_bytes().as_ptr(), len);
}
}
#[cfg(target_arch = "wasm32")]
pub fn console_log_to_js_console<T: ToString>(s: T) {
let s: String = s.to_string();
let len = s.len();
unsafe {
console_log_from_wasm(s.as_bytes().as_ptr(), len);
}
}