mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 10:20:03 +00:00
Add an option to serialize DbgPrint - don't worry, it's disabled by default and meant only for those who are tired of reading mixed debug messages.
svn path=/trunk/; revision=11998
This commit is contained in:
parent
30fd9c8072
commit
bc28145d48
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: print.c,v 1.20 2004/08/21 15:34:32 tamlin Exp $
|
||||
/* $Id: print.c,v 1.21 2004/12/10 14:58:25 blight Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -61,6 +61,13 @@ DbgPrint(PCH Format, ...)
|
|||
ANSI_STRING DebugString;
|
||||
CHAR Buffer[1024];
|
||||
va_list ap;
|
||||
#ifdef SERIALIZE_DBGPRINT
|
||||
LONG MyTableIndex;
|
||||
static LONG Lock = 0;
|
||||
static LONG TableWriteIndex = 0, TableReadIndex = 0;
|
||||
static PCHAR MessageTable[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
# define MESSAGETABLE_SIZE (sizeof (MessageTable) / sizeof (MessageTable[0]))
|
||||
#endif /* SERIALIZE_DBGPRINT */
|
||||
|
||||
/* init ansi string */
|
||||
DebugString.Buffer = Buffer;
|
||||
|
@ -70,7 +77,62 @@ DbgPrint(PCH Format, ...)
|
|||
DebugString.Length = _vsnprintf (Buffer, sizeof( Buffer ), Format, ap);
|
||||
va_end (ap);
|
||||
|
||||
#ifdef SERIALIZE_DBGPRINT
|
||||
/* check if we are already running */
|
||||
if (InterlockedCompareExchange(&Lock, 1, 0) == 1)
|
||||
{
|
||||
PCHAR Dup;
|
||||
Dup = ExAllocatePool(NonPagedPool, DebugString.Length + 1);
|
||||
memcpy(Dup, DebugString.Buffer, DebugString.Length);
|
||||
Dup[DebugString.Length] = '\0';
|
||||
|
||||
MyTableIndex = InterlockedIncrement(&TableWriteIndex) - 1;
|
||||
InterlockedCompareExchange(&TableWriteIndex, 0, MESSAGETABLE_SIZE);
|
||||
MyTableIndex %= MESSAGETABLE_SIZE;
|
||||
|
||||
if (MessageTable[MyTableIndex] != NULL) /* table is full */
|
||||
{
|
||||
DebugString.Buffer = "CRITICAL ERROR: DbgPrint Table is FULL!";
|
||||
DebugString.Length = 39;
|
||||
KdpPrintString(&DebugString);
|
||||
for (;;);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*DebugString.Buffer = "µµµ";
|
||||
DebugString.Length = 3;
|
||||
KdpPrintString(&DebugString);*/
|
||||
MessageTable[MyTableIndex] = Dup;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* SERIALIZE_DBGPRINT */
|
||||
KdpPrintString (&DebugString);
|
||||
#ifdef SERIALIZE_DBGPRINT
|
||||
MyTableIndex = TableReadIndex;
|
||||
while (MessageTable[MyTableIndex] != NULL)
|
||||
{
|
||||
/*DebugString.Buffer = "$$$";
|
||||
DebugString.Length = 3;
|
||||
KdpPrintString(&DebugString);*/
|
||||
|
||||
DebugString.Buffer = MessageTable[MyTableIndex];
|
||||
MessageTable[MyTableIndex] = NULL;
|
||||
DebugString.Length = strlen(DebugString.Buffer);
|
||||
DebugString.MaximumLength = DebugString.Length + 1;
|
||||
|
||||
KdpPrintString(&DebugString);
|
||||
ExFreePool(DebugString.Buffer);
|
||||
|
||||
MyTableIndex = InterlockedIncrement(&TableReadIndex);
|
||||
InterlockedCompareExchange(&TableReadIndex, 0, MESSAGETABLE_SIZE);
|
||||
MyTableIndex %= MESSAGETABLE_SIZE;
|
||||
}
|
||||
InterlockedDecrement(&Lock);
|
||||
}
|
||||
# undef MESSAGETABLE_SIZE
|
||||
#endif /* SERIALIZE_DBGPRINT */
|
||||
|
||||
return (ULONG)DebugString.Length;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
#ifndef __INCLUDE_NTOSKRNL_CONFIG_H
|
||||
#define __INCLUDE_NTOSKRNL_CONFIG_H
|
||||
|
||||
/********** dbg/print.c **********/
|
||||
|
||||
/* Enable serialization of debug messages printed with DbgPrint
|
||||
*
|
||||
* If this is enabled DbgPrint will queue messages if another thread is already
|
||||
* printing a message, and immediately returns. The other thread will print
|
||||
* queued messages before it returns.
|
||||
* It could happen that some messages are lost if the processor is halted before
|
||||
* the message queue was flushed.
|
||||
*/
|
||||
#undef SERIALIZE_DBGPRINT
|
||||
|
||||
/********** mm/ppool.c **********/
|
||||
|
||||
/* Enable strict checking of the nonpaged pool on every allocation */
|
||||
#undef ENABLE_VALIDATE_POOL
|
||||
|
||||
|
|
Loading…
Reference in a new issue