From fd94c2df866493150f0f76949dbe6549c685ed57 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Mon, 17 Dec 2018 23:54:00 -0600 Subject: [PATCH] Add more argument info to debug messages --- src/apis/emscripten/errno.rs | 2 +- src/apis/emscripten/io.rs | 2 +- src/apis/emscripten/lock.rs | 8 +-- src/apis/emscripten/memory.rs | 5 +- src/apis/emscripten/nullfunc.rs | 40 +++++++------- src/apis/emscripten/process.rs | 4 +- src/apis/emscripten/signal.rs | 11 ++-- src/apis/emscripten/syscalls.rs | 96 ++++++++++++++++----------------- src/apis/emscripten/time.rs | 2 +- 9 files changed, 84 insertions(+), 86 deletions(-) diff --git a/src/apis/emscripten/errno.rs b/src/apis/emscripten/errno.rs index 02d76b050f2..9787ea85bba 100644 --- a/src/apis/emscripten/errno.rs +++ b/src/apis/emscripten/errno.rs @@ -1,7 +1,7 @@ // use std::collections::HashMap; pub extern "C" fn ___seterrno(value: i32) -> i32 { - debug!("emscripten::___seterrno"); + debug!("emscripten::___seterrno {}", value); // TODO: Incomplete impl eprintln!("failed to set errno!"); value diff --git a/src/apis/emscripten/io.rs b/src/apis/emscripten/io.rs index c827902f3f8..5beaeb91e2a 100644 --- a/src/apis/emscripten/io.rs +++ b/src/apis/emscripten/io.rs @@ -7,7 +7,7 @@ pub use libc::putchar; /// printf pub extern "C" fn printf(memory_offset: i32, extra: i32, instance: &Instance) -> i32 { - debug!("emscripten::printf"); + debug!("emscripten::printf {}, {}", memory_offset, extra); unsafe { let addr = instance.memory_offset_addr(0, memory_offset as _) as _; _printf(addr, extra) diff --git a/src/apis/emscripten/lock.rs b/src/apis/emscripten/lock.rs index 9067be99ebd..ea875fcca27 100644 --- a/src/apis/emscripten/lock.rs +++ b/src/apis/emscripten/lock.rs @@ -2,11 +2,11 @@ use crate::webassembly::Instance; use libc::c_int; // NOTE: Not implemented by Emscripten -pub extern "C" fn ___lock(_which: c_int, _varargs: c_int, _instance: &mut Instance) { - debug!("emscripten::___lock"); +pub extern "C" fn ___lock(which: c_int, varargs: c_int, _instance: &mut Instance) { + debug!("emscripten::___lock {}, {}", which, varargs); } // NOTE: Not implemented by Emscripten -pub extern "C" fn ___unlock(_which: c_int, _varargs: c_int, _instance: &mut Instance) { - debug!("emscripten::___unlock"); +pub extern "C" fn ___unlock(which: c_int, varargs: c_int, _instance: &mut Instance) { + debug!("emscripten::___unlock {}, {}", which, varargs); } diff --git a/src/apis/emscripten/memory.rs b/src/apis/emscripten/memory.rs index 4caf652bcc2..73c4fd510d3 100644 --- a/src/apis/emscripten/memory.rs +++ b/src/apis/emscripten/memory.rs @@ -9,7 +9,10 @@ pub extern "C" fn _emscripten_memcpy_big( len: u32, instance: &mut Instance, ) -> u32 { - debug!("emscripten::_emscripten_memcpy_big"); + debug!( + "emscripten::_emscripten_memcpy_big {}, {}, {}", + dest, src, len + ); let dest_addr = instance.memory_offset_addr(0, dest as usize) as *mut c_void; let src_addr = instance.memory_offset_addr(0, src as usize) as *mut c_void; unsafe { diff --git a/src/apis/emscripten/nullfunc.rs b/src/apis/emscripten/nullfunc.rs index 2f6bced336f..6d89d0ab6cc 100644 --- a/src/apis/emscripten/nullfunc.rs +++ b/src/apis/emscripten/nullfunc.rs @@ -1,52 +1,52 @@ use super::process::abort_with_message; use crate::webassembly::Instance; -pub extern "C" fn nullfunc_ii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_ii"); +pub extern "C" fn nullfunc_ii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_ii {}", x); abort_with_message("Invalid function pointer called with signature 'ii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_iii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_iii"); +pub extern "C" fn nullfunc_iii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_iii {}", x); abort_with_message("Invalid function pointer called with signature 'iii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_iiii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_iiii"); +pub extern "C" fn nullfunc_iiii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_iiii {}", x); abort_with_message("Invalid function pointer called with signature 'iiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_iiiii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_iiiii"); +pub extern "C" fn nullfunc_iiiii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_iiiii {}", x); abort_with_message("Invalid function pointer called with signature 'iiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_iiiiii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_iiiiii"); +pub extern "C" fn nullfunc_iiiiii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_iiiiii {}", x); abort_with_message("Invalid function pointer called with signature 'iiiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_v(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_v"); +pub extern "C" fn nullfunc_v(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_v {}", x); abort_with_message("Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_vi(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_vi"); +pub extern "C" fn nullfunc_vi(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_vi {}", x); abort_with_message("Invalid function pointer called with signature 'vi'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_vii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_vii"); +pub extern "C" fn nullfunc_vii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_vii {}", x); abort_with_message("Invalid function pointer called with signature 'vii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_viii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_viii"); +pub extern "C" fn nullfunc_viii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_viii {}", x); abort_with_message("Invalid function pointer called with signature 'viii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub extern "C" fn nullfunc_viiii(_x: u32, _instance: &Instance) { - debug!("emscripten::nullfunc_viiii"); +pub extern "C" fn nullfunc_viiii(x: u32, _instance: &Instance) { + debug!("emscripten::nullfunc_viiii {}", x); abort_with_message("Invalid function pointer called with signature 'viiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } diff --git a/src/apis/emscripten/process.rs b/src/apis/emscripten/process.rs index cfb4f70eced..55b8e7b53f3 100644 --- a/src/apis/emscripten/process.rs +++ b/src/apis/emscripten/process.rs @@ -25,12 +25,12 @@ pub extern "C" fn _fork(_instance: &mut Instance) -> pid_t { } pub extern "C" fn _exit(status: c_int, _instance: &mut Instance) -> ! { - debug!("emscripten::_exit"); + debug!("emscripten::_exit {}", status); unsafe { exit(status) } } pub extern "C" fn em_abort(message: u32, instance: &mut Instance) { - debug!("emscripten::em_abort"); + debug!("emscripten::em_abort {}", message); let message_addr = instance.memory_offset_addr(0, message as usize) as *mut c_char; unsafe { let message = CStr::from_ptr(message_addr) diff --git a/src/apis/emscripten/signal.rs b/src/apis/emscripten/signal.rs index 56ab66180bc..844e7539707 100644 --- a/src/apis/emscripten/signal.rs +++ b/src/apis/emscripten/signal.rs @@ -10,18 +10,13 @@ pub extern "C" fn _sigemptyset(set: u32, instance: &mut Instance) -> i32 { 0 } -pub extern "C" fn _sigaction( - _signum: u32, - _act: u32, - _oldact: u32, - _instance: &mut Instance, -) -> i32 { - debug!("emscripten::_sigaction"); +pub extern "C" fn _sigaction(signum: u32, act: u32, oldact: u32, _instance: &mut Instance) -> i32 { + debug!("emscripten::_sigaction {}, {}, {}", signum, act, oldact); 0 } pub extern "C" fn _sigaddset(set: u32, signum: u32, instance: &mut Instance) -> i32 { - debug!("emscripten::_sigaddset"); + debug!("emscripten::_sigaddset {}, {}", set, signum); let set_addr = instance.memory_offset_addr(0, set as _) as *mut u32; unsafe { *set_addr |= 1 << (signum - 1); diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index f9d3effc0aa..15f2fee196b 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -76,8 +76,8 @@ use libc::SO_NOSIGPIPE; const SO_NOSIGPIPE: c_int = 0; /// exit -pub extern "C" fn ___syscall1(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) { - debug!("emscripten::___syscall1 (exit)"); +pub extern "C" fn ___syscall1(which: c_int, mut varargs: VarArgs, instance: &mut Instance) { + debug!("emscripten::___syscall1 (exit) {}", which); let status: i32 = varargs.get(instance); unsafe { exit(status); @@ -86,11 +86,11 @@ pub extern "C" fn ___syscall1(_which: c_int, mut varargs: VarArgs, instance: &mu /// read pub extern "C" fn ___syscall3( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> ssize_t { - debug!("emscripten::___syscall3 (read)"); + debug!("emscripten::___syscall3 (read) {}", which); let fd: i32 = varargs.get(instance); let buf: u32 = varargs.get(instance); let count: usize = varargs.get(instance); @@ -103,11 +103,11 @@ pub extern "C" fn ___syscall3( /// write pub extern "C" fn ___syscall4( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall4 (write)"); + debug!("emscripten::___syscall4 (write) {}", which); let fd: i32 = varargs.get(instance); let buf: u32 = varargs.get(instance); let count: u32 = varargs.get(instance); @@ -118,11 +118,11 @@ pub extern "C" fn ___syscall4( /// open pub extern "C" fn ___syscall5( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall5 (open)"); + debug!("emscripten::___syscall5 (open) {}", which); let pathname: u32 = varargs.get(instance); let flags: i32 = varargs.get(instance); let mode: u32 = varargs.get(instance); @@ -138,11 +138,11 @@ pub extern "C" fn ___syscall5( /// close pub extern "C" fn ___syscall6( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall6 (close)"); + debug!("emscripten::___syscall6 (close) {}", which); let fd: i32 = varargs.get(instance); debug!("fd: {}", fd); unsafe { close(fd) } @@ -150,11 +150,11 @@ pub extern "C" fn ___syscall6( // chdir pub extern "C" fn ___syscall12( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall12 (chdir)"); + debug!("emscripten::___syscall12 (chdir) {}", which); let path_addr: i32 = varargs.get(instance); unsafe { let path_ptr = instance.memory_offset_addr(0, path_addr as usize) as *const i8; @@ -173,11 +173,11 @@ pub extern "C" fn ___syscall20() -> pid_t { // mkdir pub extern "C" fn ___syscall39( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall39 (mkdir)"); + debug!("emscripten::___syscall39 (mkdir) {}", which); let pathname: u32 = varargs.get(instance); let mode: u32 = varargs.get(instance); let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8; @@ -194,11 +194,11 @@ pub extern "C" fn ___syscall64() -> pid_t { /// ioctl pub extern "C" fn ___syscall54( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall54 (ioctl)"); + debug!("emscripten::___syscall54 (ioctl) {}", which); let fd: i32 = varargs.get(instance); let request: u32 = varargs.get(instance); debug!("fd: {}, op: {}", fd, request); @@ -240,11 +240,11 @@ pub extern "C" fn ___syscall54( // socketcall pub extern "C" fn ___syscall102( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall102 (socketcall)"); + debug!("emscripten::___syscall102 (socketcall) {}", which); let call: u32 = varargs.get(instance); let mut socket_varargs: VarArgs = varargs.get(instance); @@ -518,11 +518,11 @@ pub extern "C" fn ___syscall102( /// uname // NOTE: Wondering if we should return custom utsname, like Emscripten. pub extern "C" fn ___syscall122( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall122 (uname)"); + debug!("emscripten::___syscall122 (uname) {}", which); let buf: u32 = varargs.get(instance); debug!("=> buf: {}", buf); let buf_addr = instance.memory_offset_addr(0, buf as usize) as *mut utsname; @@ -531,11 +531,11 @@ pub extern "C" fn ___syscall122( // mmap2 pub extern "C" fn ___syscall192( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall192 (mmap2)"); + debug!("emscripten::___syscall192 (mmap2) {}", which); let addr: i32 = varargs.get(instance); let len: u32 = varargs.get(instance); let prot: i32 = varargs.get(instance); @@ -566,11 +566,11 @@ pub extern "C" fn ___syscall192( /// lseek pub extern "C" fn ___syscall140( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> off_t { - debug!("emscripten::___syscall140 (lseek)"); + debug!("emscripten::___syscall140 (lseek) {}", which); let fd: i32 = varargs.get(instance); let offset: i64 = varargs.get(instance); let whence: i32 = varargs.get(instance); @@ -580,11 +580,11 @@ pub extern "C" fn ___syscall140( /// readv pub extern "C" fn ___syscall145( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> ssize_t { - debug!("emscripten::___syscall145 (readv)"); + debug!("emscripten::___syscall145 (readv) {}", which); // let fd: i32 = varargs.get(instance); // let iov: u32 = varargs.get(instance); // let iovcnt: i32 = varargs.get(instance); @@ -625,11 +625,11 @@ pub extern "C" fn ___syscall145( // writev pub extern "C" fn ___syscall146( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> ssize_t { - debug!("emscripten::___syscall146 (writev)"); + debug!("emscripten::___syscall146 (writev) {}", which); let fd: i32 = varargs.get(instance); let iov: i32 = varargs.get(instance); let iovcnt: i32 = varargs.get(instance); @@ -663,11 +663,11 @@ pub extern "C" fn ___syscall146( // pread pub extern "C" fn ___syscall180( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall180 (pread)"); + debug!("emscripten::___syscall180 (pread) {}", which); let fd: i32 = varargs.get(instance); let buf: u32 = varargs.get(instance); let count: u32 = varargs.get(instance); @@ -684,11 +684,11 @@ pub extern "C" fn ___syscall180( // pwrite pub extern "C" fn ___syscall181( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall181 (pwrite)"); + debug!("emscripten::___syscall181 (pwrite) {}", which); let fd: i32 = varargs.get(instance); let buf: u32 = varargs.get(instance); let count: u32 = varargs.get(instance); @@ -709,11 +709,11 @@ pub extern "C" fn ___syscall181( // stat64 pub extern "C" fn ___syscall195( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall195 (stat64)"); + debug!("emscripten::___syscall195 (stat64) {}", which); let pathname: u32 = varargs.get(instance); let buf: u32 = varargs.get(instance); @@ -733,11 +733,11 @@ pub extern "C" fn ___syscall195( // fstat64 pub extern "C" fn ___syscall197( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall197 (fstat64)"); + debug!("emscripten::___syscall197 (fstat64) {}", which); let fd: c_int = varargs.get(instance); let buf: u32 = varargs.get(instance); @@ -783,11 +783,11 @@ pub extern "C" fn ___syscall202() -> gid_t { // chown pub extern "C" fn ___syscall212( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall212 (chown)"); + debug!("emscripten::___syscall212 (chown) {}", which); let pathname: u32 = varargs.get(instance); let owner: u32 = varargs.get(instance); @@ -800,11 +800,11 @@ pub extern "C" fn ___syscall212( // fcntl64 pub extern "C" fn ___syscall221( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall221 (fcntl64)"); + debug!("emscripten::___syscall221 (fcntl64) {}", which); // fcntl64 let _fd: i32 = varargs.get(instance); let cmd: u32 = varargs.get(instance); @@ -816,11 +816,11 @@ pub extern "C" fn ___syscall221( // prlimit64 pub extern "C" fn ___syscall340( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall340 (prlimit64)"); + debug!("emscripten::___syscall340 (prlimit64), {}", which); // NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway. let _pid: i32 = varargs.get(instance); let _resource: i32 = varargs.get(instance); @@ -843,11 +843,11 @@ pub extern "C" fn ___syscall340( // dup2 pub extern "C" fn ___syscall63( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall63 (dup2)"); + debug!("emscripten::___syscall63 (dup2) {}", which); let src: i32 = varargs.get(instance); let dst: i32 = varargs.get(instance); @@ -857,11 +857,11 @@ pub extern "C" fn ___syscall63( // select pub extern "C" fn ___syscall142( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall142 (newselect)"); + debug!("emscripten::___syscall142 (newselect) {}", which); let nfds: i32 = varargs.get(instance); let readfds: u32 = varargs.get(instance); @@ -880,11 +880,11 @@ pub extern "C" fn ___syscall142( // setpgid pub extern "C" fn ___syscall57( - _which: c_int, + which: c_int, mut varargs: VarArgs, instance: &mut Instance, ) -> c_int { - debug!("emscripten::___syscall57 (setpgid)"); + debug!("emscripten::___syscall57 (setpgid) {}", which); let pid: i32 = varargs.get(instance); let pgid: i32 = varargs.get(instance); unsafe { setpgid(pid, pgid) } diff --git a/src/apis/emscripten/time.rs b/src/apis/emscripten/time.rs index 0ff20fc1609..ce453941136 100644 --- a/src/apis/emscripten/time.rs +++ b/src/apis/emscripten/time.rs @@ -119,7 +119,7 @@ pub extern "C" fn _asctime(time: u32, instance: &mut Instance) -> u32 { /// emscripten: _asctime_r pub extern "C" fn _asctime_r(time: u32, buf: u32, instance: &mut Instance) -> u32 { - debug!("emscripten::_asctime_r {}", time); + debug!("emscripten::_asctime_r {}, {}", time, buf); unsafe { // NOTE: asctime_r is specced to behave in an undefined manner if the algorithm would attempt