From 28256052a4b141350dc0fe4e2e5357137bb49706 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 2 May 2013 18:33:18 -0400 Subject: core: Use the new `for` protocol --- src/libcore/stackwalk.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/libcore/stackwalk.rs') diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 1958b5b9d80..e86416f2499 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -24,6 +24,7 @@ pub fn Frame(fp: *Word) -> Frame { } } +#[cfg(stage0)] pub fn walk_stack(visit: &fn(Frame) -> bool) { debug!("beginning stack walk"); @@ -51,6 +52,35 @@ pub fn walk_stack(visit: &fn(Frame) -> bool) { } } } +#[cfg(not(stage0))] +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; +} #[test] fn test_simple() { -- cgit 1.4.1-3-g733a5