blob: 8964067da0b80e6f71e9f4ad0e4a3f95c8f05453 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// NB: Don't rely on other core mods here as this has to move into the rt
import unsafe::reinterpret_cast;
import ptr::offset;
import sys::size_of;
type word = uint;
class frame {
let fp: *word;
new(fp: *word) {
self.fp = fp;
}
}
fn walk_stack(visit: fn(frame) -> bool) {
#debug("beginning stack walk");
do frame_address |frame_pointer| {
let mut frame_address: *word = unsafe {
reinterpret_cast(frame_pointer)
};
loop {
let fr = frame(frame_address);
#debug("frame: %x", unsafe { reinterpret_cast(fr.fp) });
visit(fr);
unsafe {
let next_fp: **word = reinterpret_cast(frame_address);
frame_address = *next_fp;
if *frame_address == 0u {
#debug("encountered task_start_wrapper. ending walk");
// This is the task_start_wrapper_frame. There is
// no stack beneath it and it is a foreign frame.
break;
}
}
}
}
}
#[test]
fn test_simple() {
for walk_stack |_frame| {
}
}
#[test]
fn test_simple_deep() {
fn run(i: int) {
if i == 0 { ret }
for walk_stack |_frame| {
unsafe {
breakpoint();
}
}
run(i - 1);
}
run(10);
}
fn breakpoint() {
rustrt::rust_dbg_breakpoint()
}
fn frame_address(f: fn(*u8)) {
rusti::frame_address(f)
}
extern mod rustrt {
fn rust_dbg_breakpoint();
}
#[abi = "rust-intrinsic"]
extern mod rusti {
fn frame_address(f: fn(*u8));
}
|