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.

513 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgstate.cxx
  6. Abstract:
  7. status support
  8. Author:
  9. Steve Kiraly (SteveKi) 2-Mar-1997
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgreslt.hxx"
  15. #include "dbgstate.hxx"
  16. #if DBG
  17. /********************************************************************
  18. Debugging TStatus base members
  19. ********************************************************************/
  20. TStatusBase::
  21. TStatusBase(
  22. IN BOOL dwStatus,
  23. IN UINT uDbgLevel
  24. ) : m_dwStatus(dwStatus),
  25. m_uDbgLevel(uDbgLevel),
  26. m_dwStatusSafe1(-1),
  27. m_dwStatusSafe2(-1),
  28. m_dwStatusSafe3(-1),
  29. m_uLine(0),
  30. m_pszFile(NULL)
  31. {
  32. }
  33. TStatusBase::
  34. ~TStatusBase(
  35. VOID
  36. )
  37. {
  38. }
  39. TStatusBase&
  40. TStatusBase::
  41. pNoChk(
  42. VOID
  43. )
  44. {
  45. m_pszFile = NULL;
  46. m_uLine = 0;
  47. return (TStatusBase&)*this;
  48. }
  49. TStatusBase&
  50. TStatusBase::
  51. pSetInfo(
  52. UINT uLine,
  53. LPCTSTR pszFile
  54. )
  55. {
  56. m_uLine = uLine;
  57. m_pszFile = pszFile;
  58. return (TStatusBase&)*this;
  59. }
  60. VOID
  61. TStatusBase::
  62. pConfig(
  63. IN UINT uDbgLevel,
  64. IN DWORD dwStatusSafe1,
  65. IN DWORD dwStatusSafe2,
  66. IN DWORD dwStatusSafe3
  67. )
  68. {
  69. m_uDbgLevel = uDbgLevel;
  70. m_dwStatusSafe1 = dwStatusSafe1;
  71. m_dwStatusSafe2 = dwStatusSafe2;
  72. m_dwStatusSafe3 = dwStatusSafe3;
  73. }
  74. DWORD
  75. TStatusBase::
  76. dwGeTStatusBase(
  77. VOID
  78. ) const
  79. {
  80. //
  81. // Assert if we are reading an UnInitalized variable.
  82. //
  83. if (m_dwStatus == kUnInitializedValue)
  84. {
  85. DBG_MSG(kDbgAlways|kDbgNoFileInfo, (_T("***Read of UnInitialized TStatus variable!***\n")));
  86. DBG_BREAK();
  87. }
  88. //
  89. // Return the error value.
  90. //
  91. return m_dwStatus;
  92. }
  93. DWORD
  94. TStatusBase::
  95. operator=(
  96. IN DWORD dwStatus
  97. )
  98. {
  99. //
  100. // Do nothing if the file and line number are cleared.
  101. // This is the case when the NoChk method is used.
  102. //
  103. if (m_uLine && m_pszFile)
  104. {
  105. //
  106. // Get the last error value.
  107. //
  108. DWORD LastError = GetLastError();
  109. //
  110. // Check if we have an error, and it's not one of the accepted "safe" errors.
  111. //
  112. if (dwStatus != ERROR_SUCCESS &&
  113. dwStatus != m_dwStatusSafe1 &&
  114. dwStatus != m_dwStatusSafe2 &&
  115. dwStatus != m_dwStatusSafe3)
  116. {
  117. //
  118. // Convert the last error value to a string.
  119. //
  120. TDebugResult Result(dwStatus);
  121. DBG_MSG(m_uDbgLevel, (_T("TStatus failure, %d, %s\n%s %d\n"), dwStatus, Result.GetErrorString(), m_pszFile, m_uLine));
  122. }
  123. //
  124. // Restore the last error, the message call may have destoyed the last
  125. // error value, we don't want the caller to loose this value.
  126. //
  127. SetLastError(LastError);
  128. }
  129. return m_dwStatus = dwStatus;
  130. }
  131. TStatusBase::
  132. operator DWORD(
  133. VOID
  134. ) const
  135. {
  136. return dwGeTStatusBase();
  137. }
  138. /********************************************************************
  139. Debugging TStatus members
  140. ********************************************************************/
  141. TStatus::
  142. TStatus(
  143. IN DWORD dwStatus
  144. ) : TStatusBase(dwStatus, kDbgWarning)
  145. {
  146. }
  147. TStatus::
  148. ~TStatus(
  149. VOID
  150. )
  151. {
  152. }
  153. /********************************************************************
  154. Debugging TStatusB base members
  155. ********************************************************************/
  156. TStatusBBase::
  157. TStatusBBase(
  158. IN BOOL bStatus,
  159. IN UINT uDbgLevel
  160. ) : m_bStatus(bStatus),
  161. m_uDbgLevel(uDbgLevel),
  162. m_dwStatusSafe1(-1),
  163. m_dwStatusSafe2(-1),
  164. m_dwStatusSafe3(-1),
  165. m_uLine(0),
  166. m_pszFile(NULL)
  167. {
  168. }
  169. TStatusBBase::
  170. ~TStatusBBase(
  171. VOID
  172. )
  173. {
  174. }
  175. TStatusBBase&
  176. TStatusBBase::
  177. pNoChk(
  178. VOID
  179. )
  180. {
  181. m_pszFile = NULL;
  182. m_uLine = 0;
  183. return (TStatusBBase&)*this;
  184. }
  185. TStatusBBase&
  186. TStatusBBase::
  187. pSetInfo(
  188. IN UINT uLine,
  189. IN LPCTSTR pszFile
  190. )
  191. {
  192. m_uLine = uLine;
  193. m_pszFile = pszFile;
  194. return (TStatusBBase&)*this;
  195. }
  196. VOID
  197. TStatusBBase::
  198. pConfig(
  199. IN UINT uDbgLevel,
  200. IN DWORD dwStatusSafe1,
  201. IN DWORD dwStatusSafe2,
  202. IN DWORD dwStatusSafe3
  203. )
  204. {
  205. m_uDbgLevel = uDbgLevel;
  206. m_dwStatusSafe1 = dwStatusSafe1;
  207. m_dwStatusSafe2 = dwStatusSafe2;
  208. m_dwStatusSafe3 = dwStatusSafe3;
  209. }
  210. BOOL
  211. TStatusBBase::
  212. bGetStatus(
  213. VOID
  214. ) const
  215. {
  216. //
  217. // Assert if we are reading an UnInitalized variable.
  218. //
  219. if (m_bStatus == kUnInitializedValue)
  220. {
  221. DBG_MSG(kDbgAlways|kDbgNoFileInfo, (_T("***Read of UnInitialized TStatusB variable!***\n")));
  222. DBG_BREAK();
  223. }
  224. //
  225. // Return the error value.
  226. //
  227. return m_bStatus;
  228. }
  229. BOOL
  230. TStatusBBase::
  231. operator=(
  232. IN BOOL bStatus
  233. )
  234. {
  235. //
  236. // Do nothing if the file and line number are cleared.
  237. // This is the case when the NoChk method is used.
  238. //
  239. if (m_uLine && m_pszFile)
  240. {
  241. //
  242. // Check if we have an error, and it's not one of the two
  243. // accepted "safe" errors.
  244. //
  245. if (!bStatus)
  246. {
  247. //
  248. // Get the last error value.
  249. //
  250. DWORD LastError = GetLastError();
  251. //
  252. // If the last error is not one of the safe values then display an error message
  253. //
  254. if (LastError != m_dwStatusSafe1 &&
  255. LastError != m_dwStatusSafe2 &&
  256. LastError != m_dwStatusSafe3)
  257. {
  258. //
  259. // Convert the last error value to a string.
  260. //
  261. TDebugResult Result(LastError);
  262. DBG_MSG(m_uDbgLevel, (_T("TStatusB failure, %d, %s\n%s %d\n"), LastError, Result.GetErrorString(), m_pszFile, m_uLine));
  263. }
  264. //
  265. // Restore the last error, the message call may have destoyed the last
  266. // error value, we don't want the caller to loose this value.
  267. //
  268. SetLastError(LastError);
  269. }
  270. }
  271. return m_bStatus = bStatus;
  272. }
  273. TStatusBBase::
  274. operator BOOL(
  275. VOID
  276. ) const
  277. {
  278. return bGetStatus();
  279. }
  280. /********************************************************************
  281. Debugging TStatusB members
  282. ********************************************************************/
  283. TStatusB::
  284. TStatusB(
  285. IN BOOL bStatus
  286. ) : TStatusBBase(bStatus, kDbgWarning)
  287. {
  288. }
  289. TStatusB::
  290. ~TStatusB(
  291. VOID
  292. )
  293. {
  294. }
  295. /********************************************************************
  296. Debugging TStatusH base members
  297. ********************************************************************/
  298. TStatusHBase::
  299. TStatusHBase(
  300. IN HRESULT hrStatus,
  301. IN UINT uDbgLevel
  302. ) : m_hrStatus(hrStatus),
  303. m_uDbgLevel(uDbgLevel),
  304. m_hrStatusSafe1(-1),
  305. m_hrStatusSafe2(-1),
  306. m_hrStatusSafe3(-1),
  307. m_uLine(0),
  308. m_pszFile(NULL)
  309. {
  310. }
  311. TStatusHBase::
  312. ~TStatusHBase(
  313. VOID
  314. )
  315. {
  316. }
  317. TStatusHBase&
  318. TStatusHBase::
  319. pNoChk(
  320. VOID
  321. )
  322. {
  323. m_pszFile = NULL;
  324. m_uLine = 0;
  325. return (TStatusHBase&)*this;
  326. }
  327. TStatusHBase&
  328. TStatusHBase::
  329. pSetInfo(
  330. IN UINT uLine,
  331. IN LPCTSTR pszFile
  332. )
  333. {
  334. m_uLine = uLine;
  335. m_pszFile = pszFile;
  336. return (TStatusHBase&)*this;
  337. }
  338. VOID
  339. TStatusHBase::
  340. pConfig(
  341. IN UINT uDbgLevel,
  342. IN DWORD hrStatusSafe1,
  343. IN DWORD hrStatusSafe2,
  344. IN DWORD hrStatusSafe3
  345. )
  346. {
  347. m_uDbgLevel = uDbgLevel;
  348. m_hrStatusSafe1 = hrStatusSafe1;
  349. m_hrStatusSafe2 = hrStatusSafe2;
  350. m_hrStatusSafe3 = hrStatusSafe3;
  351. }
  352. HRESULT
  353. TStatusHBase::
  354. hrGetStatus(
  355. VOID
  356. ) const
  357. {
  358. //
  359. // Assert if we are reading an UnInitalized variable.
  360. //
  361. if (m_hrStatus == kUnInitializedValue)
  362. {
  363. DBG_MSG(kDbgAlways|kDbgNoFileInfo, (_T("***Read of UnInitialized TStatusH variable!***\n")));
  364. DBG_BREAK();
  365. }
  366. //
  367. // Return the error code.
  368. //
  369. return m_hrStatus;
  370. }
  371. HRESULT
  372. TStatusHBase::
  373. operator=(
  374. IN HRESULT hrStatus
  375. )
  376. {
  377. //
  378. // Do nothing if the file and line number are cleared.
  379. // This is the case when the NoChk method is used.
  380. //
  381. if (m_uLine && m_pszFile)
  382. {
  383. //
  384. // Check if we have an error, and it's not one of the two
  385. // accepted "safe" errors.
  386. //
  387. if (FAILED(hrStatus))
  388. {
  389. //
  390. // Get the last error value.
  391. //
  392. DWORD LastError = GetLastError();
  393. //
  394. // If the last error is not one of the safe values then display an error message
  395. //
  396. if (hrStatus != m_hrStatusSafe1 &&
  397. hrStatus != m_hrStatusSafe2 &&
  398. hrStatus != m_hrStatusSafe3)
  399. {
  400. TDebugResult Result( HRESULT_FACILITY(hrStatus) == FACILITY_WIN32 ? HRESULT_CODE(hrStatus) : hrStatus);
  401. DBG_MSG(m_uDbgLevel, (_T("TStatusH failure, %x, %s\n%s %d\n"), hrStatus, Result.GetErrorString(), m_pszFile, m_uLine));
  402. }
  403. //
  404. // Restore the last error, the message call may have destoyed the last
  405. // error value, we don't want the caller to loose this value.
  406. //
  407. SetLastError(LastError);
  408. }
  409. }
  410. return m_hrStatus = hrStatus;
  411. }
  412. TStatusHBase::
  413. operator HRESULT(
  414. VOID
  415. ) const
  416. {
  417. return hrGetStatus();
  418. }
  419. /********************************************************************
  420. Debugging TStatusH members
  421. ********************************************************************/
  422. TStatusH::
  423. TStatusH(
  424. IN HRESULT hrStatus
  425. ) : TStatusHBase(hrStatus, kDbgWarning)
  426. {
  427. }
  428. TStatusH::
  429. ~TStatusH(
  430. VOID
  431. )
  432. {
  433. }
  434. #endif