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.

90 lines
1.9 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1994, Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: Debug.cpp
  6. //
  7. // Contents: Debug code.
  8. //
  9. // History: 05-Apr-94 v-kentc Created.
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "precomp.h"
  13. #include <assert.h>
  14. int __cdecl _purecall()
  15. {
  16. AssertSz(FALSE, TEXT("'__purecall called'"));
  17. return 0;
  18. }
  19. #ifdef _DEBUG
  20. static DWORD fAssertFlags = AssertDefaultBehavior;
  21. static FILE *pAssertFile;
  22. void WINAPI SetAssertOptions(DWORD dwNewOptions)
  23. {
  24. fAssertFlags = dwNewOptions;
  25. }
  26. static void
  27. OpenAssertFile()
  28. {
  29. // REVIEW - do we want a unicode file name? If so
  30. // pAssertFile = _wfopen(L"asserts.txt", L"a");
  31. pAssertFile = fopen("asserts.txt", "a");
  32. if (NULL != pAssertFile)
  33. fflush(pAssertFile);
  34. }
  35. void WINAPI DebugAssert(LPCTSTR pText, LPCTSTR pFile, UINT uLineNo)
  36. {
  37. TCHAR buf[256];
  38. if (bAssertWriteToFile() || bAssertShowAlert())
  39. {
  40. if (pText)
  41. wsprintf(buf, TEXT("Assert %ws in file %ws - line %d"), pText, pFile, uLineNo);
  42. else
  43. wsprintf(buf, TEXT("Assert in file %ws - line %d"), pFile, uLineNo);
  44. }
  45. if (bAssertWriteToFile())
  46. {
  47. if (NULL == pAssertFile)
  48. OpenAssertFile();
  49. if (NULL != pAssertFile)
  50. {
  51. fwprintf(pAssertFile, buf);
  52. fflush(pAssertFile);
  53. }
  54. }
  55. if (bAssertShowAlert())
  56. {
  57. MessageBox(NULL, buf, TEXT("THammer"), MB_SETFOREGROUND | MB_OK);
  58. }
  59. if (bAssertUseVCAssert())
  60. {
  61. _assert((PVOID)pText, (PVOID)pFile, uLineNo);
  62. }
  63. if (bAssertCallDebugger())
  64. {
  65. DebugBreak();
  66. }
  67. if (bAssertExit())
  68. {
  69. if (pAssertFile)
  70. fclose(pAssertFile);
  71. exit(EXIT_FAILURE);
  72. }
  73. }
  74. #endif // !_DEBUG