about summary refs log tree commit diff
path: root/src/rt/memory_region.cpp
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/memory_region.cpp
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/memory_region.cpp')
-rw-r--r--src/rt/memory_region.cpp17
1 files changed, 17 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();
 }