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.

206 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1992-1999 Microsoft Corporation
  3. Module Name:
  4. miscdbg.cpp
  5. Abstract:
  6. Contains code to aid in internal debugging.
  7. --*/
  8. #include "precomp.hxx"
  9. #pragma hdrstop
  10. #ifdef DBG
  11. VOID
  12. Dbg_Windbg_InitializeCriticalSection(
  13. PDBG_WINDBG_CRITICAL_SECTION pDbgCritSec,
  14. PTSTR pszName,
  15. PTSTR pszFile,
  16. int nLine
  17. )
  18. {
  19. InitializeCriticalSection( &pDbgCritSec->cs );
  20. pDbgCritSec->Initialize(pszName);
  21. }
  22. BOOL
  23. Dbg_Windbg_TryEnterCriticalSection(
  24. PDBG_WINDBG_CRITICAL_SECTION pDbgCritSec,
  25. PTSTR pszFile,
  26. int nLine
  27. )
  28. {
  29. BOOL b = TryEnterCriticalSection( &pDbgCritSec->cs );
  30. if (b) {
  31. ++pDbgCritSec->nLockCount;
  32. pDbgCritSec->OwnerId = GetCurrentThreadId();
  33. DPRINT(DP_CRITSEC_VERBOSE,
  34. ( _T(" *** TryEnterCriticalSection \'%s\' %s %d\n"),
  35. pDbgCritSec->pszName,
  36. pszFile,
  37. nLine
  38. ) );
  39. pDbgCritSec->pszLock_LastFile = pszFile;
  40. pDbgCritSec->nLock_LastFile = nLine;
  41. }
  42. if (pDbgCritSec->nLockCount++ > 1) {
  43. DPRINT(DP_CRITSEC_INFO,
  44. ( _T(" *** INFO: Locked twice. \'%s\' %s %d\n"),
  45. pDbgCritSec->pszName,
  46. pszFile,
  47. nLine
  48. ) );
  49. }
  50. return b;
  51. }
  52. VOID
  53. Dbg_Windbg_EnterCriticalSection(
  54. PDBG_WINDBG_CRITICAL_SECTION pDbgCritSec,
  55. PTSTR pszFile,
  56. int nLine
  57. )
  58. {
  59. if (pDbgCritSec->nLockCount
  60. && GetCurrentThreadId() != pDbgCritSec->OwnerId ) {
  61. DPRINT(DP_CRITSEC_INFO,
  62. ( _T(" *** INFO: Waiting on another thread. \'%s\' %s %d\n"),
  63. pDbgCritSec->pszName,
  64. pszFile,
  65. nLine
  66. ) );
  67. }
  68. EnterCriticalSection( &pDbgCritSec->cs );
  69. pDbgCritSec->OwnerId = GetCurrentThreadId();
  70. pDbgCritSec->pszLock_LastFile = pszFile;
  71. pDbgCritSec->nLock_LastFile = nLine;
  72. if (pDbgCritSec->nLockCount++ > 1) {
  73. DPRINT(DP_CRITSEC_INFO,
  74. ( _T(" *** INFO: Locked twice. \'%s\' %s %d\n"),
  75. pDbgCritSec->pszName,
  76. pszFile,
  77. nLine
  78. ) );
  79. }
  80. DPRINT(DP_CRITSEC_VERBOSE,
  81. ( _T(" *** Dbg_EnterCriticalSection \'%s\' %s %d\n"),
  82. pDbgCritSec->pszName,
  83. pszFile,
  84. nLine
  85. ) );
  86. }
  87. VOID
  88. Dbg_Windbg_LeaveCriticalSection(
  89. PDBG_WINDBG_CRITICAL_SECTION pDbgCritSec,
  90. PTSTR pszFile,
  91. int nLine
  92. )
  93. {
  94. DPRINT(DP_CRITSEC_VERBOSE,
  95. ( _T(" *** Dbg_LeaveCriticalSection \'%s\' %s %d\n"),
  96. pDbgCritSec->pszName,
  97. pszFile,
  98. nLine
  99. ) );
  100. if (GetCurrentThreadId() != pDbgCritSec->OwnerId ) {
  101. DPRINT(DP_CRITSEC_ERROR,
  102. ( _T(" *** ERROR: Not owner. Dbg_LeaveCriticalSection \'%s\' %s %d\n"),
  103. pDbgCritSec->pszName,
  104. pszFile,
  105. nLine
  106. ) );
  107. Assert(!"API lock released when not owned");
  108. }
  109. if (pDbgCritSec->nLockCount < 1) {
  110. DPRINT(DP_CRITSEC_ERROR,
  111. ( _T(" *** ERROR: Count is 0. Dbg_LeaveCriticalSection \'%s\' %s %d\n"),
  112. pDbgCritSec->pszName,
  113. pszFile,
  114. nLine
  115. ) );
  116. Assert(!"API Lock released when count is 0");
  117. } else {
  118. if (--pDbgCritSec->nLockCount == 0) {
  119. pDbgCritSec->OwnerId = 0;
  120. }
  121. LeaveCriticalSection(&pDbgCritSec->cs);
  122. }
  123. pDbgCritSec->pszUnlock_LastFile = pszFile;
  124. pDbgCritSec->nUnlock_LastFile = nLine;
  125. }
  126. VOID
  127. Dbg_Windbg_DeleteCriticalSection(
  128. PDBG_WINDBG_CRITICAL_SECTION pDbgCritSec,
  129. PTSTR pszFile,
  130. int nLine
  131. )
  132. {
  133. DeleteCriticalSection( &pDbgCritSec->cs );
  134. pDbgCritSec->Delete();
  135. }
  136. #endif // DBG
  137. VOID
  138. DebugPrint(
  139. PTSTR szFormat,
  140. ...
  141. )
  142. {
  143. __declspec( thread ) static TCHAR rgchDebug[1024 * 4];
  144. __declspec( thread ) static va_list marker;
  145. va_start( marker, szFormat );
  146. if (-1 == _vsntprintf(rgchDebug, _tsizeof(rgchDebug), szFormat, marker ) ) {
  147. rgchDebug[_tsizeof(rgchDebug)-1] = 0;
  148. }
  149. va_end( marker);
  150. OutputDebugString( rgchDebug );
  151. } /* DebugPrint() */
  152. #ifdef _CPPRTTI
  153. BOOL
  154. RttiTypesEqual(
  155. const type_info & t1,
  156. const type_info & t2
  157. )
  158. {
  159. return t1 == t2;
  160. }
  161. #endif