Mega KD64 revival patch:
[reactos.git] / reactos / ntoskrnl / kd64 / kdtrap.c
index 264b283..6ba033f 100644 (file)
@@ -44,7 +44,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
     }\r
     else if (SecondChanceException)\r
     {\r
-        /* We won't bother unless this is second chance */\r
+        /* We won't bother unless this is first chance */\r
         return FALSE;\r
     }\r
 \r
@@ -71,7 +71,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
     RtlCopyMemory(ContextRecord,\r
                   &Prcb->ProcessorState.ContextFrame,\r
                   sizeof(CONTEXT));\r
-    //KiRestoreProcessorControlState(&Prcb->ProcessorState);\r
+    KiRestoreProcessorControlState(&Prcb->ProcessorState);\r
 \r
     /* Exit the debugger and clear the CTRL-C state */\r
     KdExitDebugger(Entered);\r
@@ -89,7 +89,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
         IN BOOLEAN SecondChanceException)\r
 {\r
     BOOLEAN Unload = FALSE;\r
-    ULONG Eip, Eax;\r
+    ULONG_PTR ProgramCounter, ReturnValue;\r
     BOOLEAN Status = FALSE;\r
 \r
     /*\r
@@ -99,8 +99,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
     if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) &&\r
         (ExceptionRecord->ExceptionInformation[0] != BREAKPOINT_BREAK))\r
     {\r
-        /* Save EIP */\r
-        Eip = ContextRecord->Eip;\r
+        /* Save Program Counter */\r
+        ProgramCounter = KeGetContextPc(ContextRecord);\r
 \r
         /* Check what kind of operation was requested from us */\r
         switch (ExceptionRecord->ExceptionInformation[0])\r
@@ -109,43 +109,54 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
             case BREAKPOINT_PRINT:\r
 \r
                 /* Call the worker routine */\r
-                Eax = KdpPrint(ContextRecord->Ebx,\r
-                               ContextRecord->Edi,\r
-                               (LPSTR)ExceptionRecord->ExceptionInformation[1],\r
-                               (ULONG)ExceptionRecord->ExceptionInformation[2],\r
-                               PreviousMode,\r
-                               TrapFrame,\r
-                               ExceptionFrame,\r
-                               &Status);\r
+                ReturnValue = KdpPrint((ULONG)ContextRecord->Ebx,\r
+                                       (ULONG)ContextRecord->Edi,\r
+                                       (LPSTR)ExceptionRecord->\r
+                                       ExceptionInformation[1],\r
+                                       (USHORT)ExceptionRecord->\r
+                                       ExceptionInformation[2],\r
+                                       PreviousMode,\r
+                                       TrapFrame,\r
+                                       ExceptionFrame,\r
+                                       &Status);\r
 \r
                 /* Update the return value for the caller */\r
-                ContextRecord->Eax = Eax;\r
+                KeSetContextReturnRegister(ContextRecord, ReturnValue);\r
                 break;\r
 \r
             /* DbgPrompt */\r
             case BREAKPOINT_PROMPT:\r
 \r
                 /* Call the worker routine */\r
-                while (TRUE);\r
-                Eax = 0;\r
+                ReturnValue = KdpPrompt((LPSTR)ExceptionRecord->\r
+                                        ExceptionInformation[1],\r
+                                        (USHORT)ExceptionRecord->\r
+                                        ExceptionInformation[2],\r
+                                        (LPSTR)ContextRecord->Ebx,\r
+                                        (USHORT)ContextRecord->Edi,\r
+                                        PreviousMode,\r
+                                        TrapFrame,\r
+                                        ExceptionFrame);\r
                 Status = TRUE;\r
 \r
                 /* Update the return value for the caller */\r
-                ContextRecord->Eax = Eax;\r
+                KeSetContextReturnRegister(ContextRecord, ReturnValue);\r
                 break;\r
 \r
-            /* DbgUnloadSymbols */\r
+            /* DbgUnloadImageSymbols */\r
             case BREAKPOINT_UNLOAD_SYMBOLS:\r
 \r
                 /* Drop into the load case below, with the unload parameter */\r
                 Unload = TRUE;\r
 \r
-            /* DbgLoadSymbols */\r
+            /* DbgLoadImageSymbols */\r
             case BREAKPOINT_LOAD_SYMBOLS:\r
 \r
                 /* Call the worker routine */\r
-                KdpSymbol((PVOID)ExceptionRecord->ExceptionInformation[1],\r
-                          (PVOID)ExceptionRecord->ExceptionInformation[2],\r
+                KdpSymbol((PSTRING)ExceptionRecord->\r
+                          ExceptionInformation[1],\r
+                          (PKD_SYMBOLS_INFO)ExceptionRecord->\r
+                          ExceptionInformation[2],\r
                           Unload,\r
                           PreviousMode,\r
                           ContextRecord,\r
@@ -154,11 +165,18 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
                 Status = TRUE;\r
                 break;\r
 \r
-            /* DbgCommandString*/\r
+            /* DbgCommandString */\r
             case BREAKPOINT_COMMAND_STRING:\r
 \r
                 /* Call the worker routine */\r
-                while (TRUE);\r
+                KdpCommandString((ULONG)ExceptionRecord->\r
+                                 ExceptionInformation[1],\r
+                                 (LPSTR)ExceptionRecord->\r
+                                 ExceptionInformation[2],\r
+                                 PreviousMode,\r
+                                 ContextRecord,\r
+                                 TrapFrame,\r
+                                 ExceptionFrame);\r
                 Status = TRUE;\r
 \r
             /* Anything else, do nothing */\r
@@ -169,10 +187,15 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
         }\r
 \r
         /*\r
-         * If EIP was not updated, we'll increment it ourselves so execution\r
+         * If the PC was not updated, we'll increment it ourselves so execution\r
          * continues past the breakpoint.\r
          */\r
-        if (ContextRecord->Eip == Eip) ContextRecord->Eip++;\r
+        if (ProgramCounter == KeGetContextPc(ContextRecord))\r
+        {\r
+            /* Update it */\r
+            KeSetContextPc(ContextRecord,\r
+                           ProgramCounter + KD_BREAKPOINT_SIZE);\r
+        }\r
     }\r
     else\r
     {\r
@@ -208,8 +231,9 @@ KdpStub(IN PKTRAP_FRAME TrapFrame,
          (ExceptionCommand == BREAKPOINT_COMMAND_STRING) ||\r
          (ExceptionCommand == BREAKPOINT_PRINT)))\r
     {\r
-        /* This we can handle: simply bump EIP */\r
-        ContextRecord->Eip++;\r
+        /* This we can handle: simply bump the Program Counter */\r
+        KeSetContextPc(ContextRecord,\r
+                       KeGetContextPc(ContextRecord) + KD_BREAKPOINT_SIZE);\r
         return TRUE;\r
     }\r
     else if (KdPitchDebugger)\r
@@ -220,7 +244,7 @@ KdpStub(IN PKTRAP_FRAME TrapFrame,
     else if ((KdAutoEnableOnEvent) &&\r
              (KdPreviouslyEnabled) &&\r
              !(KdDebuggerEnabled) &&\r
-             (KdEnableDebugger()) &&\r
+             (NT_SUCCESS(KdEnableDebugger())) &&\r
              (KdDebuggerEnabled))\r
     {\r
         /* Debugging was Auto-Enabled. We can now send this to KD. */\r