Skip to content

Commit 07bba39

Browse files
committed
core: More stack walking
1 parent 41df9cb commit 07bba39

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

src/libcore/stackwalk.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,69 @@
1-
import libc::uintptr_t;
1+
// NB: Don't rely on other core mods here as this has to move into the rt
2+
3+
import unsafe::reinterpret_cast;
4+
import ptr::offset;
5+
import sys::size_of;
6+
7+
type word = uint;
28

39
class frame {
4-
let fp: uintptr_t;
10+
let fp: *word;
511

6-
new(fp: uintptr_t) {
12+
new(fp: *word) {
713
self.fp = fp;
814
}
915
}
1016

1117
fn walk_stack(visit: fn(frame) -> bool) {
18+
19+
#debug("beginning stack walk");
20+
1221
frame_address { |frame_pointer|
13-
let frame_address = unsafe {
14-
unsafe::reinterpret_cast(frame_pointer)
22+
let mut frame_address: *word = unsafe {
23+
reinterpret_cast(frame_pointer)
1524
};
16-
visit(frame(frame_address));
25+
loop {
26+
let frame = frame(frame_address);
27+
28+
#debug("frame: %x", unsafe { reinterpret_cast(frame.fp) });
29+
visit(frame);
30+
31+
unsafe {
32+
let next_fp: **word = reinterpret_cast(frame_address);
33+
frame_address = *next_fp;
34+
if *frame_address == 0u {
35+
#debug("encountered task_start_wrapper. ending walk");
36+
// This is the task_start_wrapper_frame. There is
37+
// no stack beneath it and it is a native frame.
38+
break;
39+
}
40+
}
41+
}
1742
}
1843
}
1944

2045
#[test]
21-
fn test() {
46+
fn test_simple() {
2247
for walk_stack { |frame|
23-
#debug("frame: %x", frame.fp);
24-
// breakpoint();
2548
}
2649
}
2750

51+
#[test]
52+
fn test_simple_deep() {
53+
fn run(i: int) {
54+
if i == 0 { ret }
55+
56+
for walk_stack { |frame|
57+
unsafe {
58+
breakpoint();
59+
}
60+
}
61+
run(i - 1);
62+
}
63+
64+
run(10);
65+
}
66+
2867
fn breakpoint() {
2968
rustrt::rust_dbg_breakpoint()
3069
}

0 commit comments

Comments
 (0)