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.

150 lines
3.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: dbg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "uiutil.h"
  12. /////////////////////////////////////////////////////////////////////
  13. // debug helpers
  14. #if defined(_USE_DSA_TRACE) || defined(_USE_DSA_ASSERT) || defined(_USE_DSA_TIMER)
  15. UINT GetInfoFromIniFile(LPCWSTR lpszSection, LPCWSTR lpszKey, INT nDefault = 0)
  16. {
  17. static LPCWSTR lpszFile = L"\\system32\\dsadmin.ini";
  18. WCHAR szFilePath[2*MAX_PATH];
  19. UINT nLen = ::GetSystemWindowsDirectory(szFilePath, 2*MAX_PATH);
  20. if (nLen == 0)
  21. return nDefault;
  22. wcscat(szFilePath, lpszFile);
  23. return ::GetPrivateProfileInt(lpszSection, lpszKey, nDefault, szFilePath);
  24. }
  25. #endif
  26. #if defined(_USE_DSA_TRACE)
  27. #ifdef DEBUG_DSA
  28. DWORD g_dwTrace = 0x1;
  29. #else
  30. DWORD g_dwTrace = ::GetInfoFromIniFile(L"Debug", L"Trace");
  31. #endif
  32. void __cdecl DSATrace(LPCTSTR lpszFormat, ...)
  33. {
  34. if (g_dwTrace == 0)
  35. return;
  36. va_list args;
  37. va_start(args, lpszFormat);
  38. int nBuf;
  39. //
  40. // Might need to deal with some long path names when the OU structure gets really deep.
  41. // bug #30432
  42. //
  43. WCHAR szBuffer[2048];
  44. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR), lpszFormat, args);
  45. // was there an error? was the expanded string too long?
  46. ASSERT(nBuf >= 0);
  47. ::OutputDebugString(szBuffer);
  48. va_end(args);
  49. }
  50. #endif // defined(_USE_DSA_TRACE)
  51. #if defined(_USE_DSA_ASSERT)
  52. DWORD g_dwAssert = ::GetInfoFromIniFile(L"Debug", L"Assert");
  53. BOOL DSAAssertFailedLine(LPCSTR lpszFileName, int nLine)
  54. {
  55. CThemeContextActivator activator;
  56. if (g_dwAssert == 0)
  57. return FALSE;
  58. WCHAR szMessage[_MAX_PATH*2];
  59. // assume the debugger or auxiliary port
  60. wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"),
  61. lpszFileName, nLine);
  62. OutputDebugString(szMessage);
  63. // display the assert
  64. int nCode = ::MessageBox(NULL, szMessage, _T("Assertion Failed!"),
  65. MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
  66. OutputDebugString(L"after message box\n");
  67. if (nCode == IDIGNORE)
  68. {
  69. return FALSE; // ignore
  70. }
  71. if (nCode == IDRETRY)
  72. {
  73. return TRUE; // will cause DebugBreak
  74. }
  75. abort(); // should not return
  76. return TRUE;
  77. }
  78. #endif // _USE_DSA_ASSERT
  79. #if defined(_USE_DSA_TIMER)
  80. #ifdef TIMER_DSA
  81. DWORD g_dwTimer = 0x1;
  82. #else
  83. DWORD g_dwTimer = ::GetInfoFromIniFile(L"Debug", L"Timer");
  84. #endif
  85. DWORD StartTicks = ::GetTickCount();
  86. DWORD LastTicks = 0;
  87. void __cdecl DSATimer(LPCTSTR lpszFormat, ...)
  88. {
  89. if (g_dwTimer == 0)
  90. return;
  91. va_list args;
  92. va_start(args, lpszFormat);
  93. int nBuf;
  94. WCHAR szBuffer[512], szBuffer2[512];
  95. DWORD CurrentTicks = GetTickCount() - StartTicks;
  96. DWORD Interval = CurrentTicks - LastTicks;
  97. LastTicks = CurrentTicks;
  98. //NTRAID#NTBUG9-571985-2002/03/10-jmessec buffer overrun potential: how long is lpszFormat?
  99. nBuf = swprintf(szBuffer2,
  100. L"%d, (%d): %ws", CurrentTicks,
  101. Interval, lpszFormat);
  102. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR),
  103. szBuffer2,
  104. args);
  105. // was there an error? was the expanded string too long?
  106. ASSERT(nBuf >= 0);
  107. ::OutputDebugString(szBuffer);
  108. va_end(args);
  109. }
  110. #endif // _USE_DSA_TIMER