📄 kdbreak.c
字号:
DEBUGGERMSG(KDZONE_BREAK,(L"Successfully Set BP Handle %x %8.8lx\r\n",
Handle - 1, KAddress));
} else {
DEBUGGERMSG(KDZONE_BREAK,(L"Failed to Set BP Handle %x %8.8lx\r\n",
Handle - 1, KAddress));
}
}
} else {
//
// Breakpoint is not accessible
//
DEBUGGERMSG(KDZONE_BREAK, (L"Address not accessible\r\n"));
return 0;
}
}
DEBUGGERMSG(KDZONE_BREAK, (L"Exit Add BP\r\n"));
return Handle;
}
BOOLEAN
KdpDeleteBreakpoint(IN ULONG Handle)
/*++
Routine Description:
This routine deletes an entry from the breakpoint table.
Arguments:
Handle - Supplies the index plus one of the breakpoint table entry
which is to be deleted.
Return Value:
A value of FALSE is returned if the specified handle is not a valid
value or the breakpoint cannot be deleted because the old instruction
cannot be replaced. Otherwise, a value of TRUE is returned.
--*/
{
KDP_BREAKPOINT_TYPE KdpBreakpointInstruction = KDP_BREAKPOINT_VALUE;
ULONG Length = sizeof(KDP_BREAKPOINT_TYPE);
#if 0
int Index;
//jvp
NKOtherPrintfW(L"Del, Before\r\n");
for (Index = 0; Index < 3; Index += 1) {
NKOtherPrintfW(L"table[%i].flags = %i, Addr = %x, KAddr = %x, Content = %x\r\n",
Index,
KdpBreakpointTable[Index].Flags,
KdpBreakpointTable[Index].Address,
KdpBreakpointTable[Index].KAddress,
KdpBreakpointTable[Index].Content);
}
#endif
//
// If the specified handle is not valid, then return FALSE.
//
if ((Handle == 0) || (Handle > BREAKPOINT_TABLE_SIZE)) {
DEBUGGERMSG(KDZONE_BREAK,(L"BP not a valid value %d\r\n", Handle));
return FALSE;
}
Handle -= 1;
DEBUGGERMSG(KDZONE_BREAK,(L"Removing BP Handle %d\r\n", Handle));
//
// If the specified breakpoint table is not valid, the return FALSE.
//
if (KdpBreakpointTable[Handle].Flags == 0) {
DEBUGGERMSG(KDZONE_BREAK,(L"BP Handle already removed\r\n"));
return FALSE;
}
#if defined(THUMBSUPPORT)
//
// Determine the breakpoint instruction and size
//
if (KdpBreakpointTable[Handle].Flags & KD_BREAKPOINT_16BIT) {
Length = sizeof(KDP_BREAKPOINT_16BIT_TYPE);
KdpBreakpointInstruction = KDP_BREAKPOINT_16BIT_VALUE;
}
#endif
//
// If the breakpoint is suspended, just delete from the table
//
if (KdpBreakpointTable[Handle].Flags & KD_BREAKPOINT_SUSPENDED) {
KdpBreakpointTable[Handle].Flags = 0;
DEBUGGERMSG(KDZONE_BREAK,(L"BP Suspended, this should never happen\r\n"));
return TRUE;
}
//
// Replace the instruction contents.
//
if ((KdpBreakpointTable[Handle].Flags & KD_BREAKPOINT_IN_USE) &&
(KdpBreakpointTable[Handle].Content == KdpBreakpointInstruction)) {
DEBUGGERMSG(KDZONE_BREAK, (L"BP in USE and replacing BP %8.8lx\r\n",
KdpBreakpointTable[Handle].Address));
}
if (KdpBreakpointTable[Handle].Address != NULL) {
if (KdpMoveMemory(
(PCHAR)KdpBreakpointTable[Handle].Address,
(PCHAR)&KdpBreakpointTable[Handle].Content,
Length) == Length) {
DEBUGGERMSG(KDZONE_BREAK, (L"Successfully restored BP %8.8lx\r\n",
KdpBreakpointTable[Handle].Address));
} else {
DEBUGGERMSG(KDZONE_BREAK, (L"Failed to restore BP %8.8lx\r\n",
KdpBreakpointTable[Handle].Address));
}
}
if (KdpBreakpointTable[Handle].KAddress != NULL) {
if (KdpMoveMemory(
(PCHAR)KdpBreakpointTable[Handle].KAddress,
(PCHAR)&KdpBreakpointTable[Handle].Content,
Length) == Length) {
DEBUGGERMSG(KDZONE_BREAK, (L"Successfully restored BP %8.8lx %8.8lx\r\n",
(PCHAR)&KdpBreakpointTable[Handle].Content,
KdpBreakpointTable[Handle].KAddress));
} else {
DEBUGGERMSG(KDZONE_BREAK, (L"Failed to restore BP %8.8lx\r\n", KdpBreakpointTable[Handle].KAddress));
}
}
// Release lock on memory.
// if (KdpBreakpointTable[Handle].Address != NULL)
// DbgVerify((PCHAR)KdpBreakpointTable[Handle].Address, DV_CLEARBP);
if (KdpBreakpointTable[Handle].KAddress != NULL)
DbgVerify((PCHAR)KdpBreakpointTable[Handle].KAddress, DV_CLEARBP);
//
// Delete breakpoint table entry and return TRUE.
//
KdpBreakpointTable[Handle].Flags = 0;
KdpBreakpointTable[Handle].Content = 0;
KdpBreakpointTable[Handle].Address = NULL;
KdpBreakpointTable[Handle].KAddress = NULL;
//jvp
#if 0
NKOtherPrintfW(L"Del, After\r\n");
for (Index = 0; Index < 3; Index += 1) {
NKOtherPrintfW(L"table[%i].flags = %i, Addr = %x, KAddr = %x, Content = %x\r\n",
Index,
KdpBreakpointTable[Index].Flags,
KdpBreakpointTable[Index].Address,
KdpBreakpointTable[Index].KAddress,
KdpBreakpointTable[Index].Content);
}
#endif
DEBUGGERMSG(KDZONE_BREAK, (L"Exit Del BP\r\n"));
return TRUE;
}
BOOLEAN
KdpDeleteBreakpointRange (
IN PVOID Lower,
IN PVOID Upper
)
/*++
Routine Description:
This routine deletes all breakpoints falling in a given range
from the breakpoint table.
Arguments:
Lower - inclusive lower address of range from which to remove BPs.
Upper - include upper address of range from which to remove BPs.
Return Value:
TRUE if any breakpoints removed, FALSE otherwise.
--*/
{
KDP_BREAKPOINT_TYPE KdpBreakpointInstruction = KDP_BREAKPOINT_VALUE;
ULONG Length = sizeof(KDP_BREAKPOINT_TYPE);
ULONG Index;
BOOLEAN ReturnStatus = FALSE;
//
// Examine each entry in the table in turn
//
for (Index = 0; Index < BREAKPOINT_TABLE_SIZE; Index++) {
if ( ((KdpBreakpointTable[Index].Flags & KD_BREAKPOINT_IN_USE) &&
((KdpBreakpointTable[Index].Address >= Lower) &&
(KdpBreakpointTable[Index].Address <= Upper))) ||
( KdpBreakpointTable[Index].KAddress != NULL &&
((KdpBreakpointTable[Index].Flags & KD_BREAKPOINT_IN_USE) &&
((KdpBreakpointTable[Index].KAddress >= Lower) &&
(KdpBreakpointTable[Index].KAddress <= Upper))))
) {
//
// Breakpoint is in use and falls in range, clear it.
//
#if defined(THUMBSUPPORT)
if (KdpBreakpointTable[Index].Flags & KD_BREAKPOINT_16BIT) {
KdpBreakpointInstruction = KDP_BREAKPOINT_16BIT_VALUE;
Length = sizeof(KDP_BREAKPOINT_16BIT_TYPE);
}
#endif
if (KdpBreakpointTable[Index].Content != KdpBreakpointInstruction) {
if (KdpBreakpointTable[Index].Address != NULL)
KdpMoveMemory(
(PCHAR)KdpBreakpointTable[Index].Address,
(PCHAR)&KdpBreakpointTable[Index].Content,
Length
);
if (KdpBreakpointTable[Index].KAddress != NULL)
KdpMoveMemory(
(PCHAR)KdpBreakpointTable[Index].KAddress,
(PCHAR)&KdpBreakpointTable[Index].Content,
Length
);
// Release lock on memory.
// if (KdpBreakpointTable[Index].Address != NULL)
// DbgVerify((PCHAR)KdpBreakpointTable[Index].Address, DV_CLEARBP);
if (KdpBreakpointTable[Index].KAddress != NULL)
DbgVerify((PCHAR)KdpBreakpointTable[Index].KAddress, DV_CLEARBP);
}
KdpBreakpointTable[Index].Flags = 0;
ReturnStatus = TRUE;
}
}
return ReturnStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -