Skip to content

Commit f699c78

Browse files
committed
---
yaml --- r: 15229 b: refs/heads/try c: b17145b h: refs/heads/master i: 15227: 1077202 v: v3
1 parent 0cf12ae commit f699c78

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 3ff01361d578d611d3b09c3abca059f7cecd204c
5+
refs/heads/try: b17145b4ae36f78ed9b53b8875b6822ae59da1ae
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rt/memory_region.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "rust_internal.h"
22
#include "memory_region.h"
33

4+
#if RUSTRT_TRACK_ALLOCATIONS >= 3
5+
#include <execinfo.h>
6+
#endif
7+
48
#if RUSTRT_TRACK_ALLOCATIONS >= 1
59
// For some platforms, 16 byte alignment is required.
610
# define PTR_SIZE 16
@@ -148,6 +152,13 @@ memory_region::~memory_region() {
148152
header->tag,
149153
(uintptr_t) get_data(header));
150154
++leak_count;
155+
156+
# if RUSTRT_TRACK_ALLOCATIONS >= 3
157+
if (_detailed_leaks) {
158+
backtrace_symbols_fd(header->bt + 1,
159+
header->btframes - 1, 2);
160+
}
161+
# endif
151162
}
152163
}
153164
assert(leak_count == _live_allocations);
@@ -199,6 +210,12 @@ memory_region::claim_alloc(void *mem) {
199210
if (_synchronized) { _lock.unlock(); }
200211
# endif
201212

213+
# if RUSTRT_TRACK_ALLOCATIONS >= 3
214+
if (_detailed_leaks) {
215+
alloc->btframes = ::backtrace(alloc->bt, 32);
216+
}
217+
# endif
218+
202219
add_alloc();
203220
}
204221

branches/try/src/rt/memory_region.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// 0 --- no headers, no debugging support
1717
// 1 --- support poison, but do not track allocations
1818
// 2 --- track allocations in detail
19+
// 3 --- record backtraces of every allocation
1920
//
2021
// NB: please do not commit code with level 2. It's
2122
// hugely expensive and should only be used as a last resort.
@@ -31,6 +32,10 @@ class memory_region {
3132
int index;
3233
const char *tag;
3334
uint32_t size;
35+
# if RUSTRT_TRACK_ALLOCATIONS >= 3
36+
void *bt[32];
37+
int btframes;
38+
# endif
3439
# endif
3540
};
3641

0 commit comments

Comments
 (0)