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.

105 lines
2.9 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright (c) 1994-1998 Microsoft Corporation **
  4. //*********************************************************************
  5. // ############################################################################
  6. // Debugging routines
  7. #include "pch.hpp"
  8. BOOL fInAssert=FALSE;
  9. // ############################################################################
  10. // DebugSz
  11. //
  12. // This function outputs debug string
  13. //
  14. // Created 1/28/96, Chris Kauffman
  15. // ############################################################################
  16. void DebugSz(PCSTR psz)
  17. {
  18. OutputDebugString(psz);
  19. } // DebugSz
  20. // ############################################################################
  21. // Debug Printf to debug output screen
  22. void Dprintf(PCSTR pcsz, ...)
  23. {
  24. #ifdef DEBUG
  25. va_list argp;
  26. char szBuf[1024];
  27. va_start(argp, pcsz);
  28. wvsprintf(szBuf, pcsz, argp);
  29. DebugSz(szBuf);
  30. va_end(argp);
  31. #endif
  32. } // Dprintf()
  33. // ############################################################################
  34. // Handle asserts
  35. BOOL FAssertProc(PCSTR szFile, DWORD dwLine, PCSTR szMsg, DWORD dwFlags)
  36. {
  37. char szMsgEx[1024], szTitle[255], szFileName[MAX_PATH];
  38. int id;
  39. UINT fuStyle;
  40. BOOL fAssertIntoDebugger = FALSE;
  41. LPTSTR pszCommandLine = GetCommandLine();
  42. HANDLE hAssertTxt;
  43. //BYTE szTime[80];
  44. CHAR szTime[80];
  45. SYSTEMTIME st;
  46. DWORD cbWritten;
  47. // no recursive asserts
  48. if (fInAssert)
  49. {
  50. DebugSz("***Recursive Assert***\r\n");
  51. return(FALSE);
  52. }
  53. fInAssert = TRUE;
  54. GetModuleFileName(NULL, szFileName, MAX_PATH);
  55. wsprintf(szMsgEx,"%s:#%d\r\nProcess ID: %d %s, Thread ID: %d\r\n%s",
  56. szFile,dwLine,GetCurrentProcessId(),szFileName,GetCurrentThreadId(),szMsg);
  57. wsprintf(szTitle,"Assertion Failed");
  58. fuStyle = MB_APPLMODAL | MB_ABORTRETRYIGNORE;
  59. fuStyle |= MB_ICONSTOP;
  60. DebugSz(szTitle);
  61. DebugSz(szMsgEx);
  62. // dump the assert into ASSERT.TXT
  63. hAssertTxt = CreateFile("assert.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL);
  64. if (INVALID_HANDLE_VALUE != hAssertTxt)
  65. {
  66. SetFilePointer(hAssertTxt, 0, NULL, FILE_END);
  67. GetLocalTime(&st);
  68. wsprintf(szTime, "\r\n\r\n%02d/%02d/%02d %d:%02d:%02d\r\n", st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond);
  69. WriteFile(hAssertTxt, szTime, lstrlen(szTime), &cbWritten, NULL);
  70. WriteFile(hAssertTxt, szMsgEx, lstrlen(szMsgEx), &cbWritten, NULL);
  71. CloseHandle(hAssertTxt);
  72. }
  73. id = MessageBox(NULL, szMsgEx, szTitle, fuStyle);
  74. switch (id)
  75. {
  76. case IDABORT:
  77. ExitProcess(0);
  78. break;
  79. case IDCANCEL:
  80. case IDIGNORE:
  81. break;
  82. case IDRETRY:
  83. fAssertIntoDebugger = TRUE;
  84. break;
  85. }
  86. fInAssert = FALSE;
  87. return(fAssertIntoDebugger);
  88. } // AssertProc()