ciabatta/src/_win/assert.c

43 lines
1.1 KiB
C
Raw Normal View History

2022-06-20 06:28:03 +00:00
2022-07-24 15:57:12 +00:00
#include <assert.h>
2022-06-20 06:28:03 +00:00
2022-07-24 15:57:12 +00:00
static void _print_stack_trace() {
2022-06-20 06:28:03 +00:00
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
void *stack[128];
USHORT frames = CaptureStackBackTrace(2, 128, stack, NULL);
SYMBOL_INFO* symbol = calloc(sizeof(SYMBOL_INFO)+256, 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
for(size_t i = 0; i < frames; i++) {
SymFromAddr(process, (DWORD64)stack[i], 0, symbol);
2022-06-26 06:42:17 +00:00
// if(strcmp(symbol->Name, "BaseThreadInitThunk") == 0) break;
// if(strcmp(symbol->Name, "mainCRTStartup") == 0) break;
printf(//" %u: 0x%"PRIx64" (%s)\n",
" %d: %s\n",
(int)(frames-i-1),
//symbol->Address,
symbol->Name
);
2022-06-20 06:28:03 +00:00
}
free(symbol);
}
2022-07-24 15:57:12 +00:00
void _Noreturn _assert(
char const *cond,
char const *func,
char const *file,
int line
) {
printf("Assertion failed: %s\n", cond);
printf(" Function: %s\n", func);
printf(" File: %s\n", file);
printf(" Line: %d\n", line);
printf("Trace:\n");
_print_stack_trace();
abort();
}