X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fdebug.h;h=2098942db7ec17e457fa72fb8e88d50f5e3c9d40;hb=0f0502109eac44128e87906fff30b5d049392f1d;hp=1b14c4e0a325c2b2d1fbf50f6bbee19c356e91a7;hpb=6a1670dbc31cc0e44178bbd9ad34ff0d5981a060;p=minetest.git diff --git a/src/debug.h b/src/debug.h index 1b14c4e0a..2098942db 100644 --- a/src/debug.h +++ b/src/debug.h @@ -20,31 +20,30 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef DEBUG_HEADER #define DEBUG_HEADER -#include -#include -#include #include -#include "irrlichttypes.h" -#include -#include "threads.h" +#include +#include #include "gettime.h" -#include "exceptions.h" -#include +#include "log.h" -#ifdef _WIN32 +#if (defined(WIN32) || defined(_WIN32_WCE)) #define WIN32_LEAN_AND_MEAN #ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0500 + #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 @@ -52,100 +51,39 @@ 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; - extern void debug_stacks_init(); extern void debug_stacks_print_to(std::ostream &os); extern void debug_stacks_print(); +struct DebugStack; class DebugStacker { public: @@ -184,111 +108,30 @@ class DebugStacker bool m_overflowed; }; -#define DSTACK(msg)\ +#define DSTACK(msg) \ DebugStacker __debug_stacker(msg); -#define DSTACKF(...)\ - char __buf[DEBUG_STACK_TEXT_SIZE];\ - snprintf(__buf,\ - DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ +#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) - { - std::map::iterator n = m_packets.find(command); - if(n == m_packets.end()) - { - m_packets[command] = 1; - } - else - { - n->second++; - } - } - - void clear() - { - for(std::map::iterator - i = m_packets.begin(); - i != m_packets.end(); ++i) - { - i->second = 0; - } - } - - void print(std::ostream &o) - { - for(std::map::iterator - i = m_packets.begin(); - i != m_packets.end(); ++i) - { - o<<"cmd "<first - <<" count "<second - < 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: "\ - <