mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-10 01:09:31 +03:00
Merge branch 'dev-trace' into dev-slice-trace
This commit is contained in:
commit
80c86e7cba
3 changed files with 42 additions and 24 deletions
|
@ -65,7 +65,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MI_DEBUG_TRACE_LEN)
|
#if !defined(MI_DEBUG_TRACE_LEN)
|
||||||
#define MI_DEBUG_TRACE_LEN (7) // store up to N frames if tracing is enabled
|
#define MI_DEBUG_TRACE_LEN (8) // store up to N frames if tracing is enabled
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MI_PADDING_EXTRA) // use extra padding bytes? (so a stack trace can be preserved or next block corruption prevented)
|
#if !defined(MI_PADDING_EXTRA) // use extra padding bytes? (so a stack trace can be preserved or next block corruption prevented)
|
||||||
|
|
|
@ -461,7 +461,7 @@ static void mi_allocator_done(void) {
|
||||||
// Called once by the process loader
|
// Called once by the process loader
|
||||||
static void mi_process_load(void) {
|
static void mi_process_load(void) {
|
||||||
mi_heap_main_init();
|
mi_heap_main_init();
|
||||||
#if defined(MI_TLS_RECURSE_GUARD)
|
#if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD)
|
||||||
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
|
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
|
||||||
MI_UNUSED(dummy);
|
MI_UNUSED(dummy);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -374,22 +374,31 @@ void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
||||||
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
||||||
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
||||||
(msg==NULL ? "block" : msg), block, avail, bsize);
|
(msg==NULL ? "block" : msg), block, avail, bsize);
|
||||||
PSYMBOL_INFO info = (PSYMBOL_INFO)_malloca(sizeof(SYMBOL_INFO) + 256 * sizeof(TCHAR));
|
uintptr_t uninit = 0;
|
||||||
if (info==NULL) return;
|
for( size_t i = 0; i < MI_INTPTR_SIZE; i++ ) {
|
||||||
memset(info, 0, sizeof(info));
|
uninit = (uninit << 8) | MI_DEBUG_UNINIT;
|
||||||
info->MaxNameLen = 255;
|
}
|
||||||
info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
if (strace == NULL || uninit == (uintptr_t)strace[0]) {
|
||||||
HANDLE current_process = GetCurrentProcess();
|
_mi_fprintf(NULL, NULL, " (uninitialized trace)\n");
|
||||||
if (!SymInitialize(current_process, NULL, TRUE)) return;
|
}
|
||||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
else {
|
||||||
if (SymFromAddr(current_process, (DWORD64)(strace[i]), 0, info)) {
|
PSYMBOL_INFO info = (PSYMBOL_INFO)_malloca(sizeof(SYMBOL_INFO) + 256 * sizeof(TCHAR));
|
||||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], info->Name);
|
if (info==NULL) return;
|
||||||
}
|
memset(info, 0, sizeof(info));
|
||||||
else {
|
info->MaxNameLen = 255;
|
||||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: <unknown address: error: 0x%04x>\n", i, strace[i], GetLastError());
|
info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||||
}
|
HANDLE current_process = GetCurrentProcess();
|
||||||
|
if (!SymInitialize(current_process, NULL, TRUE)) return;
|
||||||
|
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||||
|
if (SymFromAddr(current_process, (DWORD64)(strace[i]), 0, info)) {
|
||||||
|
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], info->Name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_mi_fprintf(NULL, NULL, " %2zu: %8p: <unknown address: error: 0x%04x>\n", i, strace[i], GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SymCleanup(current_process);
|
||||||
}
|
}
|
||||||
SymCleanup(current_process);
|
|
||||||
}
|
}
|
||||||
#elif (MI_DEBUG_TRACE > 0) && (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__))
|
#elif (MI_DEBUG_TRACE > 0) && (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__))
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
@ -412,13 +421,22 @@ void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
||||||
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
||||||
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
||||||
(msg==NULL ? "block" : msg), block, avail, bsize);
|
(msg==NULL ? "block" : msg), block, avail, bsize);
|
||||||
while( len > 0 && strace[len-1] == NULL) { len--; }
|
uintptr_t uninit = 0;
|
||||||
if (len == 0) return;
|
for( size_t i = 0; i < MI_INTPTR_SIZE; i++ ) {
|
||||||
char** names = backtrace_symbols(strace, len);
|
uninit = (uninit << 8) | MI_DEBUG_UNINIT;
|
||||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
}
|
||||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], (names == NULL || names[i] == NULL ? "<unknown>" : names[i]));
|
if (strace == NULL || uninit == (uintptr_t)strace[0]) {
|
||||||
|
_mi_fprintf(NULL, NULL, " (uninitialized trace)\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while( len > 0 && strace[len-1] == NULL) { len--; }
|
||||||
|
if (len == 0) return;
|
||||||
|
char** names = backtrace_symbols(strace, len);
|
||||||
|
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||||
|
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], (names == NULL || names[i] == NULL ? "<unknown>" : names[i]));
|
||||||
|
}
|
||||||
|
// free(names); // avoid potential recursion and leak the trace
|
||||||
}
|
}
|
||||||
// free(names); // avoid potential recursion and leak the trace
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue