Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add faulthandler.dump_traceback
  • Loading branch information
palaviv committed Dec 30, 2019
commit 4caf46c635cfd2783176ff3ffb1c24611f8106d8
31 changes: 31 additions & 0 deletions vm/src/stdlib/faulthandler.rs
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just for frame in vm.frames.borrow() { ... } ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure... Fixed

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),
})
}
7 changes: 6 additions & 1 deletion vm/src/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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
Expand Down