2012-06-12 00:44:55 -05:00
|
|
|
// 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;
|
2012-06-05 20:47:18 -05:00
|
|
|
|
|
|
|
class frame {
|
2012-06-12 00:44:55 -05:00
|
|
|
let fp: *word;
|
2012-06-05 20:47:18 -05:00
|
|
|
|
2012-06-12 00:44:55 -05:00
|
|
|
new(fp: *word) {
|
2012-06-05 20:47:18 -05:00
|
|
|
self.fp = fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn walk_stack(visit: fn(frame) -> bool) {
|
2012-06-12 00:44:55 -05:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"beginning stack walk"};
|
2012-06-12 00:44:55 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do frame_address |frame_pointer| {
|
2012-06-12 00:44:55 -05:00
|
|
|
let mut frame_address: *word = unsafe {
|
|
|
|
reinterpret_cast(frame_pointer)
|
2012-06-05 20:47:18 -05:00
|
|
|
};
|
2012-06-12 00:44:55 -05:00
|
|
|
loop {
|
2012-06-19 14:01:02 -05:00
|
|
|
let fr = frame(frame_address);
|
2012-06-12 00:44:55 -05:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"frame: %x", unsafe { reinterpret_cast(fr.fp) }};
|
2012-06-19 14:01:02 -05:00
|
|
|
visit(fr);
|
2012-06-12 00:44:55 -05:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let next_fp: **word = reinterpret_cast(frame_address);
|
|
|
|
frame_address = *next_fp;
|
|
|
|
if *frame_address == 0u {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"encountered task_start_wrapper. ending walk"};
|
2012-06-12 00:44:55 -05:00
|
|
|
// This is the task_start_wrapper_frame. There is
|
2012-07-03 18:11:00 -05:00
|
|
|
// no stack beneath it and it is a foreign frame.
|
2012-06-12 00:44:55 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-05 20:47:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-06-12 00:44:55 -05:00
|
|
|
fn test_simple() {
|
2012-06-30 18:19:07 -05:00
|
|
|
for walk_stack |_frame| {
|
2012-06-05 20:47:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 00:44:55 -05:00
|
|
|
#[test]
|
|
|
|
fn test_simple_deep() {
|
|
|
|
fn run(i: int) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if i == 0 { return }
|
2012-06-12 00:44:55 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for walk_stack |_frame| {
|
2012-06-12 00:44:55 -05:00
|
|
|
unsafe {
|
|
|
|
breakpoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run(i - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
run(10);
|
|
|
|
}
|
|
|
|
|
2012-06-05 20:47:18 -05:00
|
|
|
fn breakpoint() {
|
|
|
|
rustrt::rust_dbg_breakpoint()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn frame_address(f: fn(*u8)) {
|
|
|
|
rusti::frame_address(f)
|
|
|
|
}
|
|
|
|
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rustrt {
|
2012-06-05 20:47:18 -05:00
|
|
|
fn rust_dbg_breakpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[abi = "rust-intrinsic"]
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rusti {
|
2012-06-05 20:47:18 -05:00
|
|
|
fn frame_address(f: fn(*u8));
|
|
|
|
}
|