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.

147 lines
3.5 KiB

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