summaryrefslogtreecommitdiff
path: root/external/vpc/tier0/dbg.cpp
blob: 8effafbe6e070aaf704006a7d8936c696dfce0b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: 
//
// $NoKeywords: $
//
//===========================================================================//

#include "tier0/platform.h"

#if defined( PLATFORM_WINDOWS_PC )
#define WIN_32_LEAN_AND_MEAN
#include <windows.h>				// Currently needed for IsBadReadPtr and IsBadWritePtr
#pragma comment(lib,"user32.lib")	// For MessageBox
#endif

#include "tier0/minidump.h"
#include "tier0/stacktools.h"

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "color.h"
#include "tier0/dbg.h"
#include "tier0/threadtools.h"
#include "tier0/icommandline.h"
#include <math.h>

#if defined( _X360 )
#include "xbox/xbox_console.h"
#endif

#include "tier0/etwprof.h"

#ifndef STEAM
#define PvRealloc realloc
#define PvAlloc malloc
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

#if defined( ENABLE_RUNTIME_STACK_TRANSLATION )
#pragma optimize( "g", off ) //variable argument functions seem to screw up stack walking unless this optimization is disabled
#pragma warning( disable: 4748 )  // Turn off the warning telling us that optimizations are off if /GS is on
#endif

DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_LOADING, "LOADING" );

//-----------------------------------------------------------------------------
// Stack attachment management
//-----------------------------------------------------------------------------
#if defined( ENABLE_RUNTIME_STACK_TRANSLATION )

static bool s_bCallStacksWithAllWarnings = false; //if true, attach a call stack to every SPEW_WARNING message. Warning()/DevWarning()/...
static int s_iWarningMaxCallStackLength = 5;
#define AutomaticWarningCallStackLength() (s_bCallStacksWithAllWarnings ? s_iWarningMaxCallStackLength : 0)

void _Warning_AlwaysSpewCallStack_Enable( bool bEnable )
{
	s_bCallStacksWithAllWarnings = bEnable;
}

void _Warning_AlwaysSpewCallStack_Length( int iMaxCallStackLength )
{
	s_iWarningMaxCallStackLength = iMaxCallStackLength;
}

static bool s_bCallStacksWithAllErrors = false; //if true, attach a call stack to every SPEW_ERROR message. Mostly just Error()
static int s_iErrorMaxCallStackLength = 20; //default to higher output with an error since we're quitting anyways
#define AutomaticErrorCallStackLength() (s_bCallStacksWithAllErrors ? s_iErrorMaxCallStackLength : 0)

void _Error_AlwaysSpewCallStack_Enable( bool bEnable )
{
	s_bCallStacksWithAllErrors = bEnable;
}

void _Error_AlwaysSpewCallStack_Length( int iMaxCallStackLength )
{
	s_iErrorMaxCallStackLength = iMaxCallStackLength;
}

#else //#if defined( ENABLE_RUNTIME_STACK_TRANSLATION )

#define AutomaticWarningCallStackLength() 0
#define AutomaticErrorCallStackLength() 0

void _Warning_AlwaysSpewCallStack_Enable( bool bEnable )
{
}

void _Warning_AlwaysSpewCallStack_Length( int iMaxCallStackLength )
{
}

void _Error_AlwaysSpewCallStack_Enable( bool bEnable )
{
}

void _Error_AlwaysSpewCallStack_Length( int iMaxCallStackLength )
{
}

#endif //#if defined( ENABLE_RUNTIME_STACK_TRANSLATION )

void _ExitOnFatalAssert( const tchar* pFile, int line )
{
	Log_Msg( LOG_ASSERT, _T("Fatal assert failed: %s, line %d.  Application exiting.\n"), pFile, line );

	// only write out minidumps if we're not in the debugger
	if ( !Plat_IsInDebugSession() )
	{
		WriteMiniDump();
	}

	Log_Msg( LOG_DEVELOPER, _T("_ExitOnFatalAssert\n") );
	Plat_ExitProcess( EXIT_FAILURE );
}


//-----------------------------------------------------------------------------
// Templates to assist in validating pointers:
//-----------------------------------------------------------------------------
PLATFORM_INTERFACE void _AssertValidReadPtr( void* ptr, int count/* = 1*/ )
{
#if defined( _WIN32 ) && !defined( _X360 )
	Assert( !IsBadReadPtr( ptr, count ) );
#else
	Assert( !count || ptr );
#endif
}

PLATFORM_INTERFACE void _AssertValidWritePtr( void* ptr, int count/* = 1*/ )
{
#if defined( _WIN32 ) && !defined( _X360 )
	Assert( !IsBadWritePtr( ptr, count ) );
#else
	Assert( !count || ptr );
#endif
}

PLATFORM_INTERFACE void _AssertValidReadWritePtr( void* ptr, int count/* = 1*/ )
{
#if defined( _WIN32 ) && !defined( _X360 )
	Assert(!( IsBadWritePtr(ptr, count) || IsBadReadPtr(ptr,count)));
#else
	Assert( !count || ptr );
#endif
}

PLATFORM_INTERFACE void _AssertValidStringPtr( const tchar* ptr, int maxchar/* = 0xFFFFFF */ )
{
#if defined( _WIN32 ) && !defined( _X360 )
	#ifdef TCHAR_IS_CHAR
		Assert( !IsBadStringPtr( ptr, maxchar ) );
	#else
		Assert( !IsBadStringPtrW( ptr, maxchar ) );
	#endif
#else
	Assert( ptr );
#endif
}

void AppendCallStackToLogMessage( tchar *formattedMessage, int iMessageLength, int iAppendCallStackLength )
{
#if defined( ENABLE_RUNTIME_STACK_TRANSLATION )
#	if defined( TCHAR_IS_CHAR ) //I'm horrible with unicode and I don't plan on testing this with wide characters just yet
		if( iAppendCallStackLength > 0 )
		{
			int iExistingMessageLength = (int)strlen( formattedMessage ); //no V_strlen in tier 0, plus we're only compiling this for windows and 360. Seems safe
			formattedMessage += iExistingMessageLength;
			iMessageLength -= iExistingMessageLength;

			if( iMessageLength <= 32 )
				return; //no room for anything useful

			//append directly to the spew message
			if( (iExistingMessageLength > 0) && (formattedMessage[-1] == '\n') )
			{
				--formattedMessage;
				++iMessageLength;
			}

			//append preface
			int iAppendedLength = _snprintf( formattedMessage, iMessageLength, _T("\nCall Stack:\n\t") );
							
			void **CallStackBuffer = (void **)stackalloc( iAppendCallStackLength * sizeof( void * ) );
			int iCount = GetCallStack( CallStackBuffer, iAppendCallStackLength, 2 );
			if( TranslateStackInfo( CallStackBuffer, iCount, formattedMessage + iAppendedLength, iMessageLength - iAppendedLength, _T("\n\t") ) == 0 )
			{
				//failure
				formattedMessage[0] = '\0'; //this is pointing at where we wrote "\nCall Stack:\n\t"
			}
			else
			{
				iAppendedLength += (int)strlen( formattedMessage + iAppendedLength ); //no V_strlen in tier 0, plus we're only compiling this for windows and 360. Seems safe

				if( iAppendedLength < iMessageLength )
				{
					formattedMessage[iAppendedLength] = '\n'; //Add another newline.
					++iAppendedLength;

					formattedMessage[iAppendedLength] = '\0';
				}
			}
		}
#	else
		AssertMsg( false, "Fixme" );
#	endif
#endif
}

// Forward declare for internal use only.
CLoggingSystem *GetGlobalLoggingSystem();

#define Log_LegacyHelperColor_Stack( Channel, Severity, Color, MessageFormat, AppendCallStackLength ) \
	do \
{ \
	CLoggingSystem *pLoggingSystem = GetGlobalLoggingSystem(); \
	if ( pLoggingSystem->IsChannelEnabled( Channel, Severity ) ) \
{ \
	tchar formattedMessage[MAX_LOGGING_MESSAGE_LENGTH]; \
	va_list args; \
	va_start( args, MessageFormat ); \
	Tier0Internal_vsntprintf( formattedMessage, MAX_LOGGING_MESSAGE_LENGTH, MessageFormat, args ); \
	va_end( args ); \
	AppendCallStackToLogMessage( formattedMessage, MAX_LOGGING_MESSAGE_LENGTH, AppendCallStackLength ); \
	pLoggingSystem->LogDirect( Channel, Severity, Color, formattedMessage ); \
} \
} while( 0 )

#define Log_LegacyHelperColor( Channel, Severity, Color, MessageFormat ) Log_LegacyHelperColor_Stack( Channel, Severity, Color, MessageFormat, 0 )

#define Log_LegacyHelper_Stack( Channel, Severity, MessageFormat, AppendCallStackLength ) Log_LegacyHelperColor_Stack( Channel, Severity, pLoggingSystem->GetChannelColor( Channel ), MessageFormat, AppendCallStackLength )
#define Log_LegacyHelper( Channel, Severity, MessageFormat ) Log_LegacyHelperColor( Channel, Severity, pLoggingSystem->GetChannelColor( Channel ), MessageFormat )


void Msg( const tchar* pMsgFormat, ... )
{
	Log_LegacyHelper( LOG_GENERAL, LS_MESSAGE, pMsgFormat );
}

void Warning( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper_Stack( LOG_GENERAL, LS_WARNING, pMsgFormat, AutomaticWarningCallStackLength() );
}

void Warning_SpewCallStack( int iMaxCallStackLength, const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper_Stack( LOG_GENERAL, LS_WARNING, pMsgFormat, iMaxCallStackLength );
}


void Error( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper_Stack( LOG_GENERAL, LS_ERROR, pMsgFormat, AutomaticErrorCallStackLength() );
}

void Error_SpewCallStack( int iMaxCallStackLength, const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper_Stack( LOG_GENERAL, LS_ERROR, pMsgFormat, iMaxCallStackLength );
}


//-----------------------------------------------------------------------------
// A couple of super-common dynamic spew messages, here for convenience 
// These looked at the "developer" group, print if it's level 1 or higher 
//-----------------------------------------------------------------------------
void DevMsg( int level, const tchar* pMsgFormat, ... )
{
	LoggingChannelID_t channel = level >= 2 ? LOG_DEVELOPER_VERBOSE : LOG_DEVELOPER;
	Log_LegacyHelper( channel, LS_MESSAGE, pMsgFormat );
}


void DevWarning( int level, const tchar *pMsgFormat, ... )
{
	LoggingChannelID_t channel = level >= 2 ? LOG_DEVELOPER_VERBOSE : LOG_DEVELOPER;
	Log_LegacyHelper( channel, LS_WARNING, pMsgFormat );
}

void DevMsg( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper( LOG_DEVELOPER, LS_MESSAGE, pMsgFormat );
}

void DevWarning( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper( LOG_DEVELOPER, LS_WARNING, pMsgFormat );
}

void ConColorMsg( const Color& clr, const tchar* pMsgFormat, ... )
{
	Log_LegacyHelperColor( LOG_CONSOLE, LS_MESSAGE, clr, pMsgFormat );
}

void ConMsg( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper( LOG_CONSOLE, LS_MESSAGE, pMsgFormat );
}

void ConDMsg( const tchar *pMsgFormat, ... )
{
	Log_LegacyHelper( LOG_DEVELOPER_CONSOLE, LS_MESSAGE, pMsgFormat );
}

// If we don't have a function from math.h, then it doesn't link certain floating-point
// functions in and printfs with %f cause runtime errors in the C libraries.
PLATFORM_INTERFACE float CrackSmokingCompiler( float a )
{
	return (float)fabs( a );
}

void* Plat_SimpleLog( const tchar* file, int line )
{
	FILE* f = _tfopen( _T("simple.log"), _T("at+") );
	_ftprintf( f, _T("%s:%i\n"), file, line );
	fclose( f );

	return NULL;
}

//-----------------------------------------------------------------------------
// Purpose: For debugging startup times, etc.
// Input  : *fmt - 
//			... - 
//-----------------------------------------------------------------------------
void COM_TimestampedLog( char const *fmt, ... )
{
	static float s_LastStamp = 0.0;
	static bool s_bShouldLog = false;
	static bool s_bShouldLogToConsole = false;
	static bool s_bShouldLogToETW = false;
	static bool s_bChecked = false;
	static bool	s_bFirstWrite = false;

	if ( !s_bChecked )
	{
		s_bShouldLog = ( CommandLine()->CheckParm( "-profile" ) ) ? true : false;
		s_bShouldLogToConsole = ( CommandLine()->ParmValue( "-profile", 0.0f ) != 0.0f ) ? true : false;

		s_bShouldLogToETW = ( CommandLine()->CheckParm( "-etwprofile" ) ) ? true : false;
		if ( s_bShouldLogToETW )
		{
			s_bShouldLog = true;
		}

		s_bChecked = true;
	}
	if ( !s_bShouldLog )
	{
		return;
	}

	char string[1024];
	va_list argptr;
	va_start( argptr, fmt );
	Tier0Internal_vsnprintf( string, sizeof( string ), fmt, argptr );
	va_end( argptr );

	float curStamp = Plat_FloatTime();

#if defined( _X360 )
	XBX_rTimeStampLog( curStamp, string );
#elif defined( _PS3 )
	Log_Warning( LOG_LOADING, "%8.4f / %8.4f:  %s\n", curStamp, curStamp - s_LastStamp, string );
#endif

	if ( IsPC() )
	{
		// If ETW profiling is enabled then do it only.
		if ( s_bShouldLogToETW )
		{
			ETWMark( string );
		}
		else
		{
			if ( !s_bFirstWrite )
			{
				unlink( "timestamped.log" );
				s_bFirstWrite = true;
			}

			FILE* fp = fopen( "timestamped.log", "at+" );
			fprintf( fp, "%8.4f / %8.4f:  %s\n", curStamp, curStamp - s_LastStamp, string );
			fclose( fp );
		}

		if ( s_bShouldLogToConsole )
		{
			Msg( "%8.4f / %8.4f:  %s\n", curStamp, curStamp - s_LastStamp, string );
		}
	}

	s_LastStamp = curStamp;
}

#ifdef IS_WINDOWS_PC

class CHardwareBreakPoint
{
public:

	enum EOpCode
	{
		BRK_SET = 0,
		BRK_UNSET,
	};

	CHardwareBreakPoint()
	{
		m_eOperation = BRK_SET;
		m_pvAddress = 0;
		m_hThread = 0;
		m_hThreadEvent = 0;
		m_nRegister = 0;
		m_bSuccess = false;
	}

	const void				*m_pvAddress;
	HANDLE					m_hThread;
	EHardwareBreakpointType m_eType;
	EHardwareBreakpointSize m_eSize;
	HANDLE					m_hThreadEvent;
	int						m_nRegister;
	EOpCode					m_eOperation;
	bool					m_bSuccess;

	static void SetBits( DWORD_PTR& dw, int lowBit, int bits, int newValue );
	static DWORD WINAPI ThreadProc( LPVOID lpParameter );
};

void CHardwareBreakPoint::SetBits( DWORD_PTR& dw, int lowBit, int bits, int newValue )
{
	DWORD_PTR mask = (1 << bits) - 1; 
	dw = (dw & ~(mask << lowBit)) | (newValue << lowBit);
}

DWORD WINAPI CHardwareBreakPoint::ThreadProc( LPVOID lpParameter )
{
	CHardwareBreakPoint *h = reinterpret_cast< CHardwareBreakPoint * >( lpParameter );
	SuspendThread( h->m_hThread );

	// Get current context
	CONTEXT ct = {0};
	ct.ContextFlags = CONTEXT_DEBUG_REGISTERS;
	GetThreadContext(h->m_hThread,&ct);

	int FlagBit = 0;

	bool Dr0Busy = false;
	bool Dr1Busy = false;
	bool Dr2Busy = false;
	bool Dr3Busy = false;
	if (ct.Dr7 & 1)
		Dr0Busy = true;
	if (ct.Dr7 & 4)
		Dr1Busy = true;
	if (ct.Dr7 & 16)
		Dr2Busy = true;
	if (ct.Dr7 & 64)
		Dr3Busy = true;

	if ( h->m_eOperation == CHardwareBreakPoint::BRK_UNSET )
	{
		// Remove
		if (h->m_nRegister == 0)
		{
			FlagBit = 0;
			ct.Dr0 = 0;
			Dr0Busy = false;
		}
		if (h->m_nRegister == 1)
		{
			FlagBit = 2;
			ct.Dr1 = 0;
			Dr1Busy = false;
		}
		if (h->m_nRegister == 2)
		{
			FlagBit = 4;
			ct.Dr2 = 0;
			Dr2Busy = false;
		}
		if (h->m_nRegister == 3)
		{
			FlagBit = 6;
			ct.Dr3 = 0;
			Dr3Busy = false;
		}
		ct.Dr7 &= ~(1 << FlagBit);
	}
	else
	{
		if (!Dr0Busy)
		{
			h->m_nRegister = 0;
			ct.Dr0 = (DWORD_PTR)h->m_pvAddress;
			Dr0Busy = true;
		}
		else if (!Dr1Busy)
		{
			h->m_nRegister = 1;
			ct.Dr1 = (DWORD_PTR)h->m_pvAddress;
			Dr1Busy = true;
		}
		else if (!Dr2Busy)
		{
			h->m_nRegister = 2;
			ct.Dr2 = (DWORD_PTR)h->m_pvAddress;
			Dr2Busy = true;
		}
		else if (!Dr3Busy)
		{
			h->m_nRegister = 3;
			ct.Dr3 = (DWORD_PTR)h->m_pvAddress;
			Dr3Busy = true;
		}
		else
		{
			h->m_bSuccess = false;
			ResumeThread(h->m_hThread);
			SetEvent(h->m_hThreadEvent);
			return 0;
		}

		ct.Dr6 = 0;
		int st = 0;
		if (h->m_eType == BREAKPOINT_EXECUTE)
			st = 0;
		if (h->m_eType == BREAKPOINT_READWRITE)
			st = 3;
		if (h->m_eType == BREAKPOINT_WRITE)
			st = 1;

		int le = 0;
		if (h->m_eSize == BREAKPOINT_SIZE_1)
			le = 0;
		if (h->m_eSize == BREAKPOINT_SIZE_2)
			le = 1;
		if (h->m_eSize == BREAKPOINT_SIZE_4)
			le = 3;
		if (h->m_eSize == BREAKPOINT_SIZE_8)
			le = 2;

		SetBits( ct.Dr7, 16 + h->m_nRegister*4, 2, st );
		SetBits( ct.Dr7, 18 + h->m_nRegister*4, 2, le );
		SetBits( ct.Dr7, h->m_nRegister*2,1,1);
	}

	ct.ContextFlags = CONTEXT_DEBUG_REGISTERS;
	SetThreadContext(h->m_hThread,&ct);

	ResumeThread( h->m_hThread );
	h->m_bSuccess = true;
	SetEvent( h->m_hThreadEvent );
	return 0;
}

HardwareBreakpointHandle_t SetHardwareBreakpoint( EHardwareBreakpointType eType, EHardwareBreakpointSize eSize, const void *pvLocation )
{
	CHardwareBreakPoint *h = new CHardwareBreakPoint();
	h->m_pvAddress = pvLocation;
	h->m_eSize = eSize;
	h->m_eType = eType;
	HANDLE hThread = GetCurrentThread();
	h->m_hThread = hThread;

	if ( hThread == GetCurrentThread() )
	{
		DWORD nThreadId = GetCurrentThreadId();
		h->m_hThread = OpenThread( THREAD_ALL_ACCESS, 0, nThreadId );
	}

	h->m_hThreadEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
	h->m_eOperation = CHardwareBreakPoint::BRK_SET; // Set Break
	CreateThread( 0, 0, CHardwareBreakPoint::ThreadProc, (LPVOID)h, 0, 0 );
	WaitForSingleObject( h->m_hThreadEvent,INFINITE );
	CloseHandle( h->m_hThreadEvent );
	h->m_hThreadEvent = 0;
	if ( hThread == GetCurrentThread() )
	{
		CloseHandle( h->m_hThread );
	}
	h->m_hThread = hThread;
	if ( !h->m_bSuccess )
	{
		delete h;
		return (HardwareBreakpointHandle_t)0;
	}
	return (HardwareBreakpointHandle_t)h;
}

bool ClearHardwareBreakpoint( HardwareBreakpointHandle_t handle )
{
	CHardwareBreakPoint *h = reinterpret_cast< CHardwareBreakPoint* >( handle );
	if ( !h )
	{
		return false;
	}

	bool bOpened = false;
	if ( h->m_hThread == GetCurrentThread() )
	{
		DWORD nThreadId = GetCurrentThreadId();
		h->m_hThread = OpenThread( THREAD_ALL_ACCESS, 0, nThreadId );
		bOpened = true;
	}

	h->m_hThreadEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
	h->m_eOperation = CHardwareBreakPoint::BRK_UNSET; // Remove Break
	CreateThread( 0,0,CHardwareBreakPoint::ThreadProc, (LPVOID)h, 0,0 );
	WaitForSingleObject( h->m_hThreadEvent, INFINITE );
	CloseHandle( h->m_hThreadEvent );
	h->m_hThreadEvent = 0;
	if ( bOpened )
	{
		CloseHandle( h->m_hThread );
	}
	delete h;
	return true;
}

#endif // IS_WINDOWS_PC