OpenBarnyard
 
Loading...
Searching...
No Matches
TDebug_Win.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "Toshi/TDebug.h"
3#include "Thread/T2Mutex.h"
4
5#include <Windows.h>
6
7//-----------------------------------------------------------------------------
8// Enables memory debugging.
9// Note: Should be the last include!
10//-----------------------------------------------------------------------------
11#include <Core/TMemoryDebugOn.h>
12
14
18
20{
21 if ( TDebug_IsMutexCreated == FALSE )
22 {
23 TDebug_Mutex.Create();
25 }
26
27 TDebug_Mutex.Lock();
28}
29
31{
32 TDebug_Mutex.Unlock();
33}
34
35TBOOL TDebug_IsValidAddress( const void* a_pPtr )
36{
37 if ( a_pPtr != TNULL &&
38 a_pPtr != (void*)0xcdcdcdcd &&
39 a_pPtr != (void*)0xdeaddead &&
40 a_pPtr != (void*)0xbeefbeef &&
41 a_pPtr >= (void*)0x4f )
42 {
43 return TTRUE;
44 }
45
46 return TFALSE;
47}
48
49void TDebug_FinalPrintf( const TCHAR* a_szFormat, ... )
50{
51 va_list args;
52 va_start( args, a_szFormat );
53 TDebug_FinalVPrintf( a_szFormat, args );
54 va_end( args );
55}
56
57void TDebug_FinalVPrintf( const TCHAR* a_szFormat, va_list a_Args )
58{
59 TDebug_FinalVSPrintf( a_szFormat, a_Args );
61}
62
63void TDebug_FinalSPrintf( const TCHAR* a_szFormat, ... )
64{
65 va_list args;
66 va_start( args, a_szFormat );
67 TDebug_FinalVSPrintf( a_szFormat, args );
68 va_end( args );
69}
70
71void TDebug_FinalVSPrintf( const TCHAR* a_szFormat, va_list a_Args )
72{
74 vsprintf( TDebug_ScratchMem, a_szFormat, a_Args );
76}
77
78void TDebug_OutputDebugString( const TCHAR* a_szString )
79{
80 OutputDebugStringA( a_szString );
81 printf( "%s", a_szString );
82
83 TDebug_BroadcastDebugString( a_szString );
84}
85
86void TDebug_BroadcastDebugString( const TCHAR* a_szString )
87{
88 //TIMPLEMENT();
89}
90
91#include "resource.h"
92
96
97BOOL CALLBACK TDebug_AssertionDlgProc( HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam )
98{
99 switch ( Message )
100 {
101 case WM_INITDIALOG:
102 {
103 ShowCursor( TRUE );
104 SetActiveWindow( hwnd );
105 SetForegroundWindow( hwnd );
106 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
107
109 TDebug_szAssertFilename = "***INVALID***";
110
112 TDebug_szAssertExpression = "***INVALID***";
113
114 SetDlgItemTextA( hwnd, 8204, TDebug_szAssertFilename );
115 SetDlgItemInt( hwnd, 8205, TDebug_uiAssertLineNumber, TRUE );
116 SetDlgItemTextA( hwnd, 8206, TDebug_szAssertExpression );
117 return TRUE;
118 }
119 case WM_COMMAND:
120 switch ( LOWORD( wParam ) )
121 {
122 case 8200: // Quit
123 ExitProcess( 1 );
124 break;
125 case 8201: // Debug
126 EndDialog( hwnd, 1 );
127 break;
128 case 8202: // Ignore
129 ShowCursor( FALSE );
130 EndDialog( hwnd, 0 );
131 break;
132 }
133 break;
134 default:
135 return FALSE;
136 }
137
138 return TRUE;
139}
140
141TINT TDebug_AssertHandler( const TCHAR* a_szExpression, const TCHAR* a_szFileName, TUINT a_uiLineNumber, const TCHAR* a_szDescription )
142{
143 TDebug_szAssertFilename = a_szFileName;
144 TDebug_szAssertExpression = a_szExpression;
145 TDebug_uiAssertLineNumber = a_uiLineNumber;
146
147 TERROR( "Assertion (%s) failed ('%s', at line %u)\n", a_szExpression, a_szFileName, a_uiLineNumber );
148
149 HWND hWnd = GetActiveWindow();
150
151 if ( hWnd != NULL )
152 hWnd = GetLastActivePopup( hWnd );
153
154 INT_PTR result = DialogBoxParamA(
155 GetModuleHandleA( NULL ),
156 MAKEINTRESOURCEA( IDD_ASSERT ),
157 hWnd,
159 NULL
160 );
161
162 return ( result != -1 ) ? result : 1;
163}
BOOL CALLBACK TDebug_AssertionDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
TCHAR TDebug_ScratchMem[4096]
void TDebug_AcquireMutex()
void TDebug_ReleaseMutex()
void TDebug_FinalPrintf(const TCHAR *a_szFormat,...)
TBOOL TDebug_IsValidAddress(const void *a_pPtr)
const TCHAR * TDebug_szAssertExpression
void TDebug_FinalSPrintf(const TCHAR *a_szFormat,...)
void TDebug_BroadcastDebugString(const TCHAR *a_szString)
void TDebug_FinalVPrintf(const TCHAR *a_szFormat, va_list a_Args)
const TCHAR * TDebug_szAssertFilename
BOOL TDebug_IsMutexCreated
void TDebug_OutputDebugString(const TCHAR *a_szString)
T2Mutex TDebug_Mutex
TINT TDebug_AssertHandler(const TCHAR *a_szExpression, const TCHAR *a_szFileName, TUINT a_uiLineNumber, const TCHAR *a_szDescription)
TUINT TDebug_uiAssertLineNumber
void TDebug_FinalVSPrintf(const TCHAR *a_szFormat, va_list a_Args)
#define TERROR(...)
Definition Defines.h:153
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6