2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-28 16:35:52 -05:00
|
|
|
#[allow(missing_doc)];
|
|
|
|
|
2013-04-20 09:27:16 -05:00
|
|
|
use cast::transmute;
|
2013-05-09 14:49:14 -05:00
|
|
|
use unstable::intrinsics;
|
2012-06-12 00:44:55 -05:00
|
|
|
|
2012-09-23 18:42:05 -05:00
|
|
|
pub type Word = uint;
|
2012-06-05 20:47:18 -05:00
|
|
|
|
2012-09-23 18:42:05 -05:00
|
|
|
pub struct Frame {
|
2012-09-06 21:40:15 -05:00
|
|
|
fp: *Word
|
2012-09-04 17:23:28 -05:00
|
|
|
}
|
2012-06-05 20:47:18 -05:00
|
|
|
|
2012-09-23 18:42:05 -05:00
|
|
|
pub fn Frame(fp: *Word) -> Frame {
|
2012-09-04 17:23:28 -05:00
|
|
|
Frame {
|
|
|
|
fp: fp
|
2012-06-05 20:47:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 17:33:18 -05:00
|
|
|
pub fn walk_stack(visit: &fn(Frame) -> bool) -> bool {
|
|
|
|
|
|
|
|
debug!("beginning stack walk");
|
|
|
|
|
|
|
|
do frame_address |frame_pointer| {
|
|
|
|
let mut frame_address: *Word = unsafe {
|
|
|
|
transmute(frame_pointer)
|
|
|
|
};
|
|
|
|
loop {
|
|
|
|
let fr = Frame(frame_address);
|
|
|
|
|
|
|
|
debug!("frame: %x", unsafe { transmute(fr.fp) });
|
|
|
|
visit(fr);
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let next_fp: **Word = transmute(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
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| {
|
2013-05-05 22:13:32 -05:00
|
|
|
// Would be nice to test something here...
|
2012-06-12 00:44:55 -05:00
|
|
|
}
|
|
|
|
run(i - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
run(10);
|
|
|
|
}
|
|
|
|
|
2013-03-27 19:14:10 -05:00
|
|
|
fn frame_address(f: &fn(x: *u8)) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-05-09 14:49:14 -05:00
|
|
|
intrinsics::frame_address(f)
|
2013-03-05 13:57:50 -06:00
|
|
|
}
|
2012-06-05 20:47:18 -05:00
|
|
|
}
|