File tree Expand file tree Collapse file tree 1 file changed +48
-9
lines changed Expand file tree Collapse file tree 1 file changed +48
-9
lines changed Original file line number Diff line number Diff line change 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 ;
2
8
3
9
class frame {
4
- let fp: uintptr_t ;
10
+ let fp: * word ;
5
11
6
- new ( fp: uintptr_t ) {
12
+ new ( fp: * word ) {
7
13
self . fp = fp;
8
14
}
9
15
}
10
16
11
17
fn walk_stack ( visit : fn ( frame ) -> bool ) {
18
+
19
+ #debug ( "beginning stack walk" ) ;
20
+
12
21
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)
15
24
} ;
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 == 0 u {
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
+ }
17
42
}
18
43
}
19
44
20
45
#[ test]
21
- fn test ( ) {
46
+ fn test_simple ( ) {
22
47
for walk_stack { |frame|
23
- #debug( "frame: %x" , frame. fp) ;
24
- // breakpoint();
25
48
}
26
49
}
27
50
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
+
28
67
fn breakpoint ( ) {
29
68
rustrt:: rust_dbg_breakpoint ( )
30
69
}
You can’t perform that action at this time.
0 commit comments