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.

493 lines
9.7 KiB

  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. HANDLE (*pfnAllocBackTraceFile)( VOID );
  21. VOID (*pfnFreeBackTrace)( HANDLE hBackTrace );
  22. VOID (*pfnCaptureBackTrace)( HANDLE hBackTrace, ULONG_PTR, ULONG_PTR, ULONG_PTR );
  23. HANDLE (*pfnAllocCritSec)( VOID );
  24. VOID (*pfnFreeCritSec)( HANDLE hCritSec );
  25. BOOL (*pfnInsideCritSec )( HANDLE hCritSec );
  26. BOOL (*pfnOutsideCritSec )( HANDLE hCritSec );
  27. VOID (*pfnEnterCritSec )( HANDLE hCritSec );
  28. VOID (*pfnLeaveCritSec )( HANDLE hCritSec );
  29. VOID (*pfnSetAllocFail )( BOOL bEnable, LONG cAllocFail );
  30. HANDLE hMemHeap;
  31. HANDLE hDbgMemHeap;
  32. PVOID pbtAlloc;
  33. PVOID pbtFree;
  34. PVOID pbtErrLog;
  35. PVOID pbtTraceLog;
  36. } *PDBG_POINTERS;
  37. /********************************************************************
  38. C++ specific debug functionality.
  39. ********************************************************************/
  40. #ifdef __cplusplus
  41. #if DBG
  42. //
  43. // Capture significant errors in separate error log
  44. // (done in spllib\debug.cxx).
  45. //
  46. const UINT DBG_ERRLOG_CAPTURE = DBG_WARN | DBG_ERROR;
  47. /********************************************************************
  48. Automatic status logging.
  49. Use TStatus instead of DWORD:
  50. DWORD dwStatus; -> TStatus Status;
  51. dwStatus = ERROR_SUCCESS -> Status DBGNOCHK = ERROR_SUCCESS;
  52. dwStatus = xxx; -> Status DBGCHK = xxx;
  53. if( dwStatus ){ -> if( Status != 0 ){
  54. Anytime Status is set, the DBGCHK macro must be added before
  55. the '=.'
  56. If the variable must be set to a failure value at compilte time
  57. and logging is therefore not needed, then the DBGNOCHK macro
  58. should be used.
  59. There are different parameters to instantiation. Alternate
  60. debug level can be specified, and also 3 "benign" errors that
  61. can be ignored.
  62. TStatus Status( DBG_ERROR, ERROR_ACCESS_DENIED, ERROR_FOO );
  63. ********************************************************************/
  64. #define DBGCHK .pSetInfo( MODULE_DEBUG, __LINE__, __FILE__, MODULE )
  65. #define DBGNOCHK .pNoChk()
  66. class TStatusBase {
  67. protected:
  68. DWORD _dwStatus;
  69. DWORD _dwStatusSafe1;
  70. DWORD _dwStatusSafe2;
  71. DWORD _dwStatusSafe3;
  72. UINT _uDbgLevel;
  73. UINT _uDbg;
  74. UINT _uLine;
  75. LPCSTR _pszFileA;
  76. LPCSTR _pszModuleA;
  77. public:
  78. TStatusBase(
  79. UINT uDbgLevel,
  80. DWORD dwStatusSafe1,
  81. DWORD dwStatusSafe2,
  82. DWORD dwStatusSafe3
  83. ) : _dwStatus( 0xdeacface ), _uDbgLevel( uDbgLevel ),
  84. _dwStatusSafe1( dwStatusSafe1 ), _dwStatusSafe2( dwStatusSafe2 ),
  85. _dwStatusSafe3( dwStatusSafe3 )
  86. { }
  87. TStatusBase&
  88. pSetInfo(
  89. UINT uDbg,
  90. UINT uLine,
  91. LPCSTR pszFileA,
  92. LPCSTR pszModuleA
  93. );
  94. TStatusBase&
  95. pNoChk(
  96. VOID
  97. );
  98. DWORD
  99. operator=(
  100. DWORD dwStatus
  101. );
  102. };
  103. class TStatus : public TStatusBase {
  104. private:
  105. //
  106. // Don't let clients use operator= without going through the
  107. // base class (i.e., using DBGCHK ).
  108. //
  109. // If you get an error trying to access private member function '=,'
  110. // you are trying to set the status without using the DBGCHK macro.
  111. //
  112. // This is needed to update the line and file, which must be done
  113. // at the macro level (not inline C++ function) since __LINE__ and
  114. // __FILE__ are handled by the preprocessor.
  115. //
  116. DWORD
  117. operator=(
  118. DWORD dwStatus
  119. );
  120. public:
  121. TStatus(
  122. UINT uDbgLevel = DBG_WARN,
  123. DWORD dwStatusSafe1 = (DWORD)-1,
  124. DWORD dwStatusSafe2 = (DWORD)-1,
  125. DWORD dwStatusSafe3 = (DWORD)-1
  126. ) : TStatusBase( uDbgLevel,
  127. dwStatusSafe1,
  128. dwStatusSafe2,
  129. dwStatusSafe3 )
  130. { }
  131. DWORD
  132. dwGetStatus(
  133. VOID
  134. );
  135. operator DWORD()
  136. {
  137. return dwGetStatus();
  138. }
  139. };
  140. /********************************************************************
  141. Same thing, but for HRESULT status.
  142. ********************************************************************/
  143. class TStatusHBase {
  144. protected:
  145. HRESULT _hrStatus;
  146. HRESULT _hrStatusSafe1;
  147. HRESULT _hrStatusSafe2;
  148. HRESULT _hrStatusSafe3;
  149. UINT _uDbgLevel;
  150. UINT _uDbg;
  151. UINT _uLine;
  152. LPCSTR _pszFileA;
  153. LPCSTR _pszModuleA;
  154. public:
  155. TStatusHBase(
  156. UINT uDbgLevel = DBG_WARN,
  157. HRESULT hrStatusSafe1 = S_FALSE,
  158. HRESULT hrStatusSafe2 = S_FALSE,
  159. HRESULT hrStatusSafe3 = S_FALSE
  160. ) : _hrStatus( 0xdeacface ), _uDbgLevel( uDbgLevel ),
  161. _hrStatusSafe1( hrStatusSafe1 ), _hrStatusSafe2( hrStatusSafe2 ),
  162. _hrStatusSafe3( hrStatusSafe3 )
  163. { }
  164. TStatusHBase&
  165. pSetInfo(
  166. UINT uDbg,
  167. UINT uLine,
  168. LPCSTR pszFileA,
  169. LPCSTR pszModuleA
  170. );
  171. TStatusHBase&
  172. pNoChk(
  173. VOID
  174. );
  175. HRESULT
  176. operator=(
  177. HRESULT hrStatus
  178. );
  179. };
  180. class TStatusH : public TStatusHBase {
  181. private:
  182. //
  183. // Don't let clients use operator= without going through the
  184. // base class (i.e., using DBGCHK ).
  185. //
  186. // If you get an error trying to access private member function '=,'
  187. // you are trying to set the status without using the DBGCHK macro.
  188. //
  189. // This is needed to update the line and file, which must be done
  190. // at the macro level (not inline C++ function) since __LINE__ and
  191. // __FILE__ are handled by the preprocessor.
  192. //
  193. HRESULT
  194. operator=(
  195. HRESULT hrStatus
  196. );
  197. public:
  198. TStatusH(
  199. UINT uDbgLevel = DBG_WARN,
  200. HRESULT hrStatusSafe1 = S_FALSE,
  201. HRESULT hrStatusSafe2 = S_FALSE,
  202. HRESULT hrStatusSafe3 = S_FALSE
  203. ) : TStatusHBase( uDbgLevel,
  204. hrStatusSafe1,
  205. hrStatusSafe2,
  206. hrStatusSafe3 )
  207. { }
  208. HRESULT
  209. hrGetStatus(
  210. VOID
  211. );
  212. operator HRESULT()
  213. {
  214. return hrGetStatus();
  215. }
  216. };
  217. /********************************************************************
  218. Same thing, but for BOOL status.
  219. ********************************************************************/
  220. class TStatusBBase {
  221. protected:
  222. BOOL _bStatus;
  223. DWORD _dwStatusSafe1;
  224. DWORD _dwStatusSafe2;
  225. DWORD _dwStatusSafe3;
  226. UINT _uDbgLevel;
  227. UINT _uDbg;
  228. UINT _uLine;
  229. LPCSTR _pszFileA;
  230. LPCSTR _pszModuleA;
  231. public:
  232. TStatusBBase(
  233. UINT uDbgLevel,
  234. DWORD dwStatusSafe1,
  235. DWORD dwStatusSafe2,
  236. DWORD dwStatusSafe3
  237. ) : _bStatus( 0xabababab ), _uDbgLevel( uDbgLevel ),
  238. _dwStatusSafe1( dwStatusSafe1 ), _dwStatusSafe2( dwStatusSafe2 ),
  239. _dwStatusSafe3( dwStatusSafe3 )
  240. { }
  241. TStatusBBase&
  242. pSetInfo(
  243. UINT uDbg,
  244. UINT uLine,
  245. LPCSTR pszFileA,
  246. LPCSTR pszModuleA
  247. );
  248. TStatusBBase&
  249. pNoChk(
  250. VOID
  251. );
  252. BOOL
  253. operator=(
  254. BOOL bStatus
  255. );
  256. };
  257. class TStatusB : public TStatusBBase {
  258. private:
  259. //
  260. // Don't let clients use operator= without going through the
  261. // base class (i.e., using DBGCHK ).
  262. //
  263. // If you get an error trying to access private member function '=,'
  264. // you are trying to set the status without using the DBGCHK macro.
  265. //
  266. // This is needed to update the line and file, which must be done
  267. // at the macro level (not inline C++ function) since __LINE__ and
  268. // __FILE__ are handled by the preprocessor.
  269. //
  270. BOOL
  271. operator=(
  272. BOOL bStatus
  273. );
  274. public:
  275. TStatusB(
  276. UINT uDbgLevel = DBG_WARN,
  277. DWORD dwStatusSafe1 = (DWORD)-1,
  278. DWORD dwStatusSafe2 = (DWORD)-1,
  279. DWORD dwStatusSafe3 = (DWORD)-1
  280. ) : TStatusBBase( uDbgLevel,
  281. dwStatusSafe1,
  282. dwStatusSafe2,
  283. dwStatusSafe3 )
  284. { }
  285. BOOL
  286. bGetStatus(
  287. VOID
  288. );
  289. operator BOOL()
  290. {
  291. return bGetStatus();
  292. }
  293. };
  294. #else
  295. #define DBGCHK
  296. #define DBGNOCHK
  297. class TStatus {
  298. private:
  299. DWORD _dwStatus;
  300. public:
  301. TStatus(
  302. UINT uDbgLevel = 0,
  303. DWORD dwStatusSafe1 = 0,
  304. DWORD dwStatusSafe2 = 0,
  305. DWORD dwStatusSafe3 = 0
  306. )
  307. { }
  308. DWORD
  309. operator=(
  310. DWORD dwStatus
  311. )
  312. {
  313. return _dwStatus = dwStatus;
  314. }
  315. operator DWORD()
  316. {
  317. return _dwStatus;
  318. }
  319. };
  320. class TStatusB {
  321. private:
  322. BOOL _bStatus;
  323. public:
  324. TStatusB(
  325. UINT uDbgLevel = 0,
  326. DWORD dwStatusSafe1 = 0,
  327. DWORD dwStatusSafe2 = 0,
  328. DWORD dwStatusSafe3 = 0
  329. )
  330. { }
  331. BOOL
  332. operator=(
  333. BOOL bStatus
  334. )
  335. {
  336. return _bStatus = bStatus;
  337. }
  338. operator BOOL()
  339. {
  340. return _bStatus;
  341. }
  342. };
  343. class TStatusH {
  344. private:
  345. HRESULT _hrStatus;
  346. public:
  347. TStatusH(
  348. UINT uDbgLevel = 0,
  349. HRESULT hrStatusSafe1 = 0,
  350. HRESULT hrStatusSafe2 = 0,
  351. HRESULT hrStatusSafe3 = 0
  352. )
  353. { }
  354. HRESULT
  355. operator=(
  356. HRESULT hrStatus
  357. )
  358. {
  359. return _hrStatus = hrStatus;
  360. }
  361. operator HRESULT()
  362. {
  363. return _hrStatus;
  364. }
  365. };
  366. #endif // #if DBG
  367. #endif // #ifdef __cplusplus
  368. #endif // #ifndef _DEBUG_HXX