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_debug.cpp | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'src/rt/rust_debug.cpp') diff --git a/src/rt/rust_debug.cpp b/src/rt/rust_debug.cpp index 7bb80a4f36e..9591d9ade07 100644 --- a/src/rt/rust_debug.cpp +++ b/src/rt/rust_debug.cpp @@ -1,5 +1,6 @@ // Routines useful when debugging the Rust runtime. +#include "rust_abi.h" #include "rust_debug.h" #include "rust_internal.h" @@ -8,13 +9,6 @@ #include #include -#if defined(__APPLE__) || defined(__linux__) -#define HAVE_BACKTRACE -#include -#elif defined(_WIN32) -#include -#endif - namespace { debug::flag track_origins("RUST_TRACK_ORIGINS"); @@ -23,38 +17,12 @@ debug::flag track_origins("RUST_TRACK_ORIGINS"); namespace debug { -#ifdef HAVE_BACKTRACE -std::string -backtrace() { - void *call_stack[128]; - int n_frames = ::backtrace(call_stack, 128); - char **syms = backtrace_symbols(call_stack, n_frames); - - std::cerr << "n_frames: " << n_frames << std::endl; - - std::stringstream ss; - for (int i = 0; i < n_frames; i++) { - std::cerr << syms[i] << std::endl; - ss << syms[i] << std::endl; - } - - free(syms); - - return ss.str(); -} -#else -std::string -backtrace() { - std::string s; - return s; -} -#endif - void maybe_track_origin(rust_task *task, void *ptr) { if (!*track_origins) return; - task->debug.origins[ptr] = backtrace(); + task->debug.origins[ptr] = + stack_walk::symbolicate(stack_walk::backtrace()); } void -- cgit 1.4.1-3-g733a5