[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / kdbg / kdb.c
index 7798eaa..bc7e018 100644 (file)
@@ -209,7 +209,7 @@ KdbpKdbTrapFrameFromKernelStack(
 
     RtlZeroMemory(KdbTrapFrame, sizeof(KDB_KTRAP_FRAME));
     StackPtr = (ULONG_PTR *) KernelStack;
-#if _M_X86_
+#ifdef _M_IX86
     KdbTrapFrame->Tf.Ebp = StackPtr[3];
     KdbTrapFrame->Tf.Edi = StackPtr[4];
     KdbTrapFrame->Tf.Esi = StackPtr[5];
@@ -1352,6 +1352,7 @@ KdbEnterDebuggerException(
     BOOLEAN Resume = FALSE;
     BOOLEAN EnterConditionMet = TRUE;
     ULONG OldEflags;
+    KIRQL OldIrql;
     NTSTATUS ExceptionCode;
 
     ExceptionCode = (ExceptionRecord ? ExceptionRecord->ExceptionCode : STATUS_BREAKPOINT);
@@ -1412,6 +1413,8 @@ KdbEnterDebuggerException(
             /* Delete the temporary breakpoint which was used to step over or into the instruction. */
             KdbpDeleteBreakPoint(-1, BreakPoint);
 
+            TrapFrame->Eip--;
+
             if (--KdbNumSingleSteps > 0)
             {
                 if ((KdbSingleStepOver && !KdbpStepOverInstruction(TrapFrame->Eip)) ||
@@ -1609,6 +1612,11 @@ KdbEnterDebuggerException(
     OldEflags = __readeflags();
     _disable();
 
+    /* HACK: Save the current IRQL and pretend we are at passive level,
+     * although interrupts are off. Needed because KDBG calls pageable code. */
+    OldIrql = KeGetCurrentIrql();
+    KeLowerIrql(PASSIVE_LEVEL);
+
     /* Exception inside the debugger? Game over. */
     if (InterlockedIncrement(&KdbEntryCount) > 1)
     {
@@ -1648,6 +1656,9 @@ KdbEnterDebuggerException(
     /* Decrement the entry count */
     InterlockedDecrement(&KdbEntryCount);
 
+    /* HACK: Raise back to old IRWL */
+    KeRaiseIrql(OldIrql, &OldIrql);
+
     /* Leave critical section */
     __writeeflags(OldEflags);
 
@@ -1672,8 +1683,11 @@ continue_execution:
         /* Clear dr6 status flags. */
         TrapFrame->Dr6 &= ~0x0000e00f;
 
-        /* Skip the current instruction */
-        Context->Eip++;
+        if (!(KdbEnteredOnSingleStep && KdbSingleStepOver))
+        {
+            /* Skip the current instruction */
+            Context->Eip++;
+        }
     }
 
     return ContinueType;
@@ -1688,7 +1702,7 @@ KdbpGetCommandLineSettings(
 
     while (p1 && (p2 = strchr(p1, ' ')))
     {
-        p2++;
+        p2 += 2;
 
         if (!_strnicmp(p2, "KDSERIAL", 8))
         {
@@ -1701,6 +1715,11 @@ KdbpGetCommandLineSettings(
             p2 += 8;
             KdbDebugState |= KD_DEBUG_KDNOECHO;
         }
+        else if (!_strnicmp(p2, "FIRSTCHANCE", 11))
+        {
+            p2 += 11;
+            KdbpSetEnterCondition(-1, TRUE, KdbEnterAlways);
+        }
 
         p1 = p2;
     }