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.

177 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. exceptn.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Wesley Witt (wesw) 15-Aug-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. DECLARE_API( exrlog )
  16. {
  17. ULONG LogCount;
  18. ULONG64 Address;
  19. ULONG result;
  20. ULONG64 LogPointer;
  21. ULONG64 MaxLogRecord;
  22. LAST_EXCEPTION_LOG LogRecord;
  23. ULONG MaxExceptionLog;
  24. CHAR Buffer[256];
  25. ULONG64 displacement;
  26. PUCHAR s;
  27. ULONG64 Finally=0;
  28. ULONG64 Filter=0;
  29. ULONG64 Handler=0;
  30. ULONG SizeOfLogRec;
  31. ULONG ContextRecordOffset;
  32. // Get the offset of ContextRecord in LAST_EXCEPTION_LOG
  33. if (GetFieldOffset("LAST_EXCEPTION_LOG", "ContextRecord", &ContextRecordOffset)){
  34. return E_INVALIDARG ;
  35. }
  36. Address = GetExpression( "nt!RtlpExceptionLogCount" );
  37. if (Address == 0) {
  38. dprintf("exrlog: No symbol for RtlpExceptionLogCount.\n");
  39. return E_INVALIDARG;
  40. }
  41. if ((!ReadMemory(Address,
  42. (PVOID)&LogCount,
  43. sizeof(ULONG),
  44. &result)) || (result < sizeof(ULONG))) {
  45. dprintf("exrlog: Unable to read log\n");
  46. return E_INVALIDARG;
  47. }
  48. Address = GetExpression( "nt!RtlpExceptionLogSize" );
  49. if (Address == 0) {
  50. dprintf("exrlog: No symbol for RtlpExceptionSize.\n");
  51. return E_INVALIDARG;
  52. }
  53. if ((!ReadMemory(Address,
  54. (PVOID)&MaxExceptionLog,
  55. sizeof(ULONG),
  56. &result)) || (result < sizeof(ULONG))) {
  57. dprintf("exrlog: Unable to read log\n");
  58. return E_INVALIDARG;
  59. }
  60. Address = GetExpression( "nt!RtlpExceptionLog" );
  61. if (Address == 0) {
  62. dprintf("exrlog: No symbol for RtlpExceptionLog.\n");
  63. return E_INVALIDARG;
  64. }
  65. if (!ReadPointer(Address,&LogPointer)) {
  66. dprintf("exrlog: Unable to read log pointer\n");
  67. return E_INVALIDARG;
  68. }
  69. if (LogPointer == 0 || MaxExceptionLog == 0) {
  70. dprintf("exrlog: Exception logging is not enabled.\n");
  71. return E_INVALIDARG;
  72. }
  73. MaxLogRecord = LogPointer + MaxExceptionLog;
  74. LogPointer += LogCount;
  75. if (!(SizeOfLogRec = GetTypeSize("LAST_EXCEPTION_LOG"))) {
  76. dprintf("Cannot find LAST_EXCEPTION_LOG type.\n");
  77. return E_INVALIDARG;
  78. }
  79. for (LogCount = 0; LogCount < MaxExceptionLog; LogCount++) {
  80. ULONG Disposition;
  81. if (GetFieldValue(LogPointer,
  82. "LAST_EXCEPTION_LOG",
  83. "Disposition",
  84. Disposition)) {
  85. dprintf("exrlog: Unable to read log entry at %08p\n", LogPointer);
  86. }
  87. dprintf("\n% 2d: ----------------------------------\n", LogCount);
  88. sprintf(Buffer, ".exr %I64lx", LogPointer);
  89. ExecuteCommand(Client, Buffer); // Excveptionrecord is first field in log
  90. dprintf("\n");
  91. // Incomplete - exsup.c
  92. // InterpretExceptionData(&LogRecord, &Finally, &Filter, &Handler);
  93. GetSymbol(Filter, Buffer, &displacement);
  94. dprintf("Filter: %08p", Filter);
  95. if (*Buffer) {
  96. dprintf(" (%s+0x%I64x)\n", Buffer, displacement);
  97. } else {
  98. dprintf("\n");
  99. }
  100. GetSymbol(Handler, Buffer, &displacement);
  101. dprintf("Handler: %08p", Handler);
  102. if (*Buffer) {
  103. dprintf(" (%s+0x%I64x)\n", Buffer, displacement);
  104. } else {
  105. dprintf("\n");
  106. }
  107. GetSymbol(Finally, Buffer, &displacement);
  108. dprintf("Finally: %08p", Finally);
  109. if (*Buffer) {
  110. dprintf(" (%s+0x%I64x)\n", Buffer, displacement);
  111. } else {
  112. dprintf("\n");
  113. }
  114. switch( Disposition ) {
  115. case ExceptionContinueExecution:
  116. s = "ExceptionContinueExecution";
  117. break;
  118. case ExceptionContinueSearch:
  119. s = "ExceptionContinueSearch";
  120. break;
  121. case ExceptionNestedException:
  122. s = "ExceptionNestedException";
  123. break;
  124. case 0xffffffff:
  125. s = "Executed Handler";
  126. break;
  127. }
  128. dprintf("Disposition: %d (%s)\n\n", Disposition, s);
  129. sprintf(Buffer, ".cxr %I64lx", ContextRecordOffset + LogPointer);
  130. ExecuteCommand(Client, Buffer);
  131. ExecuteCommand(Client, ".cxr");
  132. LogPointer += SizeOfLogRec;
  133. if (LogPointer >= MaxLogRecord) {
  134. LogPointer -= MaxExceptionLog;
  135. }
  136. }
  137. return S_OK;
  138. }