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.

126 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 2000
  6. //
  7. // File: dbg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////
  11. // debug helpers
  12. #if defined(_USE_ADMINPRV_TRACE) || defined(_USE_ADMINPRV_ASSERT) || defined(_USE_ADMINPRV_TIMER)
  13. UINT GetInfoFromIniFile(LPCWSTR lpszSection, LPCWSTR lpszKey, INT nDefault = 0)
  14. {
  15. static LPCWSTR lpszFile = L"\\system32\\" ADMINPRV_COMPNAME L".ini";
  16. WCHAR szFilePath[2*MAX_PATH];
  17. UINT nLen = ::GetSystemWindowsDirectory(szFilePath, 2*MAX_PATH);
  18. if (nLen == 0)
  19. return nDefault;
  20. wcscat(szFilePath, lpszFile);
  21. return ::GetPrivateProfileInt(lpszSection, lpszKey, nDefault, szFilePath);
  22. }
  23. #endif
  24. #if defined(_USE_ADMINPRV_TRACE)
  25. #ifdef DEBUG_DSA
  26. DWORD g_dwTrace = 0x1;
  27. #else
  28. DWORD g_dwTrace = ::GetInfoFromIniFile(L"Debug", L"Trace");
  29. #endif
  30. void __cdecl DSATrace(LPCTSTR lpszFormat, ...)
  31. {
  32. if (g_dwTrace == 0)
  33. return;
  34. va_list args;
  35. va_start(args, lpszFormat);
  36. int nBuf;
  37. WCHAR szBuffer[512] = {0};
  38. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR)-1, lpszFormat, args);
  39. // was there an error? was the expanded string too long?
  40. ASSERT(nBuf >= 0);
  41. ::OutputDebugString(szBuffer);
  42. va_end(args);
  43. }
  44. #endif // defined(_USE_ADMINPRV_TRACE)
  45. #if defined(_USE_ADMINPRV_ASSERT)
  46. DWORD g_dwAssert = ::GetInfoFromIniFile(L"Debug", L"Assert");
  47. BOOL DSAAssertFailedLine(LPCSTR lpszFileName, int nLine)
  48. {
  49. if (g_dwAssert == 0)
  50. return FALSE;
  51. WCHAR szMessage[_MAX_PATH*2];
  52. // assume the debugger or auxiliary port
  53. wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"),
  54. lpszFileName, nLine);
  55. OutputDebugString(szMessage);
  56. // JonN 6/28/00 Do not MessageBox here, this is a WMI provider.
  57. // Return TRUE to always DebugBreak().
  58. return TRUE;
  59. }
  60. #endif // _USE_ADMINPRV_ASSERT
  61. #if defined(_USE_ADMINPRV_TIMER)
  62. #ifdef TIMER_DSA
  63. DWORD g_dwTimer = 0x1;
  64. #else
  65. DWORD g_dwTimer = ::GetInfoFromIniFile(L"Debug", L"Timer");
  66. #endif
  67. DWORD StartTicks = ::GetTickCount();
  68. DWORD LastTicks = 0;
  69. void __cdecl DSATimer(LPCTSTR lpszFormat, ...)
  70. {
  71. if (g_dwTimer == 0)
  72. return;
  73. va_list args;
  74. va_start(args, lpszFormat);
  75. int nBuf;
  76. WCHAR szBuffer[512] = {0}, szBuffer2[512];
  77. DWORD CurrentTicks = GetTickCount() - StartTicks;
  78. DWORD Interval = CurrentTicks - LastTicks;
  79. LastTicks = CurrentTicks;
  80. nBuf = swprintf(szBuffer2,
  81. L"%d, (%d): %ws", CurrentTicks,
  82. Interval, lpszFormat);
  83. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR) - 1,
  84. szBuffer2,
  85. args);
  86. // was there an error? was the expanded string too long?
  87. ASSERT(nBuf >= 0);
  88. ::OutputDebugString(szBuffer);
  89. va_end(args);
  90. }
  91. #endif // _USE_ADMINPRV_TIMER