X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fdebug.h;h=1faeece8db56a06eee10b9f8d3547bfc25a6a1c4;hb=8e5bd82c4d19c405fbb4f2592bf91ad8b110294b;hp=8faa65eb85b7898a9e5437ae9706fa869c47f062;hpb=fa64103aa87a8f0f2a3351bb4a54e93e8ade1082;p=dragonfireclient.git diff --git a/src/debug.h b/src/debug.h index 8faa65eb8..1faeece8d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,284 +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. */ -#ifndef DEBUG_HEADER -#define DEBUG_HEADER +#pragma once -#include -#include -#include #include -#include "common_irrlicht.h" -#include "threads.h" +#include +#include #include "gettime.h" -#include "constants.h" -#include "exceptions.h" +#include "log.h" #ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif #include - #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 -/* - 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; +#define SANITY_CHECK(expr) \ + ((expr) \ + ? (void)(0) \ + : sanity_check_fn(#expr, __FILE__, __LINE__, FUNCTION_NAME)) -extern void debug_stacks_init(); -extern void debug_stacks_print(); +#define sanity_check(expr) SANITY_CHECK(expr) -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); - -/* - 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; -}; +void debug_set_exception_handler(); /* 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\ - }catch(std::exception &e){\ - dstream<