X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdebug.cpp;h=ae2ffadc3e2e5de24f5ff1f946ec80834529345d;hb=b2160bcecdecb00bb59e6ad8ece6518255dab4ad;hp=9fbdf7a396491d9c8d2304c44ad737ea41188268;hpb=fa64103aa87a8f0f2a3351bb4a54e93e8ade1082;p=dragonfireclient.git diff --git a/src/debug.cpp b/src/debug.cpp index 9fbdf7a39..ae2ffadc3 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1,42 +1,70 @@ /* -Minetest-c55 -Copyright (C) 2010 celeron55, Perttu Ahola +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "porting.h" #include "debug.h" +#include "exceptions.h" +#include "threads.h" #include #include -#include "porting.h" +#include +#include +#include "jthread/jmutex.h" +#include "jthread/jmutexautolock.h" +#include "config.h" + +#ifdef _MSC_VER + #include + #include "version.h" + #include "filesys.h" +#endif /* Debug output */ +#define DEBUGSTREAM_COUNT 2 + FILE *g_debugstreams[DEBUGSTREAM_COUNT] = {stderr, NULL}; +#define DEBUGPRINT(...)\ +{\ + for(int i=0; i g_debug_stacks; +std::map g_debug_stacks; JMutex g_debug_stacks_mutex; void debug_stacks_init() { - g_debug_stacks_mutex.Init(); +} + +void debug_stacks_print_to(std::ostream &os) +{ + JMutexAutoLock lock(g_debug_stacks_mutex); + + os<<"Debug stacks:"<::iterator + i = g_debug_stacks.begin(); + i != g_debug_stacks.end(); ++i) + { + i->second->print(os, false); + } } void debug_stacks_print() @@ -125,11 +255,11 @@ void debug_stacks_print() DEBUGPRINT("Debug stacks:\n"); - for(core::map::Iterator - i = g_debug_stacks.getIterator(); - i.atEnd() == false; i++) + for(std::map::iterator + i = g_debug_stacks.begin(); + i != g_debug_stacks.end(); ++i) { - DebugStack *stack = i.getNode()->getValue(); + DebugStack *stack = i->second; for(int i=0; i::Node *n; + std::map::iterator n; n = g_debug_stacks.find(threadid); - if(n != NULL) + if(n != g_debug_stacks.end()) { - m_stack = n->getValue(); + m_stack = n->second; } else { /*DEBUGPRINT("Creating new debug stack for thread %x\n", (unsigned int)threadid);*/ m_stack = new DebugStack(threadid); - g_debug_stacks.insert(threadid, m_stack); + g_debug_stacks[threadid] = m_stack; } if(m_stack->stack_i >= DEBUG_STACK_SIZE) @@ -178,10 +308,10 @@ DebugStacker::DebugStacker(const char *text) DebugStacker::~DebugStacker() { JMutexAutoLock lock(g_debug_stacks_mutex); - + if(m_overflowed == true) return; - + m_stack->stack_i--; if(m_stack->stack_i == 0) @@ -190,37 +320,128 @@ DebugStacker::~DebugStacker() /*DEBUGPRINT("Deleting debug stack for thread %x\n", (unsigned int)threadid);*/ delete m_stack; - g_debug_stacks.remove(threadid); + g_debug_stacks.erase(threadid); } } +#ifdef _MSC_VER -#ifdef _WIN32 -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 +}