📄 debug.c
字号:
//
// Permedia3 Sample Display Driver
// debug.c
//
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
// This module contains debugging aid functions, including debug ouput via
// CE debugging zones, asserts, exception handling and generation. Note that
// none of the functions here use the Enter/Exit semantics,as it may lead to
// recursive loops.
#include "pch.h" // Precompiled header support.
#include "struct.h"
#include "proto.h"
// This constant is the size of the buffer that the printf style formatting
// is done in. Hope nothing overflows this!
#define MESSAGE_BUFFER_SIZE 1024
void
MessageFunction(
LPWSTR Format,
...
)
{
// MessageFunction
// This function formats a message using printf-style formating and
// then spews it out to the debug logging facility. Assume that the
// Format string is terminated with a newline and a NUL character.
// Local variables.
va_list Parameters;
wchar_t Buffer[MESSAGE_BUFFER_SIZE];
va_start(Parameters, Format);
_vsnwprintf(Buffer, MESSAGE_BUFFER_SIZE, Format, Parameters);
va_end(Parameters);
OutputDebugString(Buffer);
}
void
ErrorFunction(
LPWSTR Format,
...
)
{
// ErrorFunction
// A fatal error has occured. Attempt to print out some debug spew to
// help the user, then throw an exception to halt the system.
// Assume that the Format string is terminated with a newline and a NUL
// character.
// Local variables.
va_list Parameters;
wchar_t Buffer[MESSAGE_BUFFER_SIZE];
// For some odd reason, we cannot just call MessageFunction here: passing
// through two va_lists seems to screw the variable parameter list up.
va_start(Parameters, Format);
_vsnwprintf(Buffer, MESSAGE_BUFFER_SIZE, Format, Parameters);
va_end(Parameters);
OutputDebugString(Buffer);
RaiseException(0, // Exception code
EXCEPTION_NONCONTINUABLE, // We cannot continue
0, // No parameters
NULL); // No parameters
}
void
AssertFunction(
BOOL Condition,
LPSTR FileName,
UINT Line
)
{
// AssertFunction
// This function enforces the assumption of a particular condition.
// Local variables.
wchar_t WideFileName[MAX_PATH];
if (!Condition) {
// We have to do this goofy ANSI->Unicode conversion becuase the Visual
// C++ compiler will not output the __FILE__ macro in Unicode.
if (MultiByteToWideChar(CP_ACP,
0, // No flags
FileName,
-1, // FileName is NUL terminated
WideFileName,
MAX_PATH) != 0) {
ErrorFunction(L"Assertion failed. File = %s. Line = %d.\n",
WideFileName,
Line);
}
}
}
void
AssertReadPtrFunction(
LPVOID Pointer,
ULONG SizeofPointer,
LPSTR FileName,
UINT Line
)
{
// AssertReadPtrFunction
// This function enforces the assumption that a given pointer points to a
// block of contiguous, readable memory of a certain size.
AssertFunction(!IsBadReadPtr(Pointer, SizeofPointer),
FileName,
Line);
}
void
AssertWritePtrFunction(
LPVOID Pointer,
ULONG SizeofPointer,
LPSTR FileName,
UINT Line
)
{
// AssertWritePtrFunction
// This function enforces the assumption that a given pointer points to a
// block of contiguous, writeable memory of a certain size.
AssertFunction(!IsBadWritePtr(Pointer, SizeofPointer),
FileName,
Line);
}
void
AssertVideoPtrFunction(
LPVOID Pointer,
LPSTR FileName,
UINT Line
)
{
// !TODO!
AssertFunction(1,
FileName,
Line);
}
void
EnterFunction(
LPWSTR FunctionName
)
{
// EnterFunction
// This function is called at the begining of every function in the driver
// with the exception of those in this module (debug.c.)
// !TODO!
}
void
ExitFunction(
LPWSTR FunctionName
)
{
// ExitFunction
// This function is called at the end of every function in the driver with
// the exception of those in this module (debug.c.)
// !TODO!
}
void
DumpRegistersFunction(
ULONG StartIndex,
ULONG EndIndex
)
{
// DumpRegistersFunction
// This function dumps a range of registers out by using the "Message"
// debugging helper. The range is specified in the parameters. Note
// that we assume we are dumping region 0 registers that are aligned
// to 64 bit boundaries, and that the StartIndex and EndIndex reflect
// that alignment restriction.
// Local variables.
ULONG i;
MessageFunction(L"Index\t\tData\n");
for (i = StartIndex; i <= EndIndex; i += 8) {
MessageFunction(L"0x%08.8X\t0x%08.8X\n", i, ReadRegUlong(i));
}
}
void
DumpRdRegistersFunction()
{
// DumpRdRegistersFunction
// This function dumps the entrie range of indirect RAMDAC registers
// using the Message debug helper. Because the indirect RAMDAC
// region is addressed via 12 bits, we dump 0 to 7FF.
// Local variables.
ULONG i;
MessageFunction(L"Indirect RAMDAC registers.\n");
MessageFunction(L"Index\t\tData\n");
for (i = 0; i <= 0x7FF; i += 1) {
MessageFunction(L"0x%08.8X\t0x%08.8X\n", i, ReadRdReg(i));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -