Leaked source code of windows server 2003
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.

175 lines
4.3 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_dwDebugLogAsserts = 0;
  21. #endif // _DEBUG
  22. #ifdef _DEBUG
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: InitDebugFlags, public
  26. //
  27. // Synopsis: Called to setup global debugFlags
  28. //
  29. // Arguments:
  30. //
  31. // Returns:
  32. //
  33. // Modifies:
  34. //
  35. // History: 05-Nov-97 rogerg Created.
  36. //
  37. //----------------------------------------------------------------------------
  38. STDAPI_(void) InitDebugFlags(void)
  39. {
  40. DWORD cbData;
  41. DWORD cbType;
  42. HKEY hkeyDebug;
  43. // always use Ansii version so can setup debug before
  44. g_dwDebugLogAsserts = 0;
  45. if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  46. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Syncmgr\\Debug"
  47. ,0,KEY_READ,&hkeyDebug) )
  48. {
  49. cbType = REG_DWORD;
  50. cbData = sizeof(g_dwDebugLogAsserts);
  51. if (ERROR_SUCCESS != RegQueryValueExA(hkeyDebug,
  52. "LogAsserts",
  53. NULL,
  54. &cbType,
  55. (LPBYTE) &g_dwDebugLogAsserts,
  56. &cbData))
  57. {
  58. g_dwDebugLogAsserts = 0;
  59. }
  60. RegCloseKey(hkeyDebug);
  61. }
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Function: FnAssert, public
  66. //
  67. // Synopsis: Displays the Assert dialog
  68. //
  69. // Arguments: [lpstrExptr] - Expression
  70. // [lpstrMsg] - Msg, if any, to append to the Expression
  71. // [lpstrFilename] - File Assert Occured in
  72. // [iLine] - Line Number of Assert
  73. //
  74. // Returns: Appropriate status code
  75. //
  76. // Modifies:
  77. //
  78. // History: 05-Nov-97 rogerg Created.
  79. //
  80. //----------------------------------------------------------------------------
  81. STDAPI FnAssert( LPSTR lpstrExpr, LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine )
  82. {
  83. int iResult = 0;
  84. char lpTemp[] = "";
  85. char lpBuffer[512];
  86. char lpLocBuffer[256];
  87. if (NULL == lpstrMsg)
  88. lpstrMsg = lpTemp;
  89. if (!g_dwDebugLogAsserts)
  90. {
  91. wnsprintfA(lpBuffer, ARRAYSIZE(lpBuffer), "Assertion \"%s\" failed! %s", lpstrExpr, lpstrMsg);
  92. wnsprintfA(lpLocBuffer, ARRAYSIZE(lpLocBuffer), "File %s, line %d; (A=exit; R=break; I=continue)", lpstrFileName, iLine);
  93. iResult = MessageBoxA(NULL, lpLocBuffer, lpBuffer,
  94. MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL);
  95. if (iResult == IDRETRY)
  96. {
  97. DebugBreak();
  98. }
  99. else if (iResult == IDABORT)
  100. {
  101. FatalAppExitA(0, "Assertion failure");
  102. }
  103. }
  104. else
  105. {
  106. wnsprintfA(lpBuffer, ARRAYSIZE(lpBuffer), "Assertion \"%s\" failed! %s\n", lpstrExpr, lpstrMsg);
  107. wnsprintfA(lpLocBuffer, ARRAYSIZE(lpLocBuffer), "File %s, line %d\n\n",lpstrFileName, iLine);
  108. OutputDebugStringA(lpBuffer);
  109. OutputDebugStringA(lpLocBuffer);
  110. }
  111. return NOERROR;
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // Function: FnTrace, public
  116. //
  117. // Synopsis: Displays the Assert dialog
  118. //
  119. // Arguments: [lpstrMsg] - Msg in trace
  120. // [lpstrFilename] - File TRACE Occured in
  121. // [iLine] - Line Number of TRACE
  122. //
  123. // Returns: Appropriate status code
  124. //
  125. // Modifies:
  126. //
  127. // History: 14-Jan-98 rogerg Created.
  128. //
  129. //----------------------------------------------------------------------------
  130. STDAPI FnTrace(LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine )
  131. {
  132. int iResult = 0;
  133. char lpTemp[] = "";
  134. char lpBuffer[512];
  135. if (NULL == lpstrMsg)
  136. lpstrMsg = lpTemp;
  137. // should have flag to turn tracing on instead of changing header.
  138. wnsprintfA(lpBuffer, ARRAYSIZE(lpBuffer), "%s %s(%d)\r\n",lpstrMsg,lpstrFileName,iLine);
  139. OutputDebugStringA(lpBuffer);
  140. return NOERROR;
  141. }
  142. #endif // _DEBUG