From 03f4d20bcf7f1819f31aa78315a7e8358928ca68 Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Thu, 30 Apr 2020 14:00:11 -0600 Subject: Revert "Windows: Support backtraces on release builds." Issues with older cmake. --- source/blender/blenlib/intern/system.c | 51 ++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'source/blender/blenlib/intern/system.c') diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c index f0597b0e9e7..7d9ed2598a6 100644 --- a/source/blender/blenlib/intern/system.c +++ b/source/blender/blenlib/intern/system.c @@ -32,7 +32,11 @@ /* for backtrace and gethostname/GetComputerName */ #if defined(WIN32) # include -# include "BLI_winstuff.h" +# include +# pragma warning(push) +# pragma warning(disable : 4091) +# include +# pragma warning(pop) #else # include # include @@ -70,8 +74,6 @@ int BLI_cpu_support_sse2(void) #endif } -/* Windows stackwalk lives in system_win32.c */ -#if !defined(_MSC_VER) /** * Write a backtrace into a file for systems which support it. */ @@ -79,9 +81,9 @@ void BLI_system_backtrace(FILE *fp) { /* ------------- */ /* Linux / Apple */ -# if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) -# define SIZE 100 +# define SIZE 100 void *buffer[SIZE]; int nptrs; char **strings; @@ -96,15 +98,48 @@ void BLI_system_backtrace(FILE *fp) } free(strings); -# undef SIZE +# undef SIZE + + /* -------- */ + /* Windows */ +#elif defined(_MSC_VER) + +# ifndef NDEBUG +# define MAXSYMBOL 256 +# define SIZE 100 + unsigned short i; + void *stack[SIZE]; + unsigned short nframes; + SYMBOL_INFO *symbolinfo; + HANDLE process; + + process = GetCurrentProcess(); + + SymInitialize(process, NULL, TRUE); + + nframes = CaptureStackBackTrace(0, SIZE, stack, NULL); + symbolinfo = MEM_callocN(sizeof(SYMBOL_INFO) + MAXSYMBOL * sizeof(char), "crash Symbol table"); + symbolinfo->MaxNameLen = MAXSYMBOL - 1; + symbolinfo->SizeOfStruct = sizeof(SYMBOL_INFO); + for (i = 0; i < nframes; i++) { + SymFromAddr(process, (DWORD64)(stack[i]), 0, symbolinfo); + + fprintf(fp, "%u: %s - 0x%0llX\n", nframes - i - 1, symbolinfo->Name, symbolinfo->Address); + } + + MEM_freeN(symbolinfo); +# undef MAXSYMBOL +# undef SIZE # else + fprintf(fp, "Crash backtrace not supported on release builds\n"); +# endif /* NDEBUG */ +#else /* _MSC_VER */ /* ------------------ */ /* non msvc/osx/linux */ (void)fp; -# endif -} #endif +} /* end BLI_system_backtrace */ /* NOTE: The code for CPU brand string is adopted from Cycles. */ -- cgit v1.2.3