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.

91 lines
3.2 KiB

  1. // --------------------------------------------------------------------------------
  2. // Debug.c
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include <stdarg.h>
  7. #include <shlwapi.h>
  8. ASSERTDATA
  9. #ifdef DEBUG
  10. #ifndef WIN16
  11. #include <mimeole.h>
  12. #else //WIN16 - Followings are from MIMEOLE.H
  13. #define E_PENDING _HRESULT_TYPEDEF_(0x8000000AL)
  14. #define FACILITY_INTERNET 12
  15. #define MIME_E_NOT_FOUND MAKE_SCODE(SEVERITY_ERROR, FACILITY_INTERNET, 0xCE05)
  16. #endif //WIN16
  17. // --------------------------------------------------------------------------------
  18. // DebugStrf
  19. // --------------------------------------------------------------------------------
  20. __cdecl DebugStrf(LPTSTR lpszFormat, ...)
  21. {
  22. static TCHAR szDebugBuff[500];
  23. va_list arglist;
  24. va_start(arglist, lpszFormat);
  25. wvnsprintf(szDebugBuff, ARRAYSIZE(szDebugBuff), lpszFormat, arglist);
  26. va_end(arglist);
  27. OutputDebugString(szDebugBuff);
  28. }
  29. // --------------------------------------------------------------------------------
  30. // HrTrace
  31. // --------------------------------------------------------------------------------
  32. OESTDAPI_(HRESULT) HrTrace(HRESULT hr, LPSTR lpszFile, INT nLine)
  33. {
  34. if (FAILED(hr) && MIME_E_NOT_FOUND != hr && E_PENDING != hr && E_NOINTERFACE != hr)
  35. DebugTrace ("%s(%d) - HRESULT - %0X\n", lpszFile, nLine, hr);
  36. return hr;
  37. }
  38. // --------------------------------------------------------------------------------
  39. // AssertSzFn
  40. // --------------------------------------------------------------------------------
  41. OESTDAPI_(void) AssertSzFn(LPSTR szMsg, LPSTR szFile, int nLine)
  42. {
  43. static const char rgch1[] = "File %s, line %d:";
  44. static const char rgch2[] = "Unknown file:";
  45. static const char szAssert[] = "Assert Failure";
  46. char rgch[512];
  47. char *lpsz;
  48. int ret, cch;
  49. if (szFile)
  50. wnsprintf(rgch, ARRAYSIZE(rgch), rgch1, szFile, nLine);
  51. else
  52. StrCpyN(rgch, rgch2, ARRAYSIZE(rgch));
  53. StrCatBuff(rgch, "\n\n", ARRAYSIZE(rgch));
  54. StrCatBuff(rgch, szMsg, ARRAYSIZE(rgch));
  55. ret = MessageBox(GetActiveWindow(), rgch, szAssert, MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SYSTEMMODAL|MB_SETFOREGROUND);
  56. if (ret != IDIGNORE)
  57. DebugBreak();
  58. /* Force a hard exit w/ a GP-fault so that Dr. Watson generates a nice stack trace log. */
  59. if (ret == IDABORT)
  60. *(LPBYTE)0 = 1; // write to address 0 causes GP-fault
  61. }
  62. // --------------------------------------------------------------------------------
  63. // NFAssertSzFn
  64. // --------------------------------------------------------------------------------
  65. OESTDAPI_(void) NFAssertSzFn(LPSTR szMsg, LPSTR szFile, int nLine)
  66. {
  67. char rgch[512];
  68. #ifdef MAC
  69. static const char rgch1[] = "Non-fatal assert:\n\tFile %s, line %u:\n\t%s\n";
  70. #else // !MAC
  71. static const char rgch1[] = "Non-fatal assert:\r\n\tFile %s, line %u:\r\n\t%s\r\n";
  72. #endif // MAC
  73. wnsprintf(rgch, ARRAYSIZE(rgch), rgch1, szFile, nLine, szMsg ? szMsg : "");
  74. OutputDebugString(rgch);
  75. }
  76. #endif