Author: ion Date: Mon Mar 5 20:09:44 2007 New Revision: 26004
URL: http://svn.reactos.org/svn/reactos?rev=26004&view=rev Log: - Implement simple breakpoints (KdWriteBreakPointApi, KdpWriteBreakpoint, KdpAddBreakpoint). - 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 :)
Modified: trunk/reactos/ntoskrnl/include/internal/kd64.h trunk/reactos/ntoskrnl/kd64/kdapi.c trunk/reactos/ntoskrnl/kd64/kdbreak.c
Modified: trunk/reactos/ntoskrnl/include/internal/kd64.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/kd64.h (original) +++ trunk/reactos/ntoskrnl/include/internal/kd64.h Mon Mar 5 20:09:44 2007 @@ -226,6 +226,12 @@ KdpDeleteBreakpointRange( IN PVOID Base, IN PVOID Limit +); + +ULONG +NTAPI +KdpAddBreakpoint( + IN PVOID Address );
//
Modified: trunk/reactos/ntoskrnl/kd64/kdapi.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd64/kdapi.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/kd64/kdapi.c (original) +++ trunk/reactos/ntoskrnl/kd64/kdapi.c Mon Mar 5 20:09:44 2007 @@ -16,6 +16,37 @@
VOID NTAPI +KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, + IN PSTRING Data, + IN PCONTEXT Context) +{ + PDBGKD_WRITE_BREAKPOINT64 Breakpoint = &State->u.WriteBreakPoint; + STRING Header; + NTSTATUS Status; + + /* Build header */ + Header.Length = sizeof(DBGKD_MANIPULATE_STATE64); + Header.Buffer = (PCHAR)State; + ASSERT(Data->Length == 0); + + /* Create the breakpoint */ + Breakpoint->BreakPointHandle = + KdpAddBreakpoint((PVOID)(LONG_PTR)Breakpoint->BreakPointAddress); + if (!Breakpoint->BreakPointHandle) + { + /* We failed */ + Status = STATUS_UNSUCCESSFUL; + } + + /* Send the packet */ + KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE, + &Header, + NULL, + &KdpContext); +} + +VOID +NTAPI DumpTraceData(IN PSTRING TraceData) { /* Update the buffer */ @@ -545,9 +576,8 @@
case DbgKdWriteBreakPointApi:
- /* FIXME: TODO */ - Ke386SetCr2(DbgKdWriteBreakPointApi); - while (TRUE); + /* Write the breakpoint */ + KdpWriteBreakpoint(&ManipulateState, &Data, Context); break;
case DbgKdRestoreBreakPointApi:
Modified: trunk/reactos/ntoskrnl/kd64/kdbreak.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd64/kdbreak.c?rev... ============================================================================== --- trunk/reactos/ntoskrnl/kd64/kdbreak.c (original) +++ trunk/reactos/ntoskrnl/kd64/kdbreak.c Mon Mar 5 20:09:44 2007 @@ -13,6 +13,54 @@ #include <debug.h>
/* FUNCTIONS *****************************************************************/ + +ULONG +NTAPI +KdpAddBreakpoint(IN PVOID Address) +{ + UCHAR Content; + ULONG i; + + /* Loop current breakpoints */ + for (i = 0; i < 20; i++) + { + /* Check if the breakpoint is valid */ + if ((KdpBreakpointTable[i].Flags & KdpBreakpointActive) && + (KdpBreakpointTable[i].Address == Address)) + { + /* Check if it's pending */ + if ((KdpBreakpointTable[i].Flags & KdpBreakpointPending)) + { + /* It's not pending anymore now */ + KdpBreakpointTable[i].Flags &= ~KdpBreakpointPending; + return i + 1; + } + else + { + /* Fail */ + return 0; + } + } + } + + /* Find a free entry */ + for (i = 0; i < 20; i++) if (!(KdpBreakpointTable[i].Flags)) break; + + /* Fail if no free entry was found */ + if (i == 20) return 0; + + /* Save the old instruction */ + RtlCopyMemory(&Content, Address, sizeof(UCHAR)); + + /* Write the entry */ + KdpBreakpointTable[i].Address = Address; + KdpBreakpointTable[i].Content = Content; + KdpBreakpointTable[i].Flags = KdpBreakpointActive; + + /* Write the INT3 and return the handle */ + RtlCopyMemory(Address, &KdpBreakpointInstruction, sizeof(UCHAR)); + return i + 1; +}
BOOLEAN NTAPI