From bc28145d487f4d9d0190f0497f29532875edeaaa Mon Sep 17 00:00:00 2001 From: Gregor Anich Date: Fri, 10 Dec 2004 14:58:26 +0000 Subject: [PATCH] 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 --- reactos/ntoskrnl/dbg/print.c | 66 ++++++++++++++++++++++++++++++- reactos/ntoskrnl/include/config.h | 14 +++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/reactos/ntoskrnl/dbg/print.c b/reactos/ntoskrnl/dbg/print.c index 7e2c7f44aa7..de196780e88 100644 --- a/reactos/ntoskrnl/dbg/print.c +++ b/reactos/ntoskrnl/dbg/print.c @@ -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); - KdpPrintString (&DebugString); +#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; } diff --git a/reactos/ntoskrnl/include/config.h b/reactos/ntoskrnl/include/config.h index d46b7877c7e..73d0d716714 100644 --- a/reactos/ntoskrnl/include/config.h +++ b/reactos/ntoskrnl/include/config.h @@ -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