📄 kdapi.c
字号:
}
a->ActualBytesRead = AdditionalData->Length;
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
AdditionalData
);
UNREFERENCED_PARAMETER(Context);
}
VOID
KdpWriteVirtualMemory(
IN PDBGKD_MANIPULATE_STATE m,
IN PSTRING AdditionalData,
IN CONTEXT * Context
)
/*++
Routine Description:
This function is called in response of a write virtual memory
state manipulation message. Its function is to write virtual memory
and return.
Arguments:
m - Supplies the state manipulation message.
AdditionalData - Supplies any additional data for the message.
Context - Supplies the current context.
Return Value:
None.
--*/
{
PDBGKD_WRITE_MEMORY a = &m->u.WriteMemory;
ULONG Length;
STRING MessageHeader;
MessageHeader.Length = sizeof(*m);
MessageHeader.Buffer = (PCHAR)m;
Length = KdpMoveMemory(
a->TargetBaseAddress,
AdditionalData->Buffer,
AdditionalData->Length
);
if (Length == AdditionalData->Length) {
m->ReturnStatus = STATUS_SUCCESS;
} else {
m->ReturnStatus = STATUS_UNSUCCESSFUL;
}
a->ActualBytesWritten = Length;
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
NULL
);
UNREFERENCED_PARAMETER(Context);
}
VOID
KdpGetContext(
IN PDBGKD_MANIPULATE_STATE m,
IN PSTRING AdditionalData,
IN CONTEXT * Context
)
/*++
Routine Description:
This function is called in response of a get context state
manipulation message. Its function is to return the current
context.
Arguments:
m - Supplies the state manipulation message.
AdditionalData - Supplies any additional data for the message.
Context - Supplies the current context.
Return Value:
None.
--*/
{
STRING MessageHeader;
#if defined(SH3e) || defined(SH4)
DEBUG_REGISTERS DebugRegisters;
#endif
MessageHeader.Length = sizeof(*m);
MessageHeader.Buffer = (PCHAR)m;
KD_ASSERT(AdditionalData->Length == 0);
m->ReturnStatus = STATUS_SUCCESS;
AdditionalData->Length = sizeof(CONTEXT);
#if defined(SH3)
Context->DebugRegisters.BarA = READ_REGISTER_ULONG(UBCBarA);
Context->DebugRegisters.BasrA = READ_REGISTER_UCHAR(UBCBasrA);
Context->DebugRegisters.BamrA = READ_REGISTER_UCHAR(UBCBamrA);
Context->DebugRegisters.BbrA = READ_REGISTER_USHORT(UBCBbrA);
Context->DebugRegisters.BarB = READ_REGISTER_ULONG(UBCBarB);
Context->DebugRegisters.BasrB = READ_REGISTER_UCHAR(UBCBasrB);
Context->DebugRegisters.BamrB = READ_REGISTER_UCHAR(UBCBamrB);
Context->DebugRegisters.BbrB = READ_REGISTER_USHORT(UBCBbrB);
Context->DebugRegisters.BdrB = READ_REGISTER_ULONG(UBCBdrB);
Context->DebugRegisters.BdmrB = READ_REGISTER_ULONG(UBCBdmrB);
Context->DebugRegisters.Brcr = READ_REGISTER_USHORT(UBCBrcr);
Context->DebugRegisters.Align = 0;
#elif defined(SH3e) || defined(SH4)
DebugRegisters.BarA = READ_REGISTER_ULONG(UBCBarA);
DebugRegisters.BasrA = READ_REGISTER_UCHAR(UBCBasrA);
DebugRegisters.BamrA = READ_REGISTER_UCHAR(UBCBamrA);
DebugRegisters.BbrA = READ_REGISTER_USHORT(UBCBbrA);
DebugRegisters.BarB = READ_REGISTER_ULONG(UBCBarB);
DebugRegisters.BasrB = READ_REGISTER_UCHAR(UBCBasrB);
DebugRegisters.BamrB = READ_REGISTER_UCHAR(UBCBamrB);
DebugRegisters.BbrB = READ_REGISTER_USHORT(UBCBbrB);
DebugRegisters.BdrB = READ_REGISTER_ULONG(UBCBdrB);
DebugRegisters.BdmrB = READ_REGISTER_ULONG(UBCBdmrB);
DebugRegisters.Brcr = READ_REGISTER_USHORT(UBCBrcr);
DebugRegisters.Align = 0;
//
// Follow the context in the buffer with the debug register values.
//
AdditionalData->Length += sizeof(DEBUG_REGISTERS);
#endif
#if defined(SH4)
FPUFlushContext();
KdpQuickMoveMemory((PCHAR)&(Context->Psr), (PCHAR)&(pCurThread->ctx.Psr),sizeof(DWORD));
KdpQuickMoveMemory((PCHAR)&(Context->Fpscr), (PCHAR)&(pCurThread->ctx.Fpscr),sizeof(DWORD)*34);
#elif defined(MIPS_HAS_FPU)
// Get the floating point registers from the thread context
FPUFlushContext();
KdpQuickMoveMemory((PCHAR)&(Context->FltF0), (PCHAR)&(pCurThread->ctx.FltF0),sizeof(DWORD)*32);
#elif defined(x86)
if (g_CurFPUOwner)
{
KCall((LPVOID)FPUFlushContext,0,0,0);
Context->FloatSave = *(PTH_TO_FLTSAVEAREAPTR(pCurThread));
}
#endif
KdpQuickMoveMemory(AdditionalData->Buffer, (PCHAR)Context, sizeof(CONTEXT));
#if defined(SH3e) || defined(SH4)
KdpQuickMoveMemory(AdditionalData->Buffer + sizeof(CONTEXT),
(PCHAR)&DebugRegisters, sizeof(DEBUG_REGISTERS));
#endif
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
AdditionalData
);
}
VOID
KdpSetContext(
IN PDBGKD_MANIPULATE_STATE m,
IN PSTRING AdditionalData,
IN CONTEXT * Context
)
/*++
Routine Description:
This function is called in response of a set context state
manipulation message. Its function is set the current
context.
Arguments:
m - Supplies the state manipulation message.
AdditionalData - Supplies any additional data for the message.
Context - Supplies the current context.
Return Value:
None.
--*/
{
STRING MessageHeader;
#if defined(SH3e) || defined(SH4)
PDEBUG_REGISTERS DebugRegisters = (PDEBUG_REGISTERS)(AdditionalData->Buffer + sizeof(CONTEXT));
#endif
MessageHeader.Length = sizeof(*m);
MessageHeader.Buffer = (PCHAR)m;
#if defined(SH3e) || defined(SH4)
//
// Debug register values passed following the context
//
KD_ASSERT(AdditionalData->Length == sizeof(CONTEXT) + sizeof(DEBUG_REGISTERS));
#else
KD_ASSERT(AdditionalData->Length == sizeof(CONTEXT));
#endif
m->ReturnStatus = STATUS_SUCCESS;
KdpQuickMoveMemory((PCHAR)Context, AdditionalData->Buffer, sizeof(CONTEXT));
// copy the floating point registers into the thread context
#if defined(SH4)
FPUFlushContext();
KdpQuickMoveMemory((PCHAR)&(pCurThread->ctx.Fpscr),(PCHAR)&(Context->Fpscr), sizeof(DWORD)*34);
#elif defined(MIPS_HAS_FPU)
FPUFlushContext();
KdpQuickMoveMemory((PCHAR)&(pCurThread->ctx.FltF0),(PCHAR)&(Context->FltF0), sizeof(DWORD)*32);
#endif
/*
#if defined(SH3)
WRITE_REGISTER_ULONG(UBCBarA, Context->DebugRegisters.BarA);
WRITE_REGISTER_UCHAR(UBCBasrA, Context->DebugRegisters.BasrA);
WRITE_REGISTER_UCHAR(UBCBamrA, Context->DebugRegisters.BamrA);
WRITE_REGISTER_USHORT(UBCBbrA, Context->DebugRegisters.BbrA);
WRITE_REGISTER_ULONG(UBCBarB, Context->DebugRegisters.BarB);
WRITE_REGISTER_UCHAR(UBCBasrB, Context->DebugRegisters.BasrB);
WRITE_REGISTER_UCHAR(UBCBamrB, Context->DebugRegisters.BamrB);
WRITE_REGISTER_USHORT(UBCBbrB, Context->DebugRegisters.BbrB);
WRITE_REGISTER_ULONG(UBCBdrB, Context->DebugRegisters.BdrB);
WRITE_REGISTER_ULONG(UBCBdmrB, Context->DebugRegisters.BdmrB);
WRITE_REGISTER_USHORT(UBCBrcr, Context->DebugRegisters.Brcr);
#elif defined(SH3e) || defined(SH4)
WRITE_REGISTER_ULONG(UBCBarA, DebugRegisters->BarA);
WRITE_REGISTER_UCHAR(UBCBasrA, DebugRegisters->BasrA);
WRITE_REGISTER_UCHAR(UBCBamrA, DebugRegisters->BamrA);
WRITE_REGISTER_USHORT(UBCBbrA, DebugRegisters->BbrA);
WRITE_REGISTER_ULONG(UBCBarB, DebugRegisters->BarB);
WRITE_REGISTER_UCHAR(UBCBasrB, DebugRegisters->BasrB);
WRITE_REGISTER_UCHAR(UBCBamrB, DebugRegisters->BamrB);
WRITE_REGISTER_USHORT(UBCBbrB, DebugRegisters->BbrB);
WRITE_REGISTER_ULONG(UBCBdrB, DebugRegisters->BdrB);
WRITE_REGISTER_ULONG(UBCBdmrB, DebugRegisters->BdmrB);
WRITE_REGISTER_USHORT(UBCBrcr, DebugRegisters->Brcr);
#endif
*/
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
NULL
);
}
VOID
KdpWriteBreakpoint(
IN PDBGKD_MANIPULATE_STATE m,
IN PSTRING AdditionalData,
IN CONTEXT * Context
)
/*++
Routine Description:
This function is called in response of a write breakpoint state
manipulation message. Its function is to write a breakpoint
and return a handle to the breakpoint.
Arguments:
m - Supplies the state manipulation message.
AdditionalData - Supplies any additional data for the message.
Context - Supplies the current context.
Return Value:
None.
--*/
{
PDBGKD_WRITE_BREAKPOINT a = &m->u.WriteBreakPoint;
STRING MessageHeader;
MessageHeader.Length = sizeof(*m);
MessageHeader.Buffer = (PCHAR)m;
KD_ASSERT(AdditionalData->Length == 0);
a->BreakPointHandle = KdpAddBreakpoint(a->BreakPointAddress);
DEBUGGERMSG(KDZONE_API,(L"Handle returned is %8.8lx for address %8.8lx\r\n",a->BreakPointHandle, a->BreakPointAddress));
if (a->BreakPointHandle != 0) {
m->ReturnStatus = STATUS_SUCCESS;
} else {
m->ReturnStatus = STATUS_UNSUCCESSFUL;
}
#ifndef SPEED_HACK
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
NULL
);
#endif
UNREFERENCED_PARAMETER(Context);
}
VOID
KdpRestoreBreakpoint(
IN PDBGKD_MANIPULATE_STATE m,
IN PSTRING AdditionalData,
IN CONTEXT * Context
)
/*++
Routine Description:
This function is called in response of a restore breakpoint state
manipulation message. Its function is to restore a breakpoint
using the specified handle.
Arguments:
m - Supplies the state manipulation message.
AdditionalData - Supplies any additional data for the message.
Context - Supplies the current context.
Return Value:
None.
--*/
{
PDBGKD_RESTORE_BREAKPOINT a = &m->u.RestoreBreakPoint;
STRING MessageHeader;
MessageHeader.Length = sizeof(*m);
MessageHeader.Buffer = (PCHAR)m;
KD_ASSERT(AdditionalData->Length == 0);
if (KdpDeleteBreakpoint(a->BreakPointHandle)) {
m->ReturnStatus = STATUS_SUCCESS;
} else {
m->ReturnStatus = STATUS_UNSUCCESSFUL;
}
#ifndef SPEED_HACK
KdpSendPacket(
PACKET_TYPE_KD_STATE_MANIPULATE,
&MessageHeader,
NULL
);
#endif
UNREFERENCED_PARAMETER(Context);
}
BOOLEAN
KdpReportExceptionStateChange (
IN PEXCEPTION_RECORD ExceptionRecord,
IN OUT CONTEXT * ContextRecord,
IN BOOLEAN SecondChance
)
/*++
Routine Description:
This routine sends an exception state change packet to the kernel
debugger and waits for a manipulate state message.
Arguments:
ExceptionRecord - Supplies a pointer to an exception record.
ContextRecord - Supplies a pointer to a context record.
SecondChance - Supplies a boolean value that determines whether this is
the first or second chance for the exception.
Return Value:
A value of TRUE is returned if the exception is handled. Otherwise, a
value of FALSE is returned.
--*/
{
STRING MessageData;
STRING MessageHeader;
DBGKD_WAIT_STATE_CHANGE WaitStateChange;
KCONTINUE_STATUS Status;
do {
//
// Construct the wait state change message and message descriptor.
//
KdpSetStateChange(&WaitStateChange,
ExceptionRecord,
ContextRecord,
SecondChance
);
MessageHeader.Length = sizeof(DBGKD_WAIT_STATE_CHANGE);
MessageHeader.Buffer = (PCHAR)&WaitStateChange;
MessageData.Length = 0;
//
// Send packet to the kernel debugger on the host machine,
// wait for answer.
//
Status = KdpSendWaitContinue(
PACKET_TYPE_KD_STATE_CHANGE,
&MessageHeader,
&MessageData,
ContextRecord
);
} while (Status == ContinueProcessorReselected) ;
return (BOOLEAN) Status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -