Only whitespace changes, no logic

svn path=/trunk/; revision=18455
This commit is contained in:
Gé van Geldorp 2005-10-14 19:28:18 +00:00
parent 2af4ba6dcb
commit 7daa792a3e

View file

@ -94,9 +94,6 @@
#define BUFMAX 1000
static BOOLEAN GspInitialized;
#if 0
static PKINTERRUPT GspInterrupt;
#endif
static BOOLEAN GspRemoteDebug;
@ -132,26 +129,27 @@ typedef struct _CPU_REGISTER
static CPU_REGISTER GspRegisters[NUMREGS] =
{
{ 4, FIELD_OFFSET (KTRAP_FRAME, Eax), FIELD_OFFSET (CONTEXT, Eax), TRUE },
{ 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, Esp), FIELD_OFFSET (CONTEXT, Esp), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, DebugEbp), 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 },
{ 4, FIELD_OFFSET (KTRAP_FRAME, DebugEip), FIELD_OFFSET (CONTEXT, Eip), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Eflags), FIELD_OFFSET (CONTEXT, EFlags), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Cs), FIELD_OFFSET (CONTEXT, SegCs), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Ss), FIELD_OFFSET (CONTEXT, SegSs), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Ds), FIELD_OFFSET (CONTEXT, SegDs), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Es), FIELD_OFFSET (CONTEXT, SegEs), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Fs), FIELD_OFFSET (CONTEXT, SegFs), TRUE },
{ 4, FIELD_OFFSET (KTRAP_FRAME, Gs), FIELD_OFFSET (CONTEXT, SegGs), TRUE }
{ 4, FIELD_OFFSET(KTRAP_FRAME, Eax), FIELD_OFFSET(CONTEXT, Eax), TRUE },
{ 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, Esp), FIELD_OFFSET(CONTEXT, Esp), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, DebugEbp), 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 },
{ 4, FIELD_OFFSET(KTRAP_FRAME, DebugEip), FIELD_OFFSET(CONTEXT, Eip), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Eflags), FIELD_OFFSET(CONTEXT, EFlags), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Cs), FIELD_OFFSET(CONTEXT, SegCs), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Ss), FIELD_OFFSET(CONTEXT, SegSs), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Ds), FIELD_OFFSET(CONTEXT, SegDs), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Es), FIELD_OFFSET(CONTEXT, SegEs), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Fs), FIELD_OFFSET(CONTEXT, SegFs), TRUE },
{ 4, FIELD_OFFSET(KTRAP_FRAME, Gs), FIELD_OFFSET(CONTEXT, SegGs), TRUE }
};
static PCHAR GspThreadStates[DeferredReady+1] =
{ "Initialized",
{
"Initialized",
"Ready",
"Running",
"Standby",
@ -163,12 +161,22 @@ static PCHAR GspThreadStates[DeferredReady+1] =
LONG
HexValue (CHAR ch)
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);
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;
}
static CHAR GspInBuffer[BUFMAX];
@ -177,7 +185,7 @@ static CHAR GspOutBuffer[BUFMAX];
VOID
GdbPutChar(UCHAR Value)
{
KdPortPutByteEx (&GdbPortInfo, Value);
KdPortPutByteEx(&GdbPortInfo, Value);
}
UCHAR
@ -185,7 +193,8 @@ GdbGetChar(VOID)
{
UCHAR Value;
while (!KdPortGetByteEx (&GdbPortInfo, &Value));
while (!KdPortGetByteEx(&GdbPortInfo, &Value))
;
return Value;
}
@ -204,7 +213,8 @@ GspGetPacket()
while (TRUE)
{
/* wait around for the start character, ignore all other characters */
while ((ch = GdbGetChar ()) != '$');
while ((ch = GdbGetChar ()) != '$')
;
retry:
Checksum = 0;
@ -214,11 +224,15 @@ GspGetPacket()
/* now, read until a # or end of Buffer is found */
while (Count < BUFMAX)
{
ch = GdbGetChar ();
ch = GdbGetChar();
if (ch == '$')
{
goto retry;
}
if (ch == '#')
{
break;
}
Checksum = Checksum + ch;
Buffer[Count] = ch;
Count = Count + 1;
@ -227,18 +241,18 @@ GspGetPacket()
if (ch == '#')
{
ch = GdbGetChar ();
XmitChecksum = (CHAR)(HexValue (ch) << 4);
ch = GdbGetChar ();
XmitChecksum += (CHAR)(HexValue (ch));
ch = GdbGetChar();
XmitChecksum = (CHAR)(HexValue(ch) << 4);
ch = GdbGetChar();
XmitChecksum += (CHAR)(HexValue(ch));
if (Checksum != XmitChecksum)
{
GdbPutChar ('-'); /* failed checksum */
GdbPutChar('-'); /* failed checksum */
}
else
{
GdbPutChar ('+'); /* successful transfer */
GdbPutChar('+'); /* successful transfer */
return &Buffer[0];
}
@ -249,7 +263,7 @@ GspGetPacket()
/* send the packet in Buffer. */
VOID
GspPutPacket (PCHAR Buffer)
GspPutPacket(PCHAR Buffer)
{
CHAR Checksum;
LONG Count;
@ -258,47 +272,47 @@ GspPutPacket (PCHAR Buffer)
/* $<packet info>#<Checksum>. */
do
{
GdbPutChar ('$');
GdbPutChar('$');
Checksum = 0;
Count = 0;
while ((ch = Buffer[Count]))
{
GdbPutChar (ch);
GdbPutChar(ch);
Checksum += ch;
Count += 1;
}
GdbPutChar ('#');
GdbPutChar (HexChars[(Checksum >> 4) & 0xf]);
GdbPutChar (HexChars[Checksum & 0xf]);
GdbPutChar('#');
GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
GdbPutChar(HexChars[Checksum & 0xf]);
}
while (GdbGetChar () != '+');
while (GdbGetChar() != '+');
}
VOID
GspPutPacketNoWait (PCHAR Buffer)
GspPutPacketNoWait(PCHAR Buffer)
{
CHAR Checksum;
LONG Count;
CHAR ch;
/* $<packet info>#<Checksum>. */
GdbPutChar ('$');
GdbPutChar('$');
Checksum = 0;
Count = 0;
while ((ch = Buffer[Count]))
{
GdbPutChar (ch);
GdbPutChar(ch);
Checksum += ch;
Count += 1;
}
GdbPutChar ('#');
GdbPutChar (HexChars[(Checksum >> 4) & 0xf]);
GdbPutChar (HexChars[Checksum & 0xf]);
GdbPutChar('#');
GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
GdbPutChar(HexChars[Checksum & 0xf]);
}
/* Indicate to caller of GspMem2Hex or GspHex2Mem that there has been an
@ -312,7 +326,7 @@ static volatile void *GspAccessLocation = 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. */
PCHAR
GspMem2Hex (PCHAR Address,
GspMem2Hex(PCHAR Address,
PCHAR Buffer,
LONG Count,
BOOLEAN MayFault)
@ -329,26 +343,28 @@ GspMem2Hex (PCHAR Address,
for (i = 0; i < (ULONG) Count; i++)
{
if (MayFault)
{
GspAccessLocation = Address;
}
ch = *Address;
GspAccessLocation = NULL;
if (MayFault && GspMemoryError)
{
return (Buffer);
return Buffer;
}
*Buffer++ = HexChars[(ch >> 4) & 0xf];
*Buffer++ = HexChars[ch & 0xf];
Address++;
}
*Buffer = 0;
return (Buffer);
return Buffer;
}
/* 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 */
PCHAR
GspHex2Mem (PCHAR Buffer,
GspHex2Mem(PCHAR Buffer,
PCHAR Address,
ULONG Count,
BOOLEAN MayFault)
@ -363,7 +379,7 @@ GspHex2Mem (PCHAR Buffer,
current = Address;
while ( current < Address + Count )
{
page = (PCHAR)PAGE_ROUND_DOWN (current);
page = (PCHAR)PAGE_ROUND_DOWN(current);
if (Address + Count <= page + PAGE_SIZE)
{
/* Fits in this page */
@ -376,14 +392,14 @@ GspHex2Mem (PCHAR Buffer,
}
if (MayFault)
{
oldprot = MmGetPageProtect (NULL, Address);
MmSetPageProtect (NULL, Address, PAGE_EXECUTE_READWRITE);
oldprot = MmGetPageProtect(NULL, Address);
MmSetPageProtect(NULL, Address, PAGE_EXECUTE_READWRITE);
}
for (i = 0; i < countinpage && ! GspMemoryError; i++)
{
ch = (CHAR)(HexValue (*Buffer++) << 4);
ch = (CHAR)(ch + HexValue (*Buffer++));
ch = (CHAR)(HexValue(*Buffer++) << 4);
ch = (CHAR)(ch + HexValue(*Buffer++));
GspAccessLocation = current;
*current = ch;
@ -392,22 +408,22 @@ GspHex2Mem (PCHAR Buffer,
}
if (MayFault)
{
MmSetPageProtect (NULL, page, oldprot);
MmSetPageProtect(NULL, page, oldprot);
if (GspMemoryError)
{
return (Buffer);
return Buffer;
}
}
}
return (Buffer);
return Buffer;
}
/* This function takes the 386 exception vector and attempts to
translate this number into a unix compatible signal value */
ULONG
GspComputeSignal (NTSTATUS ExceptionCode)
GspComputeSignal(NTSTATUS ExceptionCode)
{
ULONG SigVal;
@ -427,11 +443,6 @@ GspComputeSignal (NTSTATUS ExceptionCode)
case STATUS_ILLEGAL_INSTRUCTION:
SigVal = 4; /* Invalid opcode */
break;
#if 0
case STATUS_FLT_INVALID_OPERATION:
SigVal = 8;
break;
#endif
case STATUS_STACK_OVERFLOW:
case STATUS_DATATYPE_MISALIGNMENT:
case STATUS_ACCESS_VIOLATION:
@ -449,7 +460,7 @@ GspComputeSignal (NTSTATUS ExceptionCode)
/* RETURN NUMBER OF CHARS PROCESSED */
/**********************************************/
LONG
GspHex2Long (PCHAR *Address,
GspHex2Long(PCHAR *Address,
PLONG Value)
{
LONG NumChars = 0;
@ -459,7 +470,7 @@ GspHex2Long (PCHAR *Address,
while (**Address)
{
Hex = HexValue (**Address);
Hex = HexValue(**Address);
if (Hex >= 0)
{
*Value = (*Value << 4) | Hex;
@ -473,12 +484,12 @@ GspHex2Long (PCHAR *Address,
(*Address)++;
}
return (NumChars);
return NumChars;
}
VOID
GspLong2Hex (PCHAR *Address,
GspLong2Hex(PCHAR *Address,
LONG Value)
{
LONG Save;
@ -487,7 +498,7 @@ GspLong2Hex (PCHAR *Address,
(((Value >> 8) & 0xff) << 16) |
(((Value >> 16) & 0xff) << 8) |
(((Value >> 24) & 0xff) << 0);
*Address = GspMem2Hex ((PCHAR) &Save, *Address, 4, FALSE);
*Address = GspMem2Hex((PCHAR) &Save, *Address, 4, FALSE);
}
@ -500,7 +511,6 @@ GspLong2Hex (PCHAR *Address,
static LONG
GspGetEspFromTrapFrame(PKTRAP_FRAME TrapFrame)
{
return KeGetPreviousMode() == KernelMode
? (LONG) &TrapFrame->Esp : (LONG)TrapFrame->Esp;
}
@ -517,17 +527,17 @@ GspGetRegistersFromTrapFrame(PCHAR Address,
DWORD i;
Buffer = Address;
for (i = 0; i < sizeof (GspRegisters) / sizeof (GspRegisters[0]); i++)
for (i = 0; i < sizeof(GspRegisters) / sizeof(GspRegisters[0]); i++)
{
if (TrapFrame)
{
if (ESP == i)
{
Value = GspGetEspFromTrapFrame (TrapFrame);
Value = GspGetEspFromTrapFrame(TrapFrame);
}
else
{
p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[i].OffsetInTF);
p = (PULONG)((ULONG_PTR) TrapFrame + GspRegisters[i].OffsetInTF);
Value = *p;
}
}
@ -543,7 +553,7 @@ GspGetRegistersFromTrapFrame(PCHAR Address,
{
Value = 0;
}
Buffer = GspMem2Hex ((PCHAR) &Value, Buffer, GspRegisters[i].Size, FALSE);
Buffer = GspMem2Hex((PCHAR) &Value, Buffer, GspRegisters[i].Size, FALSE);
}
}
@ -559,17 +569,23 @@ GspSetRegistersInTrapFrame(PCHAR Address,
DWORD i;
if (!TrapFrame)
{
return;
}
Buffer = Address;
for (i = 0; i < NUMREGS; i++)
{
if (GspRegisters[i].SetInContext)
{
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[i].OffsetInContext);
}
else
{
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;
}
}
@ -585,14 +601,20 @@ GspSetSingleRegisterInTrapFrame(PCHAR Address,
PULONG p;
if (!TrapFrame)
{
return;
}
if (GspRegisters[Number].SetInContext)
{
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[Number].OffsetInContext);
}
else
{
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;
}
@ -614,10 +636,10 @@ 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)))
if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &ThreadInfo)))
{
*Thread = NULL;
return FALSE;
@ -658,18 +680,26 @@ GspSetThread(PCHAR Request)
}
break;
case 'g': /* Debug thread */
if (GspFindThread (ptr, &ThreadInfo))
if (GspFindThread(ptr, &ThreadInfo))
{
GspOutBuffer[0] = 'O';
GspOutBuffer[1] = 'K';
if (GspDbgThread)
if (NULL != GspDbgThread)
{
ObDereferenceObject(GspDbgThread);
}
if (ThreadInfo == PsGetCurrentThread())
{
GspDbgThread = NULL;
ObDereferenceObject(ThreadInfo);
}
else
{
GspDbgThread = ThreadInfo;
}
}
else
{
GspOutBuffer[0] = 'E';
@ -701,9 +731,9 @@ GspQuery(PCHAR Request)
{
Value = (ULONG) PsGetCurrentThread()->Cid.UniqueThread;
}
GspLong2Hex (&ptr, Value);
GspLong2Hex(&ptr, Value);
}
else if (strncmp (Request, "fThreadInfo", 11) == 0)
else if (strncmp(Request, "fThreadInfo", 11) == 0)
{
PEPROCESS Process;
PLIST_ENTRY AThread, AProcess;
@ -716,9 +746,9 @@ GspQuery(PCHAR Request)
{
Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
AThread = Process->ThreadListHead.Flink;
if(AThread != &Process->ThreadListHead)
if (AThread != &Process->ThreadListHead)
{
GspEnumThread = CONTAINING_RECORD (Process->ThreadListHead.Flink,
GspEnumThread = CONTAINING_RECORD(Process->ThreadListHead.Flink,
ETHREAD, ThreadListEntry);
break;
}
@ -728,7 +758,7 @@ GspQuery(PCHAR Request)
{
GspOutBuffer[0] = 'm';
Value = (ULONG) GspEnumThread->Cid.UniqueThread;
GspLong2Hex (&ptr, Value);
GspLong2Hex(&ptr, Value);
}
else
{
@ -737,7 +767,7 @@ GspQuery(PCHAR Request)
/* GspOutBuffer[0] = 'l'; */
}
}
else if (strncmp (Request, "sThreadInfo", 11) == 0)
else if (strncmp(Request, "sThreadInfo", 11) == 0)
{
PEPROCESS Process;
PLIST_ENTRY AThread, AProcess;
@ -750,7 +780,7 @@ GspQuery(PCHAR Request)
Process = GspEnumThread->ThreadsProcess;
if(GspEnumThread->ThreadListEntry.Flink != &Process->ThreadListHead)
{
GspEnumThread = CONTAINING_RECORD (GspEnumThread->ThreadListEntry.Flink,
GspEnumThread = CONTAINING_RECORD(GspEnumThread->ThreadListEntry.Flink,
ETHREAD, ThreadListEntry);
}
else
@ -761,9 +791,9 @@ GspQuery(PCHAR Request)
{
Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
AThread = Process->ThreadListHead.Flink;
if(AThread != &Process->ThreadListHead)
if (AThread != &Process->ThreadListHead)
{
Thread = CONTAINING_RECORD (Process->ThreadListHead.Flink,
Thread = CONTAINING_RECORD(Process->ThreadListHead.Flink,
ETHREAD, ThreadListEntry);
break;
}
@ -772,12 +802,12 @@ GspQuery(PCHAR Request)
GspEnumThread = Thread;
}
if(GspEnumThread != NULL)
if (GspEnumThread != NULL)
{
/* return the ID */
GspOutBuffer[0] = 'm';
Value = (ULONG) GspEnumThread->Cid.UniqueThread;
GspLong2Hex (&ptr, Value);
GspLong2Hex(&ptr, Value);
}
else
{
@ -789,7 +819,7 @@ GspQuery(PCHAR Request)
GspOutBuffer[0] = 'l';
}
}
else if (strncmp (Request, "ThreadExtraInfo", 15) == 0)
else if (strncmp(Request, "ThreadExtraInfo", 15) == 0)
{
PETHREAD ThreadInfo;
@ -808,19 +838,14 @@ GspQuery(PCHAR Request)
(int) Proc->UniqueProcessId,
(int) ThreadInfo->Cid.UniqueThread);
}
strcpy(Buffer + strlen(Buffer), GspThreadStates[ThreadInfo->Tcb.State]);
strcpy(Buffer + strlen(Buffer),
GspThreadStates[ThreadInfo->Tcb.State]);
ObDereferenceObject(ThreadInfo);
GspMem2Hex(Buffer, &GspOutBuffer[0], strlen(Buffer), FALSE);
}
}
#if 0
else if (strncmp (Request, "Offsets", 7) == 0)
{
strcpy (GspOutBuffer, "Text=0;Data=0;Bss=0");
}
#endif
}
VOID
@ -829,7 +854,7 @@ GspQueryThreadStatus(PCHAR Request)
PETHREAD ThreadInfo;
PCHAR ptr = &Request[0];
if (GspFindThread (ptr, &ThreadInfo))
if (GspFindThread(ptr, &ThreadInfo))
{
ObDereferenceObject(ThreadInfo);
@ -1061,11 +1086,10 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
}
else
{
/* Don't switch threads */
/* Always use the current thread when entering the exception handler */
/* Make sure we're debugging the current thread. */
if (NULL != GspDbgThread)
{
DPRINT1("Internal error: entering stub with non-NULL GspDbgThread\n");
ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL;
}
@ -1078,7 +1102,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
stop_reply:
/* reply to host that an exception has occurred */
SigVal = GspComputeSignal (ExceptionRecord->ExceptionCode);
SigVal = GspComputeSignal(ExceptionRecord->ExceptionCode);
ptr = &GspOutBuffer[0];
@ -1089,13 +1113,13 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
*ptr++ = HexChars[ESP];
*ptr++ = ':';
Esp = GspGetEspFromTrapFrame (TrapFrame); /* SP */
ptr = GspMem2Hex ((PCHAR) &Esp, ptr, 4, 0);
Esp = GspGetEspFromTrapFrame(TrapFrame); /* SP */
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];
@ -1105,7 +1129,7 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
*ptr = '\0';
GspPutPacket (&GspOutBuffer[0]);
GspPutPacket(&GspOutBuffer[0]);
}
else
{
@ -1117,10 +1141,10 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
while (TRUE)
{
/* Zero the buffer now so we don't have to worry about the terminating zero character */
memset (GspOutBuffer, 0, sizeof (GspInBuffer));
ptr = GspGetPacket ();
memset(GspOutBuffer, 0, sizeof(GspInBuffer));
ptr = GspGetPacket();
switch (*ptr++)
switch(*ptr++)
{
case '?':
/* a little hack to send more complete status information */
@ -1136,94 +1160,105 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
case 'g': /* return the value of the CPU Registers */
if (NULL != GspDbgThread)
{
GspGetRegistersFromTrapFrame (&GspOutBuffer[0], Context, GspDbgThread->Tcb.TrapFrame);
GspGetRegistersFromTrapFrame(&GspOutBuffer[0], Context, GspDbgThread->Tcb.TrapFrame);
}
else
{
GspGetRegistersFromTrapFrame (&GspOutBuffer[0], Context, TrapFrame);
GspGetRegistersFromTrapFrame(&GspOutBuffer[0], Context, TrapFrame);
}
break;
case 'G': /* set the value of the CPU Registers - return OK */
if (NULL != GspDbgThread)
{
GspSetRegistersInTrapFrame (ptr, Context, GspDbgThread->Tcb.TrapFrame);
GspSetRegistersInTrapFrame(ptr, Context, GspDbgThread->Tcb.TrapFrame);
}
else
{
GspSetRegistersInTrapFrame (ptr, Context, TrapFrame);
GspSetRegistersInTrapFrame(ptr, Context, TrapFrame);
}
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
break;
case 'P': /* set the value of a single CPU register - return OK */
{
LONG Register;
if ((GspHex2Long (&ptr, &Register)) && (*ptr++ == '='))
if ((GspHex2Long(&ptr, &Register)) && (*ptr++ == '='))
{
if ((Register >= 0) && (Register < NUMREGS))
{
if (GspDbgThread)
{
GspSetSingleRegisterInTrapFrame(ptr, Register,
Context, GspDbgThread->Tcb.TrapFrame);
Context,
GspDbgThread->Tcb.TrapFrame);
}
else
{
GspSetSingleRegisterInTrapFrame (ptr, Register, Context, TrapFrame);
GspSetSingleRegisterInTrapFrame(ptr, Register,
Context, TrapFrame);
}
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
break;
}
}
strcpy (GspOutBuffer, "E01");
strcpy(GspOutBuffer, "E01");
break;
}
/* 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))
if (*(ptr++) == ',')
if (GspHex2Long (&ptr, &Length))
if (GspHex2Long(&ptr, &Address) &&
*(ptr++) == ',' &&
GspHex2Long(&ptr, &Length))
{
ptr = 0;
GspMemoryError = FALSE;
GspMem2Hex ((PCHAR) Address, GspOutBuffer, Length, 1);
GspMem2Hex((PCHAR) Address, GspOutBuffer, Length, 1);
if (GspMemoryError)
{
strcpy (GspOutBuffer, "E03");
DPRINT ("Fault during memory read\n");
strcpy(GspOutBuffer, "E03");
DPRINT("Fault during memory read\n");
}
}
if (ptr)
strcpy (GspOutBuffer, "E01");
{
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++) == ',')
if (GspHex2Long (&ptr, &Length))
if (*(ptr++) == ':')
if (GspHex2Long(&ptr, &Address))
{
if (*(ptr++) == ',' &&
GspHex2Long(&ptr, &Length) &&
*(ptr++) == ':')
{
GspMemoryError = FALSE;
GspHex2Mem (ptr, (PCHAR) Address, Length, TRUE);
GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE);
if (GspMemoryError)
{
strcpy (GspOutBuffer, "E03");
DPRINT ("Fault during memory write\n");
strcpy(GspOutBuffer, "E03");
DPRINT("Fault during memory write\n");
}
else
{
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
}
ptr = NULL;
}
if (ptr)
strcpy (GspOutBuffer, "E02");
}
if (NULL != ptr)
{
strcpy(GspOutBuffer, "E02");
}
break;
/* cAA..AA Continue at address AA..AA(optional) */
@ -1237,7 +1272,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
/* try to read optional parameter, pc unchanged if no parm */
if (GspHex2Long (&ptr, &Address))
{
Context->Eip = Address;
}
NewPC = Context->Eip;
@ -1246,7 +1283,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
/* set the trace bit if we're Stepping */
if (Stepping)
{
Context->EFlags |= 0x100;
}
#if defined(__GNUC__)
asm volatile ("movl %%db6, %0\n" : "=r" (dr6_) : );
@ -1279,25 +1318,31 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
#error Unknown compiler for inline assembler
#endif
if (NULL != GspDbgThread)
{
ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL;
}
return kdContinue;
break;
}
case 'k': /* kill the program */
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
break;
/* kill the program */
case 'H': /* Set thread */
GspSetThread (ptr);
GspSetThread(ptr);
break;
case 'q': /* Query */
GspQuery (ptr);
GspQuery(ptr);
break;
case 'T': /* Query thread status */
GspQueryThreadStatus (ptr);
GspQueryThreadStatus(ptr);
break;
case 'Y':
@ -1308,20 +1353,20 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
LONG Address;
ptr = &GspOutBuffer[1];
GspHex2Long (&ptr, &Number);
GspHex2Long(&ptr, &Number);
ptr++;
GspHex2Long (&ptr, &Type);
GspHex2Long(&ptr, &Type);
ptr++;
GspHex2Long (&ptr, &Length);
GspHex2Long(&ptr, &Length);
ptr++;
GspHex2Long (&ptr, &Address);
if (GspSetHwBreakpoint (Number & 0x3, Type & 0x3 , Length & 0x3, Address) == 0)
GspHex2Long(&ptr, &Address);
if (GspSetHwBreakpoint(Number & 0x3, Type & 0x3 , Length & 0x3, Address) == 0)
{
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
}
else
{
strcpy (GspOutBuffer, "E");
strcpy(GspOutBuffer, "E");
}
break;
}
@ -1333,13 +1378,13 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
ptr = &GspOutBuffer[1];
GspHex2Long(&ptr, &Number);
if (GspRemoveHwBreakpoint (Number & 0x3) == 0)
if (GspRemoveHwBreakpoint(Number & 0x3) == 0)
{
strcpy (GspOutBuffer, "OK");
strcpy(GspOutBuffer, "OK");
}
else
{
strcpy (GspOutBuffer, "E");
strcpy(GspOutBuffer, "E");
}
break;
}
@ -1349,13 +1394,19 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
}
/* reply to the request */
GspPutPacket (&GspOutBuffer[0]);
GspPutPacket(&GspOutBuffer[0]);
}
/* not reached */
ASSERT(0);
}
if (NULL != GspDbgThread)
{
ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL;
}
return kdContinue;
}
@ -1371,78 +1422,53 @@ GspBreakIn(PKINTERRUPT Interrupt,
KIRQL OldIrql;
UCHAR Value;
DPRINT ("Break In\n");
DPRINT("Break In\n");
DoBreakIn = FALSE;
while (KdPortGetByteEx (&GdbPortInfo, &Value))
while (KdPortGetByteEx(&GdbPortInfo, &Value))
{
if (Value == 0x03)
{
DoBreakIn = TRUE;
}
}
if (!DoBreakIn)
{
return TRUE;
}
KeRaiseIrql (HIGH_LEVEL, &OldIrql);
KeRaiseIrql(HIGH_LEVEL, &OldIrql);
TrapFrame = PsGetCurrentThread()->Tcb.TrapFrame;
KeTrapFrameToContext (TrapFrame, NULL, &Context);
KeTrapFrameToContext(TrapFrame, NULL, &Context);
KdpGdbEnterDebuggerException (NULL, &Context, TrapFrame);
KdpGdbEnterDebuggerException(NULL, &Context, TrapFrame);
KeContextToTrapFrame (&Context, NULL, TrapFrame, KernelMode);
KeContextToTrapFrame(&Context, NULL, TrapFrame, KernelMode);
KeLowerIrql (OldIrql);
KeLowerIrql(OldIrql);
return TRUE;
}
extern ULONG KdpPortIrq;
VOID
STDCALL
KdpGdbDebugPrint(PCH Message, ULONG Length)
{
}
extern LIST_ENTRY ModuleListHead;
VOID
KdGdbListModules()
{
PLIST_ENTRY CurrentEntry;
PLDR_DATA_TABLE_ENTRY Current;
ULONG ModuleCount;
DPRINT1("\n");
ModuleCount = 0;
CurrentEntry = ModuleListHead.Flink;
while (CurrentEntry != (&ModuleListHead))
{
Current = CONTAINING_RECORD (CurrentEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
DbgPrint ("Module %wZ Base 0x%.08x Length 0x%.08x\n",
&Current->BaseDllName, Current->DllBase, Current->SizeOfImage);
ModuleCount++;
CurrentEntry = CurrentEntry->Flink;
}
DbgPrint ("%d modules listed\n", ModuleCount);
}
/* Initialize the GDB stub */
VOID
STDCALL
KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable,
ULONG BootPhase)
{
if (!KdDebuggerEnabled || !KdpDebugMode.Gdb) return;
if (!KdDebuggerEnabled || !KdpDebugMode.Gdb)
{
return;
}
if (BootPhase == 0)
{
@ -1464,7 +1490,7 @@ KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable,
HalDisplayString("Waiting for GDB to attach\n");
DbgPrint("Module 'hal.dll' loaded at 0x%.08x.\n", LdrHalBase);
DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C);
DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
}
else if (BootPhase == 2)
{