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.

255 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Debug.cpp
  7. //
  8. // Contents: Debug Code
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "lib.h"
  18. #ifdef _DEBUG
  19. // globals for keeping track of debug flags
  20. DWORD g_dwDebugLeakDetection = 0;
  21. DWORD g_dwDebugLogAsserts = 0;
  22. #endif // _DEBUG
  23. #if _ZAWTRACK
  24. // SENS DLL and function strings
  25. STRING_FILENAME(szTrk1OneStopDll, "trk1stop.dll");
  26. STRING_INTERFACE(szpfnOneStopTrk,"OneStopTrk");
  27. // globals for ZawTrack. Set up in Init before
  28. // any other threads are created.
  29. HINSTANCE g_hInstTrk1StopDll = NULL;
  30. PFNONESTOPTRK g_pfnOneStopTrk = NULL;
  31. // Called by WinMain to set up ZawTracking.
  32. void InitZawTrack()
  33. {
  34. g_pfnOneStopTrk = NULL;
  35. g_hInstTrk1StopDll = LoadLibrary(szTrk1OneStopDll);
  36. if (g_hInstTrk1StopDll)
  37. {
  38. // for now, don't return an error is GetProc Fails but check in each function.
  39. g_pfnOneStopTrk = (PFNONESTOPTRK)
  40. GetProcAddress(g_hInstTrk1StopDll,(LPCSTR) 0x01);
  41. if (NULL == g_pfnOneStopTrk)
  42. {
  43. FreeLibrary(g_hInstTrk1StopDll);
  44. g_hInstTrk1StopDll = NULL;
  45. }
  46. }
  47. }
  48. // called to log the flags
  49. void LogZawTrack(DWORD dwFlags)
  50. {
  51. if (g_pfnOneStopTrk)
  52. {
  53. g_pfnOneStopTrk(dwFlags);
  54. }
  55. }
  56. // Called by winmain to free
  57. void UninitZawTrack()
  58. {
  59. if (NULL != g_hInstTrk1StopDll)
  60. {
  61. g_pfnOneStopTrk = NULL;
  62. FreeLibrary(g_hInstTrk1StopDll);
  63. g_hInstTrk1StopDll = NULL;
  64. }
  65. }
  66. #endif // _ZAWTRACK
  67. #ifdef _DEBUG
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Function: InitDebugFlags, public
  71. //
  72. // Synopsis: Called to setup global debugFlags
  73. //
  74. // Arguments:
  75. //
  76. // Returns:
  77. //
  78. // Modifies:
  79. //
  80. // History: 05-Nov-97 rogerg Created.
  81. //
  82. //----------------------------------------------------------------------------
  83. STDAPI_(void) InitDebugFlags(void)
  84. {
  85. DWORD cbData;
  86. DWORD cbType;
  87. HKEY hkeyDebug;
  88. // always use Ansii version so can setup debug before
  89. // initializing WideWrap
  90. g_dwDebugLeakDetection = 0;
  91. g_dwDebugLogAsserts = 0;
  92. if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  93. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Syncmgr\\Debug"
  94. ,0,KEY_READ,&hkeyDebug) )
  95. {
  96. cbType = REG_DWORD;
  97. cbData = sizeof(g_dwDebugLeakDetection);
  98. if (ERROR_SUCCESS != RegQueryValueExA(hkeyDebug,
  99. "LeakDetection",
  100. NULL,
  101. &cbType,
  102. (LPBYTE) &g_dwDebugLeakDetection,
  103. &cbData))
  104. {
  105. g_dwDebugLeakDetection = 0;
  106. }
  107. cbType = REG_DWORD;
  108. cbData = sizeof(g_dwDebugLogAsserts);
  109. if (ERROR_SUCCESS != RegQueryValueExA(hkeyDebug,
  110. "LogAsserts",
  111. NULL,
  112. &cbType,
  113. (LPBYTE) &g_dwDebugLogAsserts,
  114. &cbData))
  115. {
  116. g_dwDebugLogAsserts = 0;
  117. }
  118. RegCloseKey(hkeyDebug);
  119. }
  120. }
  121. //+---------------------------------------------------------------------------
  122. //
  123. // Function: FnAssert, public
  124. //
  125. // Synopsis: Displays the Assert dialog
  126. //
  127. // Arguments: [lpstrExptr] - Expression
  128. // [lpstrMsg] - Msg, if any, to append to the Expression
  129. // [lpstrFilename] - File Assert Occured in
  130. // [iLine] - Line Number of Assert
  131. //
  132. // Returns: Appropriate status code
  133. //
  134. // Modifies:
  135. //
  136. // History: 05-Nov-97 rogerg Created.
  137. //
  138. //----------------------------------------------------------------------------
  139. STDAPI FnAssert( LPSTR lpstrExpr, LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine )
  140. {
  141. int iResult = 0;
  142. char lpTemp[] = "";
  143. char lpBuffer[512];
  144. char lpLocBuffer[256];
  145. if (NULL == lpstrMsg)
  146. lpstrMsg = lpTemp;
  147. if (!g_dwDebugLogAsserts)
  148. {
  149. wsprintfA(lpBuffer, "Assertion \"%s\" failed! %s", lpstrExpr, lpstrMsg);
  150. wsprintfA(lpLocBuffer, "File %s, line %d; (A=exit; R=break; I=continue)",
  151. lpstrFileName, iLine);
  152. iResult = MessageBoxA(NULL, lpLocBuffer, lpBuffer,
  153. MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL);
  154. if (iResult == IDRETRY)
  155. {
  156. DebugBreak();
  157. }
  158. else if (iResult == IDABORT)
  159. {
  160. FatalAppExitA(0, "Assertion failure");
  161. }
  162. }
  163. else
  164. {
  165. wsprintfA(lpBuffer, "Assertion \"%s\" failed! %s\n", lpstrExpr, lpstrMsg);
  166. wsprintfA(lpLocBuffer, "File %s, line %d\n\n",lpstrFileName, iLine);
  167. OutputDebugStringA(lpBuffer);
  168. OutputDebugStringA(lpLocBuffer);
  169. }
  170. return NOERROR;
  171. }
  172. //+---------------------------------------------------------------------------
  173. //
  174. // Function: FnTrace, public
  175. //
  176. // Synopsis: Displays the Assert dialog
  177. //
  178. // Arguments: [lpstrMsg] - Msg in trace
  179. // [lpstrFilename] - File TRACE Occured in
  180. // [iLine] - Line Number of TRACE
  181. //
  182. // Returns: Appropriate status code
  183. //
  184. // Modifies:
  185. //
  186. // History: 14-Jan-98 rogerg Created.
  187. //
  188. //----------------------------------------------------------------------------
  189. STDAPI FnTrace(LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine )
  190. {
  191. int iResult = 0;
  192. char lpTemp[] = "";
  193. char lpBuffer[512];
  194. if (NULL == lpstrMsg)
  195. lpstrMsg = lpTemp;
  196. // should have flag to turn tracing on instead of changing header.
  197. wsprintfA(lpBuffer, "%s %s(%d)\r\n",lpstrMsg,lpstrFileName,iLine);
  198. OutputDebugStringA(lpBuffer);
  199. return NOERROR;
  200. }
  201. #endif // _DEBUG