X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fdebug.h;h=3e8066f4de7c55a317209b358e3ecc5c16872fe3;hb=98ff4eb4ee2ed22c5dc3ed2923bbd83d43a13436;hp=3f269176abcf889cf7fe06fff820382efde4b6d0;hpb=3f5bad938a3fcb601ad41924a4707476b8b87241;p=dragonfireclient.git diff --git a/src/debug.h b/src/debug.h index 3f269176a..3e8066f4d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -3,16 +3,16 @@ Minetest-c55 Copyright (C) 2010 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. */ @@ -24,9 +24,29 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include "common_irrlicht.h" +#include "irrlichttypes.h" +#include #include "threads.h" #include "gettime.h" +#include "exceptions.h" + +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #ifdef _MSC_VER + #include + #endif +#else +#endif + +// Whether to catch all std::exceptions. +// Assert will be called on such an event. +// In debug mode, leave these for the debugger and don't catch them. +#ifdef NDEBUG + #define CATCH_UNHANDLED_EXCEPTIONS 1 +#else + #define CATCH_UNHANDLED_EXCEPTIONS 0 +#endif /* Debug output @@ -67,21 +87,21 @@ class Debugbuf : public std::streambuf if(g_debugstreams[i] == stderr && m_disable_stderr) continue; if(g_debugstreams[i] != NULL) - fwrite(&c, 1, 1, g_debugstreams[i]); + (void)fwrite(&c, 1, 1, g_debugstreams[i]); //TODO: Is this slow? fflush(g_debugstreams[i]); } return c; } - int xsputn(const char *s, int n) + std::streamsize xsputn(const char *s, std::streamsize n) { for(int i=0; i g_debug_stacks; extern JMutex g_debug_stacks_mutex; extern void debug_stacks_init(); +extern void debug_stacks_print_to(std::ostream &os); extern void debug_stacks_print(); class DebugStacker @@ -158,7 +180,10 @@ class DebugStacker bool m_overflowed; }; -#define DSTACK(...)\ +#define DSTACK(msg)\ + DebugStacker __debug_stacker(msg); + +#define DSTACKF(...)\ char __buf[DEBUG_STACK_TEXT_SIZE];\ snprintf(__buf,\ DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ @@ -215,6 +240,52 @@ class PacketCounter core::map m_packets; }; +/* + These should be put into every thread +*/ + +#if CATCH_UNHANDLED_EXCEPTIONS == 1 + #define BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER try{ + #define END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)\ + }catch(std::exception &e){\ + logstream<<"ERROR: An unhandled exception occurred: "\ + <