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.

314 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. reflect.c
  5. Abstract:
  6. This module contains extensions having to do with event and exception
  7. reflection.
  8. Author:
  9. Dave Hastings (daveh) 20-Apr-1992
  10. Revision History:
  11. Neil Sandlin (NeilSa) 15-Jan-1996 Merged with vdmexts
  12. Neil Sandlin (NeilSa) 15-Jul-1996 Added 'SX' commands
  13. --*/
  14. #include <precomp.h>
  15. #pragma hdrstop
  16. #include <dbgsvc.h>
  17. VOID
  18. ClearVdmDbgTraceFlags(
  19. VOID
  20. )
  21. {
  22. ULONG lpAddress;
  23. ULONG ulTF;
  24. lpAddress = (*GetExpression)("ntvdmd!VdmDbgTraceFlags");
  25. if (!lpAddress) {
  26. lpAddress = (*GetExpression)("ntvdm!InitialVdmDbgFlags");
  27. }
  28. if (!READMEM((PVOID)lpAddress, &ulTF, sizeof(ULONG))) {
  29. PRINTF("Error reading memory\n");
  30. return;
  31. }
  32. ulTF = 0;
  33. WRITEMEM((PVOID)lpAddress, &ulTF, sizeof(ULONG));
  34. }
  35. VOID
  36. dr(
  37. CMD_ARGLIST
  38. )
  39. {
  40. CMD_INIT();
  41. PRINTF("\nThe DR command is obselete and has been removed. The debugger now\n");
  42. PRINTF("breaks on ntvdm debug exceptions by default. If you are debugging\n");
  43. PRINTF("an unusual scenario where you need the debugger to reflect (ignore)\n");
  44. PRINTF("these exceptions (like in debugging a 16-bit debugger), use the\n");
  45. PRINTF("vdmexts.sxd command.\n\n");
  46. }
  47. VOID
  48. er(
  49. CMD_ARGLIST
  50. )
  51. {
  52. CMD_INIT();
  53. PRINTF("\nThe ER command is obselete and has been removed. By default,\n");
  54. PRINTF("the debugger will break on 'second chance' GP faults, which is\n");
  55. PRINTF("typically the desired behavior. If you are debugging an unusual\n");
  56. PRINTF("scenario that requires you to examine FIRST CHANCE faults, use\n");
  57. PRINTF("the vdmexts.sxe command.\n\n");
  58. PRINTF("If you are not sure if you need to turn this notification on, then\n");
  59. PRINTF("you probably don't need it.\n\n");
  60. }
  61. VOID
  62. DoVdmtibFlag(
  63. ULONG Flag,
  64. BOOL bSet,
  65. LPSTR pTitle
  66. )
  67. /*++
  68. Routine Description:
  69. This routine toggles the exception reflection bit in the vdmtib, and
  70. reports the current state
  71. Arguments:
  72. None.
  73. Return Value:
  74. None.
  75. --*/
  76. {
  77. BOOL Status;
  78. PVOID Address;
  79. ULONG Flags;
  80. Address = (PVOID) (FIXED_NTVDMSTATE_LINEAR + GetIntelBase());
  81. //
  82. // Read the current value of the flags
  83. //
  84. Status = READMEM(Address, &Flags, sizeof(ULONG));
  85. if (!Status) {
  86. (ULONG)Address = (*GetExpression)("ntvdm!InitialVdmTibFlags");
  87. Status = READMEM((PVOID)Address, &Flags, sizeof(ULONG));
  88. if (!Status) {
  89. GetLastError();
  90. (*Print)("Could not get InitialTibflags\n");
  91. return;
  92. }
  93. }
  94. //
  95. // Toggle exception bit
  96. //
  97. if (bSet) {
  98. if (!(Flags & Flag)) {
  99. PRINTF("%s enabled\n", pTitle);
  100. }
  101. Flags |= Flag;
  102. } else {
  103. if (Flags & Flag) {
  104. PRINTF("%s disabled\n", pTitle);
  105. }
  106. Flags &= ~Flag;
  107. }
  108. Status = WRITEMEM(Address, &Flags, sizeof(ULONG));
  109. if (!Status) {
  110. GetLastError();
  111. (*Print)("Could not get set Flags\n");
  112. return;
  113. }
  114. }
  115. VOID
  116. EnableDebuggerBreakpoints(
  117. VOID
  118. )
  119. {
  120. DoVdmtibFlag(VDM_BREAK_DEBUGGER, TRUE, "Debug faults");
  121. }
  122. ULONG
  123. TraceFlagFromName(
  124. LPSTR lpName
  125. )
  126. {
  127. ULONG ulRet = 0;
  128. if (_strnicmp(lpName, "cw", 2) == 0) {
  129. ulRet = VDMDBG_BREAK_WOWTASK;
  130. } else if (_strnicmp(lpName, "cd", 2) == 0) {
  131. ulRet = VDMDBG_BREAK_DOSTASK;
  132. } else if (_strnicmp(lpName, "ld", 2) == 0) {
  133. ulRet = VDMDBG_BREAK_LOADDLL;
  134. }
  135. return ulRet;
  136. }
  137. VOID
  138. sx(
  139. CMD_ARGLIST
  140. )
  141. {
  142. ULONG lpAddress;
  143. ULONG Flags;
  144. BOOL Status;
  145. CMD_INIT();
  146. lpAddress = (*GetExpression)("ntvdmd!VdmDbgTraceFlags");
  147. if (!lpAddress) {
  148. lpAddress = (*GetExpression)("ntvdm!InitialVdmDbgFlags");
  149. }
  150. if (!READMEM((PVOID)lpAddress, &Flags, sizeof(ULONG))) {
  151. PRINTF("Error reading memory\n");
  152. return;
  153. }
  154. PRINTF("VDM DEBUG OPTIONS:\n\n");
  155. PRINTF("cd - break on create DOS task - %s\n", (Flags & VDMDBG_BREAK_DOSTASK)? "enabled" : "disabled");
  156. PRINTF("cw - break on create WOW task - %s\n", (Flags & VDMDBG_BREAK_WOWTASK)? "enabled" : "disabled");
  157. PRINTF("ld - break on load DLL - %s\n", (Flags & VDMDBG_BREAK_LOADDLL)? "enabled" : "disabled");
  158. lpAddress = (ULONG) (FIXED_NTVDMSTATE_LINEAR + GetIntelBase());
  159. Status = READMEM((PVOID)lpAddress, &Flags, sizeof(ULONG));
  160. if (!Status) {
  161. lpAddress = (*GetExpression)("ntvdm!InitialVdmTibFlags");
  162. Status = READMEM((PVOID)lpAddress, &Flags, sizeof(ULONG));
  163. if (!Status) {
  164. GetLastError();
  165. (*Print)("Could not get InitialTibflags\n");
  166. return;
  167. }
  168. }
  169. PRINTF("ex - break on FIRST CHANCE exceptions- %s\n", (Flags & VDM_BREAK_EXCEPTIONS)? "enabled" : "disabled");
  170. PRINTF("db - break on INT1, INT3 - %s\n", (Flags & VDM_BREAK_DEBUGGER) ? "enabled" : "disabled");
  171. PRINTF("lg - NTVDM trace history log - %s\n", (Flags & VDM_TRACE_HISTORY) ? "enabled" : "disabled");
  172. }
  173. VOID
  174. DoSxCmd(
  175. BOOL fEnable
  176. )
  177. {
  178. ULONG lpAddress;
  179. ULONG ulTF;
  180. ULONG ulParm;
  181. if (!GetNextToken()) {
  182. PRINTF("Please enter an trace flag (enter 'sx' for list)\n");
  183. return;
  184. }
  185. if (!(ulParm = TraceFlagFromName(lpArgumentString))) {
  186. if (_strnicmp(lpArgumentString, "db", 2) == 0) {
  187. DoVdmtibFlag(VDM_BREAK_DEBUGGER, fEnable, "Debugger trapping of debug faults");
  188. } else if (_strnicmp(lpArgumentString, "ex", 2) == 0) {
  189. DoVdmtibFlag(VDM_BREAK_EXCEPTIONS, fEnable, "Debugger trapping of exceptions");
  190. } else if (_strnicmp(lpArgumentString, "lg", 2) == 0) {
  191. DoVdmtibFlag(VDM_TRACE_HISTORY, fEnable, "NTVDM trace log");
  192. } else {
  193. PRINTF("Invalid trace flag\n");
  194. }
  195. return;
  196. }
  197. lpAddress = (*GetExpression)("ntvdmd!VdmDbgTraceFlags");
  198. if (!lpAddress) {
  199. lpAddress = (*GetExpression)("ntvdm!InitialVdmDbgFlags");
  200. }
  201. if (!READMEM((PVOID)lpAddress, &ulTF, sizeof(ULONG))) {
  202. PRINTF("Error reading memory\n");
  203. return;
  204. }
  205. if (fEnable) {
  206. ulTF |= ulParm;
  207. } else {
  208. ulTF &= ~ulParm;
  209. }
  210. WRITEMEM((PVOID)lpAddress, &ulTF, sizeof(ULONG));
  211. }
  212. VOID
  213. sxd(
  214. CMD_ARGLIST
  215. )
  216. {
  217. CMD_INIT();
  218. DoSxCmd(FALSE);
  219. }
  220. VOID
  221. sxe(
  222. CMD_ARGLIST
  223. )
  224. {
  225. CMD_INIT();
  226. EnableDebuggerBreakpoints();
  227. DoSxCmd(TRUE);
  228. }