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.

103 lines
2.0 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Diagnositc/debug routines for Windows NT Setup API dll.
  7. Author:
  8. Ted Miller (tedm) 17-Jan-1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #if ASSERTS_ON
  14. extern BOOL InInitialization;
  15. VOID
  16. AssertFail(
  17. IN PCSTR FileName,
  18. IN UINT LineNumber,
  19. IN PSTR Condition,
  20. IN BOOL NoUI
  21. )
  22. {
  23. int i;
  24. CHAR Name[MAX_PATH];
  25. PCHAR p;
  26. LPSTR Msg;
  27. DWORD msglen;
  28. DWORD sz;
  29. DWORD rc;
  30. rc = GetLastError(); // preserve GLE
  31. //
  32. // Use dll name as caption
  33. //
  34. sz = GetModuleFileNameA(NULL,Name,MAX_PATH);
  35. if((sz == 0) || (sz > MAX_PATH)) {
  36. strcpy(Name,"?");
  37. }
  38. if(p = strrchr(Name,'\\')) {
  39. p++;
  40. } else {
  41. p = Name;
  42. }
  43. msglen = strlen(p)+strlen(FileName)+strlen(Condition)+128;
  44. //
  45. // assert might be out of memory condition
  46. // stack alloc is more likely to succeed than memory alloc
  47. //
  48. try {
  49. Msg = (LPSTR)_alloca(msglen);
  50. wsprintfA(
  51. Msg,
  52. "Assertion failure at line %u in file %s!%s: %s%s",
  53. LineNumber,
  54. p,
  55. FileName,
  56. Condition,
  57. (GlobalSetupFlags & PSPGF_NONINTERACTIVE) ? "\r\n" : "\n\nCall DebugBreak()?"
  58. );
  59. OutputDebugStringA(Msg);
  60. if((GlobalSetupFlags & PSPGF_NONINTERACTIVE) || InInitialization || NoUI) {
  61. i = IDYES;
  62. } else {
  63. i = MessageBoxA(
  64. NULL,
  65. Msg,
  66. p,
  67. MB_YESNO | MB_TASKMODAL | MB_ICONSTOP | MB_SETFOREGROUND
  68. );
  69. }
  70. } except (EXCEPTION_EXECUTE_HANDLER) {
  71. OutputDebugStringA("SetupAPI ASSERT!!!! (out of stack)\r\n");
  72. i=IDYES;
  73. }
  74. if(i == IDYES) {
  75. SetLastError(rc);
  76. DebugBreak();
  77. }
  78. SetLastError(rc);
  79. }
  80. #endif