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.

232 lines
8.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: except.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 6-19-95 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "debuglib.h"
  18. #define DEB_TRACE 0x00000004
  19. #define DSYS_EXCEPT_BREAK 0x00000008
  20. DWORD __ExceptionsInfoLevel = 0x1;
  21. DebugModule __ExceptionsModule = {NULL, &__ExceptionsInfoLevel, 0, 7,
  22. NULL, 0, 0, "Exceptions",
  23. {"Error", "Warning", "Trace", "Break",
  24. "", "", "", "",
  25. "", "", "", "", "", "", "", "",
  26. "", "", "", "", "", "", "", "",
  27. "", "", "", "", "", "", "", "" }
  28. };
  29. DebugModule * __pExceptionModule = &__ExceptionsModule;
  30. #define DebugOut(x) __ExceptionsDebugOut x
  31. typedef struct _ExName {
  32. LONG ExceptionCode;
  33. PSTR Name;
  34. } ExName, * PExName;
  35. ExName __ExceptNames[] = { {EXCEPTION_ACCESS_VIOLATION, "Access Violation"},
  36. {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Bounds Exceeded"},
  37. {EXCEPTION_BREAKPOINT, "Break Point"},
  38. {EXCEPTION_DATATYPE_MISALIGNMENT, "Alignment (Data)"},
  39. {EXCEPTION_FLT_DENORMAL_OPERAND, "(Float) Denormal Operand"},
  40. {EXCEPTION_FLT_DIVIDE_BY_ZERO, "(Float) Divide By Zero"},
  41. {EXCEPTION_FLT_INEXACT_RESULT, "(Float) Inexact Result"},
  42. {EXCEPTION_FLT_INVALID_OPERATION, "(Float) Invalid Op"},
  43. {EXCEPTION_FLT_OVERFLOW, "(Float) Overflow"},
  44. {EXCEPTION_FLT_STACK_CHECK, "(Float) Stack Check"},
  45. {EXCEPTION_FLT_UNDERFLOW, "(Float) Underflow"},
  46. {EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal Instruction"},
  47. {EXCEPTION_IN_PAGE_ERROR, "In Page Error"},
  48. {EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide By Zero"},
  49. {EXCEPTION_INT_OVERFLOW, "Overflow"},
  50. {EXCEPTION_INVALID_DISPOSITION, "Illegal Disposition"},
  51. {EXCEPTION_NONCONTINUABLE_EXCEPTION, "Can't Continue"},
  52. {EXCEPTION_PRIV_INSTRUCTION, "Privileged Instruction"},
  53. {EXCEPTION_SINGLE_STEP, "Single Step"},
  54. {EXCEPTION_STACK_OVERFLOW, "Stack OverFlow"},
  55. {0xC0000194, "Deadlock"},
  56. };
  57. VOID
  58. __ExceptionsDebugOut(
  59. ULONG Mask,
  60. CHAR * Format,
  61. ... )
  62. {
  63. va_list ArgList;
  64. va_start(ArgList, Format);
  65. _DebugOut( __pExceptionModule, Mask, Format, ArgList);
  66. }
  67. BOOL
  68. DbgpDumpExceptionRecord(
  69. PEXCEPTION_RECORD pExceptRecord)
  70. {
  71. PSTR pszExcept;
  72. BOOL StopOnException;
  73. DWORD i;
  74. ULONG InfoLevel = NT_SUCCESS(pExceptRecord->ExceptionCode) ? DEB_TRACE : DEB_ERROR;
  75. StopOnException = FALSE;
  76. pszExcept = NULL;
  77. for (i = 0; i < sizeof(__ExceptNames) / sizeof(ExName) ; i++ )
  78. {
  79. if (pExceptRecord->ExceptionCode == __ExceptNames[i].ExceptionCode)
  80. {
  81. pszExcept = __ExceptNames[i].Name;
  82. break;
  83. }
  84. }
  85. if (pszExcept)
  86. {
  87. DebugOut((InfoLevel, "Exception %#x (%s)\n",
  88. pExceptRecord->ExceptionCode, pszExcept));
  89. }
  90. else
  91. DebugOut((InfoLevel, "Exception %#x\n", pExceptRecord->ExceptionCode));
  92. DebugOut((InfoLevel, " %s\n",
  93. pExceptRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE ?
  94. "Non-Continuable" : "Continuable"));
  95. DebugOut((InfoLevel, " Address %#x\n", pExceptRecord->ExceptionAddress));
  96. switch (pExceptRecord->ExceptionCode)
  97. {
  98. case EXCEPTION_ACCESS_VIOLATION:
  99. case EXCEPTION_DATATYPE_MISALIGNMENT:
  100. DebugOut((InfoLevel, " %s at address %#x\n",
  101. pExceptRecord->ExceptionInformation[0] ? "Write" : "Read",
  102. pExceptRecord->ExceptionInformation[1] ));
  103. StopOnException = TRUE;
  104. break;
  105. case STATUS_POSSIBLE_DEADLOCK:
  106. DebugOut((InfoLevel, " Resource at %#x\n",
  107. pExceptRecord->ExceptionInformation[0] ));
  108. StopOnException = TRUE;
  109. break;
  110. default:
  111. // StopOnException = TRUE;
  112. DebugOut((InfoLevel, " %d Parameters\n", pExceptRecord->NumberParameters));
  113. for (i = 0; i < pExceptRecord->NumberParameters ; i++ )
  114. {
  115. DebugOut((InfoLevel, " [%d] %#x\n", i,
  116. pExceptRecord->ExceptionInformation[i] ));
  117. }
  118. break;
  119. }
  120. return(StopOnException);
  121. }
  122. VOID
  123. DbgpDumpContextRecord(
  124. PCONTEXT pContext,
  125. BOOL StopOnException)
  126. {
  127. ULONG InfoLevel = StopOnException ? DEB_ERROR : DEB_TRACE;
  128. #ifdef _MIPS_
  129. DebugOut((InfoLevel, "MIPS Context Record at %x\n", pContext));
  130. if (pContext->ContextFlags & CONTEXT_INTEGER)
  131. {
  132. DebugOut((InfoLevel, "at=%08x v0=%08x v1=%08x a0=%08x\n",
  133. pContext->IntAt, pContext->IntV0, pContext->IntV1, pContext->IntA0));
  134. DebugOut((InfoLevel, "a1=%08x a2=%08x a3=%08x t0=%08x\n",
  135. pContext->IntA1, pContext->IntA2, pContext->IntA3, pContext->IntT0));
  136. DebugOut((InfoLevel, "t1=%08x t2=%08x t3=%08x t4=%08x\n",
  137. pContext->IntT1, pContext->IntT2, pContext->IntT3, pContext->IntT4));
  138. DebugOut((InfoLevel, "t5=%08x t6=%08x t7=%08x s0=%08x\n",
  139. pContext->IntT5, pContext->IntT6, pContext->IntT7, pContext->IntS0));
  140. DebugOut((InfoLevel, "s1=%08x s2=%08x s3=%08x s4=%08x\n",
  141. pContext->IntS1, pContext->IntS2, pContext->IntS3, pContext->IntS4));
  142. DebugOut((InfoLevel, "s5=%08x s6=%08x s7=%08x t8=%08x\n",
  143. pContext->IntS5, pContext->IntS6, pContext->IntS7, pContext->IntT8));
  144. DebugOut((InfoLevel, "t9=%08x s8=%08x hi=%08x lo=%08x\n",
  145. pContext->IntT9, pContext->IntS8, pContext->IntLo, pContext->IntHi));
  146. DebugOut((InfoLevel, "k0=%08x k1=%08x gp=%08x sp=%08x\n",
  147. pContext->IntK0, pContext->IntK1, pContext->IntGp, pContext->IntSp));
  148. DebugOut((InfoLevel, "ra=%08x\n",
  149. pContext->IntRa));
  150. }
  151. if (pContext->ContextFlags & CONTEXT_CONTROL)
  152. {
  153. DebugOut((InfoLevel, "Fir=%08x Psr=%08x\n", pContext->Fir,
  154. pContext->Psr));
  155. }
  156. #elif _X86_
  157. DebugOut((InfoLevel, "x86 Context Record at %x\n", pContext));
  158. if (pContext->ContextFlags & CONTEXT_DEBUG_REGISTERS)
  159. {
  160. DebugOut((InfoLevel, "Dr0=%08x Dr1=%08x Dr2=%08x Dr3=%08x \n",
  161. pContext->Dr0, pContext->Dr1, pContext->Dr2, pContext->Dr3));
  162. DebugOut((InfoLevel, "Dr6=%08x Dr7=%08x\n",
  163. pContext->Dr6, pContext->Dr7));
  164. }
  165. if (pContext->ContextFlags & CONTEXT_SEGMENTS)
  166. {
  167. DebugOut((InfoLevel, "gs=%08x fs=%08x es=%08x ds=%08x\n",
  168. pContext->SegGs, pContext->SegFs, pContext->SegEs,
  169. pContext->SegDs));
  170. }
  171. if (pContext->ContextFlags & CONTEXT_INTEGER)
  172. {
  173. DebugOut((InfoLevel, "edi=%08x esi=%08x ebx=%08x\n",
  174. pContext->Edi, pContext->Esi, pContext->Ebx));
  175. DebugOut((InfoLevel, "edx=%08x ecx=%08x eax=%08x\n",
  176. pContext->Edx, pContext->Ecx, pContext->Eax));
  177. }
  178. if (pContext->ContextFlags & CONTEXT_CONTROL)
  179. {
  180. DebugOut((InfoLevel, "ebp=%08x eip=%08x cs=%08x\n",
  181. pContext->Ebp, pContext->Eip, pContext->SegCs));
  182. DebugOut((InfoLevel, "flags=%08x esp=%08x ss=%08x\n",
  183. pContext->EFlags, pContext->Esp, pContext->SegSs));
  184. }
  185. #elif _ALPHA_
  186. DebugOut((InfoLevel, "ALPHA Context Record at %x\n", pContext));
  187. #elif _PPC_
  188. DebugOut((InfoLevel, "PPC Context Record at %x\n", pContext));
  189. #else
  190. DebugOut((InfoLevel, "Unknown Context Record, %x\n", pContext));
  191. #endif
  192. }
  193. VOID
  194. DbgpDumpException(
  195. PEXCEPTION_POINTERS pExceptInfo)
  196. {
  197. BOOL StopOnException;
  198. StopOnException = DbgpDumpExceptionRecord(pExceptInfo->ExceptionRecord);
  199. DbgpDumpContextRecord( pExceptInfo->ContextRecord, StopOnException );
  200. if (StopOnException &&
  201. ((__ExceptionsInfoLevel & DSYS_EXCEPT_BREAK) != 0))
  202. {
  203. DsysAssertMsgEx(FALSE, "Skip Exceptions", DSYSDBG_ASSERT_DEBUGGER);
  204. }
  205. }