mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 14:25:52 +00:00
[FORMATTING]
svn path=/trunk/; revision=41537
This commit is contained in:
parent
1fcd100e50
commit
d103f7f548
1 changed files with 935 additions and 1016 deletions
|
@ -33,7 +33,7 @@
|
|||
static BOOLEAN GspInitialized;
|
||||
static BOOLEAN GspRemoteDebug;
|
||||
|
||||
static CONST CHAR HexChars[]="0123456789abcdef";
|
||||
static CONST CHAR HexChars[] = "0123456789abcdef";
|
||||
|
||||
static PETHREAD GspRunThread; /* NULL means run all threads */
|
||||
static PETHREAD GspDbgThread;
|
||||
|
@ -55,8 +55,8 @@ static CHAR GspOutBuffer[1000];
|
|||
enum REGISTER_NAMES
|
||||
{
|
||||
EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
|
||||
PC /* also known as eip */,
|
||||
PS /* also known as eflags */,
|
||||
PC /* also known as eip */ ,
|
||||
PS /* also known as eflags */ ,
|
||||
CS, SS, DS, ES, FS, GS
|
||||
};
|
||||
|
||||
|
@ -74,7 +74,7 @@ static CPU_REGISTER GspRegisters[NUMREGS] =
|
|||
{ 4, FIELD_OFFSET(KTRAP_FRAME, Ecx), FIELD_OFFSET(CONTEXT, Ecx), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, Edx), FIELD_OFFSET(CONTEXT, Edx), FALSE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, Ebx), FIELD_OFFSET(CONTEXT, Ebx), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp ), FIELD_OFFSET(CONTEXT, Esp), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp), FIELD_OFFSET(CONTEXT, Esp), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, DbgEbp), FIELD_OFFSET(CONTEXT, Ebp), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, Esi), FIELD_OFFSET(CONTEXT, Esi), TRUE },
|
||||
{ 4, FIELD_OFFSET(KTRAP_FRAME, Edi), FIELD_OFFSET(CONTEXT, Edi), TRUE },
|
||||
|
@ -88,7 +88,7 @@ static CPU_REGISTER GspRegisters[NUMREGS] =
|
|||
{ 4, FIELD_OFFSET(KTRAP_FRAME, SegGs), FIELD_OFFSET(CONTEXT, SegGs), TRUE }
|
||||
};
|
||||
|
||||
static PCHAR GspThreadStates[DeferredReady+1] =
|
||||
static PCHAR GspThreadStates[DeferredReady + 1] =
|
||||
{
|
||||
"Initialized",
|
||||
"Ready",
|
||||
|
@ -100,27 +100,21 @@ static PCHAR GspThreadStates[DeferredReady+1] =
|
|||
"DeferredReady"
|
||||
};
|
||||
|
||||
|
||||
LONG
|
||||
HexValue(CHAR ch)
|
||||
{
|
||||
if ((ch >= '0') && (ch <= '9'))
|
||||
{
|
||||
return (ch - '0');
|
||||
}
|
||||
|
||||
if ((ch >= 'a') && (ch <= 'f'))
|
||||
{
|
||||
return (ch - 'a' + 10);
|
||||
}
|
||||
|
||||
if ((ch >= 'A') && (ch <= 'F'))
|
||||
{
|
||||
return (ch - 'A' + 10);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GdbPutChar(UCHAR Value)
|
||||
{
|
||||
|
@ -151,10 +145,10 @@ GspGetPacket()
|
|||
while (TRUE)
|
||||
{
|
||||
/* wait around for the start character, ignore all other characters */
|
||||
while ((ch = GdbGetChar ()) != '$')
|
||||
while ((ch = GdbGetChar()) != '$')
|
||||
;
|
||||
|
||||
retry:
|
||||
retry:
|
||||
Checksum = 0;
|
||||
XmitChecksum = -1;
|
||||
Count = 0;
|
||||
|
@ -164,13 +158,11 @@ GspGetPacket()
|
|||
{
|
||||
ch = GdbGetChar();
|
||||
if (ch == '$')
|
||||
{
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (ch == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Checksum = Checksum + ch;
|
||||
Buffer[Count] = ch;
|
||||
Count = Count + 1;
|
||||
|
@ -191,7 +183,6 @@ GspGetPacket()
|
|||
else
|
||||
{
|
||||
GdbPutChar('+'); /* successful transfer */
|
||||
|
||||
return &Buffer[0];
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +218,6 @@ GspPutPacket(PCHAR Buffer)
|
|||
while (GdbGetChar() != '+');
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspPutPacketNoWait(PCHAR Buffer)
|
||||
{
|
||||
|
@ -259,8 +249,10 @@ static CHAR
|
|||
GspReadMemSafe(PCHAR Address)
|
||||
{
|
||||
CHAR ch = 0;
|
||||
|
||||
if (!KdpSafeReadMemory((ULONG_PTR)Address, 1, &ch))
|
||||
GspMemoryError = TRUE;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -271,29 +263,25 @@ GspWriteMemSafe(PCHAR Address, CHAR Ch)
|
|||
GspMemoryError = TRUE;
|
||||
}
|
||||
|
||||
/* Convert the memory pointed to by Address into hex, placing result in Buffer */
|
||||
/* Return a pointer to the last char put in Buffer (null) */
|
||||
/* If MayFault is TRUE, then we should set GspMemoryError in response to
|
||||
a fault; if FALSE treat a fault like any other fault in the stub. */
|
||||
/* Convert the memory pointed to by Address into hex, placing result in Buffer
|
||||
* Return a pointer to the last char put in Buffer (null)
|
||||
* If MayFault is TRUE, then we should set GspMemoryError in response to
|
||||
* a fault; if FALSE treat a fault like any other fault in the stub.
|
||||
*/
|
||||
static PCHAR
|
||||
GspMem2Hex(PCHAR Address,
|
||||
PCHAR Buffer,
|
||||
LONG Count,
|
||||
BOOLEAN MayFault)
|
||||
GspMem2Hex(PCHAR Address, PCHAR Buffer, LONG Count, BOOLEAN MayFault)
|
||||
{
|
||||
ULONG i;
|
||||
CHAR ch;
|
||||
|
||||
for (i = 0; i < (ULONG) Count; i++)
|
||||
for (i = 0; i < (ULONG)Count; i++)
|
||||
{
|
||||
if (MayFault)
|
||||
{
|
||||
ch = GspReadMemSafe(Address);
|
||||
if (GspMemoryError)
|
||||
{
|
||||
return Buffer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = *Address;
|
||||
|
@ -308,11 +296,8 @@ GspMem2Hex(PCHAR Address,
|
|||
}
|
||||
|
||||
static ULONG
|
||||
GspWriteMem(PCHAR Address,
|
||||
ULONG Count,
|
||||
BOOLEAN MayFault,
|
||||
CHAR (*GetContent)(PVOID Context, ULONG Offset),
|
||||
PVOID Context)
|
||||
GspWriteMem(PCHAR Address, ULONG Count, BOOLEAN MayFault,
|
||||
CHAR (*GetContent)(PVOID Context, ULONG Offset), PVOID Context)
|
||||
{
|
||||
PCHAR Current;
|
||||
PCHAR Page;
|
||||
|
@ -335,29 +320,23 @@ GspWriteMem(PCHAR Address,
|
|||
CountInPage = PAGE_SIZE - (Address - Page);
|
||||
}
|
||||
|
||||
for (i = 0; i < CountInPage && ! GspMemoryError; i++)
|
||||
for (i = 0; i < CountInPage && !GspMemoryError; i++)
|
||||
{
|
||||
ch = (*GetContent)(Context, Current - Address);
|
||||
|
||||
if (MayFault)
|
||||
{
|
||||
GspWriteMemSafe(Current, ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
*Current = ch;
|
||||
}
|
||||
|
||||
Current++;
|
||||
}
|
||||
if (MayFault)
|
||||
{
|
||||
if (GspMemoryError)
|
||||
{
|
||||
return Current - Address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Current - Address;
|
||||
}
|
||||
|
@ -365,20 +344,16 @@ GspWriteMem(PCHAR Address,
|
|||
static CHAR
|
||||
GspHex2MemGetContent(PVOID Context, ULONG Offset)
|
||||
{
|
||||
return (CHAR)((HexValue(*((PCHAR) Context + 2 * Offset)) << 4) +
|
||||
HexValue(*((PCHAR) Context + 2 * Offset + 1)));
|
||||
return (CHAR)((HexValue(*((PCHAR)Context + 2 * Offset)) << 4) +
|
||||
HexValue(*((PCHAR)Context + 2 * Offset + 1)));
|
||||
}
|
||||
|
||||
/* Convert the hex array pointed to by Buffer into binary to be placed at Address
|
||||
* Return a pointer to the character AFTER the last byte read from Buffer */
|
||||
static PCHAR
|
||||
GspHex2Mem(PCHAR Buffer,
|
||||
PCHAR Address,
|
||||
ULONG Count,
|
||||
BOOLEAN MayFault)
|
||||
GspHex2Mem(PCHAR Buffer, PCHAR Address, ULONG Count, BOOLEAN MayFault)
|
||||
{
|
||||
Count = GspWriteMem(Address, Count, MayFault, GspHex2MemGetContent, Buffer);
|
||||
|
||||
return Buffer + 2 * Count;
|
||||
}
|
||||
|
||||
|
@ -387,8 +362,7 @@ GspHex2Mem(PCHAR Buffer,
|
|||
/* RETURN NUMBER OF CHARS PROCESSED */
|
||||
/**********************************************/
|
||||
LONG
|
||||
GspHex2Long(PCHAR *Address,
|
||||
PLONG Value)
|
||||
GspHex2Long(PCHAR *Address, PLONG Value)
|
||||
{
|
||||
LONG NumChars = 0;
|
||||
LONG Hex;
|
||||
|
@ -414,20 +388,16 @@ GspHex2Long(PCHAR *Address,
|
|||
return NumChars;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspLong2Hex(PCHAR *Address,
|
||||
LONG Value)
|
||||
GspLong2Hex(PCHAR *Address, LONG Value)
|
||||
{
|
||||
LONG Save;
|
||||
|
||||
Save = (((Value >> 0) & 0xff) << 24) |
|
||||
(((Value >> 8) & 0xff) << 16) |
|
||||
(((Value >> 16) & 0xff) << 8) |
|
||||
(((Value >> 24) & 0xff) << 0);
|
||||
*Address = GspMem2Hex((PCHAR) &Save, *Address, 4, FALSE);
|
||||
}
|
||||
Save = (((Value >> 0) & 0xff) << 24) | (((Value >> 8) & 0xff) << 16) |
|
||||
(((Value >> 16) & 0xff) << 8) | (((Value >> 24) & 0xff) << 0);
|
||||
|
||||
*Address = GspMem2Hex((PCHAR)&Save, *Address, 4, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* When coming from kernel mode, Esp is not stored in the trap frame.
|
||||
|
@ -438,14 +408,12 @@ GspLong2Hex(PCHAR *Address,
|
|||
static LONG
|
||||
GspGetEspFromTrapFrame(PKTRAP_FRAME TrapFrame)
|
||||
{
|
||||
return KeGetPreviousMode() == KernelMode
|
||||
? (LONG) &TrapFrame->HardwareEsp : (LONG)TrapFrame->HardwareEsp;
|
||||
return KeGetPreviousMode() == KernelMode ?
|
||||
(LONG)&TrapFrame->HardwareEsp : (LONG)TrapFrame->HardwareEsp;
|
||||
}
|
||||
|
||||
|
||||
static VOID
|
||||
GspGetRegisters(PCHAR Address,
|
||||
PKTRAP_FRAME TrapFrame)
|
||||
GspGetRegisters(PCHAR Address, PKTRAP_FRAME TrapFrame)
|
||||
{
|
||||
ULONG_PTR Value;
|
||||
PULONG p;
|
||||
|
@ -468,7 +436,7 @@ GspGetRegisters(PCHAR Address,
|
|||
KernelStack = Thread->Tcb.KernelStack;
|
||||
for (i = 0; i < sizeof(GspRegisters) / sizeof(GspRegisters[0]); i++)
|
||||
{
|
||||
switch(i)
|
||||
switch (i)
|
||||
{
|
||||
case EBP:
|
||||
Value = KernelStack[3];
|
||||
|
@ -486,7 +454,7 @@ GspGetRegisters(PCHAR Address,
|
|||
Value = KernelStack[7];
|
||||
break;
|
||||
case ESP:
|
||||
Value = (ULONG_PTR) (KernelStack + 8);
|
||||
Value = (ULONG_PTR)(KernelStack + 8);
|
||||
break;
|
||||
case CS:
|
||||
Value = KGDT_R0_CODE;
|
||||
|
@ -498,8 +466,8 @@ GspGetRegisters(PCHAR Address,
|
|||
Value = 0;
|
||||
break;
|
||||
}
|
||||
Address = GspMem2Hex((PCHAR) &Value, Address, GspRegisters[i].Size,
|
||||
FALSE);
|
||||
|
||||
Address = GspMem2Hex((PCHAR)&Value, Address, GspRegisters[i].Size, FALSE);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -514,8 +482,7 @@ GspGetRegisters(PCHAR Address,
|
|||
}
|
||||
else
|
||||
{
|
||||
p = (PULONG)((ULONG_PTR) TrapFrame +
|
||||
GspRegisters[i].OffsetInTF);
|
||||
p = (PULONG)((ULONG_PTR)TrapFrame + GspRegisters[i].OffsetInTF);
|
||||
Value = *p;
|
||||
}
|
||||
}
|
||||
|
@ -531,17 +498,14 @@ GspGetRegisters(PCHAR Address,
|
|||
{
|
||||
Value = 0;
|
||||
}
|
||||
Address = GspMem2Hex((PCHAR) &Value, Address,
|
||||
GspRegisters[i].Size, FALSE);
|
||||
|
||||
Address = GspMem2Hex((PCHAR)&Value, Address, GspRegisters[i].Size, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspSetRegistersInTrapFrame(PCHAR Address,
|
||||
PCONTEXT Context,
|
||||
PKTRAP_FRAME TrapFrame)
|
||||
GspSetRegistersInTrapFrame(PCHAR Address, PCONTEXT Context, PKTRAP_FRAME TrapFrame)
|
||||
{
|
||||
ULONG Value;
|
||||
PCHAR Buffer;
|
||||
|
@ -549,63 +513,55 @@ GspSetRegistersInTrapFrame(PCHAR Address,
|
|||
ULONG i;
|
||||
|
||||
if (!TrapFrame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Buffer = Address;
|
||||
for (i = 0; i < NUMREGS; i++)
|
||||
{
|
||||
if (GspRegisters[i].SetInContext)
|
||||
{
|
||||
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[i].OffsetInContext);
|
||||
p = (PULONG)((ULONG_PTR)Context + GspRegisters[i].OffsetInContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[i].OffsetInTF);
|
||||
p = (PULONG)((ULONG_PTR)TrapFrame + GspRegisters[i].OffsetInTF);
|
||||
}
|
||||
|
||||
Value = 0;
|
||||
Buffer = GspHex2Mem(Buffer, (PCHAR) &Value, GspRegisters[i].Size, FALSE);
|
||||
Buffer = GspHex2Mem(Buffer, (PCHAR)&Value, GspRegisters[i].Size, FALSE);
|
||||
*p = Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspSetSingleRegisterInTrapFrame(PCHAR Address,
|
||||
LONG Number,
|
||||
PCONTEXT Context,
|
||||
PKTRAP_FRAME TrapFrame)
|
||||
GspSetSingleRegisterInTrapFrame(PCHAR Address, LONG Number, PCONTEXT Context, PKTRAP_FRAME TrapFrame)
|
||||
{
|
||||
ULONG Value;
|
||||
PULONG p;
|
||||
|
||||
if (!TrapFrame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GspRegisters[Number].SetInContext)
|
||||
{
|
||||
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[Number].OffsetInContext);
|
||||
p = (PULONG)((ULONG_PTR)Context + GspRegisters[Number].OffsetInContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[Number].OffsetInTF);
|
||||
p = (PULONG)((ULONG_PTR)TrapFrame + GspRegisters[Number].OffsetInTF);
|
||||
}
|
||||
|
||||
Value = 0;
|
||||
GspHex2Mem(Address, (PCHAR) &Value, GspRegisters[Number].Size, FALSE);
|
||||
GspHex2Mem(Address, (PCHAR)&Value, GspRegisters[Number].Size, FALSE);
|
||||
*p = Value;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
GspFindThread(PCHAR Data,
|
||||
PETHREAD *Thread)
|
||||
GspFindThread(PCHAR Data, PETHREAD *Thread)
|
||||
{
|
||||
PETHREAD ThreadInfo = NULL;
|
||||
|
||||
if (strcmp (Data, "-1") == 0)
|
||||
if (strcmp(Data, "-1") == 0)
|
||||
{
|
||||
/* All threads */
|
||||
ThreadInfo = NULL;
|
||||
|
@ -616,7 +572,7 @@ GspFindThread(PCHAR Data,
|
|||
HANDLE ThreadId;
|
||||
PCHAR ptr = &Data[0];
|
||||
|
||||
GspHex2Long(&ptr, (PLONG) &uThreadId);
|
||||
GspHex2Long(&ptr, (PLONG)&uThreadId);
|
||||
ThreadId = (HANDLE)uThreadId;
|
||||
|
||||
if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &ThreadInfo)))
|
||||
|
@ -625,11 +581,11 @@ GspFindThread(PCHAR Data,
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
*Thread = ThreadInfo;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspSetThread(PCHAR Request)
|
||||
{
|
||||
|
@ -645,20 +601,19 @@ GspSetThread(PCHAR Request)
|
|||
GspOutBuffer[1] = 'K';
|
||||
|
||||
if (NULL != GspRunThread)
|
||||
{
|
||||
ObDereferenceObject(GspRunThread);
|
||||
}
|
||||
|
||||
GspRunThread = ThreadInfo;
|
||||
|
||||
if (NULL != GspRunThread)
|
||||
{
|
||||
ObReferenceObject(GspRunThread);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GspOutBuffer[0] = 'E';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'g': /* Debug thread */
|
||||
if (GspFindThread(ptr, &ThreadInfo))
|
||||
{
|
||||
|
@ -666,9 +621,7 @@ GspSetThread(PCHAR Request)
|
|||
GspOutBuffer[1] = 'K';
|
||||
|
||||
if (NULL != GspDbgThread)
|
||||
{
|
||||
ObDereferenceObject(GspDbgThread);
|
||||
}
|
||||
|
||||
if (ThreadInfo == PsGetCurrentThread())
|
||||
{
|
||||
|
@ -685,12 +638,12 @@ GspSetThread(PCHAR Request)
|
|||
GspOutBuffer[0] = 'E';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
GspQuery(PCHAR Request)
|
||||
{
|
||||
|
@ -703,14 +656,12 @@ GspQuery(PCHAR Request)
|
|||
/* Get current thread id */
|
||||
GspOutBuffer[0] = 'Q';
|
||||
GspOutBuffer[1] = 'C';
|
||||
|
||||
if (NULL != GspDbgThread)
|
||||
{
|
||||
Value = (ULONG) GspDbgThread->Cid.UniqueThread;
|
||||
}
|
||||
Value = (ULONG)GspDbgThread->Cid.UniqueThread;
|
||||
else
|
||||
{
|
||||
Value = (ULONG) PsGetCurrentThread()->Cid.UniqueThread;
|
||||
}
|
||||
Value = (ULONG)PsGetCurrentThread()->Cid.UniqueThread;
|
||||
|
||||
GspLong2Hex(&ptr, Value);
|
||||
}
|
||||
else if (strncmp(Request, "fThreadInfo", 11) == 0)
|
||||
|
@ -722,7 +673,7 @@ GspQuery(PCHAR Request)
|
|||
/* Get first thread id */
|
||||
GspEnumThread = NULL;
|
||||
AProcess = PsActiveProcessHead.Flink;
|
||||
while(AProcess != &PsActiveProcessHead)
|
||||
while (AProcess != &PsActiveProcessHead)
|
||||
{
|
||||
Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
|
||||
AThread = Process->ThreadListHead.Flink;
|
||||
|
@ -734,10 +685,10 @@ GspQuery(PCHAR Request)
|
|||
}
|
||||
AProcess = AProcess->Flink;
|
||||
}
|
||||
if(GspEnumThread != NULL)
|
||||
if (GspEnumThread != NULL)
|
||||
{
|
||||
GspOutBuffer[0] = 'm';
|
||||
Value = (ULONG) GspEnumThread->Cid.UniqueThread;
|
||||
Value = (ULONG)GspEnumThread->Cid.UniqueThread;
|
||||
GspLong2Hex(&ptr, Value);
|
||||
}
|
||||
else
|
||||
|
@ -758,7 +709,7 @@ GspQuery(PCHAR Request)
|
|||
{
|
||||
/* find the next thread */
|
||||
Process = GspEnumThread->ThreadsProcess;
|
||||
if(GspEnumThread->ThreadListEntry.Flink != &Process->ThreadListHead)
|
||||
if (GspEnumThread->ThreadListEntry.Flink != &Process->ThreadListHead)
|
||||
{
|
||||
GspEnumThread = CONTAINING_RECORD(GspEnumThread->ThreadListEntry.Flink,
|
||||
ETHREAD, ThreadListEntry);
|
||||
|
@ -767,7 +718,7 @@ GspQuery(PCHAR Request)
|
|||
{
|
||||
PETHREAD Thread = NULL;
|
||||
AProcess = Process->ActiveProcessLinks.Flink;
|
||||
while(AProcess != &PsActiveProcessHead)
|
||||
while (AProcess != &PsActiveProcessHead)
|
||||
{
|
||||
Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
|
||||
AThread = Process->ThreadListHead.Flink;
|
||||
|
@ -786,7 +737,7 @@ GspQuery(PCHAR Request)
|
|||
{
|
||||
/* return the ID */
|
||||
GspOutBuffer[0] = 'm';
|
||||
Value = (ULONG) GspEnumThread->Cid.UniqueThread;
|
||||
Value = (ULONG)GspEnumThread->Cid.UniqueThread;
|
||||
GspLong2Hex(&ptr, Value);
|
||||
}
|
||||
else
|
||||
|
@ -809,17 +760,17 @@ GspQuery(PCHAR Request)
|
|||
char Buffer[64];
|
||||
PEPROCESS Proc;
|
||||
|
||||
Proc = (PEPROCESS) ThreadInfo->ThreadsProcess;
|
||||
Proc = (PEPROCESS)ThreadInfo->ThreadsProcess;
|
||||
|
||||
Buffer[0] = '\0';
|
||||
if (NULL != Proc )
|
||||
{
|
||||
sprintf(Buffer, "%s [%d:0x%x], ", Proc->ImageFileName,
|
||||
(int) Proc->UniqueProcessId,
|
||||
(int) ThreadInfo->Cid.UniqueThread);
|
||||
}
|
||||
strcpy(Buffer + strlen(Buffer),
|
||||
GspThreadStates[ThreadInfo->Tcb.State]);
|
||||
|
||||
if (NULL != Proc)
|
||||
sprintf(Buffer, "%s [%d:0x%x], ",
|
||||
Proc->ImageFileName,
|
||||
(int)Proc->UniqueProcessId,
|
||||
(int)ThreadInfo->Cid.UniqueThread);
|
||||
|
||||
strcpy(Buffer + strlen(Buffer), GspThreadStates[ThreadInfo->Tcb.State]);
|
||||
|
||||
ObDereferenceObject(ThreadInfo);
|
||||
|
||||
|
@ -939,8 +890,7 @@ GspSetHwBreakpoint(ULONG Type, ULONG_PTR Address, ULONG Length)
|
|||
}
|
||||
else if (0 != (Address & (Length - 1)))
|
||||
{
|
||||
DPRINT1("Invalid alignment for address 0x%p and length %d\n",
|
||||
Address, Length);
|
||||
DPRINT1("Invalid alignment for address 0x%p and length %d\n", Address, Length);
|
||||
strcpy(GspOutBuffer, "E22");
|
||||
}
|
||||
else if (MAX_HW_BREAKPOINTS == GspHwBreakpointCount)
|
||||
|
@ -973,12 +923,10 @@ GspRemoveHwBreakpoint(ULONG Type, ULONG_PTR Address, ULONG Length)
|
|||
{
|
||||
DPRINT("Found match at index %u\n", Index);
|
||||
if (Index + 1 < GspHwBreakpointCount)
|
||||
{
|
||||
memmove(GspHwBreakpoints + Index,
|
||||
GspHwBreakpoints + (Index + 1),
|
||||
(GspHwBreakpointCount - Index - 1) *
|
||||
sizeof(GSPHWBREAKPOINT));
|
||||
}
|
||||
(GspHwBreakpointCount - Index - 1) * sizeof(GSPHWBREAKPOINT));
|
||||
|
||||
GspHwBreakpointCount--;
|
||||
strcpy(GspOutBuffer, "OK");
|
||||
return;
|
||||
|
@ -997,7 +945,8 @@ GspFindSwBreakpoint(ULONG_PTR Address, PULONG PIndex)
|
|||
for (Index = 0; Index < GspSwBreakpointCount; Index++)
|
||||
if (GspSwBreakpoints[Index].Address == Address)
|
||||
{
|
||||
if (PIndex) *PIndex = Index;
|
||||
if (PIndex)
|
||||
*PIndex = Index;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1039,15 +988,13 @@ GspRemoveSwBreakpoint(ULONG_PTR Address)
|
|||
if (GspFindSwBreakpoint(Address, &Index))
|
||||
{
|
||||
DPRINT("Found match at index %u\n", Index);
|
||||
ASSERT(! GspSwBreakpoints[Index].Active);
|
||||
ASSERT(!GspSwBreakpoints[Index].Active);
|
||||
|
||||
if (Index + 1 < GspSwBreakpointCount)
|
||||
{
|
||||
memmove(GspSwBreakpoints + Index,
|
||||
GspSwBreakpoints + (Index + 1),
|
||||
(GspSwBreakpointCount - Index - 1) *
|
||||
sizeof(GSPSWBREAKPOINT));
|
||||
}
|
||||
(GspSwBreakpointCount - Index - 1) * sizeof(GSPSWBREAKPOINT));
|
||||
|
||||
GspSwBreakpointCount--;
|
||||
strcpy(GspOutBuffer, "OK");
|
||||
return;
|
||||
|
@ -1058,14 +1005,11 @@ GspRemoveSwBreakpoint(ULONG_PTR Address)
|
|||
}
|
||||
|
||||
static void
|
||||
GspLoadHwBreakpoint(PKTRAP_FRAME TrapFrame,
|
||||
unsigned BpIndex,
|
||||
ULONG_PTR Address,
|
||||
ULONG Length,
|
||||
ULONG Type)
|
||||
GspLoadHwBreakpoint(PKTRAP_FRAME TrapFrame, unsigned BpIndex,
|
||||
ULONG_PTR Address, ULONG Length, ULONG Type)
|
||||
{
|
||||
DPRINT("GspLoadHwBreakpoint(0x%p, %d, 0x%p, %d)\n", TrapFrame, BpIndex,
|
||||
Address, Type);
|
||||
DPRINT("GspLoadHwBreakpoint(0x%p, %d, 0x%p, %d)\n",
|
||||
TrapFrame, BpIndex, Address, Type);
|
||||
|
||||
/* Set the DR7_Gx bit to globally enable the breakpoint */
|
||||
TrapFrame->Dr7 |= DR7_GLOBAL_ENABLE(BpIndex) |
|
||||
|
@ -1100,22 +1044,18 @@ static void
|
|||
GspLoadSwBreakpoint(ULONG Index)
|
||||
{
|
||||
GspMemoryError = FALSE;
|
||||
GspSwBreakpoints[Index].PrevContent = GspReadMemSafe((PCHAR) GspSwBreakpoints[Index].Address);
|
||||
if (! GspMemoryError)
|
||||
{
|
||||
GspWriteMemSafe((PCHAR) GspSwBreakpoints[Index].Address, I386_OPCODE_INT3);
|
||||
}
|
||||
GspSwBreakpoints[Index].Active = ! GspMemoryError;
|
||||
|
||||
GspSwBreakpoints[Index].PrevContent = GspReadMemSafe((PCHAR)GspSwBreakpoints[Index].Address);
|
||||
|
||||
if (!GspMemoryError)
|
||||
GspWriteMemSafe((PCHAR)GspSwBreakpoints[Index].Address, I386_OPCODE_INT3);
|
||||
|
||||
GspSwBreakpoints[Index].Active = !GspMemoryError;
|
||||
|
||||
if (GspMemoryError)
|
||||
{
|
||||
DPRINT1("Failed to set software breakpoint at 0x%p\n",
|
||||
GspSwBreakpoints[Index].Address);
|
||||
}
|
||||
DPRINT1("Failed to set software breakpoint at 0x%p\n", GspSwBreakpoints[Index].Address);
|
||||
else
|
||||
{
|
||||
DPRINT("Successfully set software breakpoint at 0x%p\n",
|
||||
GspSwBreakpoints[Index].Address);
|
||||
}
|
||||
DPRINT("Successfully set software breakpoint at 0x%p\n", GspSwBreakpoints[Index].Address);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1137,7 +1077,7 @@ GspLoadBreakpoints(PKTRAP_FRAME TrapFrame)
|
|||
|
||||
for (Index = 0; Index < GspHwBreakpointCount; Index++)
|
||||
{
|
||||
switch(GspHwBreakpoints[Index].Type)
|
||||
switch (GspHwBreakpoints[Index].Type)
|
||||
{
|
||||
case GDB_ZTYPE_HARDWARE_BREAKPOINT:
|
||||
i386Type = I386_BP_TYPE_EXECUTE;
|
||||
|
@ -1182,7 +1122,7 @@ GspUnloadBreakpoints(void)
|
|||
if (GspSwBreakpoints[Index].Active)
|
||||
{
|
||||
GspMemoryError = FALSE;
|
||||
GspWriteMemSafe((PCHAR) GspSwBreakpoints[Index].Address,
|
||||
GspWriteMemSafe((PCHAR)GspSwBreakpoints[Index].Address,
|
||||
GspSwBreakpoints[Index].PrevContent);
|
||||
GspSwBreakpoints[Index].Active = FALSE;
|
||||
if (GspMemoryError)
|
||||
|
@ -1241,23 +1181,22 @@ GspStopReply(NTSTATUS ExceptionCode, PKTRAP_FRAME TrapFrame)
|
|||
*ptr++ = ':';
|
||||
|
||||
Esp = GspGetEspFromTrapFrame(TrapFrame); /* SP */
|
||||
ptr = GspMem2Hex((PCHAR) &Esp, ptr, 4, 0);
|
||||
ptr = GspMem2Hex((PCHAR)&Esp, ptr, 4, 0);
|
||||
*ptr++ = ';';
|
||||
|
||||
*ptr++ = HexChars[EBP];
|
||||
*ptr++ = ':';
|
||||
ptr = GspMem2Hex((PCHAR) &TrapFrame->Ebp, ptr, 4, 0); /* FP */
|
||||
ptr = GspMem2Hex((PCHAR)&TrapFrame->Ebp, ptr, 4, 0); /* FP */
|
||||
*ptr++ = ';';
|
||||
|
||||
*ptr++ = HexChars[PC];
|
||||
*ptr++ = ':';
|
||||
ptr = GspMem2Hex((PCHAR) &TrapFrame->Eip, ptr, 4, 0); /* PC */
|
||||
ptr = GspMem2Hex((PCHAR)&TrapFrame->Eip, ptr, 4, 0); /* PC */
|
||||
*ptr++ = ';';
|
||||
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function does all command procesing for interfacing to GDB.
|
||||
*/
|
||||
|
@ -1277,7 +1216,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
/* FIXME: Stop on other CPUs too */
|
||||
|
||||
DPRINT("Thread %p entering stub\n", PsGetCurrentThread());
|
||||
ExceptionCode = (NTSTATUS) ExceptionRecord->ExceptionCode;
|
||||
ExceptionCode = (NTSTATUS)ExceptionRecord->ExceptionCode;
|
||||
|
||||
/* Can only debug 1 thread at a time... */
|
||||
ExAcquireFastMutex(&GspLock);
|
||||
|
@ -1311,29 +1250,30 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
ptr = GspGetPacket();
|
||||
// DbgPrint("<<< (%s) <<<\n", ptr);
|
||||
|
||||
switch(*ptr++)
|
||||
switch (*ptr++)
|
||||
{
|
||||
case '?':
|
||||
/* a little hack to send more complete status information */
|
||||
GspStopReply(ExceptionCode, TrapFrame);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
GspRemoteDebug = !GspRemoteDebug; /* toggle debug flag */
|
||||
break;
|
||||
|
||||
case 'g': /* return the value of the CPU Registers */
|
||||
GspGetRegisters(GspOutBuffer, TrapFrame);
|
||||
break;
|
||||
|
||||
case 'G': /* set the value of the CPU Registers - return OK */
|
||||
if (NULL != GspDbgThread)
|
||||
{
|
||||
GspSetRegistersInTrapFrame(ptr, Context, GspDbgThread->Tcb.TrapFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
GspSetRegistersInTrapFrame(ptr, Context, TrapFrame);
|
||||
}
|
||||
|
||||
strcpy(GspOutBuffer, "OK");
|
||||
break;
|
||||
|
||||
case 'P': /* set the value of a single CPU register - return OK */
|
||||
{
|
||||
LONG Register;
|
||||
|
@ -1344,14 +1284,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
{
|
||||
if (GspDbgThread)
|
||||
{
|
||||
GspSetSingleRegisterInTrapFrame(ptr, Register,
|
||||
Context,
|
||||
GspSetSingleRegisterInTrapFrame(ptr, Register, Context,
|
||||
GspDbgThread->Tcb.TrapFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
GspSetSingleRegisterInTrapFrame(ptr, Register,
|
||||
Context, TrapFrame);
|
||||
GspSetSingleRegisterInTrapFrame(ptr, Register, Context, TrapFrame);
|
||||
}
|
||||
strcpy(GspOutBuffer, "OK");
|
||||
break;
|
||||
|
@ -1364,10 +1302,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
|
||||
/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
|
||||
case 'm':
|
||||
{
|
||||
/* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
|
||||
if (GspHex2Long(&ptr, &Address) &&
|
||||
*(ptr++) == ',' &&
|
||||
GspHex2Long(&ptr, &Length))
|
||||
if (GspHex2Long(&ptr, &Address) && *(ptr++) == ',' && GspHex2Long(&ptr, &Length))
|
||||
{
|
||||
PEPROCESS DbgProcess = NULL;
|
||||
|
||||
|
@ -1378,12 +1315,13 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
DbgProcess = GspDbgThread->ThreadsProcess;
|
||||
KeAttachProcess(&DbgProcess->Pcb);
|
||||
}
|
||||
|
||||
GspMemoryError = FALSE;
|
||||
GspMem2Hex((PCHAR) Address, GspOutBuffer, Length, 1);
|
||||
GspMem2Hex((PCHAR)Address, GspOutBuffer, Length, 1);
|
||||
|
||||
if (NULL != DbgProcess)
|
||||
{
|
||||
KeDetachProcess();
|
||||
}
|
||||
|
||||
if (GspMemoryError)
|
||||
{
|
||||
strcpy(GspOutBuffer, "E03");
|
||||
|
@ -1392,19 +1330,18 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
}
|
||||
|
||||
if (NULL != ptr)
|
||||
{
|
||||
strcpy(GspOutBuffer, "E01");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
|
||||
case 'M':
|
||||
{
|
||||
/* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
|
||||
if (GspHex2Long(&ptr, &Address))
|
||||
{
|
||||
if (*(ptr++) == ',' &&
|
||||
GspHex2Long(&ptr, &Length) &&
|
||||
*(ptr++) == ':')
|
||||
if (*(ptr++) == ',' && GspHex2Long(&ptr, &Length) && *(ptr++) == ':')
|
||||
{
|
||||
PEPROCESS DbgProcess = NULL;
|
||||
|
||||
|
@ -1415,11 +1352,10 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
KeAttachProcess(&DbgProcess->Pcb);
|
||||
}
|
||||
GspMemoryError = FALSE;
|
||||
GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE);
|
||||
GspHex2Mem(ptr, (PCHAR)Address, Length, TRUE);
|
||||
if (NULL != DbgProcess)
|
||||
{
|
||||
KeDetachProcess();
|
||||
}
|
||||
|
||||
if (GspMemoryError)
|
||||
{
|
||||
strcpy(GspOutBuffer, "E03");
|
||||
|
@ -1434,13 +1370,13 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
}
|
||||
|
||||
if (NULL != ptr)
|
||||
{
|
||||
strcpy(GspOutBuffer, "E02");
|
||||
}
|
||||
break;
|
||||
|
||||
/* cAA..AA Continue at address AA..AA(optional) */
|
||||
/* sAA..AA Step one instruction from AA..AA(optional) */
|
||||
break;
|
||||
}
|
||||
|
||||
/* cAA..AA Continue at address AA..AA */
|
||||
/* sAA..AA Step one instruction from AA..AA */
|
||||
case 's':
|
||||
Stepping = TRUE;
|
||||
case 'c':
|
||||
|
@ -1449,31 +1385,29 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
ULONG Dr6;
|
||||
|
||||
/* try to read optional parameter, pc changed if param */
|
||||
if (GspHex2Long (&ptr, &Address))
|
||||
if (GspHex2Long(&ptr, &Address))
|
||||
{
|
||||
Context->Eip = Address;
|
||||
}
|
||||
else if (ExceptionCode == STATUS_BREAKPOINT)
|
||||
{
|
||||
if (GspReadMemSafe((PCHAR) Context->Eip) == (CHAR) I386_OPCODE_INT3)
|
||||
{
|
||||
if (GspReadMemSafe((PCHAR)Context->Eip) == (CHAR)I386_OPCODE_INT3)
|
||||
Context->Eip++;
|
||||
}
|
||||
}
|
||||
|
||||
/* clear the trace bit */
|
||||
Context->EFlags &= ~EFLAGS_TF;
|
||||
|
||||
/* set the trace bit if we're Stepping */
|
||||
if (Stepping)
|
||||
{
|
||||
Context->EFlags |= EFLAGS_TF;
|
||||
}
|
||||
|
||||
Dr6 = Ke386GetDr6();
|
||||
if (!(Dr6 & DR6_BS))
|
||||
{
|
||||
for (BreakpointNumber = 0; BreakpointNumber < MAX_HW_BREAKPOINTS; ++BreakpointNumber)
|
||||
for (BreakpointNumber = 0;
|
||||
BreakpointNumber < MAX_HW_BREAKPOINTS;
|
||||
BreakpointNumber++)
|
||||
{
|
||||
if (Dr6 & (1 << BreakpointNumber))
|
||||
{
|
||||
|
@ -1502,9 +1436,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
|
||||
if (ExceptionCode == STATUS_BREAKPOINT ||
|
||||
ExceptionCode == STATUS_SINGLE_STEP)
|
||||
{
|
||||
return kdContinue;
|
||||
}
|
||||
|
||||
return kdHandleException;
|
||||
}
|
||||
|
@ -1536,14 +1468,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
GspHex2Long(&ptr, &Address);
|
||||
ptr++;
|
||||
GspHex2Long(&ptr, &Length);
|
||||
|
||||
if (0 == Type)
|
||||
{
|
||||
GspSetSwBreakpoint((ULONG_PTR) Address);
|
||||
}
|
||||
GspSetSwBreakpoint((ULONG_PTR)Address);
|
||||
else
|
||||
{
|
||||
GspSetHwBreakpoint(Type, (ULONG_PTR) Address, Length);
|
||||
}
|
||||
GspSetHwBreakpoint(Type, (ULONG_PTR)Address, Length);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1558,14 +1488,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
GspHex2Long(&ptr, &Address);
|
||||
ptr++;
|
||||
GspHex2Long(&ptr, &Length);
|
||||
|
||||
if (0 == Type)
|
||||
{
|
||||
GspRemoveSwBreakpoint((ULONG_PTR) Address);
|
||||
}
|
||||
GspRemoveSwBreakpoint((ULONG_PTR)Address);
|
||||
else
|
||||
{
|
||||
GspRemoveHwBreakpoint(Type, (ULONG_PTR) Address, Length);
|
||||
}
|
||||
GspRemoveHwBreakpoint(Type, (ULONG_PTR)Address, Length);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1579,11 +1507,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
GspBreakIn(PKINTERRUPT Interrupt,
|
||||
PVOID ServiceContext)
|
||||
GspBreakIn(PKINTERRUPT Interrupt, PVOID ServiceContext)
|
||||
{
|
||||
PKTRAP_FRAME TrapFrame;
|
||||
BOOLEAN DoBreakIn;
|
||||
|
@ -1597,15 +1523,11 @@ GspBreakIn(PKINTERRUPT Interrupt,
|
|||
while (KdPortGetByteEx(&GdbPortInfo, &Value))
|
||||
{
|
||||
if (Value == 0x03)
|
||||
{
|
||||
DoBreakIn = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!DoBreakIn)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
KeRaiseIrql(HIGH_LEVEL, &OldIrql);
|
||||
|
||||
|
@ -1631,13 +1553,10 @@ KdpGdbDebugPrint(PCH Message, ULONG Length)
|
|||
/* Initialize the GDB stub */
|
||||
VOID
|
||||
NTAPI
|
||||
KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable,
|
||||
ULONG BootPhase)
|
||||
KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable, ULONG BootPhase)
|
||||
{
|
||||
if (!KdDebuggerEnabled || !KdpDebugMode.Gdb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (BootPhase == 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue