1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Simple backtrace functionality (to print on panic)
13 #![allow(non_camel_case_types)]
20 pub use sys::backtrace::write;
22 // For now logging is turned off by default, and this function checks to see
23 // whether the magical environment variable is present to see if it's turned on.
24 pub fn log_enabled() -> bool {
25 static ENABLED: atomic::AtomicInt = atomic::ATOMIC_INT_INIT;
26 match ENABLED.load(atomic::SeqCst) {
32 let val = match os::getenv("RUST_BACKTRACE") {
36 ENABLED.store(val, atomic::SeqCst);
44 macro_rules! t { ($a:expr, $b:expr) => ({
45 let mut m = Vec::new();
46 sys_common::backtrace::demangle(&mut m, $a).unwrap();
47 assert_eq!(String::from_utf8(m).unwrap(), $b);
53 t!("_ZN4testE", "test");
54 t!("_ZN4test", "_ZN4test");
55 t!("_ZN4test1a2bcE", "test::a::bc");
59 fn demangle_dollars() {
60 t!("_ZN4$UP$E", "Box");
61 t!("_ZN8$UP$testE", "Boxtest");
62 t!("_ZN8$UP$test4foobE", "Boxtest::foob");
63 t!("_ZN10$u{20}test4foobE", " test::foob");
67 fn demangle_many_dollars() {
68 t!("_ZN14test$u{20}test4foobE", "test test::foob");
69 t!("_ZN12test$UP$test4foobE", "testBoxtest::foob");
73 fn demangle_windows() {
74 t!("ZN4testE", "test");
75 t!("ZN14test$u{20}test4foobE", "test test::foob");
76 t!("ZN12test$UP$test4foobE", "testBoxtest::foob");