- 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);
}
BOOLEAN VirtCalled = FALSE;
VOID
NTAPI
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
@ -326,6 +323,54 @@ KdpGetContext(IN PDBGKD_MANIPULATE_STATE64 State,
&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
NTAPI
@ -377,7 +422,6 @@ SendPacket:
/* Read virtual memory */
KdpReadVirtualMemory(&ManipulateState, &Data, Context);
VirtCalled = TRUE;
break;
case DbgKdWriteVirtualMemoryApi:
@ -389,15 +433,14 @@ SendPacket:
case DbgKdGetContextApi:
/* FIXME: TODO */
/* Get the current context */
KdpGetContext(&ManipulateState, &Data, Context);
break;
case DbgKdSetContextApi:
/* FIXME: TODO */
Ke386SetCr2(DbgKdSetContextApi);
while (TRUE);
/* Set a new context */
KdpSetContext(&ManipulateState, &Data, Context);
break;
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*/
KdBreakAfterSymbolLoad = KdPollBreakIn();
while (TRUE);
}
else
{

View file

@ -25,68 +25,64 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
{
BOOLEAN Entered, Status;
PKPRCB Prcb;
while (TRUE);
NTSTATUS ExceptionCode = ExceptionRecord->ExceptionCode;
/*
* Only go ahead with this if this is an INT3 or an INT1, or if the global
* flag forces us to call up the debugger on exception, or if this is a
* second chance exception which means it hasn't been handled by now.
*/
if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) ||
(ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP) ||
(NtGlobalFlag & FLG_STOP_ON_EXCEPTION) ||
(SecondChanceException))
/* Check if this is INT1 or 3, or if we're forced to handle it */
if ((ExceptionCode == STATUS_BREAKPOINT) ||
(ExceptionCode == STATUS_SINGLE_STEP) ||
//(ExceptionCode == STATUS_ASSERTION_FAILURE) ||
(NtGlobalFlag & FLG_STOP_ON_EXCEPTION))
{
/*
* Also, unless this is a second chance exception, then do not call up
* the debugger if the debug port is disconnected or the exception code
* indicates success.
*/
if (!(SecondChanceException) &&
((ExceptionRecord->ExceptionCode == STATUS_PORT_DISCONNECTED) ||
(NT_SUCCESS(ExceptionRecord->ExceptionCode))))
/* Check if we can't really handle this */
if ((SecondChanceException) ||
(ExceptionCode == STATUS_PORT_DISCONNECTED) ||
(NT_SUCCESS(ExceptionCode)))
{
/* Return false to hide the exception */
/* Return false to have someone else take care of the exception */
return FALSE;
}
/* Enter the debugger */
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
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;
}
else if (SecondChanceException)
{
/* We won't bother unless this is second chance */
return FALSE;
}
/* Fail if we got here */
return FALSE;
/* Enter the debugger */
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