- Implement KdpSetContext.

- Fix KdpReport, it was totally out of whack.

svn path=/branches/alex-kd-branch/; revision=25853
This commit is contained in:
Alex Ionescu 2007-02-20 03:45:11 +00:00
parent 3006d54080
commit bf616180df
3 changed files with 103 additions and 63 deletions

View file

@ -121,9 +121,6 @@ KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
&KdpContext); &KdpContext);
} }
BOOLEAN VirtCalled = FALSE;
VOID VOID
NTAPI NTAPI
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State, KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
@ -326,6 +323,54 @@ KdpGetContext(IN PDBGKD_MANIPULATE_STATE64 State,
&KdpContext); &KdpContext);
} }
VOID
NTAPI
KdpSetContext(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PVOID ControlStart;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Make sure that this is a valid request */
if (State->Processor < KeNumberProcessors)
{
/* Check if the request is for this CPU */
if (State->Processor == KeGetCurrentPrcb()->Number)
{
/* We're just copying our own context */
ControlStart = Context;
}
else
{
/* SMP not yet handled */
ControlStart = NULL;
while (TRUE);
}
/* Copy the memory */
RtlCopyMemory(ControlStart, Data->Buffer, sizeof(CONTEXT));
/* Finish up */
State->ReturnStatus = STATUS_SUCCESS;
}
else
{
/* Invalid request */
State->ReturnStatus = STATUS_UNSUCCESSFUL;
}
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
Data,
&KdpContext);
}
KCONTINUE_STATUS KCONTINUE_STATUS
NTAPI NTAPI
@ -377,7 +422,6 @@ SendPacket:
/* Read virtual memory */ /* Read virtual memory */
KdpReadVirtualMemory(&ManipulateState, &Data, Context); KdpReadVirtualMemory(&ManipulateState, &Data, Context);
VirtCalled = TRUE;
break; break;
case DbgKdWriteVirtualMemoryApi: case DbgKdWriteVirtualMemoryApi:
@ -389,15 +433,14 @@ SendPacket:
case DbgKdGetContextApi: case DbgKdGetContextApi:
/* FIXME: TODO */ /* Get the current context */
KdpGetContext(&ManipulateState, &Data, Context); KdpGetContext(&ManipulateState, &Data, Context);
break; break;
case DbgKdSetContextApi: case DbgKdSetContextApi:
/* FIXME: TODO */ /* Set a new context */
Ke386SetCr2(DbgKdSetContextApi); KdpSetContext(&ManipulateState, &Data, Context);
while (TRUE);
break; break;
case DbgKdWriteBreakPointApi: case DbgKdWriteBreakPointApi:

View file

@ -248,6 +248,7 @@ KdInitSystem(IN ULONG BootPhase,
/* Check for incoming breakin and break on symbol load if we have it*/ /* Check for incoming breakin and break on symbol load if we have it*/
KdBreakAfterSymbolLoad = KdPollBreakIn(); KdBreakAfterSymbolLoad = KdPollBreakIn();
while (TRUE);
} }
else else
{ {

View file

@ -25,68 +25,64 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
{ {
BOOLEAN Entered, Status; BOOLEAN Entered, Status;
PKPRCB Prcb; PKPRCB Prcb;
while (TRUE); NTSTATUS ExceptionCode = ExceptionRecord->ExceptionCode;
/* /* Check if this is INT1 or 3, or if we're forced to handle it */
* Only go ahead with this if this is an INT3 or an INT1, or if the global if ((ExceptionCode == STATUS_BREAKPOINT) ||
* flag forces us to call up the debugger on exception, or if this is a (ExceptionCode == STATUS_SINGLE_STEP) ||
* second chance exception which means it hasn't been handled by now. //(ExceptionCode == STATUS_ASSERTION_FAILURE) ||
*/ (NtGlobalFlag & FLG_STOP_ON_EXCEPTION))
if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) ||
(ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP) ||
(NtGlobalFlag & FLG_STOP_ON_EXCEPTION) ||
(SecondChanceException))
{ {
/* /* Check if we can't really handle this */
* Also, unless this is a second chance exception, then do not call up if ((SecondChanceException) ||
* the debugger if the debug port is disconnected or the exception code (ExceptionCode == STATUS_PORT_DISCONNECTED) ||
* indicates success. (NT_SUCCESS(ExceptionCode)))
*/
if (!(SecondChanceException) &&
((ExceptionRecord->ExceptionCode == STATUS_PORT_DISCONNECTED) ||
(NT_SUCCESS(ExceptionRecord->ExceptionCode))))
{ {
/* Return false to hide the exception */ /* Return false to have someone else take care of the exception */
return FALSE; return FALSE;
} }
}
/* Enter the debugger */ else if (SecondChanceException)
Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); {
/* We won't bother unless this is second chance */
/* return FALSE;
* Get the KPRCB and save the CPU Control State manually instead of
* using KiSaveProcessorState, since we already have a valid CONTEXT.
*/
Prcb = KeGetCurrentPrcb();
KiSaveProcessorControlState(&Prcb->ProcessorState);
RtlCopyMemory(&Prcb->ProcessorState.ContextFrame,
ContextRecord,
sizeof(CONTEXT));
/* Report the new state */
#if 0
Status = KdpReportExceptionStateChange(ExceptionRecord,
&Prcb->ProcessorState.
ContextFrame,
SecondChanceException);
#else
Status = FALSE;
#endif
/* Now restore the processor state, manually again. */
RtlCopyMemory(ContextRecord,
&Prcb->ProcessorState.ContextFrame,
sizeof(CONTEXT));
KiRestoreProcessorControlState(&Prcb->ProcessorState);
/* Exit the debugger and clear the CTRL-C state */
KdExitDebugger(Entered);
KdpControlCPressed = FALSE;
return Status;
} }
/* Fail if we got here */ /* Enter the debugger */
return FALSE; while (TRUE);
Entered = KdEnterDebugger(TrapFrame, ExceptionFrame);
/*
* Get the KPRCB and save the CPU Control State manually instead of
* using KiSaveProcessorState, since we already have a valid CONTEXT.
*/
Prcb = KeGetCurrentPrcb();
KiSaveProcessorControlState(&Prcb->ProcessorState);
RtlCopyMemory(&Prcb->ProcessorState.ContextFrame,
ContextRecord,
sizeof(CONTEXT));
/* Report the new state */
#if 0
Status = KdpReportExceptionStateChange(ExceptionRecord,
&Prcb->ProcessorState.
ContextFrame,
SecondChanceException);
#else
while (TRUE);
Status = FALSE;
#endif
/* Now restore the processor state, manually again. */
RtlCopyMemory(ContextRecord,
&Prcb->ProcessorState.ContextFrame,
sizeof(CONTEXT));
KiRestoreProcessorControlState(&Prcb->ProcessorState);
/* Exit the debugger and clear the CTRL-C state */
KdExitDebugger(Entered);
KdpControlCPressed = FALSE;
return Status;
} }
BOOLEAN BOOLEAN