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.

269 lines
7.1 KiB

  1. /*
  2. * brkpt.c - Breakpoint functions of DBG DLL.
  3. *
  4. */
  5. #include <precomp.h>
  6. #pragma hdrstop
  7. BOOL bWantsTraceInteractive = FALSE;
  8. VDM_BREAKPOINT VdmBreakPoints[MAX_VDM_BREAKPOINTS] = {0};
  9. #define X86_BP_OPCODE 0xCC
  10. void
  11. DbgSetTemporaryBP(
  12. WORD Seg,
  13. DWORD Offset,
  14. BOOL mode
  15. )
  16. /*
  17. This routine writes a 'CC' to the specified location, and sets up
  18. the breakpoint structure so that we handle it correctly in DbgBPInt().
  19. */
  20. {
  21. PBYTE lpInst;
  22. if (VdmBreakPoints[VDM_TEMPBP].Flags & VDMBP_SET) {
  23. // remove previous bp
  24. lpInst = VdmMapFlat(VdmBreakPoints[VDM_TEMPBP].Seg,
  25. VdmBreakPoints[VDM_TEMPBP].Offset,
  26. ((VdmBreakPoints[VDM_TEMPBP].Flags & VDMBP_V86)==0) ? VDM_PM : VDM_V86 );
  27. if (lpInst && (*lpInst == X86_BP_OPCODE)) {
  28. *lpInst = VdmBreakPoints[VDM_TEMPBP].Opcode;
  29. Sim32FlushVDMPointer(
  30. ((ULONG)VdmBreakPoints[VDM_TEMPBP].Seg << 16) +
  31. VdmBreakPoints[VDM_TEMPBP].Offset,
  32. 1,
  33. NULL,
  34. (BOOL)((VdmBreakPoints[VDM_TEMPBP].Flags & VDMBP_V86)==0) );
  35. }
  36. }
  37. lpInst = VdmMapFlat(Seg, Offset, mode ? VDM_PM : VDM_V86);
  38. if (lpInst) {
  39. VdmBreakPoints[VDM_TEMPBP].Seg = Seg;
  40. VdmBreakPoints[VDM_TEMPBP].Offset = Offset;
  41. VdmBreakPoints[VDM_TEMPBP].Flags = VDMBP_SET | VDMBP_ENABLED;
  42. VdmBreakPoints[VDM_TEMPBP].Flags |= (mode ? 0 : VDMBP_V86);
  43. VdmBreakPoints[VDM_TEMPBP].Opcode = *lpInst;
  44. *lpInst = X86_BP_OPCODE;
  45. Sim32FlushVDMPointer(((ULONG)Seg << 16) + Offset, 1, NULL, mode);
  46. } else {
  47. VdmBreakPoints[VDM_TEMPBP].Flags = 0;
  48. }
  49. }
  50. BOOL
  51. xxxDbgBPInt(
  52. )
  53. /*
  54. * DbgBPInt
  55. *
  56. * Handles an INT 3
  57. *
  58. * Exit
  59. * Returns TRUE if the event was handled
  60. * FALSE if it should be reflected
  61. */
  62. {
  63. BOOL bEventHandled = FALSE;
  64. ULONG vdmEip;
  65. int i;
  66. PBYTE lpInst;
  67. if ( fDebugged ) {
  68. DbgGetContext();
  69. if ((getMSW() & MSW_PE) && SEGMENT_IS_BIG(vcContext.SegCs)) {
  70. vdmEip = vcContext.Eip;
  71. } else {
  72. vdmEip = (ULONG)LOWORD(vcContext.Eip);
  73. }
  74. for (i=0; i<MAX_VDM_BREAKPOINTS; i++) {
  75. if ((VdmBreakPoints[i].Flags & VDMBP_ENABLED) &&
  76. (VdmBreakPoints[i].Flags & VDMBP_SET) &&
  77. (vcContext.SegCs == VdmBreakPoints[i].Seg) &&
  78. (vdmEip == VdmBreakPoints[i].Offset+1) &&
  79. (!!(getMSW() & MSW_PE) == !(VdmBreakPoints[i].Flags & VDMBP_V86)) ){
  80. // We must have hit this breakpoint. Back up the eip and
  81. // restore the original data
  82. setEIP(getEIP()-1);
  83. vcContext.Eip--;
  84. lpInst = VdmMapFlat(VdmBreakPoints[i].Seg,
  85. VdmBreakPoints[i].Offset,
  86. ((VdmBreakPoints[i].Flags & VDMBP_V86)==0) ? VDM_PM : VDM_V86 );
  87. if (lpInst && (*lpInst == X86_BP_OPCODE)) {
  88. *lpInst = VdmBreakPoints[i].Opcode;
  89. Sim32FlushVDMPointer(
  90. ((ULONG)VdmBreakPoints[i].Seg << 16) +
  91. VdmBreakPoints[i].Offset,
  92. 1,
  93. NULL,
  94. (BOOL)((VdmBreakPoints[i].Flags & VDMBP_V86)==0) );
  95. VdmBreakPoints[i].Flags |= VDMBP_PENDING;
  96. VdmBreakPoints[i].Flags &= ~VDMBP_FLUSH;
  97. if (i == VDM_TEMPBP) {
  98. // non-persistent breakpoint
  99. VdmBreakPoints[i].Flags &= ~VDMBP_SET;
  100. }
  101. }
  102. SendVDMEvent( DBG_BREAK );
  103. bEventHandled = TRUE;
  104. bWantsTraceInteractive = (BOOL) (vcContext.EFlags & V86FLAGS_TRACE);
  105. if (bWantsTraceInteractive || (i != VDM_TEMPBP)) {
  106. vcContext.EFlags |= V86FLAGS_TRACE;
  107. }
  108. RestoreVDMContext(&vcContext);
  109. break;
  110. }
  111. }
  112. if (!bEventHandled) {
  113. OutputDebugString("VDM: Unexpected breakpoint hit\n");
  114. SendVDMEvent( DBG_BREAK );
  115. bWantsTraceInteractive = (BOOL) (vcContext.EFlags & V86FLAGS_TRACE);
  116. RestoreVDMContext(&vcContext);
  117. }
  118. bEventHandled = TRUE;
  119. }
  120. return bEventHandled;
  121. }
  122. BOOL
  123. xxxDbgTraceInt(
  124. )
  125. /*
  126. * DbgTraceInt
  127. *
  128. * Handles an INT 1 fault
  129. *
  130. * Exit
  131. * Returns TRUE if the event was handled
  132. * FALSE if it should be reflected
  133. */
  134. {
  135. BOOL bEventHandled = FALSE;
  136. int i;
  137. PBYTE lpInst;
  138. if ( fDebugged ) {
  139. DbgGetContext();
  140. setEFLAGS(vcContext.EFlags & ~V86FLAGS_TRACE);
  141. for (i=0; i<MAX_VDM_BREAKPOINTS; i++) {
  142. if ((VdmBreakPoints[i].Flags & VDMBP_ENABLED) &&
  143. (VdmBreakPoints[i].Flags & VDMBP_SET) &&
  144. (VdmBreakPoints[i].Flags & VDMBP_PENDING)) {
  145. lpInst = VdmMapFlat(VdmBreakPoints[i].Seg,
  146. VdmBreakPoints[i].Offset,
  147. ((VdmBreakPoints[i].Flags & VDMBP_V86)==0) ? VDM_PM : VDM_V86 );
  148. if (lpInst) {
  149. *lpInst = X86_BP_OPCODE;
  150. }
  151. Sim32FlushVDMPointer(
  152. ((ULONG)VdmBreakPoints[i].Seg << 16) +
  153. VdmBreakPoints[i].Offset,
  154. 1,
  155. NULL,
  156. (BOOL)((VdmBreakPoints[i].Flags & VDMBP_V86)==0) );
  157. VdmBreakPoints[i].Flags &= ~(VDMBP_PENDING | VDMBP_FLUSH);
  158. bEventHandled = TRUE;
  159. }
  160. }
  161. if (bWantsTraceInteractive) {
  162. SendVDMEvent( DBG_BREAK );
  163. RestoreVDMContext(&vcContext);
  164. bWantsTraceInteractive = (BOOL) (vcContext.EFlags & V86FLAGS_TRACE);
  165. } else if (!bEventHandled) {
  166. OutputDebugString("VDM: Unexpected trace interrupt\n");
  167. SendVDMEvent( DBG_BREAK );
  168. bWantsTraceInteractive = (BOOL) (vcContext.EFlags & V86FLAGS_TRACE);
  169. RestoreVDMContext(&vcContext);
  170. }
  171. bEventHandled = TRUE;
  172. }
  173. return bEventHandled;
  174. }
  175. VOID
  176. FlushVdmBreakPoints(
  177. )
  178. {
  179. int i;
  180. for (i=0; i<MAX_VDM_BREAKPOINTS; i++) {
  181. if (VdmBreakPoints[i].Flags & VDMBP_FLUSH) {
  182. Sim32FlushVDMPointer(
  183. ((ULONG)VdmBreakPoints[i].Seg << 16) +
  184. VdmBreakPoints[i].Offset,
  185. 1,
  186. NULL,
  187. (BOOL)((VdmBreakPoints[i].Flags & VDMBP_V86)==0) );
  188. VdmBreakPoints[i].Flags &= ~VDMBP_FLUSH;
  189. }
  190. }
  191. }