]> git.lizzy.rs Git - rust.git/blob - src/libstd/dbg.rs
Remove 'Local Variable' comments
[rust.git] / src / libstd / dbg.rs
1 // Copyright 2012 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.
4 //
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.
10
11 //! Unsafe debugging functions for inspecting values.
12
13 use core::cast::transmute;
14 use core::sys;
15
16 pub mod rustrt {
17     use core::sys;
18
19     #[abi = "cdecl"]
20     pub extern {
21         pub unsafe fn debug_tydesc(td: *sys::TypeDesc);
22         pub unsafe fn debug_opaque(td: *sys::TypeDesc, x: *());
23         pub unsafe fn debug_box(td: *sys::TypeDesc, x: *());
24         pub unsafe fn debug_tag(td: *sys::TypeDesc, x: *());
25         pub unsafe fn debug_fn(td: *sys::TypeDesc, x: *());
26         pub unsafe fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
27         pub unsafe fn rust_dbg_breakpoint();
28     }
29 }
30
31 pub fn debug_tydesc<T>() {
32     unsafe {
33         rustrt::debug_tydesc(sys::get_type_desc::<T>());
34     }
35 }
36
37 pub fn debug_opaque<T>(x: T) {
38     unsafe {
39         rustrt::debug_opaque(sys::get_type_desc::<T>(), transmute(&x));
40     }
41 }
42
43 pub fn debug_box<T>(x: @T) {
44     unsafe {
45         rustrt::debug_box(sys::get_type_desc::<T>(), transmute(&x));
46     }
47 }
48
49 pub fn debug_tag<T>(x: T) {
50     unsafe {
51         rustrt::debug_tag(sys::get_type_desc::<T>(), transmute(&x));
52     }
53 }
54
55 pub fn debug_fn<T>(x: T) {
56     unsafe {
57         rustrt::debug_fn(sys::get_type_desc::<T>(), transmute(&x));
58     }
59 }
60
61 pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
62     transmute(
63         rustrt::debug_ptrcast(sys::get_type_desc::<T>(), transmute(x)))
64 }
65
66 /// Triggers a debugger breakpoint
67 pub fn breakpoint() {
68     unsafe {
69         rustrt::rust_dbg_breakpoint();
70     }
71 }
72
73 #[test]
74 fn test_breakpoint_should_not_abort_process_when_not_under_gdb() {
75     // Triggering a breakpoint involves raising SIGTRAP, which terminates
76     // the process under normal circumstances
77     breakpoint();
78 }