about summary refs log tree commit diff
path: root/src/rt/rust_abi.cpp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-09-23 12:48:55 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-09-23 12:49:20 -0700
commitaabff480c92d7c72f8a8ff6652d328e6624585d5 (patch)
tree18fcb23d732ca89997de2901883efeddfc7137f7 /src/rt/rust_abi.cpp
parentd10d23f0ad4763642619d2d3e42f8150f7d91af3 (diff)
downloadrust-aabff480c92d7c72f8a8ff6652d328e6624585d5.tar.gz
rust-aabff480c92d7c72f8a8ff6652d328e6624585d5.zip
rt: Factor out stack walking into rust_abi.cpp
Diffstat (limited to 'src/rt/rust_abi.cpp')
-rw-r--r--src/rt/rust_abi.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/rt/rust_abi.cpp b/src/rt/rust_abi.cpp
index 98b80fb41bd..2a08a25a9fa 100644
--- a/src/rt/rust_abi.cpp
+++ b/src/rt/rust_abi.cpp
@@ -1,10 +1,35 @@
+// ABI-specific routines.
+
+#include <vector>
 #include <cstdlib>
 #include <stdint.h>
 #include "rust_abi.h"
 
+#define END_OF_STACK_RA     (void (*)())0xdeadbeef
+
 weak_symbol<uint32_t> abi_version("rust_abi_version");
 
 uint32_t get_abi_version() {
     return (*abi_version == NULL) ? 0 : **abi_version;
 }
 
+namespace stack_walk {
+
+std::vector<frame>
+backtrace() {
+    std::vector<frame> frames;
+
+    // Ideally we would use the current value of EIP here, but there's no
+    // portable way to get that and there are never any GC roots in our C++
+    // frames anyhow.
+    frame f(__builtin_frame_address(0), (void (*)())NULL);
+
+    while (f.ra != END_OF_STACK_RA) {
+        frames.push_back(f);
+        f.next();
+    }
+    return frames;
+}
+
+}   // end namespace stack_walk
+