X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fdebug.h;h=1faeece8db56a06eee10b9f8d3547bfc25a6a1c4;hb=e3bd6704a0eb65e9490347680441c7a08df36f7a;hp=44fcf4b5150f83aa20312efdad2e1cd7d6140f91;hpb=123e8fdf53ffb40c7464d0559a49e048fed79d7d;p=dragonfireclient.git diff --git a/src/debug.h b/src/debug.h index 44fcf4b51..1faeece8d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,223 +1,102 @@ /* -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. */ +#pragma once -/* - Debug stuff -*/ - -#ifndef DEBUG_HEADER -#define DEBUG_HEADER - -#include -#include -#include #include -#include "common_irrlicht.h" -#include "threads.h" - -/* - Debug output -*/ +#include +#include +#include "gettime.h" +#include "log.h" + +#ifdef _WIN32 + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif + #include + #ifdef _MSC_VER + #include + #endif + #define NORETURN __declspec(noreturn) + #define FUNCTION_NAME __FUNCTION__ +#else + #define NORETURN __attribute__ ((__noreturn__)) + #define FUNCTION_NAME __PRETTY_FUNCTION__ +#endif + +// Whether to catch all std::exceptions. +// When "catching", the program will abort with an error message. +// 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 + +/* Abort program execution immediately + */ +NORETURN extern void fatal_error_fn( + const char *msg, const char *file, + unsigned int line, const char *function); -#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(...)\ - char __buf[DEBUG_STACK_TEXT_SIZE];\ - snprintf(__buf,\ - DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ - DebugStacker __debug_stacker(__buf); +void debug_set_exception_handler(); /* - Packet counter + These should be put into every thread */ -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; -}; - - -#endif // DEBUG_HEADER - - +#else + // Dummy ones + #define BEGIN_DEBUG_EXCEPTION_HANDLER + #define END_DEBUG_EXCEPTION_HANDLER +#endif