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.

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