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 #define BUFMAX 1000
static BOOLEAN GspInitialized; static BOOLEAN GspInitialized;
#if 0
static PKINTERRUPT GspInterrupt;
#endif
static BOOLEAN GspRemoteDebug; static BOOLEAN GspRemoteDebug;
@ -151,7 +148,8 @@ static CPU_REGISTER GspRegisters[NUMREGS] =
}; };
static PCHAR GspThreadStates[DeferredReady+1] = static PCHAR GspThreadStates[DeferredReady+1] =
{ "Initialized", {
"Initialized",
"Ready", "Ready",
"Running", "Running",
"Standby", "Standby",
@ -165,10 +163,20 @@ static PCHAR GspThreadStates[DeferredReady+1] =
LONG LONG
HexValue(CHAR ch) HexValue(CHAR ch)
{ {
if ((ch >= '0') && (ch <= '9')) return (ch - '0'); if ((ch >= '0') && (ch <= '9'))
if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10); {
if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10); return (ch - '0');
return (-1); }
if ((ch >= 'a') && (ch <= 'f'))
{
return (ch - 'a' + 10);
}
if ((ch >= 'A') && (ch <= 'F'))
{
return (ch - 'A' + 10);
}
return -1;
} }
static CHAR GspInBuffer[BUFMAX]; static CHAR GspInBuffer[BUFMAX];
@ -185,7 +193,8 @@ GdbGetChar(VOID)
{ {
UCHAR Value; UCHAR Value;
while (!KdPortGetByteEx (&GdbPortInfo, &Value)); while (!KdPortGetByteEx(&GdbPortInfo, &Value))
;
return Value; return Value;
} }
@ -204,7 +213,8 @@ GspGetPacket()
while (TRUE) while (TRUE)
{ {
/* wait around for the start character, ignore all other characters */ /* wait around for the start character, ignore all other characters */
while ((ch = GdbGetChar ()) != '$'); while ((ch = GdbGetChar ()) != '$')
;
retry: retry:
Checksum = 0; Checksum = 0;
@ -216,9 +226,13 @@ GspGetPacket()
{ {
ch = GdbGetChar(); ch = GdbGetChar();
if (ch == '$') if (ch == '$')
{
goto retry; goto retry;
}
if (ch == '#') if (ch == '#')
{
break; break;
}
Checksum = Checksum + ch; Checksum = Checksum + ch;
Buffer[Count] = ch; Buffer[Count] = ch;
Count = Count + 1; Count = Count + 1;
@ -329,19 +343,21 @@ GspMem2Hex (PCHAR Address,
for (i = 0; i < (ULONG) Count; i++) for (i = 0; i < (ULONG) Count; i++)
{ {
if (MayFault) if (MayFault)
{
GspAccessLocation = Address; GspAccessLocation = Address;
}
ch = *Address; ch = *Address;
GspAccessLocation = NULL; GspAccessLocation = NULL;
if (MayFault && GspMemoryError) if (MayFault && GspMemoryError)
{ {
return (Buffer); return Buffer;
} }
*Buffer++ = HexChars[(ch >> 4) & 0xf]; *Buffer++ = HexChars[(ch >> 4) & 0xf];
*Buffer++ = HexChars[ch & 0xf]; *Buffer++ = HexChars[ch & 0xf];
Address++; Address++;
} }
*Buffer = 0; *Buffer = 0;
return (Buffer); return Buffer;
} }
@ -395,12 +411,12 @@ GspHex2Mem (PCHAR Buffer,
MmSetPageProtect(NULL, page, oldprot); MmSetPageProtect(NULL, page, oldprot);
if (GspMemoryError) if (GspMemoryError)
{ {
return (Buffer); return Buffer;
} }
} }
} }
return (Buffer); return Buffer;
} }
@ -427,11 +443,6 @@ GspComputeSignal (NTSTATUS ExceptionCode)
case STATUS_ILLEGAL_INSTRUCTION: case STATUS_ILLEGAL_INSTRUCTION:
SigVal = 4; /* Invalid opcode */ SigVal = 4; /* Invalid opcode */
break; break;
#if 0
case STATUS_FLT_INVALID_OPERATION:
SigVal = 8;
break;
#endif
case STATUS_STACK_OVERFLOW: case STATUS_STACK_OVERFLOW:
case STATUS_DATATYPE_MISALIGNMENT: case STATUS_DATATYPE_MISALIGNMENT:
case STATUS_ACCESS_VIOLATION: case STATUS_ACCESS_VIOLATION:
@ -473,7 +484,7 @@ GspHex2Long (PCHAR *Address,
(*Address)++; (*Address)++;
} }
return (NumChars); return NumChars;
} }
@ -500,7 +511,6 @@ GspLong2Hex (PCHAR *Address,
static LONG static LONG
GspGetEspFromTrapFrame(PKTRAP_FRAME TrapFrame) GspGetEspFromTrapFrame(PKTRAP_FRAME TrapFrame)
{ {
return KeGetPreviousMode() == KernelMode return KeGetPreviousMode() == KernelMode
? (LONG) &TrapFrame->Esp : (LONG)TrapFrame->Esp; ? (LONG) &TrapFrame->Esp : (LONG)TrapFrame->Esp;
} }
@ -559,15 +569,21 @@ GspSetRegistersInTrapFrame(PCHAR Address,
DWORD i; DWORD i;
if (!TrapFrame) if (!TrapFrame)
{
return; return;
}
Buffer = Address; Buffer = Address;
for (i = 0; i < NUMREGS; i++) for (i = 0; i < NUMREGS; i++)
{ {
if (GspRegisters[i].SetInContext) if (GspRegisters[i].SetInContext)
{
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[i].OffsetInContext); p = (PULONG) ((ULONG_PTR) Context + GspRegisters[i].OffsetInContext);
}
else else
{
p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[i].OffsetInTF); p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[i].OffsetInTF);
}
Value = 0; Value = 0;
Buffer = GspHex2Mem(Buffer, (PCHAR) &Value, GspRegisters[i].Size, FALSE); Buffer = GspHex2Mem(Buffer, (PCHAR) &Value, GspRegisters[i].Size, FALSE);
*p = Value; *p = Value;
@ -585,12 +601,18 @@ GspSetSingleRegisterInTrapFrame(PCHAR Address,
PULONG p; PULONG p;
if (!TrapFrame) if (!TrapFrame)
{
return; return;
}
if (GspRegisters[Number].SetInContext) if (GspRegisters[Number].SetInContext)
{
p = (PULONG) ((ULONG_PTR) Context + GspRegisters[Number].OffsetInContext); p = (PULONG) ((ULONG_PTR) Context + GspRegisters[Number].OffsetInContext);
}
else else
{
p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[Number].OffsetInTF); p = (PULONG) ((ULONG_PTR) TrapFrame + GspRegisters[Number].OffsetInTF);
}
Value = 0; Value = 0;
GspHex2Mem(Address, (PCHAR) &Value, GspRegisters[Number].Size, FALSE); GspHex2Mem(Address, (PCHAR) &Value, GspRegisters[Number].Size, FALSE);
*p = Value; *p = Value;
@ -663,13 +685,21 @@ GspSetThread(PCHAR Request)
GspOutBuffer[0] = 'O'; GspOutBuffer[0] = 'O';
GspOutBuffer[1] = 'K'; GspOutBuffer[1] = 'K';
if (GspDbgThread) if (NULL != GspDbgThread)
{ {
ObDereferenceObject(GspDbgThread); ObDereferenceObject(GspDbgThread);
} }
if (ThreadInfo == PsGetCurrentThread())
{
GspDbgThread = NULL;
ObDereferenceObject(ThreadInfo);
}
else
{
GspDbgThread = ThreadInfo; GspDbgThread = ThreadInfo;
} }
}
else else
{ {
GspOutBuffer[0] = 'E'; GspOutBuffer[0] = 'E';
@ -808,19 +838,14 @@ GspQuery(PCHAR Request)
(int) Proc->UniqueProcessId, (int) Proc->UniqueProcessId,
(int) ThreadInfo->Cid.UniqueThread); (int) ThreadInfo->Cid.UniqueThread);
} }
strcpy(Buffer + strlen(Buffer), GspThreadStates[ThreadInfo->Tcb.State]); strcpy(Buffer + strlen(Buffer),
GspThreadStates[ThreadInfo->Tcb.State]);
ObDereferenceObject(ThreadInfo); ObDereferenceObject(ThreadInfo);
GspMem2Hex(Buffer, &GspOutBuffer[0], strlen(Buffer), FALSE); 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 VOID
@ -1061,11 +1086,10 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
} }
else else
{ {
/* Don't switch threads */ /* Make sure we're debugging the current thread. */
/* Always use the current thread when entering the exception handler */
if (NULL != GspDbgThread) if (NULL != GspDbgThread)
{ {
DPRINT1("Internal error: entering stub with non-NULL GspDbgThread\n");
ObDereferenceObject(GspDbgThread); ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL; GspDbgThread = NULL;
} }
@ -1159,20 +1183,24 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
LONG Register; LONG Register;
if ((GspHex2Long(&ptr, &Register)) && (*ptr++ == '=')) if ((GspHex2Long(&ptr, &Register)) && (*ptr++ == '='))
{
if ((Register >= 0) && (Register < NUMREGS)) if ((Register >= 0) && (Register < NUMREGS))
{ {
if (GspDbgThread) if (GspDbgThread)
{ {
GspSetSingleRegisterInTrapFrame(ptr, Register, GspSetSingleRegisterInTrapFrame(ptr, Register,
Context, GspDbgThread->Tcb.TrapFrame); Context,
GspDbgThread->Tcb.TrapFrame);
} }
else else
{ {
GspSetSingleRegisterInTrapFrame (ptr, Register, Context, TrapFrame); GspSetSingleRegisterInTrapFrame(ptr, Register,
Context, TrapFrame);
} }
strcpy(GspOutBuffer, "OK"); strcpy(GspOutBuffer, "OK");
break; break;
} }
}
strcpy(GspOutBuffer, "E01"); strcpy(GspOutBuffer, "E01");
break; break;
@ -1181,9 +1209,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
case 'm': case 'm':
/* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
if (GspHex2Long (&ptr, &Address)) if (GspHex2Long(&ptr, &Address) &&
if (*(ptr++) == ',') *(ptr++) == ',' &&
if (GspHex2Long (&ptr, &Length)) GspHex2Long(&ptr, &Length))
{ {
ptr = 0; ptr = 0;
GspMemoryError = FALSE; GspMemoryError = FALSE;
@ -1196,16 +1224,19 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
} }
if (ptr) if (ptr)
{
strcpy(GspOutBuffer, "E01"); strcpy(GspOutBuffer, "E01");
}
break; break;
/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
case 'M': case 'M':
/* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
if (GspHex2Long(&ptr, &Address)) if (GspHex2Long(&ptr, &Address))
if (*(ptr++) == ',') {
if (GspHex2Long (&ptr, &Length)) if (*(ptr++) == ',' &&
if (*(ptr++) == ':') GspHex2Long(&ptr, &Length) &&
*(ptr++) == ':')
{ {
GspMemoryError = FALSE; GspMemoryError = FALSE;
GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE); GspHex2Mem(ptr, (PCHAR) Address, Length, TRUE);
@ -1222,8 +1253,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
ptr = NULL; ptr = NULL;
} }
if (ptr) }
if (NULL != ptr)
{
strcpy(GspOutBuffer, "E02"); strcpy(GspOutBuffer, "E02");
}
break; break;
/* cAA..AA Continue at address AA..AA(optional) */ /* 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 */ /* try to read optional parameter, pc unchanged if no parm */
if (GspHex2Long (&ptr, &Address)) if (GspHex2Long (&ptr, &Address))
{
Context->Eip = Address; Context->Eip = Address;
}
NewPC = Context->Eip; NewPC = Context->Eip;
@ -1246,7 +1283,9 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
/* set the trace bit if we're Stepping */ /* set the trace bit if we're Stepping */
if (Stepping) if (Stepping)
{
Context->EFlags |= 0x100; Context->EFlags |= 0x100;
}
#if defined(__GNUC__) #if defined(__GNUC__)
asm volatile ("movl %%db6, %0\n" : "=r" (dr6_) : ); asm volatile ("movl %%db6, %0\n" : "=r" (dr6_) : );
@ -1279,6 +1318,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
#error Unknown compiler for inline assembler #error Unknown compiler for inline assembler
#endif #endif
if (NULL != GspDbgThread)
{
ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL;
}
return kdContinue; return kdContinue;
break; break;
} }
@ -1356,6 +1401,12 @@ KdpGdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
ASSERT(0); ASSERT(0);
} }
if (NULL != GspDbgThread)
{
ObDereferenceObject(GspDbgThread);
GspDbgThread = NULL;
}
return kdContinue; return kdContinue;
} }
@ -1377,11 +1428,15 @@ GspBreakIn(PKINTERRUPT Interrupt,
while (KdPortGetByteEx(&GdbPortInfo, &Value)) while (KdPortGetByteEx(&GdbPortInfo, &Value))
{ {
if (Value == 0x03) if (Value == 0x03)
{
DoBreakIn = TRUE; DoBreakIn = TRUE;
} }
}
if (!DoBreakIn) if (!DoBreakIn)
{
return TRUE; return TRUE;
}
KeRaiseIrql(HIGH_LEVEL, &OldIrql); KeRaiseIrql(HIGH_LEVEL, &OldIrql);
@ -1398,51 +1453,22 @@ GspBreakIn(PKINTERRUPT Interrupt,
return TRUE; return TRUE;
} }
extern ULONG KdpPortIrq;
VOID VOID
STDCALL STDCALL
KdpGdbDebugPrint(PCH Message, ULONG Length) 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 */ /* Initialize the GDB stub */
VOID VOID
STDCALL STDCALL
KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable, KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable,
ULONG BootPhase) ULONG BootPhase)
{ {
if (!KdDebuggerEnabled || !KdpDebugMode.Gdb) return; if (!KdDebuggerEnabled || !KdpDebugMode.Gdb)
{
return;
}
if (BootPhase == 0) if (BootPhase == 0)
{ {