From 557d641175c505d34bf3eac194597d1d2fc3a494 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 23 Sep 2011 15:05:24 -0700 Subject: rt: Get RUST_TRACK_ORIGINS working. You can now call 'debug::dump_origin' in gdb and get a backtrace saying where a box came from. --- src/rt/rust_abi.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/rt/rust_abi.cpp') diff --git a/src/rt/rust_abi.cpp b/src/rt/rust_abi.cpp index 2a08a25a9fa..3fba1ada3f3 100644 --- a/src/rt/rust_abi.cpp +++ b/src/rt/rust_abi.cpp @@ -1,10 +1,19 @@ // ABI-specific routines. +#include +#include #include #include #include #include "rust_abi.h" +#if defined(__APPLE__) || defined(__linux__) +#define HAVE_DLFCN_H +#include +#elif defined(_WIN32) +// TODO +#endif + #define END_OF_STACK_RA (void (*)())0xdeadbeef weak_symbol abi_version("rust_abi_version"); @@ -15,6 +24,29 @@ uint32_t get_abi_version() { namespace stack_walk { +#ifdef HAVE_DLFCN_H +std::string +frame::symbol() const { + std::stringstream ss; + + Dl_info info; + if (!dladdr((void *)ra, &info)) + ss << "??"; + else + ss << info.dli_sname; + + ss << " @ " << std::hex << (uintptr_t)ra; + return ss.str(); +} +#else +std::string +frame::symbol() { + std::stringstream ss; + ss << std::hex << (uintptr_t)ra; + return ss.str(); +} +#endif + std::vector backtrace() { std::vector frames; @@ -31,5 +63,17 @@ backtrace() { return frames; } +std::string +symbolicate(const std::vector &frames) { + std::stringstream ss; + std::vector::const_iterator begin(frames.begin()), + end(frames.end()); + while (begin != end) { + ss << begin->symbol() << std::endl; + ++begin; + } + return ss.str(); +} + } // end namespace stack_walk -- cgit 1.4.1-3-g733a5