WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.6% of users enabled 2FA.

Commit d0bd8e72 authored by qinsoon's avatar qinsoon
Browse files

[wip] more clear debug print

parent 7667e451
...@@ -490,7 +490,11 @@ pub struct CallData { ...@@ -490,7 +490,11 @@ pub struct CallData {
impl CallData { impl CallData {
fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String { fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String {
format!("{:?} {} [{}]", self.convention, ops[self.func], op_vector_str(&self.args, ops)) let func_name = match ops[self.func].name() {
Some(name) => name,
None => "Anonymous Function".to_string()
};
format!("{:?} {} [{}]", self.convention, func_name, op_vector_str(&self.args, ops))
} }
} }
......
...@@ -3057,14 +3057,7 @@ impl CodeGenerator for ASMCodeGen { ...@@ -3057,14 +3057,7 @@ impl CodeGenerator for ASMCodeGen {
} }
} }
fn create_emit_directory(vm: &VM) { use compiler::backend::code_emission::create_emit_directory;
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {},
Err(_) => {}
}
}
use std::fs::File; use std::fs::File;
pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) { pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
......
...@@ -4,9 +4,18 @@ use compiler::CompilerPass; ...@@ -4,9 +4,18 @@ use compiler::CompilerPass;
use ast::ir::*; use ast::ir::*;
use vm::VM; use vm::VM;
use compiler::backend::emit_code; use compiler::backend::emit_code;
use std::any::Any; use std::any::Any;
const EMIT_MUIR : bool = true;
pub fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {},
Err(_) => {}
}
}
pub struct CodeEmission { pub struct CodeEmission {
name: &'static str name: &'static str
} }
...@@ -17,6 +26,25 @@ impl CodeEmission { ...@@ -17,6 +26,25 @@ impl CodeEmission {
name: "Code Emission" name: "Code Emission"
} }
} }
fn emit_muir(&self, func: &MuFunctionVersion, vm: &VM) {
use std::path;
use std::io::prelude::*;
use std::fs::File;
// create emit directory
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(func.name().unwrap().to_string() + ".muir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!("couldn't create muir file {}: {}", file_path.to_str().unwrap(), why),
Ok(file) => file
};
file.write_fmt(format_args!("{:?}", func)).unwrap();
}
} }
impl CompilerPass for CodeEmission { impl CompilerPass for CodeEmission {
...@@ -30,5 +58,9 @@ impl CompilerPass for CodeEmission { ...@@ -30,5 +58,9 @@ impl CompilerPass for CodeEmission {
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) { fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
emit_code(func, vm); emit_code(func, vm);
if EMIT_MUIR {
self.emit_muir(func, vm);
}
} }
} }
...@@ -33,36 +33,27 @@ impl Encodable for CompiledFunction { ...@@ -33,36 +33,27 @@ impl Encodable for CompiledFunction {
s.emit_struct("CompiledFunction", CF_SERIALIZE_FIELDS, |s| { s.emit_struct("CompiledFunction", CF_SERIALIZE_FIELDS, |s| {
let mut i = 0; let mut i = 0;
trace!("......serializing func_id");
try!(s.emit_struct_field("func_id", i, |s| self.func_id.encode(s))); try!(s.emit_struct_field("func_id", i, |s| self.func_id.encode(s)));
i += 1; i += 1;
trace!("......serializing func_ver_id");
try!(s.emit_struct_field("func_ver_id", i, |s| self.func_ver_id.encode(s))); try!(s.emit_struct_field("func_ver_id", i, |s| self.func_ver_id.encode(s)));
i += 1; i += 1;
trace!("......serializing temps");
try!(s.emit_struct_field("temps", i, |s| self.temps.encode(s))); try!(s.emit_struct_field("temps", i, |s| self.temps.encode(s)));
i += 1; i += 1;
trace!("......serializing consts");
try!(s.emit_struct_field("consts", i, |s| self.consts.encode(s))); try!(s.emit_struct_field("consts", i, |s| self.consts.encode(s)));
i += 1; i += 1;
trace!("......serializing const_mem");
try!(s.emit_struct_field("const_mem", i, |s| self.const_mem.encode(s))); try!(s.emit_struct_field("const_mem", i, |s| self.const_mem.encode(s)));
i += 1; i += 1;
trace!("......serializing frame");
trace!("{}", self.frame);
try!(s.emit_struct_field("frame", i, |s| self.frame.encode(s))); try!(s.emit_struct_field("frame", i, |s| self.frame.encode(s)));
i += 1; i += 1;
trace!("......serializing start");
try!(s.emit_struct_field("start", i, |s| self.start.encode(s))); try!(s.emit_struct_field("start", i, |s| self.start.encode(s)));
i += 1; i += 1;
trace!("......serializing end");
try!(s.emit_struct_field("end", i, |s| self.end.encode(s))); try!(s.emit_struct_field("end", i, |s| self.end.encode(s)));
Ok(()) Ok(())
......
...@@ -268,26 +268,35 @@ impl FrameCursor { ...@@ -268,26 +268,35 @@ impl FrameCursor {
} }
} }
const TRACE_FIND_FUNC : bool = false;
#[allow(unused_imports)]
fn find_func_for_address (cf: &RwLockReadGuard<HashMap<MuID, RwLock<CompiledFunction>>>, funcs: &RwLockReadGuard<HashMap<MuID, RwLock<MuFunction>>>, pc_addr: Address) -> (MuID, MuID) { fn find_func_for_address (cf: &RwLockReadGuard<HashMap<MuID, RwLock<CompiledFunction>>>, funcs: &RwLockReadGuard<HashMap<MuID, RwLock<MuFunction>>>, pc_addr: Address) -> (MuID, MuID) {
// use std::ops::Deref; use std::ops::Deref;
// trace!("trying to find FuncVersion for address 0x{:x}", pc_addr); if TRACE_FIND_FUNC {
trace!("trying to find FuncVersion for address 0x{:x}", pc_addr);
}
for (_, func) in cf.iter() { for (_, func) in cf.iter() {
let func = func.read().unwrap(); let func = func.read().unwrap();
let f = match funcs.get(&func.func_id) {
Some(f) => f,
None => panic!("failed to find func #{}", func.func_id)
};
// let f_lock = f.read().unwrap();
let start = func.start.to_address(); let start = func.start.to_address();
let end = func.end.to_address(); let end = func.end.to_address();
// trace!("CompiledFunction: func={}, fv_id={}, start=0x{:x}, end=0x{:x}", f_lock.deref(), func.func_ver_id, start, end);
if TRACE_FIND_FUNC {
let f = match funcs.get(&func.func_id) {
Some(f) => f,
None => panic!("failed to find func #{}", func.func_id)
};
let f_lock = f.read().unwrap();
trace!("CompiledFunction: func={}, fv_id={}, start=0x{:x}, end=0x{:x}", f_lock.deref(), func.func_ver_id, start, end);
}
// pc won't be the start of a function, but could be the end // pc won't be the start of a function, but could be the end
if pc_addr > start && pc_addr <= end { if pc_addr > start && pc_addr <= end {
// trace!("Found CompiledFunction: func_id={}, fv_id={}", func.func_id, func.func_ver_id); if TRACE_FIND_FUNC {
trace!("Found CompiledFunction: func_id={}, fv_id={}", func.func_id, func.func_ver_id);
}
return (func.func_id, func.func_ver_id); return (func.func_id, func.func_ver_id);
} }
} }
......
...@@ -56,23 +56,21 @@ impl VMOptions { ...@@ -56,23 +56,21 @@ impl VMOptions {
pub fn init(str: &str) -> VMOptions { pub fn init(str: &str) -> VMOptions {
info!("init vm options with: {:?}", str); info!("init vm options with: {:?}", str);
let ret : VMOptions = Docopt::new(USAGE) let mut ret : VMOptions = Docopt::new(USAGE)
.and_then(|d| d.argv(str.split_whitespace().into_iter()).parse()) .and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
.unwrap_or_else(|e| e.exit()).decode().unwrap(); .unwrap_or_else(|e| e.exit()).decode().unwrap();
info!("parsed as {:?}", ret); info!("parsed as {:?}", ret);
// at the moment disable collection for debugging
ret.flag_gc_disable_collection = true;
ret ret
} }
} }
impl Default for VMOptions { impl Default for VMOptions {
fn default() -> VMOptions { fn default() -> VMOptions {
let mut options = VMOptions::init(""); VMOptions::init("")
// by default, disable colleciton for easier debugging
options.flag_gc_disable_collection = true;
options
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment