- Implement simple breakpoints (KdWriteBreakPointApi, KdpWriteBreakpoint, KdpAddBreak...
authorAlex Ionescu <aionescu@gmail.com>
Mon, 5 Mar 2007 17:09:44 +0000 (17:09 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Mon, 5 Mar 2007 17:09:44 +0000 (17:09 +0000)
- Stepping out with WinDBG now works, but not adding breakpoints (that's KdWriteBreakpointExApi, coming up soon).
- This was supposed to be 26000 but oh well, back porting features to a locked branch seems to have won out :)

svn path=/trunk/; revision=26004

reactos/ntoskrnl/include/internal/kd64.h
reactos/ntoskrnl/kd64/kdapi.c
reactos/ntoskrnl/kd64/kdbreak.c

index fe849dc..6387e6f 100644 (file)
@@ -228,6 +228,12 @@ KdpDeleteBreakpointRange(
     IN PVOID Limit\r
 );\r
 \r
+ULONG\r
+NTAPI\r
+KdpAddBreakpoint(\r
+    IN PVOID Address\r
+);\r
+\r
 //\r
 // Global KD Data\r
 //\r
index 2307dda..5e5c044 100644 (file)
 \r
 /* PRIVATE FUNCTIONS *********************************************************/\r
 \r
+VOID\r
+NTAPI\r
+KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                   IN PSTRING Data,\r
+                   IN PCONTEXT Context)\r
+{\r
+    PDBGKD_WRITE_BREAKPOINT64 Breakpoint = &State->u.WriteBreakPoint;\r
+    STRING Header;\r
+    NTSTATUS Status;\r
+\r
+    /* Build header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Create the breakpoint */\r
+    Breakpoint->BreakPointHandle =\r
+        KdpAddBreakpoint((PVOID)(LONG_PTR)Breakpoint->BreakPointAddress);\r
+    if (!Breakpoint->BreakPointHandle)\r
+    {\r
+        /* We failed */\r
+        Status = STATUS_UNSUCCESSFUL;\r
+    }\r
+\r
+    /* Send the packet */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
 VOID\r
 NTAPI\r
 DumpTraceData(IN PSTRING TraceData)\r
@@ -545,9 +576,8 @@ SendPacket:
 \r
             case DbgKdWriteBreakPointApi:\r
 \r
-                /* FIXME: TODO */\r
-                Ke386SetCr2(DbgKdWriteBreakPointApi);\r
-                while (TRUE);\r
+                /* Write the breakpoint */\r
+                KdpWriteBreakpoint(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdRestoreBreakPointApi:\r
index 4b9b9af..31c8b68 100644 (file)
 \r
 /* FUNCTIONS *****************************************************************/\r
 \r
+ULONG\r
+NTAPI\r
+KdpAddBreakpoint(IN PVOID Address)\r
+{\r
+    UCHAR Content;\r
+    ULONG i;\r
+\r
+    /* Loop current breakpoints */\r
+    for (i = 0; i < 20; i++)\r
+    {\r
+        /* Check if the breakpoint is valid */\r
+        if ((KdpBreakpointTable[i].Flags & KdpBreakpointActive) &&\r
+            (KdpBreakpointTable[i].Address == Address))\r
+        {\r
+            /* Check if it's pending */\r
+            if ((KdpBreakpointTable[i].Flags & KdpBreakpointPending))\r
+            {\r
+                /* It's not pending anymore now */\r
+                KdpBreakpointTable[i].Flags &= ~KdpBreakpointPending;\r
+                return i + 1;\r
+            }\r
+            else\r
+            {\r
+                /* Fail */\r
+                return 0;\r
+            }\r
+        }\r
+    }\r
+\r
+    /* Find a free entry */\r
+    for (i = 0; i < 20; i++) if (!(KdpBreakpointTable[i].Flags)) break;\r
+\r
+    /* Fail if no free entry was found */\r
+    if (i == 20) return 0;\r
+\r
+    /* Save the old instruction */\r
+    RtlCopyMemory(&Content, Address, sizeof(UCHAR));\r
+\r
+    /* Write the entry */\r
+    KdpBreakpointTable[i].Address = Address;\r
+    KdpBreakpointTable[i].Content = Content;\r
+    KdpBreakpointTable[i].Flags = KdpBreakpointActive;\r
+\r
+    /* Write the INT3 and return the handle */\r
+    RtlCopyMemory(Address, &KdpBreakpointInstruction, sizeof(UCHAR));\r
+    return i + 1;\r
+}\r
+\r
 BOOLEAN\r
 NTAPI\r
 KdpLowWriteContent(IN ULONG BpIndex)\r