forked from Rust-related/RustPython
Add faulthandler.dump_traceback
This commit is contained in:
31
vm/src/stdlib/faulthandler.rs
Normal file
31
vm/src/stdlib/faulthandler.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use crate::frame::FrameRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::PyObjectRef;
|
||||
use crate::vm::VirtualMachine;
|
||||
use std::cell::Ref;
|
||||
|
||||
fn dump_frame(frame: &FrameRef) {
|
||||
eprintln!(
|
||||
" File \"{}\", line {} in {}",
|
||||
frame.code.source_path,
|
||||
frame.get_lineno().row(),
|
||||
frame.code.obj_name
|
||||
)
|
||||
}
|
||||
|
||||
fn dump_traceback(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, vm: &VirtualMachine) {
|
||||
eprintln!("Stack (most recent call first):");
|
||||
|
||||
Ref::map(vm.frames.borrow(), |frames| {
|
||||
&for frame in frames {
|
||||
dump_frame(frame);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let ctx = &vm.ctx;
|
||||
py_module!(vm, "faulthandler", {
|
||||
"dump_traceback" => ctx.new_rustfunc(dump_traceback),
|
||||
})
|
||||
}
|
||||
@@ -35,7 +35,8 @@ mod weakref;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod faulthandler;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod multiprocessing;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -116,6 +117,10 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
|
||||
modules.insert("select".to_string(), Box::new(select::make_module));
|
||||
modules.insert("_subprocess".to_string(), Box::new(subprocess::make_module));
|
||||
modules.insert("zlib".to_string(), Box::new(zlib::make_module));
|
||||
modules.insert(
|
||||
"faulthandler".to_string(),
|
||||
Box::new(faulthandler::make_module),
|
||||
);
|
||||
}
|
||||
|
||||
// Unix-only
|
||||
|
||||
Reference in New Issue
Block a user