提交 b17145b4 编写于 作者: B Brian Anderson

rt: Track backtraces of all allocations with RUSTRT_TRACK_ALLOCATIONS=3

上级 3ff01361
#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();
}
......
......@@ -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
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册