Only whitespace changes, no logic
Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
_____
Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
--- trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c 2005-10-14
19:09:45 UTC (rev 18454)
+++ trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c 2005-10-14
19:28:18 UTC (rev 18455)
@@ -94,9 +94,6 @@
#define BUFMAX 1000
static BOOLEAN GspInitialized;
-#if 0
-static PKINTERRUPT GspInterrupt;
-#endif
static BOOLEAN GspRemoteDebug;
@@ -132,26 +129,27 @@
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 @@
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 @@
VOID
GdbPutChar(UCHAR Value)
{
- KdPortPutByteEx (&GdbPortInfo, Value);
+ KdPortPutByteEx(&GdbPortInfo, Value);
}
UCHAR
@@ -185,7 +193,8 @@
{
UCHAR Value;
- while (!KdPortGetByteEx (&GdbPortInfo, &Value));
+ while (!KdPortGetByteEx(&GdbPortInfo, &Value))
+ ;
return Value;
}
@@ -204,7 +213,8 @@
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 @@
/* now, read until a # or end of Buffer is found */
while (Count < BUFMAX)
{
- ch = GdbGetChar ();
+ ch = GdbGetChar();
if (ch == '$')
- goto retry;
+ {
+ goto retry;
+ }
if (ch == '#')
- break;
+ {
+ break;
+ }
Checksum = Checksum + ch;
Buffer[Count] = ch;
Count = Count + 1;
@@ -227,18 +241,18 @@
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 @@
/* send the packet in Buffer. */
VOID
-GspPutPacket (PCHAR Buffer)
+GspPutPacket(PCHAR Buffer)
{
CHAR Checksum;
LONG Count;
@@ -258,47 +272,47 @@
/* $<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 @@
/* 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 @@
for (i = 0; i < (ULONG) Count; i++)
{
if (MayFault)
- GspAccessLocation = Address;
+ {
+ 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 @@
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 @@
}
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 @@
}
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 @@
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 @@
/* RETURN NUMBER OF CHARS PROCESSED */
/**********************************************/
LONG
-GspHex2Long (PCHAR *Address,
+GspHex2Long(PCHAR *Address,
PLONG Value)
{
LONG NumChars = 0;
@@ -459,7 +470,7 @@
while (**Address)
{
- Hex = HexValue (**Address);
+ Hex = HexValue(**Address);
if (Hex >= 0)
{
*Value = (*Value << 4) | Hex;
@@ -473,12 +484,12 @@
(*Address)++;
}
- return (NumChars);
+ return NumChars;
}
VOID
-GspLong2Hex (PCHAR *Address,
+GspLong2Hex(PCHAR *Address,
LONG Value)
{
LONG Save;
@@ -487,7 +498,7 @@
(((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 @@
static LONG
GspGetEspFromTrapFrame(PKTRAP_FRAME TrapFrame)
{
-
return KeGetPreviousMode() == KernelMode
? (LONG) &TrapFrame->Esp : (LONG)TrapFrame->Esp;
}
@@ -517,34 +527,34 @@
DWORD i;
Buffer = Address;
- for (i = 0; i < sizeof (GspRegisters) / sizeof (GspRegisters[0]);
i++)
- {
- if (TrapFrame)
+ for (i = 0; i < sizeof(GspRegisters) / sizeof(GspRegisters[0]); i++)
{
- if (ESP == i)
- {
- Value = GspGetEspFromTrapFrame (TrapFrame);
- }
+ if (TrapFrame)
+ {
+ if (ESP == i)
+ {
+ Value = GspGetEspFromTrapFrame(TrapFrame);
+ }
+ else
+ {
+ p = (PULONG)((ULONG_PTR) TrapFrame +
GspRegisters[i].OffsetInTF);
+ Value = *p;
+ }
+ }
+ else if (i == EIP_REGNO)
+ {
+ /*
+ * This thread has not been sheduled yet so assume it
+ * is still in PsBeginThreadWithContextInternal().
+ */
+ Value = (ULONG)KiThreadStartup;
+ }
else
- {
- p = (PULONG) ((ULONG_PTR) TrapFrame +
GspRegisters[i].OffsetInTF);
- Value = *p;
- }
+ {
+ Value = 0;
+ }
+ Buffer = GspMem2Hex((PCHAR) &Value, Buffer, GspRegisters[i].Size,
FALSE);
}
- else if (i == EIP_REGNO)
- {
- /*
- * This thread has not been sheduled yet so assume it
- * is still in PsBeginThreadWithContextInternal().
- */
- Value = (ULONG)KiThreadStartup;
- }
- else
- {
- Value = 0;
- }
- Buffer = GspMem2Hex ((PCHAR) &Value, Buffer, GspRegisters[i].Size,
FALSE);
- }
}
@@ -559,19 +569,25 @@
DWORD i;
if (!TrapFrame)
- return;
+ {
+ 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);
- *p = Value;
- }
+ {
+ 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);
+ *p = Value;
+ }
}
@@ -585,14 +601,20 @@
PULONG p;
if (!TrapFrame)
- return;
+ {
+ 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;
}
@@ -608,16 +630,16 @@
/* All threads */
ThreadInfo = NULL;
}
- else
+ else
{
ULONG uThreadId;
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,17 +680,25 @@
}
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);
}
- GspDbgThread = ThreadInfo;
+ if (ThreadInfo == PsGetCurrentThread())
+ {
+ GspDbgThread = NULL;
+ ObDereferenceObject(ThreadInfo);
+ }
+ else
+ {
+ GspDbgThread = ThreadInfo;
+ }
}
else
{
@@ -687,140 +717,135 @@
ULONG Value;
if (strncmp(Request, "C", 1) == 0)
- {
- PCHAR ptr = &GspOutBuffer[2];
-
- /* Get current thread id */
- GspOutBuffer[0] = 'Q';
- GspOutBuffer[1] = 'C';
- if (NULL != GspDbgThread)
{
- Value = (ULONG) GspDbgThread->Cid.UniqueThread;
- }
- else
- {
- Value = (ULONG) PsGetCurrentThread()->Cid.UniqueThread;
- }
- GspLong2Hex (&ptr, Value);
- }
- else if (strncmp (Request, "fThreadInfo", 11) == 0)
- {
- PEPROCESS Process;
- PLIST_ENTRY AThread, AProcess;
- PCHAR ptr = &GspOutBuffer[1];
+ PCHAR ptr = &GspOutBuffer[2];
- /* Get first thread id */
- GspEnumThread = NULL;
- AProcess = PsActiveProcessHead.Flink;
- while(AProcess != &PsActiveProcessHead)
- {
- Process = CONTAINING_RECORD(AProcess, EPROCESS,
ActiveProcessLinks);
- AThread = Process->ThreadListHead.Flink;
- if(AThread != &Process->ThreadListHead)
- {
- GspEnumThread = CONTAINING_RECORD
(Process->ThreadListHead.Flink,
- ETHREAD, ThreadListEntry);
- break;
- }
- AProcess = AProcess->Flink;
+ /* Get current thread id */
+ GspOutBuffer[0] = 'Q';
+ GspOutBuffer[1] = 'C';
+ if (NULL != GspDbgThread)
+ {
+ Value = (ULONG) GspDbgThread->Cid.UniqueThread;
+ }
+ else
+ {
+ Value = (ULONG) PsGetCurrentThread()->Cid.UniqueThread;
+ }
+ GspLong2Hex(&ptr, Value);
}
- if(GspEnumThread != NULL)
+ else if (strncmp(Request, "fThreadInfo", 11) == 0)
{
- GspOutBuffer[0] = 'm';
- Value = (ULONG) GspEnumThread->Cid.UniqueThread;
- GspLong2Hex (&ptr, Value);
- }
- else
- {
- /* FIXME - what to do here? This case should never happen though,
there
- should always be at least one thread on the system...
*/
- /* GspOutBuffer[0] = 'l'; */
- }
- }
- else if (strncmp (Request, "sThreadInfo", 11) == 0)
- {
- PEPROCESS Process;
- PLIST_ENTRY AThread, AProcess;
- PCHAR ptr = &GspOutBuffer[1];
+ PEPROCESS Process;
+ PLIST_ENTRY AThread, AProcess;
+ PCHAR ptr = &GspOutBuffer[1];
- /* Get next thread id */
- if (GspEnumThread != NULL)
- {
- /* find the next thread */
- Process = GspEnumThread->ThreadsProcess;
- if(GspEnumThread->ThreadListEntry.Flink !=
&Process->ThreadListHead)
- {
- GspEnumThread = CONTAINING_RECORD
(GspEnumThread->ThreadListEntry.Flink,
- ETHREAD, ThreadListEntry);
- }
- else
- {
- PETHREAD Thread = NULL;
- AProcess = Process->ActiveProcessLinks.Flink;
- while(AProcess != &PsActiveProcessHead)
+ /* Get first thread id */
+ GspEnumThread = NULL;
+ AProcess = PsActiveProcessHead.Flink;
+ while(AProcess != &PsActiveProcessHead)
{
Process = CONTAINING_RECORD(AProcess, EPROCESS,
ActiveProcessLinks);
AThread = Process->ThreadListHead.Flink;
- if(AThread != &Process->ThreadListHead)
- {
- Thread = CONTAINING_RECORD (Process->ThreadListHead.Flink,
- ETHREAD, ThreadListEntry);
- break;
- }
+ if (AThread != &Process->ThreadListHead)
+ {
+ GspEnumThread =
CONTAINING_RECORD(Process->ThreadListHead.Flink,
+ ETHREAD,
ThreadListEntry);
+ break;
+ }
AProcess = AProcess->Flink;
}
- GspEnumThread = Thread;
- }
-
if(GspEnumThread != NULL)
- {
- /* return the ID */
- GspOutBuffer[0] = 'm';
- Value = (ULONG) GspEnumThread->Cid.UniqueThread;
- GspLong2Hex (&ptr, Value);
- }
+ {
+ GspOutBuffer[0] = 'm';
+ Value = (ULONG) GspEnumThread->Cid.UniqueThread;
+ GspLong2Hex(&ptr, Value);
+ }
else
- {
- GspOutBuffer[0] = 'l';
- }
+ {
+ /* FIXME - what to do here? This case should never happen
though, there
+ should always be at least one thread on the
system... */
+ /* GspOutBuffer[0] = 'l'; */
+ }
}
- else
+ else if (strncmp(Request, "sThreadInfo", 11) == 0)
{
- GspOutBuffer[0] = 'l';
+ PEPROCESS Process;
+ PLIST_ENTRY AThread, AProcess;
+ PCHAR ptr = &GspOutBuffer[1];
+
+ /* Get next thread id */
+ if (GspEnumThread != NULL)
+ {
+ /* find the next thread */
+ Process = GspEnumThread->ThreadsProcess;
+ if(GspEnumThread->ThreadListEntry.Flink !=
&Process->ThreadListHead)
+ {
+ GspEnumThread =
CONTAINING_RECORD(GspEnumThread->ThreadListEntry.Flink,
+ ETHREAD,
ThreadListEntry);
+ }
+ else
+ {
+ PETHREAD Thread = NULL;
+ AProcess = Process->ActiveProcessLinks.Flink;
+ while(AProcess != &PsActiveProcessHead)
+ {
+ Process = CONTAINING_RECORD(AProcess, EPROCESS,
ActiveProcessLinks);
+ AThread = Process->ThreadListHead.Flink;
+ if (AThread != &Process->ThreadListHead)
+ {
+ Thread =
CONTAINING_RECORD(Process->ThreadListHead.Flink,
+ ETHREAD,
ThreadListEntry);
+ break;
+ }
+ AProcess = AProcess->Flink;
+ }
+ GspEnumThread = Thread;
+ }
+
+ if (GspEnumThread != NULL)
+ {
+ /* return the ID */
+ GspOutBuffer[0] = 'm';
+ Value = (ULONG) GspEnumThread->Cid.UniqueThread;
+ GspLong2Hex(&ptr, Value);
+ }
+ else
+ {
+ GspOutBuffer[0] = 'l';
+ }
+ }
+ else
+ {
+ GspOutBuffer[0] = 'l';
+ }
}
- }
- else if (strncmp (Request, "ThreadExtraInfo", 15) == 0)
- {
- PETHREAD ThreadInfo;
-
- /* Get thread information */
- if (GspFindThread(Request + 16, &ThreadInfo))
+ else if (strncmp(Request, "ThreadExtraInfo", 15) == 0)
{
- char Buffer[64];
- PEPROCESS Proc;
+ PETHREAD ThreadInfo;
- Proc = (PEPROCESS) ThreadInfo->Tcb.ApcState.Process;
+ /* Get thread information */
+ if (GspFindThread(Request + 16, &ThreadInfo))
+ {
+ char Buffer[64];
+ PEPROCESS Proc;
- 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]);
+ Proc = (PEPROCESS) ThreadInfo->Tcb.ApcState.Process;
- ObDereferenceObject(ThreadInfo);
+ 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]);
- GspMem2Hex(Buffer, &GspOutBuffer[0], strlen(Buffer), FALSE);
+ 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,19 +854,19 @@
PETHREAD ThreadInfo;
PCHAR ptr = &Request[0];
- if (GspFindThread (ptr, &ThreadInfo))
- {
- ObDereferenceObject(ThreadInfo);
+ if (GspFindThread(ptr, &ThreadInfo))
+ {
+ ObDereferenceObject(ThreadInfo);
- GspOutBuffer[0] = 'O';
- GspOutBuffer[1] = 'K';
- GspOutBuffer[2] = '\0';
- }
+ GspOutBuffer[0] = 'O';
+ GspOutBuffer[1] = 'K';
+ GspOutBuffer[2] = '\0';
+ }
else
- {
- GspOutBuffer[0] = 'E';
- GspOutBuffer[1] = '\0';
- }
+ {
+ GspOutBuffer[0] = 'E';
+ GspOutBuffer[1] = '\0';
+ }
}
@@ -1061,11 +1086,10 @@
}
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 @@
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 @@
*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 @@
*ptr = '\0';
- GspPutPacket (&GspOutBuffer[0]);
+ GspPutPacket(&GspOutBuffer[0]);
}
else
{
@@ -1117,10 +1141,10 @@
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 @@
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 ((Register >= 0) && (Register < NUMREGS))
- {
- if (GspDbgThread)
- {
- GspSetSingleRegisterInTrapFrame(ptr,
Register,
- Context,
GspDbgThread->Tcb.TrapFrame);
- }
- else
- {
- GspSetSingleRegisterInTrapFrame (ptr,
Register, Context, TrapFrame);
- }
- strcpy (GspOutBuffer, "OK");
- break;
- }
+ if ((GspHex2Long(&ptr, &Register)) && (*ptr++ ==
'='))
+ {
+ if ((Register >= 0) && (Register < NUMREGS))
+ {
+ if (GspDbgThread)
+ {
+ GspSetSingleRegisterInTrapFrame(ptr,
Register,
+ Context,
+
GspDbgThread->Tcb.TrapFrame);
+ }
+ else
+ {
+ GspSetSingleRegisterInTrapFrame(ptr,
Register,
+ Context,
TrapFrame);
+ }
+ 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);
+ if (GspMemoryError)
{
- ptr = 0;
- GspMemoryError = FALSE;
- 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");
}
+ }
[truncated at 1000 lines; 306 more skipped]