implement DbgPrintEx, vDbgPrintEx, and vDbgPrintExWithPrefix

svn path=/trunk/; revision=17378
This commit is contained in:
Royce Mitchell III 2005-08-14 04:24:01 +00:00
parent 199bb66de3
commit ffa5fea7b6

View file

@ -12,6 +12,17 @@
#include <ntoskrnl.h> #include <ntoskrnl.h>
#include <internal/debug.h> #include <internal/debug.h>
/* DATA *********************************************************************/
typedef struct
{
ULONG ComponentId;
ULONG Level;
} KD_COMPONENT_DATA;
#define MAX_KD_COMPONENT_TABLE_ENTRIES 128
KD_COMPONENT_DATA KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES];
ULONG KdComponentTableEntries = 0;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
/* /*
@ -23,12 +34,17 @@
/* /*
* @implemented * @implemented
*/ */
ULONG ULONG WINAPI
DbgPrint(PCH Format, ...) vDbgPrintExWithPrefix(IN LPCSTR Prefix,
IN ULONG ComponentId,
IN ULONG Level,
IN LPCSTR Format,
IN va_list ap)
{ {
ANSI_STRING DebugString; ANSI_STRING DebugString;
CHAR Buffer[1024]; CHAR Buffer[513];
va_list ap; PCHAR pBuffer;
ULONG pBufferSize;
#ifdef SERIALIZE_DBGPRINT #ifdef SERIALIZE_DBGPRINT
# define MESSAGETABLE_SIZE 16 # define MESSAGETABLE_SIZE 16
LONG MyTableIndex; LONG MyTableIndex;
@ -37,13 +53,30 @@ DbgPrint(PCH Format, ...)
static CHAR MessageTable[MESSAGETABLE_SIZE][sizeof(Buffer)] = { { '\0' } }; static CHAR MessageTable[MESSAGETABLE_SIZE][sizeof(Buffer)] = { { '\0' } };
#endif /* SERIALIZE_DBGPRINT */ #endif /* SERIALIZE_DBGPRINT */
/* TODO FIXME - call NtQueryDebugFilterState() instead per Alex */
if ( !DbgQueryDebugFilterState ( ComponentId, Level ) )
return 0;
/* init ansi string */ /* init ansi string */
DebugString.Buffer = Buffer; DebugString.Buffer = Buffer;
DebugString.MaximumLength = sizeof(Buffer); DebugString.MaximumLength = sizeof(Buffer);
va_start (ap, Format); pBuffer = Buffer;
DebugString.Length = _vsnprintf (Buffer, sizeof( Buffer ), Format, ap); pBufferSize = sizeof(Buffer);
va_end (ap); DebugString.Length = 0;
if ( Prefix && *Prefix )
{
DebugString.Length = strlen(Prefix);
if ( DebugString.Length >= sizeof(Buffer) )
DebugString.Length = sizeof(Buffer) - 1;
memmove ( Buffer, Prefix, DebugString.Length );
Buffer[DebugString.Length] = '\0';
pBuffer = &Buffer[DebugString.Length];
pBufferSize -= DebugString.Length;
}
DebugString.Length += _vsnprintf ( pBuffer, pBufferSize, Format, ap );
Buffer[sizeof(Buffer)-1] = '\0';
#ifdef SERIALIZE_DBGPRINT #ifdef SERIALIZE_DBGPRINT
/* check if we are already running */ /* check if we are already running */
@ -62,9 +95,6 @@ DbgPrint(PCH Format, ...)
} }
else else
{ {
/*DebugString.Buffer = "µµµ";
DebugString.Length = 3;
KdpPrintString(&DebugString);*/
memcpy(MessageTable[MyTableIndex], DebugString.Buffer, DebugString.Length); memcpy(MessageTable[MyTableIndex], DebugString.Buffer, DebugString.Length);
MessageTable[MyTableIndex][DebugString.Length] = '\0'; MessageTable[MyTableIndex][DebugString.Length] = '\0';
} }
@ -101,7 +131,44 @@ DbgPrint(PCH Format, ...)
} }
/* /*
* @unimplemented * @implemented
*/
ULONG WINAPI
vDbgPrintEx(IN ULONG ComponentId,
IN ULONG Level,
IN LPCSTR Format,
IN va_list ap)
{
return vDbgPrintExWithPrefix ( NULL, ComponentId, Level, Format, ap );
}
/*
* @implemented
*/
ULONG
DbgPrint(PCH Format, ...)
{
va_list ap;
ULONG rc;
va_start (ap, Format);
/* TODO FIXME - use DPFLTR_DEFAULT_ID and DPFLTR_INFO_LEVEL
*
* https://www.osronline.com/article.cfm?article=295
*
* ( first need to add those items to registry by default tho so we don't anger
* ros-devs when DbgPrint() suddenly stops working )
*
* ( also when you do this, remove -1 hack from DbgQueryDebugFilterState() )
*/
rc = vDbgPrintExWithPrefix ( NULL, (ULONG)-1, (ULONG)-1, Format, ap );
va_end (ap);
return rc;
}
/*
* @implemented
*/ */
ULONG ULONG
__cdecl __cdecl
@ -110,8 +177,14 @@ DbgPrintEx(IN ULONG ComponentId,
IN PCH Format, IN PCH Format,
...) ...)
{ {
UNIMPLEMENTED; va_list ap;
return 0; ULONG rc;
va_start (ap, Format);
rc = vDbgPrintExWithPrefix ( NULL, ComponentId, Level, Format, ap );
va_end (ap);
return rc;
} }
/* /*
@ -151,19 +224,36 @@ DbgPrompt(PCH OutputString,
} }
/* /*
* @unimplemented * @implemented
*/ */
NTSTATUS BOOLEAN
STDCALL STDCALL
DbgQueryDebugFilterState(IN ULONG ComponentId, DbgQueryDebugFilterState(IN ULONG ComponentId,
IN ULONG Level) IN ULONG Level)
{ {
UNIMPLEMENTED; int i;
return STATUS_NOT_IMPLEMENTED;
if ( ComponentId == -1 )
return TRUE;
/* convert Level to mask if it isn't already one */
if ( Level < 32 )
Level = 1 << Level;
for ( i = 0; i < KdComponentTableEntries; i++ )
{
if ( ComponentId == KdComponentTable[i].ComponentId )
{
if ( Level & KdComponentTable[i].Level )
return TRUE;
break;
}
}
return FALSE;
} }
/* /*
* @unimplemented * @implemented
*/ */
NTSTATUS NTSTATUS
STDCALL STDCALL
@ -171,8 +261,25 @@ DbgSetDebugFilterState(IN ULONG ComponentId,
IN ULONG Level, IN ULONG Level,
IN BOOLEAN State) IN BOOLEAN State)
{ {
UNIMPLEMENTED; int i;
return STATUS_NOT_IMPLEMENTED; for ( i = 0; i < KdComponentTableEntries; i++ )
{
if ( ComponentId == KdComponentTable[i].ComponentId )
break;
}
if ( i == KdComponentTableEntries )
{
if ( i == MAX_KD_COMPONENT_TABLE_ENTRIES )
return STATUS_INVALID_PARAMETER_1;
++KdComponentTableEntries;
KdComponentTable[i].ComponentId = ComponentId;
KdComponentTable[i].Level = 0;
}
if ( State )
KdComponentTable[i].Level |= Level;
else
KdComponentTable[i].Level &= ~Level;
return STATUS_SUCCESS;
} }
/* /*