/* 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 (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. You should have received a copy of the GNU 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. */ #ifndef DEBUG_HEADER #define DEBUG_HEADER #include #include #include #include #include "common_irrlicht.h" #include "threads.h" #include "gettime.h" #include "constants.h" #include "exceptions.h" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #ifdef _MSC_VER #include #endif #else #endif /* Debug output */ #define DTIME (getTimestamp()+": ") #define DEBUGSTREAM_COUNT 2 extern FILE *g_debugstreams[DEBUGSTREAM_COUNT]; extern void debugstreams_init(bool disable_stderr, const char *filename); extern void debugstreams_deinit(); #define DEBUGPRINT(...)\ {\ for(int i=0; i g_debug_stacks; extern JMutex g_debug_stacks_mutex; extern void debug_stacks_init(); extern void debug_stacks_print(); class DebugStacker { public: DebugStacker(const char *text); ~DebugStacker(); private: DebugStack *m_stack; bool m_overflowed; }; #define DSTACK(msg)\ DebugStacker __debug_stacker(msg); #define DSTACKF(...)\ char __buf[DEBUG_STACK_TEXT_SIZE];\ snprintf(__buf,\ DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ DebugStacker __debug_stacker(__buf); /* Packet counter */ class PacketCounter { public: PacketCounter() { } void add(u16 command) { core::map::Node *n = m_packets.find(command); if(n == NULL) { m_packets[command] = 1; } else { n->setValue(n->getValue()+1); } } void clear() { for(core::map::Iterator i = m_packets.getIterator(); i.atEnd() == false; i++) { i.getNode()->setValue(0); } } void print(std::ostream &o) { for(core::map::Iterator i = m_packets.getIterator(); i.atEnd() == false; i++) { o<<"cmd "<getKey() <<" count "<getValue() < 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: "\ <