X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fdebug.h;h=1faeece8db56a06eee10b9f8d3547bfc25a6a1c4;hb=9ef3c8ce388011f4f57adc9a7eb0326376aec750;hp=3e8066f4de7c55a317209b358e3ecc5c16872fe3;hpb=9f031a67594162a53b07acbfbc65faf8c4938e99;p=minetest.git diff --git a/src/debug.h b/src/debug.h index 3e8066f4d..1faeece8d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,6 +1,6 @@ /* -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 Lesser General Public License as published by @@ -17,30 +17,31 @@ 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 "irrlichttypes.h" -#include -#include "threads.h" +#include +#include #include "gettime.h" -#include "exceptions.h" +#include "log.h" #ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN + #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. -// Assert will be called on such an event. +// 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 @@ -48,245 +49,54 @@ with this program; if not, write to the Free Software Foundation, Inc., #define CATCH_UNHANDLED_EXCEPTIONS 0 #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_to(std::ostream &os); -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(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; -}; +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(logstream)\ - }catch(std::exception &e){\ - logstream<<"ERROR: An unhandled exception occurred: "\ - <