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.

139 lines
3.3 KiB

  1. /*-----------------------------------------------------------------------------
  2. debug.cpp
  3. This file implements the debuggin features
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved
  6. Authors:
  7. ChrisK Chris Kauffman
  8. Histroy:
  9. 7/22/96 ChrisK Cleaned and formatted
  10. 7/31/96 ValdonB Changes for Win16
  11. -----------------------------------------------------------------------------*/
  12. #include "pch.hpp"
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. BOOL fInAssert=FALSE;
  17. // ############################################################################
  18. // DebugSz
  19. //
  20. // This function outputs debug string
  21. //
  22. // Created 1/28/96, Chris Kauffman
  23. // ############################################################################
  24. void DebugSz(LPCSTR psz)
  25. {
  26. #if defined(DEBUG)
  27. OutputDebugString(psz);
  28. #endif
  29. } // DebugSz
  30. // ############################################################################
  31. // Debug Printf to debug output screen
  32. void Dprintf(LPCSTR pcsz, ...)
  33. {
  34. #ifdef DEBUG
  35. va_list argp;
  36. char szBuf[1024];
  37. va_start(argp, pcsz);
  38. wvsprintf(szBuf, pcsz, argp);
  39. DebugSz(szBuf);
  40. va_end(argp);
  41. #endif
  42. } // Dprintf()
  43. // ############################################################################
  44. // Handle asserts
  45. BOOL FAssertProc(LPCSTR szFile, DWORD dwLine, LPCSTR szMsg, DWORD dwFlags)
  46. {
  47. BOOL fAssertIntoDebugger = FALSE;
  48. char szMsgEx[1024], szTitle[255], szFileName[MAX_PATH];
  49. int id;
  50. UINT fuStyle;
  51. //BYTE szTime[80];
  52. #if !defined(WIN16)
  53. CHAR szTime[80];
  54. HANDLE hAssertTxt;
  55. SYSTEMTIME st;
  56. DWORD cbWritten;
  57. #endif
  58. // no recursive asserts
  59. if (fInAssert)
  60. {
  61. DebugSz("***Recursive Assert***\r\n");
  62. return(FALSE);
  63. }
  64. fInAssert = TRUE;
  65. #if defined(WIN16)
  66. GetModuleFileName(g_hInstDll, szFileName, MAX_PATH);
  67. wsprintf(szMsgEx,"%s:#%ld\r\n%s,\r\n%s", szFile, dwLine, szFileName, szMsg);
  68. #else
  69. GetModuleFileName(NULL, szFileName, MAX_PATH);
  70. wsprintf(szMsgEx,"%s:#%d\r\nProcess ID: %d %s, Thread ID: %d\r\n%s",
  71. szFile,dwLine,GetCurrentProcessId(),szFileName,GetCurrentThreadId(),szMsg);
  72. #endif
  73. wsprintf(szTitle,"Assertion Failed");
  74. fuStyle = MB_APPLMODAL | MB_ABORTRETRYIGNORE;
  75. fuStyle |= MB_ICONSTOP;
  76. DebugSz(szTitle);
  77. DebugSz(szMsgEx);
  78. // dump the assert into ASSERT.TXT
  79. #if !defined(WIN16)
  80. hAssertTxt = CreateFile("assert.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL);
  81. if (INVALID_HANDLE_VALUE != hAssertTxt)
  82. {
  83. SetFilePointer(hAssertTxt, 0, NULL, FILE_END);
  84. GetLocalTime(&st);
  85. 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);
  86. WriteFile(hAssertTxt, szTime, lstrlen(szTime), &cbWritten, NULL);
  87. WriteFile(hAssertTxt, szMsgEx, lstrlen(szMsgEx), &cbWritten, NULL);
  88. CloseHandle(hAssertTxt);
  89. }
  90. #endif
  91. id = MessageBox(NULL, szMsgEx, szTitle, fuStyle);
  92. switch (id)
  93. {
  94. case IDABORT:
  95. #if defined(WIN16)
  96. abort();
  97. #else
  98. ExitProcess(0);
  99. #endif
  100. break;
  101. case IDCANCEL:
  102. case IDIGNORE:
  103. break;
  104. case IDRETRY:
  105. fAssertIntoDebugger = TRUE;
  106. break;
  107. }
  108. fInAssert = FALSE;
  109. return(fAssertIntoDebugger);
  110. } // AssertProc()