Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1918 lines
56 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Debug.h
  7. //
  8. // Description:
  9. // Debugging utilities header.
  10. //
  11. // Maintained By:
  12. // Geoffrey Pease (GPease) 22-NOV-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #pragma once
  16. //
  17. // KB: USES_SYSALLOCSTRING gpease 8-NOV-1999
  18. // Turn this on if you are going to use the OLE automation
  19. // functions: SysAllocString, SysFreeString, etc..
  20. //
  21. // #define USES_SYSALLOCSTRING
  22. //
  23. // WMI tracing needs these defined
  24. //
  25. #include <wmistr.h>
  26. #include <evntrace.h>
  27. //
  28. // Trace Flags
  29. //
  30. typedef enum _TRACEFLAGS
  31. {
  32. mtfALWAYS = 0xFFFFFFFF,
  33. mtfNEVER = 0x00000000,
  34. // function entry/exits, call, scoping
  35. mtfCALLS = 0x00000001, // Function calls that use the TraceMsgDo macro
  36. mtfFUNC = 0x00000002, // Functions entrances w/parameters
  37. mtfQUERYINTERFACE = 0x00000004, // Query Interface details
  38. mtfSTACKSCOPE = 0x00000008, // if set, debug spew will generate bar/space for level each of the call stack
  39. // other
  40. mtfWM = 0x00000010, // Window Messages
  41. mtfDLL = 0x00000020, // DLL specific
  42. mtfASSERT_HR = 0x00000040, // Assert if HRESULT is an error
  43. // memory
  44. mtfMEMORYLEAKS = 0x01000000, // Halts when a memory leak is detected on thread exit.
  45. mtfMEMORYINIT = 0x02000000, // Initializes new memory allocations
  46. mtfMEMORYALLOCS = 0x04000000, // Turns on spew to display each de/allocation.
  47. // citracker spew
  48. mtfCITRACKERS = 0x08000000, // CITrackers will spew entrances and exits
  49. // output prefixes
  50. mtfADDTIMEDATE = 0x10000000, // Replaces Filepath(Line) with Date/Time
  51. mtfBYMODULENAME = 0x20000000, // Puts the module name at the beginning of the line
  52. // per thread
  53. mtfPERTHREADTRACE = 0x40000000, // Enables per thread tracing
  54. // ouput to disk
  55. mtfOUTPUTTODISK = 0x80000000, // Logs output to disk
  56. } TRACEFLAGS;
  57. typedef DWORD TRACEFLAG;
  58. #ifdef DEBUG
  59. #pragma message( "BUILD: DEBUG macros being built" )
  60. //
  61. // Globals
  62. //
  63. extern DWORD g_TraceMemoryIndex; // TLS index for the memory tracking link list
  64. extern DWORD g_dwCounter; // Stack depth counter
  65. extern TRACEFLAG g_tfModule; // Global tracing flags
  66. extern const LPCTSTR g_pszModuleIn; // Local module name - use DEFINE_MODULE
  67. extern const TCHAR g_szTrue[]; // Array "TRUE"
  68. extern const TCHAR g_szFalse[]; // Array "FALSE"
  69. //
  70. // Definition Macros
  71. //
  72. #define DEFINE_MODULE( _module ) const LPCTSTR g_pszModuleIn = TEXT(_module);
  73. #define __MODULE__ g_pszModuleIn
  74. #define DEFINE_THISCLASS( _class ) static const TCHAR g_szClass[] = TEXT(_class);
  75. #define __THISCLASS__ g_szClass
  76. #define DEFINE_BASECLASS( _class ) static const TCHAR g_szBaseClass[] = TEXT(_class);
  77. #define __BASECLASS__ g_szBaseClass
  78. //
  79. // ImageHlp Stuff - not ready for prime time yet.
  80. //
  81. #if defined( IMAGEHLP_ENABLED )
  82. #include <imagehlp.h>
  83. typedef BOOL ( * PFNSYMGETSYMFROMADDR )( HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL );
  84. typedef BOOL ( * PFNSYMGETLINEFROMADDR )( HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE );
  85. typedef BOOL ( * PFNSYMGETMODULEINFO )( HANDLE, DWORD, PIMAGEHLP_MODULE );
  86. extern HINSTANCE g_hImageHlp; // IMAGEHLP.DLL instance handle
  87. extern PFNSYMGETSYMFROMADDR g_pfnSymGetSymFromAddr;
  88. extern PFNSYMGETLINEFROMADDR g_pfnSymGetLineFromAddr;
  89. extern PFNSYMGETMODULEINFO g_pfnSymGetModuleInfo;
  90. #endif // IMAGEHLP_ENABLED
  91. void
  92. DebugIncrementStackDepthCounter( void );
  93. void
  94. DebugDecrementStackDepthCounter( void );
  95. //////////////////////////////////////////////////////////////////////////////
  96. //++
  97. //
  98. // MACRO
  99. // TraceInitializeProcess(
  100. // _rgControl,
  101. // _sizeofControl
  102. // )
  103. //
  104. // Description:
  105. // Should be called in the DLL main on process attach or in the entry
  106. // routine of an EXE. Initializes debugging globals and TLS. Registers
  107. // the WMI tracing facilities.
  108. //
  109. // Arguments:
  110. // _rgControl WMI control block (see DEBUG_WMI_CONTROL_GUIDS)
  111. // _sizeofControl The sizeof( _rgControl )
  112. //
  113. // Return Values:
  114. // None.
  115. //
  116. //--
  117. //////////////////////////////////////////////////////////////////////////////
  118. #define TraceInitializeProcess( _rgControl, _sizeofControl ) \
  119. { \
  120. DebugInitializeTraceFlags( ); \
  121. WMIInitializeTracing( _rgControl, _sizeofControl ); \
  122. }
  123. //////////////////////////////////////////////////////////////////////////////
  124. //++
  125. //
  126. // MACRO
  127. // TraceInitializeThread(
  128. // _name
  129. // )
  130. //
  131. // Description:
  132. // Should be called in the DLL thread attach or when a new thread is
  133. // created. Sets up the memory tracing for that thread as well as
  134. // establishing the tfThread for each thread (if mtfPERTHREADTRACE
  135. // is set in g_tfModule).
  136. //
  137. // Arguments:
  138. // _name NULL or the name of the thread.
  139. //
  140. // Return Values:
  141. // None.
  142. //
  143. //--
  144. //////////////////////////////////////////////////////////////////////////////
  145. #define TraceInitializeThread( _name ) \
  146. do \
  147. { \
  148. TlsSetValue( g_TraceMemoryIndex, NULL); \
  149. DebugInitializeThreadTraceFlags( _name ); \
  150. } while ( 0 )
  151. //////////////////////////////////////////////////////////////////////////////
  152. //++
  153. //
  154. // MACRO
  155. // TraceRundownThread( void )
  156. //
  157. // Description:
  158. // Should be called before a thread terminates. It will check to make
  159. // sure all memory allocated by the thread was released properly. It
  160. // will also cleanup any per thread structures.
  161. //
  162. // Arguments:
  163. // None.
  164. //
  165. // Return Values:
  166. // None.
  167. //
  168. //--
  169. //////////////////////////////////////////////////////////////////////////////
  170. #define TraceRundownThread( ) \
  171. do \
  172. { \
  173. DebugMemoryCheck( NULL, NULL ); \
  174. DebugTerminiateThreadTraceFlags( ); \
  175. } while ( 0 )
  176. //////////////////////////////////////////////////////////////////////////////
  177. //++
  178. //
  179. // MACRO
  180. // TraceCreateMemoryList(
  181. // _pmbIn
  182. // )
  183. //
  184. // Description:
  185. // Creates a thread independent list to track objects.
  186. //
  187. // _pmbIn should be an LPVOID.
  188. //
  189. // Arguments:
  190. // _pmbIn - Pointer to store the head of the list.
  191. //
  192. // Return Values:
  193. // None.
  194. //
  195. //--
  196. //////////////////////////////////////////////////////////////////////////////
  197. #define TraceCreateMemoryList( _pmbIn ) \
  198. DebugCreateMemoryList( TEXT(__FILE__), __LINE__, __MODULE__, &_pmbIn, TEXT(#_pmbIn) );
  199. //////////////////////////////////////////////////////////////////////////////
  200. //++
  201. //
  202. // MACRO
  203. // TraceTerminateMemoryList(
  204. // _pmbIn
  205. // )
  206. //
  207. // Description:
  208. // Checks to make sure the list is empty before destroying the list.
  209. //
  210. // _pmbIn should be an LPVOID.
  211. //
  212. // Arguments:
  213. // _pmbIn - Pointer to store the head of the list.
  214. //
  215. // Return Values:
  216. // None.
  217. //
  218. //--
  219. //////////////////////////////////////////////////////////////////////////////
  220. // BUGBUG: DavidP 09-DEC-1999
  221. // _pmbIn is evaluated multiple times but the name of the
  222. // macro is mixed case.
  223. #define TraceTerminateMemoryList( _pmbIn ) \
  224. do \
  225. { \
  226. DebugMemoryCheck( _pmbIn, TEXT(#_pmbIn) ); \
  227. DebugFree( _pmbIn, TEXT(__FILE__), __LINE__, __MODULE__ ); \
  228. } while ( 0 )
  229. //////////////////////////////////////////////////////////////////////////////
  230. //++
  231. //
  232. // MACRO
  233. // TraceMoveToMemoryList(
  234. // _addr
  235. // _pmbIn
  236. // )
  237. //
  238. // Description:
  239. // Moves and object from the thread tracking list to a thread independent
  240. // memory list (_pmbIn).
  241. //
  242. // _pmbIn should be an LPVOID.
  243. //
  244. // Arguments:
  245. // _addr - Address of object to move.
  246. // _pmbIn - Pointer to store the head of the list.
  247. //
  248. // Return Values:
  249. // None.
  250. //
  251. //--
  252. //////////////////////////////////////////////////////////////////////////////
  253. #define TraceMoveToMemoryList( _addr, _pmbIn ) \
  254. DebugMoveToMemoryList( TEXT(__FILE__), __LINE__, __MODULE__, _addr, _pmbIn, TEXT(#_pmbIn) );
  255. //////////////////////////////////////////////////////////////////////////////
  256. //++
  257. //
  258. // MACRO
  259. // TraceMemoryListDelete(
  260. // _addr
  261. // _pmbIn
  262. // )
  263. //
  264. // Description:
  265. // Moves and object from the thread tracking list to a thread independent
  266. // memory list (_pmbIn).
  267. //
  268. // _pmbIn should be an LPVOID.
  269. //
  270. // Arguments:
  271. // _addr - Address of object to delete.
  272. // _pmbIn - Pointer to store the head of the list.
  273. //
  274. // Return Values:
  275. // None.
  276. //
  277. //--
  278. //////////////////////////////////////////////////////////////////////////////
  279. #define TraceMemoryListDelete( _addr, _pmbIn, _fClobberIn ) \
  280. DebugMemoryListDelete( TEXT(__FILE__), __LINE__, __MODULE__, _addr, _pmbIn, TEXT(#_pmbIn), _fClobberIn );
  281. //////////////////////////////////////////////////////////////////////////////
  282. //++
  283. //
  284. // MACRO
  285. // TraceTerminateProcess
  286. //
  287. // Description:
  288. // Should be called before a process terminates. It cleans up anything
  289. // that the Debug APIs created. It will check to make sure all memory
  290. // allocated by the main thread was released properly. It will also
  291. // terminate WMI tracing. It also closes the logging handle.
  292. //
  293. // Arguments:
  294. // _rgControl - WMI control block (see DEBUG_WMI_CONTROL_GUIDS)
  295. // _sizeofControl - the sizeof( _rgControl )
  296. //
  297. // Return Values:
  298. // None.
  299. //
  300. //--
  301. //////////////////////////////////////////////////////////////////////////////
  302. #define TraceTerminateProcess( _rgControl, _sizeofControl ) \
  303. do \
  304. { \
  305. LogTerminateProcess( ); \
  306. WMITerminateTracing( _rgControl, _sizeofControl ); \
  307. DebugMemoryCheck( NULL, NULL ); \
  308. DebugTerminateProcess( ); \
  309. } while ( 0 )
  310. //****************************************************************************
  311. //
  312. // Debug initialization routines
  313. //
  314. // Uses should use the TraceInitializeXXX and TraceTerminateXXX macros, not
  315. // these routines.
  316. //
  317. //****************************************************************************
  318. void
  319. DebugInitializeTraceFlags( void );
  320. void
  321. DebugInitializeThreadTraceFlags(
  322. LPCTSTR pszThreadNameIn
  323. );
  324. void
  325. DebugTerminateProcess( void );
  326. void
  327. DebugTerminiateThreadTraceFlags( void );
  328. void
  329. DebugCreateMemoryList(
  330. LPCTSTR pszFileIn,
  331. const int nLineIn,
  332. LPCTSTR pszModuleIn,
  333. LPVOID * ppvListOut,
  334. LPCTSTR pszListNameIn
  335. );
  336. void
  337. DebugMemoryListDelete(
  338. LPCTSTR pszFileIn,
  339. const int nLineIn,
  340. LPCTSTR pszModuleIn,
  341. HGLOBAL hGlobalIn,
  342. LPVOID pvListIn,
  343. LPCTSTR pszListNameIn,
  344. BOOL fClobberIn
  345. );
  346. void
  347. DebugMoveToMemoryList(
  348. LPCTSTR pszFileIn,
  349. const int nLineIn,
  350. LPCTSTR pszModuleIn,
  351. HGLOBAL hGlobal,
  352. LPVOID pmbListIn,
  353. LPCTSTR pszListNameIn
  354. );
  355. //****************************************************************************
  356. //
  357. // Memmory Allocation Subsitution Macros
  358. //
  359. // Replaces LocalAlloc/LocalFree and GlobalAlloc/GlobalFree
  360. //
  361. //****************************************************************************
  362. #define TraceAlloc( _flags, _size ) DebugAlloc( TEXT(__FILE__), __LINE__, __MODULE__, _flags, _size, TEXT(#_size) )
  363. #define TraceReAlloc( _hmem, _size, _flags ) DebugReAlloc( TEXT(__FILE__), __LINE__, __MODULE__, _hmem, _flags, _size, TEXT(#_size) )
  364. #define TraceFree( _hmem ) DebugFree( _hmem, TEXT(__FILE__), __LINE__, __MODULE__ )
  365. //////////////////////////////////////////////////////////////////////////////
  366. //++
  367. //
  368. // MACRO
  369. // TraceAllocString(
  370. // _flags,
  371. // _size
  372. // )
  373. //
  374. // Description:
  375. // Quick way to allocation a string that is the proper size and that will
  376. // be tracked by memory tracking.
  377. //
  378. // Arguments:
  379. // _flags - Allocation attributes.
  380. // _size - Number of characters in the string to be allocated.
  381. //
  382. // Return Values:
  383. // Handle/pointer to memory to be used as a string.
  384. //
  385. //////////////////////////////////////////////////////////////////////////////
  386. #define TraceAllocString( _flags, _size ) \
  387. (LPTSTR) DebugAlloc( TEXT(__FILE__), \
  388. __LINE__, \
  389. __MODULE__, \
  390. _flags, \
  391. (_size) * sizeof( TCHAR ), \
  392. TEXT(#_size) \
  393. )
  394. //****************************************************************************
  395. //
  396. // Code Tracing Macros
  397. //
  398. //****************************************************************************
  399. //////////////////////////////////////////////////////////////////////////////
  400. //++
  401. //
  402. // MACRO
  403. // TraceFunc(
  404. // _pszfn
  405. // )
  406. //
  407. // Description:
  408. // Displays file, line number, module and "_pszfn" only if the mtfFUNC is
  409. // set in g_tfModule. "_pszfn" is the name of the function just
  410. // entered. It also increments the stack counter.
  411. //
  412. // Arguments:
  413. // _pszfn - Name of the function just entered.
  414. //
  415. // Return Values:
  416. // None.
  417. //
  418. //--
  419. //////////////////////////////////////////////////////////////////////////////
  420. #define TraceFunc( _pszfn ) \
  421. do \
  422. { \
  423. if ( g_tfModule != 0 ) \
  424. { \
  425. DebugIncrementStackDepthCounter( ); \
  426. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn) ); \
  427. } \
  428. } while ( 0 )
  429. //
  430. // These next macros are just like TraceFunc except they take additional
  431. // arguments to display the values passed into the function call. "_pszfn"
  432. // should contain a printf string on how to display the arguments.
  433. //
  434. #define TraceFunc1( _pszfn, _arg1 ) \
  435. do \
  436. { \
  437. if ( g_tfModule != 0 ) \
  438. { \
  439. DebugIncrementStackDepthCounter( ); \
  440. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1 ); \
  441. } \
  442. } while ( 0 )
  443. #define TraceFunc2( _pszfn, _arg1, _arg2 ) \
  444. do \
  445. { \
  446. if ( g_tfModule != 0 ) \
  447. { \
  448. DebugIncrementStackDepthCounter( ); \
  449. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1, _arg2 ); \
  450. } \
  451. } while ( 0 )
  452. #define TraceFunc3( _pszfn, _arg1, _arg2, _arg3 ) \
  453. do \
  454. { \
  455. if ( g_tfModule != 0 ) \
  456. { \
  457. DebugIncrementStackDepthCounter( ); \
  458. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1, _arg2, _arg3 ); \
  459. } \
  460. } while ( 0 )
  461. #define TraceFunc4( _pszfn, _arg1, _arg2, _arg3, _arg4 ) \
  462. do \
  463. { \
  464. if ( g_tfModule != 0 ) \
  465. { \
  466. DebugIncrementStackDepthCounter( ); \
  467. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4 ); \
  468. } \
  469. } while ( 0 )
  470. #define TraceFunc5( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  471. do \
  472. { \
  473. if ( g_tfModule != 0 ) \
  474. { \
  475. DebugIncrementStackDepthCounter( ); \
  476. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4, arg5 ); \
  477. } \
  478. } while ( 0 )
  479. #define TraceFunc6( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  480. do \
  481. { \
  482. if ( g_tfModule != 0 ) \
  483. { \
  484. DebugIncrementStackDepthCounter( ); \
  485. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4, arg5, arg6 ); \
  486. } \
  487. } while ( 0 )
  488. //////////////////////////////////////////////////////////////////////////////
  489. //++
  490. //
  491. // MACRO
  492. // TraceClsFunc(
  493. // _pszfn
  494. // )
  495. //
  496. // Description:
  497. // Displays file, line number, module, class name and "_msg" only if the
  498. // mtfFUNC is set in g_tfModule. It also increments the stack counter
  499. //
  500. // Arguments:
  501. // _pszfn - Name of the method just entered.
  502. //
  503. // Return Values:
  504. // None.
  505. //
  506. //--
  507. //////////////////////////////////////////////////////////////////////////////
  508. #define TraceClsFunc( _pszfn ) \
  509. do \
  510. { \
  511. if ( g_tfModule != 0 ) \
  512. { \
  513. DebugIncrementStackDepthCounter( ); \
  514. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass ); \
  515. } \
  516. } while ( 0 )
  517. //
  518. // These next macros are just like TraceClsFunc except they take additional
  519. // arguments to display the values passed into the function call. "_pszfn"
  520. // should contain a printf string on how to display the arguments.
  521. //
  522. #define TraceClsFunc1( _pszfn, _arg1 ) \
  523. do \
  524. { \
  525. if ( g_tfModule != 0 ) \
  526. { \
  527. DebugIncrementStackDepthCounter( ); \
  528. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1 ); \
  529. } \
  530. } while ( 0 )
  531. #define TraceClsFunc2( _pszfn, _arg1, _arg2 ) \
  532. do \
  533. { \
  534. if ( g_tfModule != 0 ) \
  535. { \
  536. DebugIncrementStackDepthCounter( ); \
  537. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1, _arg2 ); \
  538. } \
  539. } while ( 0 )
  540. #define TraceClsFunc3( _pszfn, _arg1, _arg2, _arg3 ) \
  541. do \
  542. { \
  543. if ( g_tfModule != 0 ) \
  544. { \
  545. DebugIncrementStackDepthCounter( ); \
  546. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1, _arg2, _arg3 ); \
  547. } \
  548. } while ( 0 )
  549. #define TraceClsFunc4( _pszfn, _arg1, _arg2, _arg3, _arg4 ) \
  550. do \
  551. { \
  552. if ( g_tfModule != 0 ) \
  553. { \
  554. DebugIncrementStackDepthCounter( ); \
  555. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1, _arg2, _arg3, _arg4 ); \
  556. } \
  557. } while ( 0 )
  558. #define TraceClsFunc5( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  559. do \
  560. { \
  561. if ( g_tfModule != 0 ) \
  562. { \
  563. DebugIncrementStackDepthCounter( ); \
  564. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  565. } \
  566. } while ( 0 )
  567. #define TraceClsFunc6( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  568. do \
  569. { \
  570. if ( g_tfModule != 0 ) \
  571. { \
  572. DebugIncrementStackDepthCounter( ); \
  573. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ %s::") TEXT(_pszfn), g_szClass, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  574. } \
  575. } while ( 0 )
  576. //////////////////////////////////////////////////////////////////////////////
  577. //++
  578. //
  579. // MACRO
  580. // TraceFuncExit( void )
  581. //
  582. // Description:
  583. // Return macro for TraceFunc() and TraceClsFunc() if the return type is
  584. // void. It also decrements the stack counter.
  585. //
  586. // Arguments:
  587. // None.
  588. //
  589. // Return Values:
  590. // None.
  591. //
  592. //--
  593. //////////////////////////////////////////////////////////////////////////////
  594. #define TraceFuncExit( ) \
  595. do \
  596. { \
  597. if ( g_tfModule != 0 ) \
  598. { \
  599. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  600. DebugDecrementStackDepthCounter( ); \
  601. } \
  602. return; \
  603. } while ( 0 )
  604. //////////////////////////////////////////////////////////////////////////////
  605. //++
  606. //
  607. // MACRO
  608. // RETURN(
  609. // _rval
  610. // )
  611. //
  612. // Description:
  613. // Return macro for TraceFunc() and TraceClsFunc(). The _rval will be
  614. // returned as the result of the function. It also decrements the stack
  615. // counter.
  616. //
  617. // Arguments:
  618. // _rval - Result of the function.
  619. //
  620. // Return Values:
  621. // None.
  622. //
  623. //--
  624. //////////////////////////////////////////////////////////////////////////////
  625. #define RETURN( _rval ) \
  626. do \
  627. { \
  628. if ( g_tfModule != 0 ) \
  629. { \
  630. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  631. DebugDecrementStackDepthCounter( ); \
  632. } \
  633. return _rval; \
  634. } while ( 0 )
  635. //////////////////////////////////////////////////////////////////////////////
  636. //++
  637. //
  638. // MACRO
  639. // FRETURN(
  640. // _rval
  641. // )
  642. //
  643. // Description:
  644. // This is a fake version of the return macro for TraceFunc() and
  645. // TraceClsFunc(). *** This doesn't return. *** It also decrements
  646. // the stack counter.
  647. //
  648. // Arguments:
  649. // _rval - Result of the function.
  650. //
  651. // Return Values:
  652. // None.
  653. //
  654. //--
  655. //////////////////////////////////////////////////////////////////////////////
  656. #define FRETURN( _rval ) \
  657. do \
  658. { \
  659. if ( g_tfModule != 0 ) \
  660. { \
  661. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  662. DebugDecrementStackDepthCounter( ); \
  663. } \
  664. } while ( 0 )
  665. //////////////////////////////////////////////////////////////////////////////
  666. //++
  667. //
  668. // MACRO
  669. // HRETURN(
  670. // _hr
  671. // )
  672. //
  673. // Description:
  674. // Return macro for TraceFunc() and TraceClsFunc(). The _hr will be
  675. // returned as the result of the function. If the value is not S_OK, it
  676. // will be displayed in the debugger. It also decrements the stack
  677. // counter.
  678. //
  679. // Arguments:
  680. // _hr - Result of the function.
  681. //
  682. // Return Values:
  683. // None.
  684. //
  685. //--
  686. //////////////////////////////////////////////////////////////////////////////
  687. #define HRETURN( _hr ) \
  688. do \
  689. { \
  690. if ( g_tfModule != 0 ) \
  691. { \
  692. if ( _hr != S_OK ) \
  693. { \
  694. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)\n"), _hr ); \
  695. } \
  696. else \
  697. { \
  698. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  699. } \
  700. DebugDecrementStackDepthCounter( ); \
  701. } \
  702. return _hr; \
  703. } while ( 0 )
  704. //
  705. // These next macros are just like HRETURN except they allow other
  706. // exceptable values to be passed.back without causing extra spew.
  707. //
  708. #define HRETURN1( _hr, _arg1 ) \
  709. do \
  710. { \
  711. if ( g_tfModule != 0 ) \
  712. { \
  713. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) ) \
  714. { \
  715. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)\n"), _hr ); \
  716. } \
  717. else \
  718. { \
  719. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  720. } \
  721. DebugDecrementStackDepthCounter( ); \
  722. } \
  723. return _hr; \
  724. } while ( 0 )
  725. #define HRETURN2( _hr, _arg1, _arg2 ) \
  726. do \
  727. { \
  728. if ( g_tfModule != 0 ) \
  729. { \
  730. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) && ( _hr != _arg2 ) ) \
  731. { \
  732. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)\n"), _hr ); \
  733. } \
  734. else \
  735. { \
  736. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  737. } \
  738. DebugDecrementStackDepthCounter( ); \
  739. } \
  740. return _hr; \
  741. } while ( 0 )
  742. #define HRETURN3( _hr, _arg1, _arg2, _arg3 ) \
  743. do \
  744. { \
  745. if ( g_tfModule != 0 ) \
  746. { \
  747. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) && ( _hr != _arg2 ) && ( _hr != _arg3 ) ) \
  748. { \
  749. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)\n"), _hr ); \
  750. } \
  751. else \
  752. { \
  753. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  754. } \
  755. DebugDecrementStackDepthCounter( ); \
  756. } \
  757. return _hr; \
  758. } while ( 0 )
  759. //////////////////////////////////////////////////////////////////////////////
  760. //++
  761. //
  762. // MACRO
  763. // TraceDo(
  764. // _szExp
  765. // )
  766. //
  767. // Description:
  768. // Displays the file, line number, module and function call and return
  769. // from the function call (no return value displayed) for "_szExp" only
  770. // if the mtfCALLS is set in g_tfModule. Note return value is not
  771. // displayed. _szExp will be in RETAIL version of the product.
  772. //
  773. // Arguments:
  774. // _szExp
  775. // The expression to be traced including assigment to the return
  776. // variable.
  777. //
  778. // Return Values:
  779. // None. The return value should be defined within _szExp.
  780. //
  781. //--
  782. //////////////////////////////////////////////////////////////////////////////
  783. #define TraceDo( _szExp ) \
  784. do \
  785. { \
  786. if ( g_tfModule != 0 ) \
  787. { \
  788. DebugIncrementStackDepthCounter( ); \
  789. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_szExp ) TEXT("\n") ); \
  790. _szExp; \
  791. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("V\n") ); \
  792. DebugDecrementStackDepthCounter( ); \
  793. } \
  794. else \
  795. { \
  796. _szExp; \
  797. } \
  798. } while ( 0 )
  799. //////////////////////////////////////////////////////////////////////////////
  800. //++
  801. //
  802. // MACRO
  803. // TraceMsgDo(
  804. // _szExp,
  805. // _szMsg
  806. // )
  807. //
  808. // Description:
  809. // Displays the file, line number, module and function call and return
  810. // value which is formatted in "_szMsg" for "_szExp" only if the mtfCALLS
  811. // is set in g_tfModule. _szExp will be in the RETAIL version of the
  812. // product.
  813. //
  814. // Arguments:
  815. // _szExp
  816. // The expression to be traced including assigment to the return
  817. // variable.
  818. // _szMsg
  819. // A format string on how the return value should be displayed in the
  820. // debugger.
  821. //
  822. // Return Values:
  823. // None. The return value should be defined within _szExp.
  824. //
  825. //--
  826. //////////////////////////////////////////////////////////////////////////////
  827. #define TraceMsgDo( _szExp, _szMsg ) \
  828. do \
  829. { \
  830. if ( g_tfModule != 0 ) \
  831. { \
  832. DebugIncrementStackDepthCounter( ); \
  833. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_szExp) TEXT("\n") ); \
  834. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_szMsg), TEXT(#_szExp), _szExp ); \
  835. DebugDecrementStackDepthCounter( ); \
  836. } \
  837. else \
  838. { \
  839. _szExp; \
  840. } \
  841. } while ( 0 )
  842. //////////////////////////////////////////////////////////////////////////////
  843. //++
  844. //
  845. // MACRO
  846. // TraceMsgGUID(
  847. // _flags,
  848. // _msg
  849. // _guid
  850. // )
  851. //
  852. // Description:
  853. // Dumps a GUID to the debugger only if one of the flags in _flags is
  854. // set in g_tfModule.
  855. //
  856. // Arguments:
  857. // _flags - Flags to check
  858. // _msg - msg to print before GUID
  859. // _guid - GUID to dump
  860. //
  861. // Return Values:
  862. // None.
  863. //
  864. //--
  865. //////////////////////////////////////////////////////////////////////////////
  866. // BUGBUG: DavidP 09-DEC-1999
  867. // _guid is evaluated multiple times but the name of the
  868. // macro is mixed case.
  869. #define TraceMsgGUID( _flags, _msg, _guid ) \
  870. do \
  871. { \
  872. if ( g_tfModule != 0 ) \
  873. { \
  874. TraceMessage( TEXT(__FILE__), \
  875. __LINE__, \
  876. __MODULE__, \
  877. _flags, \
  878. TEXT("%s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n"), \
  879. _msg, \
  880. _guid.Data1, _guid.Data2, _guid.Data3, \
  881. _guid.Data4[ 0 ], _guid.Data4[ 1 ], _guid.Data4[ 2 ], _guid.Data4[ 3 ], \
  882. _guid.Data4[ 4 ], _guid.Data4[ 5 ], _guid.Data4[ 6 ], _guid.Data4[ 7 ] ); \
  883. } \
  884. } while ( 0 )
  885. //////////////////////////////////////////////////////////////////////////////
  886. //++
  887. //
  888. // MACRO
  889. // ErrorMsg(
  890. // _szMsg,
  891. // _err
  892. // )
  893. //
  894. // Description:
  895. // Print an error out. Can be used to log errors to a log file. Note that
  896. // it will also print the source filename, line number and module name.
  897. //
  898. // Arguments:
  899. // _szMsg - Format string to be displayed.
  900. // _err - Error code of the error.
  901. //
  902. // Return Values:
  903. // None.
  904. //
  905. //--
  906. //////////////////////////////////////////////////////////////////////////////
  907. #define ErrorMsg( _szMsg, _err ) \
  908. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfALWAYS, TEXT(_szMsg), _err );
  909. //////////////////////////////////////////////////////////////////////////////
  910. //++
  911. //
  912. // MACRO
  913. // WndMsg(
  914. // _hwnd,
  915. // _umsg,
  916. // _wparam,
  917. // _lparam
  918. // )
  919. //
  920. // Description:
  921. // Prints out a message to trace windows messages.
  922. //
  923. // Arguments:
  924. // _hwnd - The HWND
  925. // _umsg - The uMsg
  926. // _wparam - The WPARAM
  927. // _lparam _ The LPARAM
  928. //
  929. // Return Values:
  930. // None.
  931. //
  932. //--
  933. //////////////////////////////////////////////////////////////////////////////
  934. // BUGBUG: DavidP 09-DEC-1999
  935. // _wparam and _lparam are evaluated multiple times but the name
  936. // of the macro is mixed case.
  937. #define WndMsg( _hwnd, _umsg, _wparam, _lparam ) \
  938. do \
  939. { \
  940. if ( g_tfModule & mtfWM ) \
  941. { \
  942. DebugMsg( TEXT("%s: WM : hWnd = 0x%08x, uMsg = %u, wParam = 0x%08x (%u), lParam = 0x%08x (%u)\n"), __MODULE__, _hwnd, _umsg, _wparam, _wparam, _lparam, _lparam ); \
  943. } \
  944. } while ( 0 )
  945. //****************************************************************************
  946. //
  947. // Debug Macros
  948. //
  949. // These calls are only compiled in DEBUG. They are a NOP in RETAIL
  950. // (not even compiled in).
  951. //
  952. //****************************************************************************
  953. //
  954. // Same as TraceDo() but only compiled in DEBUG.
  955. //
  956. #define DebugDo( _fn ) \
  957. do \
  958. { \
  959. DebugIncrementStackDepthCounter( ); \
  960. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("+ ") TEXT(#_fn ) TEXT("\n") ); \
  961. _fn; \
  962. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("V\n") ); \
  963. DebugDecrementStackDepthCounter( ); \
  964. } while ( 0 )
  965. //
  966. // Same as TraceMsgDo() but only compiled in DEBUG.
  967. //
  968. #define DebugMsgDo( _fn, _msg ) \
  969. do \
  970. { \
  971. DebugIncrementStackDepthCounter( ); \
  972. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("+ ") TEXT(#_fn) TEXT("\n") ); \
  973. DebugMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), TEXT(#_fn), _fn ); \
  974. DebugDecrementStackDepthCounter( ); \
  975. } while ( 0 )
  976. //****************************************************************************
  977. //
  978. // HRESULT testing macros
  979. //
  980. // These functions check HRESULT return values and display UI if conditions
  981. // warrant only in DEBUG.
  982. //
  983. //****************************************************************************
  984. //////////////////////////////////////////////////////////////////////////////
  985. //++
  986. //
  987. // MACRO
  988. // IsTraceFlagSet(
  989. // _flag
  990. // )
  991. //
  992. // Description:
  993. // Checks to see of the flag is set in the global flags or in the per
  994. // thread flags. If you specify more than one flag and if any of them are
  995. // set, it will return TRUE.
  996. //
  997. // In RETAIL this always return FALSE thereby effectively deleting the
  998. // block of the if statement. Example:
  999. //
  1000. // if ( IsTraceFlagSet( mtfPERTHREADTRACE ) )
  1001. // {
  1002. // //
  1003. // // This code only exists in DEBUG.
  1004. // .
  1005. // .
  1006. // .
  1007. // }
  1008. //
  1009. // Arguments:
  1010. // _flags - Flag to check for.
  1011. //
  1012. // Return Values:
  1013. // TRUE - If DEBUG and flag set.
  1014. // FLASE - If RETAIL or flag not set.
  1015. //
  1016. //--
  1017. //////////////////////////////////////////////////////////////////////////////
  1018. #define IsTraceFlagSet( _flag ) ( g_tfModule && IsDebugFlagSet( _flag ) )
  1019. //////////////////////////////////////////////////////////////////////////////
  1020. //++
  1021. //
  1022. // MACRO
  1023. // THR(
  1024. // _hr
  1025. // )
  1026. //
  1027. // Description:
  1028. // Warning is display if HRESULT is anything but S_OK (0). This can be
  1029. // use in an expression. Example:
  1030. //
  1031. // hr = THR( pSomething->DoSomething( arg ) );
  1032. //
  1033. // Arguments:
  1034. // _hr - Function expression to check.
  1035. //
  1036. // Return Values:
  1037. // Result of the "_hr" expression.
  1038. //
  1039. //--
  1040. //////////////////////////////////////////////////////////////////////////////
  1041. #define THR( _hr ) \
  1042. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, FALSE )
  1043. //////////////////////////////////////////////////////////////////////////////
  1044. //++
  1045. //
  1046. // MACRO
  1047. // STHR(
  1048. // _hr
  1049. // )
  1050. //
  1051. // Description:
  1052. // Warning is display if FAILED( _hr ) is TRUE. This can be use in an
  1053. // expression. Example:
  1054. //
  1055. // hr = STHR( pSomething->DoSomething( arg ) );
  1056. //
  1057. // Arguments:
  1058. // _hr - Function expression to check.
  1059. //
  1060. // Return Values:
  1061. // Result of the "_hr" expression.
  1062. //
  1063. //--
  1064. //////////////////////////////////////////////////////////////////////////////
  1065. #define STHR( _hr ) \
  1066. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, TRUE )
  1067. //////////////////////////////////////////////////////////////////////////////
  1068. //++
  1069. //
  1070. // MACRO
  1071. // TW32(
  1072. // _fn
  1073. // )
  1074. //
  1075. // Description:
  1076. // Warning is display if result is anything but ERROR_SUCCESS (0). This
  1077. // can be use in an expression. Example:
  1078. //
  1079. // dwErr = TW32( RegOpenKey( HKLM, "foobar", &hkey ) );
  1080. //
  1081. // Arguments:
  1082. // _fn - Function expression to check.
  1083. //
  1084. // Return Values:
  1085. // Result of the "_fn" expression.
  1086. //
  1087. //--
  1088. //////////////////////////////////////////////////////////////////////////////
  1089. #define TW32( _fn ) \
  1090. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_fn), _fn )
  1091. //////////////////////////////////////////////////////////////////////////////
  1092. //++
  1093. //
  1094. // MACRO
  1095. // RRETURN(
  1096. // _fn
  1097. // )
  1098. //
  1099. // Description:
  1100. // Warning is display if return value is anything but ERROR_SUCCESS (0).
  1101. //
  1102. // Argument:
  1103. // _fn - Value to return.
  1104. //
  1105. // Return Values:
  1106. // _fn always.
  1107. //
  1108. //--
  1109. //////////////////////////////////////////////////////////////////////////////
  1110. #define RRETURN( _fn ) \
  1111. do \
  1112. { \
  1113. if ( g_tfModule != 0 ) \
  1114. { \
  1115. if ( _fn != ERROR_SUCCESS ) \
  1116. { \
  1117. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V ") TEXT(#_fn) TEXT(" = 0x%08x (%s)\n"), _fn ); \
  1118. } \
  1119. else \
  1120. { \
  1121. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V\n") ); \
  1122. } \
  1123. DebugDecrementStackDepthCounter( ); \
  1124. } \
  1125. return _fn; \
  1126. } while ( 0 )
  1127. //////////////////////////////////////////////////////////////////////////////
  1128. //++
  1129. //
  1130. // MACRO
  1131. // QIRETURN(
  1132. // _hr,
  1133. // _riid
  1134. // )
  1135. //
  1136. // Description:
  1137. // Warning is display if HRESULT is anything but S_OK (0) only if
  1138. // mtfQUERYINTERFACE is set in g_tfModule, otherwise only a debug
  1139. // message will be printed. Note that TraceFunc or TraceClsFunc must
  1140. // have been called on the call stack counter must be incremented
  1141. // prior to using.
  1142. //
  1143. // Arguments:
  1144. // _hr - Result of the query interface call.
  1145. // _riid - The reference ID of the interfaced queried for.
  1146. //
  1147. // Return Values:
  1148. // None - calls RETURN macro.
  1149. //
  1150. //--
  1151. //////////////////////////////////////////////////////////////////////////////
  1152. #define QIRETURN( _hr, _riid ) \
  1153. do \
  1154. { \
  1155. if ( _hr ) \
  1156. { \
  1157. TCHAR szGuid[ 40 ]; \
  1158. TCHAR szSymbolicName[ 64 ]; \
  1159. DWORD cchSymbolicName = 64; \
  1160. DebugFindWinerrorSymbolicName( _hr, szSymbolicName, &cchSymbolicName ); \
  1161. Assert( cchSymbolicName != 64 ); \
  1162. DebugMessage( TEXT(__FILE__), \
  1163. __LINE__, \
  1164. __MODULE__, \
  1165. TEXT("*HRESULT* QueryInterface( %s, ppv ) failed(), hr = 0x%08x (%s)\n"), \
  1166. PszDebugFindInterface( _riid, szGuid ), \
  1167. _hr, \
  1168. szSymbolicName \
  1169. ); \
  1170. } \
  1171. if ( g_tfModule & mtfQUERYINTERFACE ) \
  1172. { \
  1173. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, FALSE ); \
  1174. } \
  1175. HRETURN( _hr ); \
  1176. } while ( 0 )
  1177. //////////////////////////////////////////////////////////////////////////////
  1178. //++
  1179. //
  1180. // MACRO
  1181. // BOOLTOSTRING(
  1182. // _fBool
  1183. // )
  1184. //
  1185. // Desfription:
  1186. // If _fBool is true, returns address of "TRUE" else returns address of
  1187. // "FALSE".
  1188. //
  1189. // Argument:
  1190. // _fBool - Expression to evaluate.
  1191. //
  1192. // Return Values:
  1193. // address of "TRUE" if _fBool is true.
  1194. // address of "FALSE" if _fBool is false.
  1195. //
  1196. //--
  1197. //////////////////////////////////////////////////////////////////////////////
  1198. #define BOOLTOSTRING( _fBool ) ( (_fBool) ? g_szTrue : g_szFalse )
  1199. //****************************************************************************
  1200. //
  1201. // Trace/Debug Functions - these do not exist in RETAIL.
  1202. //
  1203. //****************************************************************************
  1204. BOOL
  1205. IsDebugFlagSet(
  1206. TRACEFLAG tfIn
  1207. );
  1208. void
  1209. TraceMsg(
  1210. TRACEFLAG tfIn,
  1211. LPCSTR pszFormatIn,
  1212. ...
  1213. );
  1214. void
  1215. TraceMsg(
  1216. TRACEFLAG tfIn,
  1217. LPCWSTR pszFormatIn,
  1218. ...
  1219. );
  1220. void
  1221. DebugMsg(
  1222. LPCSTR pszFormatIn,
  1223. ...
  1224. );
  1225. void
  1226. DebugMsg(
  1227. LPCWSTR pszFormatIn,
  1228. ...
  1229. );
  1230. void
  1231. TraceMessage(
  1232. LPCTSTR pszFileIn,
  1233. const int nLineIn,
  1234. LPCTSTR pszModuleIn,
  1235. TRACEFLAG tfIn,
  1236. LPCTSTR pszFormatIn,
  1237. ...
  1238. );
  1239. void
  1240. TraceMessageDo(
  1241. LPCTSTR pszFileIn,
  1242. const int nLineIn,
  1243. LPCTSTR pszModuleIn,
  1244. TRACEFLAG tfIn,
  1245. LPCTSTR pszFormatIn,
  1246. LPCTSTR pszFuncIn,
  1247. ...
  1248. );
  1249. void
  1250. DebugMessage(
  1251. LPCTSTR pszFileIn,
  1252. const int nLineIn,
  1253. LPCTSTR pszModuleIn,
  1254. LPCTSTR pszFormatIn,
  1255. ...
  1256. );
  1257. void
  1258. DebugMessageDo(
  1259. LPCTSTR pszFileIn,
  1260. const int nLineIn,
  1261. LPCTSTR pszModuleIn,
  1262. LPCTSTR pszFormatIn,
  1263. LPCTSTR pszFuncIn,
  1264. ...
  1265. );
  1266. BOOL
  1267. AssertMessage(
  1268. LPCTSTR pszFileIn,
  1269. const int nLineIn,
  1270. LPCTSTR pszModuleIn,
  1271. LPCTSTR pszfnIn,
  1272. BOOL fTrueIn
  1273. );
  1274. HRESULT
  1275. TraceHR(
  1276. LPCTSTR pszFileIn,
  1277. const int nLineIn,
  1278. LPCTSTR pszModuleIn,
  1279. LPCTSTR pszfnIn,
  1280. HRESULT hrIn,
  1281. BOOL fSuccessIn
  1282. );
  1283. ULONG
  1284. TraceWin32(
  1285. LPCTSTR pszFileIn,
  1286. const int nLineIn,
  1287. LPCTSTR pszModuleIn,
  1288. LPCTSTR pszfnIn,
  1289. ULONG ulErrIn
  1290. );
  1291. #if 0
  1292. //
  1293. // Trying to get the NTSTATUS stuff to play in "user world"
  1294. // is just about impossible. This is here in case it is needed
  1295. // and one could find the right combination of headers to
  1296. // make it work. Inflicting such pain on others is the reason
  1297. // why this function is #ifdef'fed.
  1298. //
  1299. void
  1300. DebugFindNTStatusSymbolicName(
  1301. NTSTATUS dwStatusIn,
  1302. LPTSTR pszNameOut,
  1303. LPDWORD pcchNameInout
  1304. );
  1305. #endif
  1306. void
  1307. DebugFindWinerrorSymbolicName(
  1308. DWORD dwErrIn,
  1309. LPTSTR pszNameOut,
  1310. LPDWORD pcchNameInout
  1311. );
  1312. void
  1313. DebugReturnMessage(
  1314. LPCTSTR pszFileIn,
  1315. const int nLineIn,
  1316. LPCTSTR pszModuleIn,
  1317. LPCTSTR pszMessageIn,
  1318. DWORD dwErrIn
  1319. );
  1320. //****************************************************************************
  1321. //
  1322. // Use the TraceMemoryXXX wrappers, not the DebugMemoryXXX functions.
  1323. // The memory tracking functions do not exist in RETAIL (converted to NOP).
  1324. //
  1325. //****************************************************************************
  1326. typedef enum EMEMORYBLOCKTYPE
  1327. {
  1328. mmbtUNKNOWN = 0, // Never used
  1329. mmbtMEMORYALLOCATION, // Global/LocalAlloc
  1330. mmbtOBJECT, // Object pointer
  1331. mmbtHANDLE, // Object handle
  1332. mmbtPUNK, // IUnknown pointer
  1333. mmbtSYSALLOCSTRING // SysAllocString
  1334. } EMEMORYBLOCKTYPE;
  1335. #define TraceMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _uFlagsIn, _dwBytesIn, _pszCommentIn ) \
  1336. DebugMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _uFlagsIn, _dwBytesIn, _pszCommentIn )
  1337. #define TraceMemoryAddAddress( _pv ) \
  1338. DebugMemoryAdd( mmbtMEMORYALLOCATION, _pv, TEXT(__FILE__), __LINE__, __MODULE__, GMEM_FIXED, 0, TEXT(#_pv) )
  1339. #define TraceMemoryAddHandle( _handle ) \
  1340. DebugMemoryAdd( mmbtHANDLE, _handle, TEXT(__FILE__), __LINE__, __MODULE__, GMEM_MOVEABLE, 0, TEXT(#_handle) )
  1341. #define TraceMemoryAddObject( _pv ) \
  1342. DebugMemoryAdd( mmbtOBJECT, _pv, TEXT(__FILE__), __LINE__, __MODULE__, GMEM_INVALID_HANDLE, 0, TEXT(#_pv) )
  1343. #define TraceMemoryAddPunk( _punk ) \
  1344. DebugMemoryAdd( mmbtPUNK, _punk, TEXT(__FILE__), __LINE__, __MODULE__, GMEM_INVALID_HANDLE, 0, TEXT(#_punk) )
  1345. #define TraceMemoryDelete( _hGlobalIn, _fClobberIn ) \
  1346. DebugMemoryDelete( mmbtUNKNOWN, _hGlobalIn, TEXT(__FILE__), __LINE__, __MODULE__, _fClobberIn )
  1347. #define TraceStrDup( _sz ) \
  1348. (LPTSTR) DebugMemoryAdd( mmbtMEMORYALLOCATION, StrDup( _sz ), TEXT(__FILE__), __LINE__, __MODULE__, GMEM_FIXED, 0, TEXT("StrDup( ") TEXT(#_sz) TEXT(" )") )
  1349. #if defined( USES_SYSALLOCSTRING )
  1350. // BUGBUG: DavidP 09-DEC-1999
  1351. // _sz is evaluated multiple times but the name of the
  1352. // macro is mixed case.
  1353. #define TraceSysAllocString( _sz ) \
  1354. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocString( _sz ), TEXT(__FILE__), __LINE__, __MODULE__, 0, wcslen( _sz ) + 1, TEXT("SysAllocString( ") TEXT(#_sz) TEXT(")") )
  1355. // BUGBUG: DavidP 09-DEC-1999
  1356. // _sz and _len are evaluated multiple times but the name of the
  1357. // macro is mixed case.
  1358. #define TraceSysAllocStringByteLen( _sz, _len ) \
  1359. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocStringByteLen( _sz, _len ), TEXT(__FILE__), __LINE__, __MODULE__, 0, _len, TEXT("SysAllocStringByteLen( ") TEXT(#_sz) TEXT(")") )
  1360. // BUGBUG: DavidP 09-DEC-1999
  1361. // _sz and _len are evaluated multiple times but the name of the
  1362. // macro is mixed case.
  1363. #define TraceSysAllocStringLen( _sz, _len ) \
  1364. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocStringLen( _sz, _len ), TEXT(__FILE__), __LINE__, __MODULE__, 0, _len + 1, TEXT("SysAllocStringLen( ") TEXT(#_sz) TEXT(")") )
  1365. #define TraceSysReAllocString( _bstrOrg, _bstrNew ) \
  1366. DebugSysReAllocString( TEXT(__FILE__), __LINE__, __MODULE__, _bstrOrg, _bstrNew, TEXT("TraceSysReAllocString(") TEXT(#_bstrOrg) TEXT(", ") TEXT(#_bstrNew) TEXT(" )") )
  1367. #define TraceSysReAllocStringLen( _bstrOrg, _bstrNew, _cch ) \
  1368. DebugSysReAllocStringLen( TEXT(__FILE__), __LINE__, __MODULE__, _bstrOrg, _bstrNew, _cch, TEXT("TraceSysReAllocString(") TEXT(#_bstrOrg) TEXT(", ") TEXT(#_bstrNew) TEXT(", ") TEXT(#_cch) TEXT(" )") )
  1369. #define TraceSysFreeString( _bstr ) \
  1370. DebugMemoryDelete( mmbtSYSALLOCSTRING, _bstr, TEXT(__FILE__), __LINE__, __MODULE__, TRUE ); \
  1371. SysFreeString( _bstr )
  1372. #endif // USES_SYSALLOCSTRING
  1373. //****************************************************************************
  1374. //
  1375. // Memory tracing functions - these are remapped to the GlobalAlloc/GlobalFree
  1376. // heap functions when in RETAIL. Use the TraceMemoryXXX wrappers, not the
  1377. // DebugMemoryXXX functions.
  1378. //
  1379. //****************************************************************************
  1380. HGLOBAL
  1381. DebugAlloc(
  1382. LPCTSTR pszFileIn,
  1383. const int nLineIn,
  1384. LPCTSTR pszModuleIn,
  1385. UINT uFlagsIn,
  1386. DWORD dwBytesIn,
  1387. LPCTSTR pszCommentIn
  1388. );
  1389. HGLOBAL
  1390. DebugReAlloc(
  1391. LPCTSTR pszFileIn,
  1392. const int nLineIn,
  1393. LPCTSTR pszModuleIn,
  1394. HGLOBAL hMemIn,
  1395. UINT uFlagsIn,
  1396. DWORD dwBytesIn,
  1397. LPCTSTR pszCommentIn
  1398. );
  1399. HGLOBAL
  1400. DebugFree(
  1401. HGLOBAL hMemIn,
  1402. LPCTSTR pszFileIn,
  1403. const int nLineIn,
  1404. LPCTSTR pszModuleIn
  1405. );
  1406. HGLOBAL
  1407. DebugMemoryAdd(
  1408. EMEMORYBLOCKTYPE mbtType,
  1409. HGLOBAL hGlobalIn,
  1410. LPCTSTR pszFileIn,
  1411. const int nLineIn,
  1412. LPCTSTR pszModuleIn,
  1413. UINT uFlagsIn,
  1414. DWORD dwBytesIn,
  1415. LPCTSTR pszCommentIn
  1416. );
  1417. void
  1418. DebugMemoryDelete(
  1419. EMEMORYBLOCKTYPE mbtTypeIn,
  1420. HGLOBAL hGlobalIn,
  1421. LPCTSTR pszFileIn,
  1422. const int nLineIn,
  1423. LPCTSTR pszModuleIn,
  1424. BOOL fClobberIn
  1425. );
  1426. #if defined( USES_SYSALLOCSTRING )
  1427. INT
  1428. DebugSysReAllocString(
  1429. LPCTSTR pszFileIn,
  1430. const int nLineIn,
  1431. LPCTSTR pszModuleIn,
  1432. BSTR * pbstrIn,
  1433. const OLECHAR * pszIn,
  1434. LPCTSTR pszCommentIn
  1435. );
  1436. INT
  1437. DebugSysReAllocStringLen(
  1438. LPCTSTR pszFileIn,
  1439. const int nLineIn,
  1440. LPCTSTR pszModuleIn,
  1441. BSTR * pbstrIn,
  1442. const OLECHAR * pszIn,
  1443. unsigned int ucchIn,
  1444. LPCTSTR pszCommentIn
  1445. );
  1446. #endif // USES_SYSALLOCSTRING
  1447. void
  1448. DebugMemoryCheck(
  1449. LPVOID pvListIn,
  1450. LPCTSTR pszListNameIn
  1451. );
  1452. //****************************************************************************
  1453. //
  1454. // operator new( ) for C++
  1455. //
  1456. //****************************************************************************
  1457. #ifdef __cplusplus
  1458. extern
  1459. void *
  1460. __cdecl
  1461. operator new(
  1462. size_t nSizeIn,
  1463. LPCTSTR pszFileIn,
  1464. const int nLineIn,
  1465. LPCTSTR pszModuleIn
  1466. );
  1467. //
  1468. // Remap "new" to our macro so "we" don't have to type anything extra and
  1469. // so it magically dissappears in RETAIL.
  1470. //
  1471. #define new new( TEXT(__FILE__), __LINE__, __MODULE__ )
  1472. #endif
  1473. //****************************************************************************
  1474. //
  1475. //
  1476. #else // it's RETAIL ******************************************************
  1477. //
  1478. //
  1479. //****************************************************************************
  1480. #pragma message("BUILD: RETAIL macros being built")
  1481. //
  1482. // Debugging -> NOPs
  1483. //
  1484. #define DEFINE_MODULE( _module )
  1485. #define __MODULE__ NULL
  1486. #define DEFINE_THISCLASS( _class )
  1487. #define __THISCLASS__ NULL
  1488. #define DEFINE_SUPER( _super )
  1489. #define __SUPERCLASS__ NULL
  1490. #define BOOLTOSTRING( _fBool ) NULL
  1491. #define DebugDo( _fn )
  1492. #define DebugMsgDo( _fn, _msg )
  1493. #define TraceMsgGUID( _f, _m, _g )
  1494. #define AssertMessage( _f, _l, _m, _e, _msg ) TRUE
  1495. //
  1496. // TODO: gpease 08-NOV-1999
  1497. // We probably want to do something special for ErrorMsg( )
  1498. //
  1499. #define ErrorMsg 1 ? (void)0 : (void)
  1500. #define TraceMsg 1 ? (void)0 : (void)
  1501. #define WndMsg 1 ? (void)0 : (void)
  1502. #define DebugMsg 1 ? (void)0 : (void)
  1503. #define TraceMessage 1 ? (void)0 : (void)
  1504. #define DebugMessage 1 ? (void)0 : (void)
  1505. #define TraceHR 1 ? (void)0 : (void)
  1506. #define TraceFunc 1 ? (void)0 : (void)
  1507. #define TraceFunc1 1 ? (void)0 : (void)
  1508. #define TraceFunc2 1 ? (void)0 : (void)
  1509. #define TraceFunc3 1 ? (void)0 : (void)
  1510. #define TraceFunc4 1 ? (void)0 : (void)
  1511. #define TraceFunc5 1 ? (void)0 : (void)
  1512. #define TraceFunc6 1 ? (void)0 : (void)
  1513. #define TraceClsFunc 1 ? (void)0 : (void)
  1514. #define TraceClsFunc1 1 ? (void)0 : (void)
  1515. #define TraceClsFunc2 1 ? (void)0 : (void)
  1516. #define TraceClsFunc3 1 ? (void)0 : (void)
  1517. #define TraceClsFunc4 1 ? (void)0 : (void)
  1518. #define TraceClsFunc5 1 ? (void)0 : (void)
  1519. #define TraceClsFunc6 1 ? (void)0 : (void)
  1520. #define TraceFuncExit() return
  1521. #define TraceInitializeThread( _name )
  1522. #define TraceRundownThread( )
  1523. #define TraceMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _uFlagsIn, _dwBytesIn, _pszCommentIn ) _hGlobalIn
  1524. #define TraceMemoryAddHandle( _handle ) _handle
  1525. #define TraceMemoryAddAddress( _pv ) _pv
  1526. #define TraceMemoryAddHandle( _obj ) _obj
  1527. #define TraceMemoryAddPunk( _punk ) _punk
  1528. #define TraceMemoryDelete( _h, _b ) _h
  1529. #define TraceMemoryAddObject( _pv ) _pv
  1530. #define IsTraceFlagSet( _flag ) FALSE
  1531. //
  1532. // Enable WMI
  1533. //
  1534. #define TraceInitializeProcess( _rg, _sizeof ) \
  1535. WMIInitializeTracing( _rg, _sizeof );
  1536. #define TraceTerminateProcess( _rg, _sizeof ) \
  1537. WMITerminateTracing( _rg, _sizeof );
  1538. //
  1539. // Tracing -> just do operation
  1540. //
  1541. #define TraceDo( _fn ) _fn
  1542. #define TraceMsgDo( _fn, _msg ) _fn
  1543. #define TraceAssertIfZero( _fn ) _fn
  1544. //
  1545. // RETURN testing -> do retail
  1546. //
  1547. #define THR
  1548. #define STHR
  1549. #define TW32
  1550. #define RETURN( _fn ) return _fn
  1551. #define FRETURN( _fn )
  1552. #define RRETURN( _fn ) return _fn
  1553. #define HRETURN( _hr ) return _hr
  1554. #define QIRETURN( _qi, _riid ) return _qi
  1555. //
  1556. // Memory Functions -> do retail
  1557. //
  1558. #define TraceAlloc( _flags, _size ) GlobalAlloc( _flags, _size )
  1559. #define TraceAllocString( _flags, _size ) (LPTSTR) GlobalAlloc( _flags, (_size) * sizeof( TCHAR ) )
  1560. #define TraceReAlloc( _hGlobal, _uBytes, _uFlags ) GlobalReAlloc( _hGlobal, _uBytes, _uFlags )
  1561. #define TraceFree( _pv ) GlobalFree( _pv )
  1562. #define TraceStrDup( _sz ) StrDup( _sz )
  1563. #define TraceSysAllocString( _sz ) SysAllocString( _sz )
  1564. #define TraceSysAllocStringByteLen( _sz, _len ) SysAllocStringByteLen( _sz, _len )
  1565. #define TraceSysAllocStringLen( _sz, _len ) SysAllocStringLen( _sz, _len )
  1566. #define TraceSysReAllocString( _bstrOrg, _bstrNew ) SysReAllocString( _bstrOrg, _bstrNew )
  1567. #define TraceSysReAllocStringLen( _bstrOrg, _bstrNew, _cch ) SysReAllocStringLen( _bstrOrg, _bstrNew, _cch )
  1568. #define TraceSysFreeString( _bstr ) SysFreeString( _bstr )
  1569. #define TraceCreateMemoryList( _pvIn )
  1570. #define TraceMoveToMemoryList( _addr, _pvIn )
  1571. #define TraceMemoryListDelete( _addr, _pvIn, _fClobber )
  1572. #define TraceTerminateMemoryList( _pvIn )
  1573. #endif // DEBUG
  1574. #if DBG==1 || defined( _DEBUG )
  1575. //////////////////////////////////////////////////////////////////////////////
  1576. //
  1577. // MACRO
  1578. // DEBUG_BREAK
  1579. //
  1580. // Description:
  1581. // Because the system expection handler can hick-up over INT 3s and
  1582. // DebugBreak()s, This x86 only macro causes the program to break in the
  1583. // right spot.
  1584. //
  1585. //////////////////////////////////////////////////////////////////////////////
  1586. #if defined( _X86_ )
  1587. #define DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while (0)
  1588. #else
  1589. #define DEBUG_BREAK DebugBreak( )
  1590. #endif
  1591. //////////////////////////////////////////////////////////////////////////////
  1592. //++
  1593. //
  1594. // MACRO
  1595. // Assert(
  1596. // _fn
  1597. // )
  1598. //
  1599. // Description:
  1600. // Checks to see if the Expression is TRUE. If not, a message will be
  1601. // displayed to the user on wether the program should break or continue.
  1602. //
  1603. // Arguments:
  1604. // _fn - Expression being asserted.
  1605. //
  1606. // Return Values:
  1607. // None.
  1608. //
  1609. //--
  1610. //////////////////////////////////////////////////////////////////////////////
  1611. #ifdef Assert
  1612. #undef Assert
  1613. #endif
  1614. // BUGBUG: DavidP 09-DEC-1999
  1615. // __fn is evaluated multiple times but the name of the
  1616. // macro is mixed case.
  1617. #define Assert( _fn ) \
  1618. do \
  1619. { \
  1620. if ( !(_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_fn), !!(_fn) ) ) \
  1621. DEBUG_BREAK; \
  1622. } while ( 0 )
  1623. //////////////////////////////////////////////////////////////////////////////
  1624. //++
  1625. //
  1626. // MACRO
  1627. // AssertMsg(
  1628. // _fn,
  1629. // _msg
  1630. // )
  1631. //
  1632. // Descrption:
  1633. // Just like an Assert but has an (hopefully) informative message
  1634. // associated with it.
  1635. //
  1636. // Arguments:
  1637. // _fn - Expression to be evaluated.
  1638. // _msg - Message to be display if assertion fails.
  1639. //
  1640. // Return Values:
  1641. // None.
  1642. //
  1643. //--
  1644. //////////////////////////////////////////////////////////////////////////////
  1645. #ifdef AssertMsg
  1646. #undef AssertMsg
  1647. #endif
  1648. // BUGBUG: DavidP 09-DEC-1999
  1649. // _fn is evaluated multiple times but the name of the
  1650. // macro is mixed case.
  1651. #define AssertMsg( _fn, _msg ) \
  1652. do \
  1653. { \
  1654. if ( !(_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), !!(_fn) ) ) \
  1655. DEBUG_BREAK; \
  1656. } while ( 0 )
  1657. #else // DBG!=1 && !_DEBUG
  1658. #define DEBUG_BREAK DebugBreak( );
  1659. #ifndef Assert
  1660. #define Assert( _e )
  1661. #endif
  1662. #ifndef AssertMsg
  1663. #define AssertMsg( _e, _m )
  1664. #endif
  1665. #endif // DBG==1 || _DEBUG
  1666. //****************************************************************************
  1667. //
  1668. // WMI Tracing stuctures and prototypes
  1669. //
  1670. //****************************************************************************
  1671. typedef struct
  1672. {
  1673. DWORD dwFlags; // Flags to be set
  1674. LPCTSTR pszName; // Usefull description of the level
  1675. } DEBUG_MAP_LEVEL_TO_FLAGS;
  1676. typedef struct
  1677. {
  1678. LPCTSTR pszName; // Usefull description of the flag
  1679. } DEBUG_MAP_FLAGS_TO_COMMENTS;
  1680. typedef struct
  1681. {
  1682. LPCGUID guidControl; // Control guid to register
  1683. LPCTSTR pszName; // Internal associative name
  1684. DWORD dwSizeOfTraceList; // Count of the guids in pTraceList
  1685. const TRACE_GUID_REGISTRATION * pTraceList; // List of the of Tracing guids to register
  1686. BYTE bSizeOfLevelList; // Count of the level<->flags
  1687. const DEBUG_MAP_LEVEL_TO_FLAGS * pMapLevelToFlags; // List of level->flags mapping. NULL if no mapping.
  1688. const DEBUG_MAP_FLAGS_TO_COMMENTS * pMapFlagsToComments; // List of descriptions describing the flag bits. NULL if no mapping.
  1689. // Controlled by WMI tracing - these should be NULL/ZERO to start.
  1690. DWORD dwFlags; // Log flags
  1691. BYTE bLevel; // Log level
  1692. TRACEHANDLE hTrace; // Active logger handle
  1693. // From here down is initialized by InitializeWMITracing
  1694. TRACEHANDLE hRegistration; // Return control handle
  1695. } DEBUG_WMI_CONTROL_GUIDS;
  1696. void
  1697. WMIInitializeTracing(
  1698. DEBUG_WMI_CONTROL_GUIDS dwcgControlListIn[],
  1699. int nCountOfControlGuidsIn
  1700. );
  1701. void
  1702. WMITerminateTracing(
  1703. DEBUG_WMI_CONTROL_GUIDS dwcgControlListIn[],
  1704. int nCountOfControlGuidsIn
  1705. );
  1706. void
  1707. WMIMessageByFlags(
  1708. DEBUG_WMI_CONTROL_GUIDS * pEntryIn,
  1709. const DWORD dwFlagsIn,
  1710. LPCWSTR pszFormatIn,
  1711. ...
  1712. );
  1713. void
  1714. WMIMessageByLevel(
  1715. DEBUG_WMI_CONTROL_GUIDS * pEntryIn,
  1716. const BYTE bLogLevelIn,
  1717. LPCWSTR pszFormatIn,
  1718. ...
  1719. );
  1720. void
  1721. WMIMessageByFlagsAndLevel(
  1722. DEBUG_WMI_CONTROL_GUIDS * pEntryIn,
  1723. const DWORD dwFlagsIn,
  1724. const BYTE bLogLevelIn,
  1725. LPCWSTR pszFormatIn,
  1726. ...
  1727. );
  1728. //
  1729. // Sample WMI message macros
  1730. //
  1731. // Typically you will want a particular level to map to a set of flags. This
  1732. // way as you increase the level, you activate more and more messages.
  1733. //
  1734. // To be versatile, there there types of filtering. Choose the one that suits
  1735. // the situation that you supports your logging needs. Remember that depending
  1736. // on the use, you might need to specify additional parameters.
  1737. //
  1738. // These macros on x86 turn into 2 ops ( cmp and jnz ) in the regular code path
  1739. // thereby lessening the impact of keeping the macros enabled in RETAIL. Since
  1740. // other platforms were not available while developing these macros, you should
  1741. // wrap the definitions in protecting against other architectures.
  1742. //
  1743. // #if defined( _X86_ )
  1744. // #define WMIMsg ( g_pTraceGuidControl[0].dwFlags == 0 ) ? (void)0 : WMIMessageByFlags
  1745. // #define WMIMsg ( g_pTraceGuidControl[0].dwFlags == 0 ) ? (void)0 : WMIMessageByLevel
  1746. // #define WMIMsg ( g_pTraceGuidControl[0].dwFlags == 0 ) ? (void)0 : WMIMessageByFlagsAndLevel
  1747. // #else // not X86
  1748. // #define WMIMsg 1 ? (void)0 : (void)
  1749. // #endif // defined( _X86_ )
  1750. //
  1751. //
  1752. //****************************************************************************
  1753. //
  1754. // Logging Functions
  1755. //
  1756. //****************************************************************************
  1757. void
  1758. LogMsg(
  1759. LPCSTR pszFormatIn,
  1760. ...
  1761. );
  1762. void
  1763. LogMsg(
  1764. LPCWSTR pszFormatIn,
  1765. ...
  1766. );
  1767. void
  1768. LogTerminateProcess( void );