X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdebug.cpp;h=3761e416d5c0b2ef4bbf7ace693b2cb086121a75;hb=fdede6003446efe2002fc650f635f1be73265116;hp=3b2fb641a132eb76b34449b64f29ac536c561c28;hpb=0fd1ee03808ee8121e7b65e5c7c9ba19599d185e;p=dragonfireclient.git diff --git a/src/debug.cpp b/src/debug.cpp index 3b2fb641a..3761e416d 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -26,118 +26,43 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include "jthread/jmutex.h" -#include "jthread/jmutexautolock.h" +#include +#include "threading/mutex.h" +#include "threading/mutex_auto_lock.h" #include "config.h" -/* - Debug output -*/ - -#define DEBUGSTREAM_COUNT 2 -FILE *g_debugstreams[DEBUGSTREAM_COUNT] = {stderr, NULL}; +#ifdef _MSC_VER + #include + #include "version.h" + #include "filesys.h" +#endif -#define DEBUGPRINT(...)\ -{\ - for(int i=0; i g_debug_stacks; -JMutex g_debug_stacks_mutex; +Mutex g_debug_stacks_mutex; void debug_stacks_init() { @@ -214,7 +148,7 @@ void debug_stacks_init() void debug_stacks_print_to(std::ostream &os) { - JMutexAutoLock lock(g_debug_stacks_mutex); + MutexAutoLock lock(g_debug_stacks_mutex); os<<"Debug stacks:"<::iterator - i = g_debug_stacks.begin(); - i != g_debug_stacks.end(); ++i) - { - DebugStack *stack = i->second; - - for(int i=0; iprint(g_debugstreams[i], true); - } - } + debug_stacks_print_to(errorstream); } DebugStacker::DebugStacker(const char *text) { - threadid_t threadid = get_current_thread_id(); + threadid_t threadid = thr_get_current_thread_id(); - JMutexAutoLock lock(g_debug_stacks_mutex); + MutexAutoLock lock(g_debug_stacks_mutex); std::map::iterator n; n = g_debug_stacks.find(threadid); @@ -284,11 +203,11 @@ DebugStacker::DebugStacker(const char *text) DebugStacker::~DebugStacker() { - JMutexAutoLock lock(g_debug_stacks_mutex); - + MutexAutoLock lock(g_debug_stacks_mutex); + if(m_overflowed == true) return; - + m_stack->stack_i--; if(m_stack->stack_i == 0) @@ -301,35 +220,124 @@ DebugStacker::~DebugStacker() } } - #ifdef _MSC_VER -#if CATCH_UNHANDLED_EXCEPTIONS == 1 -void se_trans_func(unsigned int u, EXCEPTION_POINTERS* pExp) + +const char *Win32ExceptionCodeToString(DWORD exception_code) { - dstream<<"In trans_func.\n"; - if(u == EXCEPTION_ACCESS_VIOLATION) - { - PEXCEPTION_RECORD r = pExp->ExceptionRecord; - dstream<<"Access violation at "<ExceptionAddress - <<" write?="<ExceptionInformation[0] - <<" address="<ExceptionInformation[1] - <ExceptionRecord->ExceptionCode; + _snprintf(buf, sizeof(buf), + " >> === FATAL ERROR ===\n" + " >> %s (Exception 0x%08X) at 0x%p\n", + Win32ExceptionCodeToString(excode), excode, + pExceptInfo->ExceptionRecord->ExceptionAddress); + dstream << buf; + + if (minidump_created) + dstream << " >> Saved dump to " << dumpfile << std::endl; + else + dstream << " >> Failed to save dump" << std::endl; + + return EXCEPTION_EXECUTE_HANDLER; +} + +#endif + +void debug_set_exception_handler() +{ +#ifdef _MSC_VER + SetUnhandledExceptionFilter(Win32ExceptionHandler); +#endif +}