X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fdebug.h;h=5150758be13506d070b9ed8cca5bcd6ed4fd3f1b;hb=92ae11bd3b5e95ff837f98463931e7772c455ad3;hp=9a2e282f5c2d7eba4c5f69c670aa5f5b272aa89e;hpb=0604f3f2eedb93d75ac20422849e4e710427621a;p=oweals%2Fminetest.git diff --git a/src/debug.h b/src/debug.h index 9a2e282f5..5150758be 100644 --- a/src/debug.h +++ b/src/debug.h @@ -17,11 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - -/* - Debug stuff -*/ - #ifndef DEBUG_HEADER #define DEBUG_HEADER @@ -30,34 +25,26 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "common_irrlicht.h" - -/* - Compatibility stuff -*/ - -#if (defined(WIN32) || defined(_WIN32_WCE)) -typedef DWORD threadid_t; -#define __NORETURN __declspec(noreturn) -#define __FUNCTION_NAME __FUNCTION__ -#else -typedef pthread_t threadid_t; -#define __NORETURN __attribute__ ((__noreturn__)) -#define __FUNCTION_NAME __PRETTY_FUNCTION__ -#endif - -inline threadid_t get_current_thread_id() -{ -#if (defined(WIN32) || defined(_WIN32_WCE)) - return GetCurrentThreadId(); +#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 - return pthread_self(); #endif -} /* Debug output */ +#define DTIME (getTimestamp()+": ") + #define DEBUGSTREAM_COUNT 2 extern FILE *g_debugstreams[DEBUGSTREAM_COUNT]; @@ -91,21 +78,21 @@ public: if(g_debugstreams[i] == stderr && m_disable_stderr) continue; if(g_debugstreams[i] != NULL) - fwrite(&c, 1, 1, g_debugstreams[i]); + (void)fwrite(&c, 1, 1, g_debugstreams[i]); //TODO: Is this slow? fflush(g_debugstreams[i]); } return c; } - int xsputn(const char *s, int n) + std::streamsize xsputn(const char *s, std::streamsize n) { 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(); class DebugStacker @@ -182,7 +171,10 @@ private: bool m_overflowed; }; -#define DSTACK(...)\ +#define DSTACK(msg)\ + DebugStacker __debug_stacker(msg); + +#define DSTACKF(...)\ char __buf[DEBUG_STACK_TEXT_SIZE];\ snprintf(__buf,\ DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ @@ -239,6 +231,52 @@ private: core::map 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: "\ + <