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.

141 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dbg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.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\\dsuiwiz.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 DSATrace(LPCTSTR lpszFormat, ...)
  32. {
  33. if (g_dwTrace == 0)
  34. return;
  35. va_list args;
  36. va_start(args, lpszFormat);
  37. int nBuf;
  38. WCHAR szBuffer[512];
  39. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR), lpszFormat, args);
  40. // was there an error? was the expanded string too long?
  41. ASSERT(nBuf >= 0);
  42. ::OutputDebugString(szBuffer);
  43. va_end(args);
  44. }
  45. #endif // defined(_USE_DSA_TRACE)
  46. #if defined(_USE_DSA_ASSERT)
  47. DWORD g_dwAssert = ::GetInfoFromIniFile(L"Debug", L"Assert");
  48. BOOL DSAAssertFailedLine(LPCSTR lpszFileName, int nLine)
  49. {
  50. if (g_dwAssert == 0)
  51. return FALSE;
  52. WCHAR szMessage[_MAX_PATH*2];
  53. // assume the debugger or auxiliary port
  54. wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"),
  55. lpszFileName, nLine);
  56. OutputDebugString(szMessage);
  57. // display the assert
  58. int nCode = ::MessageBox(NULL, szMessage, _T("Assertion Failed!"),
  59. MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
  60. OutputDebugString(L"after message box\n");
  61. if (nCode == IDIGNORE)
  62. {
  63. return FALSE; // ignore
  64. }
  65. if (nCode == IDRETRY)
  66. {
  67. return TRUE; // will cause DebugBreak
  68. }
  69. abort(); // should not return
  70. return TRUE;
  71. }
  72. #endif // _USE_DSA_ASSERT
  73. #if defined(_USE_DSA_TIMER)
  74. #ifdef TIMER_DSA
  75. DWORD g_dwTimer = 0x1;
  76. #else
  77. DWORD g_dwTimer = ::GetInfoFromIniFile(L"Debug", L"Timer");
  78. #endif
  79. DWORD StartTicks = ::GetTickCount();
  80. DWORD LastTicks = 0;
  81. void DSATimer(LPCTSTR lpszFormat, ...)
  82. {
  83. if (g_dwTimer == 0)
  84. return;
  85. va_list args;
  86. va_start(args, lpszFormat);
  87. int nBuf;
  88. WCHAR szBuffer[512], szBuffer2[512];
  89. DWORD CurrentTicks = GetTickCount() - StartTicks;
  90. DWORD Interval = CurrentTicks - LastTicks;
  91. LastTicks = CurrentTicks;
  92. nBuf = swprintf(szBuffer2,
  93. L"%d, (%d): %ws", CurrentTicks,
  94. Interval, lpszFormat);
  95. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer)/sizeof(WCHAR),
  96. szBuffer2,
  97. args);
  98. // was there an error? was the expanded string too long?
  99. ASSERT(nBuf >= 0);
  100. ::OutputDebugString(szBuffer);
  101. va_end(args);
  102. }
  103. #endif // _USE_DSA_TIMER