* Move the KdbEntryCount (check for exception inside KDB) into the critical section to prevent KDB from not handling simultaneous exceptions correctly.

* Flush input when KDB is entered.
* Detect if terminal is connected and filter out escape sequences if no terminal is present.

svn path=/trunk/; revision=14389
This commit is contained in:
Gregor Anich 2005-03-31 16:08:09 +00:00
parent 97db1efac1
commit 91203bfc8d
2 changed files with 67 additions and 22 deletions

View file

@ -1141,12 +1141,6 @@ KdbEnterDebuggerException(
BOOLEAN EnterConditionMet = TRUE;
ULONG OldEflags;
/* Exception inside the debugger? Game over. */
if (InterlockedIncrement(&KdbEntryCount) > 1)
{
return kdHandleException;
}
KdbCurrentProcess = PsGetCurrentProcess();
/* Set continue type to kdContinue for single steps and breakpoints */
@ -1342,7 +1336,6 @@ KdbEnterDebuggerException(
{
if (!EnterConditionMet)
{
InterlockedDecrement(&KdbEntryCount);
return ContinueType;
}
DbgPrint("Entered debugger on unexpected debug trap!\n");
@ -1357,7 +1350,6 @@ KdbEnterDebuggerException(
}
if (!EnterConditionMet)
{
InterlockedDecrement(&KdbEntryCount);
return ContinueType;
}
@ -1372,7 +1364,6 @@ KdbEnterDebuggerException(
if (!EnterConditionMet)
{
InterlockedDecrement(&KdbEntryCount);
return ContinueType;
}
@ -1419,6 +1410,12 @@ KdbEnterDebuggerException(
Ke386SaveFlags(OldEflags);
Ke386DisableInterrupts();
/* Exception inside the debugger? Game over. */
if (InterlockedIncrement(&KdbEntryCount) > 1)
{
return kdHandleException;
}
/* Call the main loop. */
KdbpInternalEnter();
@ -1461,6 +1458,9 @@ KdbEnterDebuggerException(
"r"(KdbTrapFrame.Cr3), "r"(KdbTrapFrame.Cr4));
#endif
/* Decrement the entry count */
InterlockedDecrement(&KdbEntryCount);
/* Leave critical section */
Ke386RestoreFlags(OldEflags);
@ -1479,7 +1479,6 @@ continue_execution:
}
InterlockedDecrement(&KdbEntryCount);
return ContinueType;
}

View file

@ -1678,11 +1678,12 @@ KdbpPrint(
{
STATIC CHAR Buffer[4096];
STATIC BOOLEAN TerminalInitialized = FALSE;
STATIC BOOLEAN TerminalConnected = FALSE;
STATIC BOOLEAN TerminalReportsSize = TRUE;
CHAR c = '\0';
PCHAR p;
PCHAR p, p2;
INT Length;
INT i;
INT i, j;
INT RowsPrintedByTerminal;
ULONG ScanCode;
va_list ap;
@ -1695,7 +1696,25 @@ KdbpPrint(
if (!TerminalInitialized)
{
DbgPrint("\x1b[7h"); /* Enable linewrap */
/* Query terminal type */
/*DbgPrint("\x1b[Z");*/
DbgPrint("\x05");
TerminalInitialized = TRUE;
Length = 0;
for (;;)
{
c = KdbpTryGetCharSerial(5000);
if (c == -1)
break;
Buffer[Length++] = c;
if (Length >= (sizeof (Buffer) - 1))
break;
}
Buffer[Length] = '\0';
if (Length > 0)
TerminalConnected = TRUE;
}
/* Get number of rows and columns in terminal */
@ -1706,17 +1725,17 @@ KdbpPrint(
{
/* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
TerminalReportsSize = FALSE;
//DbgPrint("\x1b[18t");
c = KdbpTryGetCharSerial(10);
DbgPrint("\x1b[18t");
c = KdbpTryGetCharSerial(5000);
if (c == KEY_ESC)
{
c = KdbpTryGetCharSerial(5);
c = KdbpTryGetCharSerial(5000);
if (c == '[')
{
Length = 0;
for (;;)
{
c = KdbpTryGetCharSerial(5);
c = KdbpTryGetCharSerial(5000);
if (c == -1)
break;
Buffer[Length++] = c;
@ -1816,6 +1835,20 @@ KdbpPrint(
c = '\0';
}
/* Remove escape sequences from the line if there's no terminal connected */
if (!TerminalConnected)
{
while ((p2 = strrchr(p, '\x1b')) != NULL) /* Look for escape character */
{
if (p2[1] == '[')
{
j = 2;
while (!isalpha(p2[j++]));
strcpy(p2, p2 + j);
}
}
}
DbgPrint("%s", p);
if (c != '\0')
@ -1920,12 +1953,12 @@ KdbpReadCommand(
OUT PCHAR Buffer,
IN ULONG Size)
{
CHAR Key, NextKey;
CHAR Key;
PCHAR Orig = Buffer;
ULONG ScanCode = 0;
BOOLEAN EchoOn;
STATIC CHAR LastCommand[1024] = "";
STATIC CHAR LastKey = '\0';
STATIC CHAR NextKey = '\0';
INT CmdHistIndex = -1;
INT i;
@ -1935,7 +1968,7 @@ KdbpReadCommand(
{
if (KdDebugState & KD_DEBUG_KDSERIAL)
{
Key = KdbpGetCharSerial();
Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
ScanCode = 0;
if (Key == KEY_ESC) /* ESC */
{
@ -1961,7 +1994,8 @@ KdbpReadCommand(
}
else
{
Key = KdbpGetCharKeyboard(&ScanCode);
ScanCode = 0;
Key = (NextKey == '\0') ? KdbpGetCharKeyboard(&ScanCode) : NextKey;
}
if ((Buffer - Orig) >= (Size - 1))
@ -1980,6 +2014,8 @@ KdbpReadCommand(
NextKey = KdbpTryGetCharSerial(5);
else
NextKey = KdbpTryGetCharKeyboard(&ScanCode, 5);
if (NextKey == '\n')
NextKey = '\0';
DbgPrint("\n");
/*
* Repeat the last command if the user presses enter. Reduces the
@ -1996,7 +2032,6 @@ KdbpReadCommand(
strncpy(LastCommand, Orig, sizeof (LastCommand));
LastCommand[sizeof (LastCommand) - 1] = '\0';
}
LastKey = Key;
return;
}
else if (Key == KEY_BS || Key == KEY_DEL)
@ -2079,7 +2114,6 @@ KdbpReadCommand(
*Buffer = Key;
Buffer++;
}
LastKey = Key;
}
}
@ -2163,6 +2197,18 @@ KdbpCliMainLoop(
DbgPrint("\n");
}
/* Flush the input buffer */
if (KdDebugState & KD_DEBUG_KDSERIAL)
{
while (KdbpTryGetCharSerial(1) != -1);
}
else
{
ULONG ScanCode;
while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
}
/* Main loop */
do
{
/* Print the prompt */