Windows NT 4.0 source code leak
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.

361 lines
7.1 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1995-6 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. debug.hxx
  6. Abstract:
  7. Debug definitions.
  8. Author:
  9. Albert Ting (AlbertT) 27-Jan-1995
  10. Revision History:
  11. --*/
  12. #ifndef _DEBUG_HXX
  13. #define _DEBUG_HXX
  14. /********************************************************************
  15. Wrapper for C functions that want debug routines.
  16. ********************************************************************/
  17. typedef struct DBG_POINTERS {
  18. HANDLE (*pfnAllocBackTrace)( VOID );
  19. HANDLE (*pfnAllocBackTraceMem)( VOID );
  20. VOID (*pfnFreeBackTrace)( HANDLE hBackTrace );
  21. VOID (*pfnCaptureBackTrace)( HANDLE hBackTrace, DWORD, DWORD, DWORD );
  22. HANDLE (*pfnAllocCritSec)( VOID );
  23. VOID (*pfnFreeCritSec)( HANDLE hCritSec );
  24. BOOL (*pfnInsideCritSec )( HANDLE hCritSec );
  25. BOOL (*pfnOutsideCritSec )( HANDLE hCritSec );
  26. VOID (*pfnEnterCritSec )( HANDLE hCritSec );
  27. VOID (*pfnLeaveCritSec )( HANDLE hCritSec );
  28. HANDLE hMemHeap;
  29. HANDLE hDbgMemHeap;
  30. PVOID pbtAlloc;
  31. PVOID pbtFree;
  32. PVOID pbtErrLog;
  33. PVOID pbtTraceLog;
  34. } *PDBG_POINTERS;
  35. /********************************************************************
  36. C++ specific debug functionality.
  37. ********************************************************************/
  38. #ifdef __cplusplus
  39. #if DBG
  40. //
  41. // Capture significant errors in separate error log
  42. // (done in spllib\debug.cxx).
  43. //
  44. const UINT DBG_ERRLOG_CAPTURE = DBG_WARN | DBG_ERROR;
  45. /********************************************************************
  46. Automatic status logging.
  47. Use TStatus instead of DWORD:
  48. DWORD dwStatus; -> TStatus Status;
  49. dwStatus = ERROR_SUCCESS -> Status DBGNOCHK = ERROR_SUCCESS;
  50. dwStatus = xxx; -> Status DBGCHK = xxx;
  51. if( dwStatus ){ -> if( Status != 0 ){
  52. Anytime Status is set, the DBGCHK macro must be added before
  53. the '=.'
  54. If the variable must be set to a failure value at compilte time
  55. and logging is therefore not needed, then the DBGNOCHK macro
  56. should be used.
  57. There are different parameters to instantiation. Alternate
  58. debug level can be specified, and also 3 "benign" errors that
  59. can be ignored.
  60. TStatus Status( DBG_ERROR, ERROR_ACCESS_DENIED, ERROR_FOO );
  61. ********************************************************************/
  62. #define DBGCHK .pSetInfo( MODULE_DEBUG, __LINE__, __FILE__, MODULE )
  63. #define DBGNOCHK .pNoChk()
  64. class TStatusBase {
  65. protected:
  66. DWORD _dwStatus;
  67. DWORD _dwStatusSafe1;
  68. DWORD _dwStatusSafe2;
  69. DWORD _dwStatusSafe3;
  70. UINT _uDbgLevel;
  71. UINT _uDbg;
  72. UINT _uLine;
  73. LPCSTR _pszFileA;
  74. LPCSTR _pszModuleA;
  75. public:
  76. TStatusBase(
  77. UINT uDbgLevel,
  78. DWORD dwStatusSafe1,
  79. DWORD dwStatusSafe2,
  80. DWORD dwStatusSafe3
  81. ) : _dwStatus( 0xdeacface ), _uDbgLevel( uDbgLevel ),
  82. _dwStatusSafe1( dwStatusSafe1 ), _dwStatusSafe2( dwStatusSafe2 ),
  83. _dwStatusSafe3( dwStatusSafe3 )
  84. { }
  85. TStatusBase&
  86. pSetInfo(
  87. UINT uDbg,
  88. UINT uLine,
  89. LPCSTR pszFileA,
  90. LPCSTR pszModuleA
  91. );
  92. TStatusBase&
  93. pNoChk(
  94. VOID
  95. );
  96. DWORD
  97. operator=(
  98. DWORD dwStatus
  99. );
  100. };
  101. class TStatus : public TStatusBase {
  102. private:
  103. //
  104. // Don't let clients use operator= without going through the
  105. // base class (i.e., using DBGCHK ).
  106. //
  107. // If you get an error trying to access private member function '=,'
  108. // you are trying to set the status without using the DBGCHK macro.
  109. //
  110. // This is needed to update the line and file, which must be done
  111. // at the macro level (not inline C++ function) since __LINE__ and
  112. // __FILE__ are handled by the preprocessor.
  113. //
  114. DWORD
  115. operator=(
  116. DWORD dwStatus
  117. );
  118. public:
  119. TStatus(
  120. UINT uDbgLevel = DBG_WARN,
  121. DWORD dwStatusSafe1 = (DWORD)-1,
  122. DWORD dwStatusSafe2 = (DWORD)-1,
  123. DWORD dwStatusSafe3 = (DWORD)-1
  124. ) : TStatusBase( uDbgLevel,
  125. dwStatusSafe1,
  126. dwStatusSafe2,
  127. dwStatusSafe3 )
  128. { }
  129. DWORD
  130. dwGetStatus(
  131. VOID
  132. );
  133. operator DWORD()
  134. {
  135. return dwGetStatus();
  136. }
  137. };
  138. /********************************************************************
  139. Same thing, but for BOOL status.
  140. ********************************************************************/
  141. class TStatusBBase {
  142. protected:
  143. BOOL _bStatus;
  144. DWORD _dwStatusSafe1;
  145. DWORD _dwStatusSafe2;
  146. DWORD _dwStatusSafe3;
  147. UINT _uDbgLevel;
  148. UINT _uDbg;
  149. UINT _uLine;
  150. LPCSTR _pszFileA;
  151. LPCSTR _pszModuleA;
  152. public:
  153. TStatusBBase(
  154. UINT uDbgLevel,
  155. DWORD dwStatusSafe1,
  156. DWORD dwStatusSafe2,
  157. DWORD dwStatusSafe3
  158. ) : _bStatus( 0xabababab ), _uDbgLevel( uDbgLevel ),
  159. _dwStatusSafe1( dwStatusSafe1 ), _dwStatusSafe2( dwStatusSafe2 ),
  160. _dwStatusSafe3( dwStatusSafe3 )
  161. { }
  162. TStatusBBase&
  163. pSetInfo(
  164. UINT uDbg,
  165. UINT uLine,
  166. LPCSTR pszFileA,
  167. LPCSTR pszModuleA
  168. );
  169. TStatusBBase&
  170. pNoChk(
  171. VOID
  172. );
  173. BOOL
  174. operator=(
  175. BOOL bStatus
  176. );
  177. };
  178. class TStatusB : public TStatusBBase {
  179. private:
  180. //
  181. // Don't let clients use operator= without going through the
  182. // base class (i.e., using DBGCHK ).
  183. //
  184. // If you get an error trying to access private member function '=,'
  185. // you are trying to set the status without using the DBGCHK macro.
  186. //
  187. // This is needed to update the line and file, which must be done
  188. // at the macro level (not inline C++ function) since __LINE__ and
  189. // __FILE__ are handled by the preprocessor.
  190. //
  191. BOOL
  192. operator=(
  193. BOOL bStatus
  194. );
  195. public:
  196. TStatusB(
  197. UINT uDbgLevel = DBG_WARN,
  198. DWORD dwStatusSafe1 = 0,
  199. DWORD dwStatusSafe2 = 0,
  200. DWORD dwStatusSafe3 = 0
  201. ) : TStatusBBase( uDbgLevel,
  202. dwStatusSafe1,
  203. dwStatusSafe2,
  204. dwStatusSafe3 )
  205. { }
  206. BOOL
  207. bGetStatus(
  208. VOID
  209. );
  210. operator BOOL()
  211. {
  212. return bGetStatus();
  213. }
  214. };
  215. #else
  216. #define DBGCHK
  217. #define DBGNOCHK
  218. class TStatus {
  219. private:
  220. DWORD _dwStatus;
  221. public:
  222. TStatus(
  223. UINT uDbgLevel = 0,
  224. DWORD dwStatusSafe1 = 0,
  225. DWORD dwStatusSafe2 = 0,
  226. DWORD dwStatusSafe3 = 0
  227. )
  228. { }
  229. DWORD
  230. operator=(
  231. DWORD dwStatus
  232. )
  233. {
  234. return _dwStatus = dwStatus;
  235. }
  236. operator DWORD()
  237. {
  238. return _dwStatus;
  239. }
  240. };
  241. class TStatusB {
  242. private:
  243. BOOL _bStatus;
  244. public:
  245. TStatusB(
  246. UINT uDbgLevel = 0,
  247. DWORD dwStatusSafe1 = 0,
  248. DWORD dwStatusSafe2 = 0,
  249. DWORD dwStatusSafe3 = 0
  250. )
  251. { }
  252. BOOL
  253. operator=(
  254. BOOL bStatus
  255. )
  256. {
  257. return _bStatus = bStatus;
  258. }
  259. operator BOOL()
  260. {
  261. return _bStatus;
  262. }
  263. };
  264. #endif // #if DBG
  265. #endif // #ifdef __cplusplus
  266. #endif // #ifndef _DEBUG_HXX