ITADebug.cpp 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <ITADebug.h>

#include <ITACriticalSection.h>
#include <stdio.h>
#include <stdarg.h>

#ifdef WIN32
#include <windows.h>

#define DEBUG_PRINTF_BUFSIZE 16384

// Lock fr den Puffer in den Ausgabe-Routinen
static ITACriticalSection g_csDebugPrintf;
14
static char g_pszDebugPrintfBuf[ 16384 ];
15 16 17

#ifdef _DEBUG

18 19
void DEBUG_PRINTF( const char * format, ... )
{
20 21 22

	g_csDebugPrintf.enter();
	va_list args;
23 24 25
	va_start( args, format );
	vsprintf_s( g_pszDebugPrintfBuf, DEBUG_PRINTF_BUFSIZE, format, args );
	va_end( args );
26

27
	OutputDebugStringA( g_pszDebugPrintfBuf );
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	g_csDebugPrintf.leave();
}

#else

void DEBUG_PRINTF(const char * format, ... ) {

	/* NUR BENUTZEN WENN DEBUG_PRINTF IM RELEASE MODE BENTIGT WIRD!!!
	g_csDebugPrintf.enter();
	va_list args;
	va_start(args, format);
	vsprintf_s(g_pszDebugPrintfBuf, DEBUG_PRINTF_BUFSIZE, format, args);
	va_end(args);

	OutputDebugStringA(g_pszDebugPrintfBuf);
	g_csDebugPrintf.leave();
	*/
}

#endif // _DEBUG

/*
 *  Kommt von hier: http://www.codeproject.com/KB/threads/Name_threads_in_debugger.aspx
 */

typedef struct tagTHREADNAME_INFO {
54 55 56 57
	DWORD dwType;			// must be 0x1000
	LPCSTR szName;		// pointer to name (in user addr space)
	DWORD dwThreadID;		// thread ID (-1=caller thread)
	DWORD dwFlags;		// reserved for future use, must be zero
58 59
} THREADNAME_INFO;

60
void SetThreadName( long lThreadID, const char* szThreadName ) {
61 62 63 64
	THREADNAME_INFO info;
	{
		info.dwType = 0x1000;
		info.szName = szThreadName;
65
		info.dwThreadID = ( DWORD ) lThreadID;
66 67 68
		info.dwFlags = 0;
	}
	__try {
69 70 71
		RaiseException( 0x406D1388, 0, sizeof( info ) / sizeof( DWORD ), ( ULONG_PTR* ) &info );
	}
	__except( EXCEPTION_CONTINUE_EXECUTION ) {}
72 73 74 75 76 77 78 79
}

#endif // Win32

#ifndef WIN32 // Linux oder was auch immer
void DEBUG_PRINTF(const char * format, ... ) {
	va_list args;
	va_start(args, format);
Fabian Schlieper's avatar
Fabian Schlieper committed
80
	vprintf(format, args);
81 82 83
	va_end(args);
}
#endif // Linux