about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-03-26 18:58:40 -0700
committerBrian Anderson <banderson@mozilla.com>2012-03-29 16:43:18 -0700
commitb17145b4ae36f78ed9b53b8875b6822ae59da1ae (patch)
treefaf8053772cd967e02dff12755edb7849c896af0 /src/rt
parent3ff01361d578d611d3b09c3abca059f7cecd204c (diff)
downloadrust-b17145b4ae36f78ed9b53b8875b6822ae59da1ae.tar.gz
rust-b17145b4ae36f78ed9b53b8875b6822ae59da1ae.zip
rt: Track backtraces of all allocations with RUSTRT_TRACK_ALLOCATIONS=3
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/memory_region.cpp17
-rw-r--r--src/rt/memory_region.h5
2 files changed, 22 insertions, 0 deletions
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp
index e4130e80f5a..770691e88ea 100644
--- a/src/rt/memory_region.cpp
+++ b/src/rt/memory_region.cpp
@@ -1,6 +1,10 @@
 #include "rust_internal.h"
 #include "memory_region.h"
 
+#if RUSTRT_TRACK_ALLOCATIONS >= 3
+#include <execinfo.h>
+#endif
+
 #if RUSTRT_TRACK_ALLOCATIONS >= 1
 // For some platforms, 16 byte alignment is required.
 #  define PTR_SIZE 16
@@ -148,6 +152,13 @@ memory_region::~memory_region() {
                        header->tag,
                        (uintptr_t) get_data(header));
                 ++leak_count;
+
+#               if RUSTRT_TRACK_ALLOCATIONS >= 3
+                if (_detailed_leaks) {
+                    backtrace_symbols_fd(header->bt + 1,
+                                         header->btframes - 1, 2);
+                }
+#               endif
             }
         }
         assert(leak_count == _live_allocations);
@@ -199,6 +210,12 @@ memory_region::claim_alloc(void *mem) {
     if (_synchronized) { _lock.unlock(); }
 #   endif
 
+#   if RUSTRT_TRACK_ALLOCATIONS >= 3
+    if (_detailed_leaks) {
+        alloc->btframes = ::backtrace(alloc->bt, 32);
+    }
+#   endif
+
     add_alloc();
 }
 
diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h
index a72c87f9be9..57108ae58a8 100644
--- a/src/rt/memory_region.h
+++ b/src/rt/memory_region.h
@@ -16,6 +16,7 @@
 // 0 --- no headers, no debugging support
 // 1 --- support poison, but do not track allocations
 // 2 --- track allocations in detail
+// 3 --- record backtraces of every allocation
 //
 // NB: please do not commit code with level 2. It's
 // hugely expensive and should only be used as a last resort.
@@ -31,6 +32,10 @@ private:
         int index;
         const char *tag;
         uint32_t size;
+#       if RUSTRT_TRACK_ALLOCATIONS >= 3
+        void *bt[32];
+        int btframes;
+#       endif
 #       endif
     };