Attach to correct process before messing around with its memory

svn path=/trunk/; revision=18458
This commit is contained in:
Gé van Geldorp 2005-10-14 20:19:23 +00:00
parent 541ca90657
commit 30a546e327

View file

@ -829,7 +829,7 @@ GspQuery(PCHAR Request)
char Buffer[64]; char Buffer[64];
PEPROCESS Proc; PEPROCESS Proc;
Proc = (PEPROCESS) ThreadInfo->Tcb.ApcState.Process; Proc = (PEPROCESS) ThreadInfo->ThreadsProcess;
Buffer[0] = '\0'; Buffer[0] = '\0';
if (NULL != Proc ) if (NULL != Proc )
@ -1104,7 +1104,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
/* reply to host that an exception has occurred */ /* reply to host that an exception has occurred */
SigVal = GspComputeSignal(ExceptionRecord->ExceptionCode); SigVal = GspComputeSignal(ExceptionRecord->ExceptionCode);
ptr = &GspOutBuffer[0]; ptr = GspOutBuffer;
*ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */
*ptr++ = HexChars[(SigVal >> 4) & 0xf]; *ptr++ = HexChars[(SigVal >> 4) & 0xf];
@ -1213,9 +1213,21 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
*(ptr++) == ',' && *(ptr++) == ',' &&
GspHex2Long(&ptr, &Length)) GspHex2Long(&ptr, &Length))
{ {
ptr = 0; PEPROCESS DbgProcess = NULL;
ptr = NULL;
if (NULL != GspDbgThread &&
PsGetCurrentProcess() != GspDbgThread->ThreadsProcess)
{
DbgProcess = GspDbgThread->ThreadsProcess;
KeAttachProcess(&DbgProcess->Pcb);
}
GspMemoryError = FALSE; GspMemoryError = FALSE;
GspMem2Hex((PCHAR) Address, GspOutBuffer, Length, 1); GspMem2Hex((PCHAR) Address, GspOutBuffer, Length, 1);
if (NULL != DbgProcess)
{
KeDetachProcess();
}
if (GspMemoryError) if (GspMemoryError)
{ {
strcpy(GspOutBuffer, "E03"); strcpy(GspOutBuffer, "E03");
@ -1223,7 +1235,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
} }
} }
if (ptr) if (NULL != ptr)
{ {
strcpy(GspOutBuffer, "E01"); strcpy(GspOutBuffer, "E01");
} }
@ -1238,9 +1250,21 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
GspHex2Long(&ptr, &Length) && GspHex2Long(&ptr, &Length) &&
*(ptr++) == ':') *(ptr++) == ':')
{ {
PEPROCESS DbgProcess = NULL;
ptr = NULL;
if (NULL != GspDbgThread &&
PsGetCurrentProcess() != GspDbgThread->ThreadsProcess)
{
DbgProcess = GspDbgThread->ThreadsProcess;
KeAttachProcess(&DbgProcess->Pcb);
}
GspMemoryError = FALSE; GspMemoryError = FALSE;
GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE); GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE);
if (NULL != DbgProcess)
{
KeDetachProcess();
}
if (GspMemoryError) if (GspMemoryError)
{ {
strcpy(GspOutBuffer, "E03"); strcpy(GspOutBuffer, "E03");
@ -1250,8 +1274,6 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
{ {
strcpy(GspOutBuffer, "OK"); strcpy(GspOutBuffer, "OK");
} }
ptr = NULL;
} }
} }