Skip to content

Instantly share code, notes, and snippets.

@wycats
Created June 4, 2014 05:56
Show Gist options
  • Save wycats/e54b90f1df36365c7ead to your computer and use it in GitHub Desktop.
Save wycats/e54b90f1df36365c7ead to your computer and use it in GitHub Desktop.
✗ RUST_BACKTRACE=1 ./test
failed at 'called `Option::get_mut_ref()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/option.rs:469
stack backtrace:
1: 0x47bd80 - rt::backtrace::imp::write::h6bc482a91e850a6bWrx::v0.11.0.pre
2: 0x45f830 - rt::unwind::begin_unwind_inner::h0c987df59e660255X1w::v0.11.0.pre
3: 0x45eb60 - rt::unwind::begin_unwind_fmt::hab4ea20b6306f10470w::v0.11.0.pre
4: 0x47bc90 - rust_begin_unwind
5: 0x4bfc80 - failure::begin_unwind::h274c645ee0d8103btZv::v0.11.0.pre
6: 0x472030 - rt::rtio::LocalIo<'a>::borrow::h842cb4f2d84fdb8b5bv::v0.11.0.pre
7: 0x4723d0 - io::stdio::src::h11364002286917177819::v0.11.0.pre
8: 0x4729a0 - io::stdio::with_task_stdout::hb01b740306898b1eALp::v0.11.0.pre
9: 0x4764a0 - io::stdio::println_args::h924873875200ca8aRQp::v0.11.0.pre
10: 0x407420 - testing::h2e53314e7edb7f5eoga::v0.0
11: 0x407360 - main::closure.2145
12: 0x4772d0 - rt::task::Task::run::closure.25247
13: 0x4855a0 - rust_try
14: 0x477220 - rt::task::Task::run::hda8101fd3672740eAQu::v0.11.0.pre
15: 0x404f60 - main::h61e0dc92ec131703Tea::v0.0
16: 0x45ea10 - start::closure.7884
17: 0x4772d0 - rt::task::Task::run::closure.25247
18: 0x4855a0 - rust_try
19: 0x477220 - rt::task::Task::run::hda8101fd3672740eAQu::v0.11.0.pre
20: 0x45e650 - start::h3ff5ebe13c0e357eqqe::v0.11.0.pre
21: 0x45e5c0 - lang_start::h8e81b66aa034d05bKpe::v0.11.0.pre
22: 0x405600 - main
23: 0x7fd662087cf0 - __libc_start_main
24: 0x402fbd - <unknown>
25: 0x0 - <unknown>
[1] 51012 illegal hardware instruction RUST_BACKTRACE=1 ./test
extern crate debug;
use std::mem::transmute;
use std::rt::task::Task;
use std::rt::local::Local;
use std::any::Any;
struct RawUnwinder {
unwinding: bool,
cause: Option<Box<Any:Send>>
}
#[deriving(Show)]
struct Inner {
text: String
}
#[deriving(Show)]
struct Args<'a> {
fail: bool,
first: String,
second: Vec<&'static str>,
reference: Option<&'a Inner>
}
fn main() {
let inner = Inner { text: "Heyo".to_str() };
let mut args = Some(box Args { fail: false, first: "hello".to_str(), second: vec!("world", "and", "stuff"), reference: Some(&inner) });
let mut fail = Some(box Args { fail: true, first: "hello".to_str(), second: vec!(), reference: None });
(box Task::new()).run(|| testing(args.take_unwrap()));
(box Task::new()).run(|| testing(fail.take_unwrap()));
//local_unwinder_try(|| testing(args.take_unwrap()));
//local_unwinder_try(|| testing(fail.take_unwrap())).map_err(|e| println!("{}", e));
}
fn testing(args: &Args) {
if args.fail { fail!("YOLO BROLO"); }
println!("{}", args);
}
fn local_task_handle() -> *mut Task {
let task: Box<Task> = Local::take();
let handle: *mut Task = unsafe { *transmute::<&Box<Task>, &*mut Task>(&task) };
Local::put(task);
handle
}
fn unwinder_for_handle(handle: *mut Task) -> &mut std::rt::unwind::Unwinder {
unsafe { &mut ((*handle).unwinder) }
}
fn local_unwinder_try(closure: ||) -> Result<(), String> {
let handle = local_task_handle();
let unwinder = unwinder_for_handle(handle);
unwinder.try(closure);
match unwinder_result(unwinder) {
Some(string) => Err(string),
None => Ok(())
}
}
fn unwinder_result(unwinder: &mut std::rt::unwind::Unwinder) -> Option<String> {
let raw: &RawUnwinder = unsafe { transmute(unwinder) };
raw.cause.as_ref().map(|err| cause_str(err))
}
fn cause_str(reason: &Box<Any:Send>) -> String {
use std::any::AnyRefExt;
match reason.as_ref::<&'static str>() {
Some(s) => *s,
None => match reason.as_ref::<String>() {
Some(s) => s.as_slice(),
None => "Box<Any>",
}
}.to_str()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment