📄 debug.c
字号:
/**************************************************************************
* Name : debug.c
* Author : BCB
* Created : 10/07/2003
*
* Copyright : 2003 by Imagination Technologies Limited. All rights reserved.
* : No part of this software, either material or conceptual
* : may be copied or distributed, transmitted, transcribed,
* : stored in a retrieval system or translated into any
* : human or computer language in any form by any means,
* : electronic, mechanical, manual or other-wise, or
* : disclosed to third parties without the express written
* : permission of Imagination Technologies Limited, Unit 8, HomePark
* : Industrial Estate, King's Langley, Hertfordshire,
* : WD4 8LZ, U.K.
*
* Platform : ANSI
*
* $Date: 2004/07/27 17:12:30 $ $Revision: 1.3 $
* $Log: debug.c $
**************************************************************************/
#define MODULE_ID MODID_DEBUG
#if defined(DEBUG) || defined(TIMING)
#ifdef _WIN32
#ifdef UNDER_CE
#include <wtypes.h>
#endif
#include <windows.h>
#endif
#include "ogles_types.h"
#include "modid.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if defined(UNICODE)
#include "tstring.h"
#endif
static IMG_CHAR *pszLevelStrings[] = {"(Fatal): ", "(Error): ", "(Warning): ", "(Message): ", "(Verbose):"};
static IMG_INT32 ai32ModuleDebugLevels[MODID_NUMMODULES];
#if defined (_MSC_VER)
#define Int3 DebugBreak
#else
#define Int3 / ## /
#endif
char sDllName[] = "GLESDRV ";
/***********************************************************************************
Function Name : WriteString
Inputs : pszString
Outputs : -
Returns : -
Description : Outputs a string to debug output
************************************************************************************/
static IMG_VOID WriteString(IMG_CHAR *pszString)
{
IMG_CHAR szBuffer[256];
strcpy(szBuffer,sDllName);
strcat(szBuffer,pszString);
strcat(szBuffer,"\r\n");
#ifdef _WIN32
#ifndef UNICODE
OutputDebugString(szBuffer);
#else
{
TCHAR szUnicodeBuffer[256];
ASCIITOTSTR( szUnicodeBuffer, szBuffer, 256 );
OutputDebugString(szUnicodeBuffer);
}
#endif
#else
printf("%s",szBuffer);
#endif /* __WIN32 */
}
/***********************************************************************************
Function Name : dprintf
Inputs : i32CodeModule, i32DebugLevel, pszFileName, i32Line, pszFormat
Outputs : -
Returns : -
Description : Outputs a string to debug output. Allows manageable
module/level based tracing with a variable arg list.
Outputs to stderr.
************************************************************************************/
IMG_VOID pvrdprintf ( IMG_INT32 i32CodeModule,
IMG_INT32 i32DebugLevel,
IMG_CHAR *pszFileName,
IMG_INT32 i32Line,
IMG_CHAR *pszFormat, ...)
{
IMG_CHAR *pszLeafName;
pszLeafName = (char *)strrchr (pszFileName, '\\');
if (pszLeafName)
{
pszFileName = pszLeafName;
}
if (ai32ModuleDebugLevels[i32CodeModule] >= i32DebugLevel)
{
va_list vaArgs;
char szBuffer[256];
va_start (vaArgs, pszFormat);
/* Add in the level of warning */
strcpy (szBuffer, pszLevelStrings[i32DebugLevel]);
vsprintf (&szBuffer[strlen(szBuffer)], pszFormat, vaArgs);
sprintf (&szBuffer[strlen(szBuffer)], " [%d, %s]", (int)i32Line, pszFileName);
WriteString(szBuffer);
va_end (vaArgs);
}
}
/***********************************************************************************
Function Name : dtprintf
Inputs : pszFormat
Outputs : -
Returns : -
Description : Outputs a string to debug output. Allows manageable
variable arg list outputs to stderr.
************************************************************************************/
IMG_VOID pvrdtprintf (IMG_CHAR *pszFormat, ...)
{
va_list vaArgs;
IMG_CHAR szBuffer[256];
va_start (vaArgs, pszFormat);
strcpy(szBuffer, "");
vsprintf (&szBuffer[strlen(szBuffer)], pszFormat, vaArgs);
WriteString(szBuffer);
va_end (vaArgs);
}
IMG_VOID DbgAssert(char *szAssertText, char *szFileName, IMG_INT32 nLine, int * ask)
{
#ifdef _WIN32
IMG_CHAR szBuffer[256];
sprintf (szBuffer,"Assertion (%s) failed! File %s, line %ld\n", szAssertText, szFileName, (long)nLine);
#ifndef UNICODE
OutputDebugString(szBuffer);
#else
{
TCHAR szUnicodeBuffer[256];
ASCIITOTSTR( szUnicodeBuffer, szBuffer, 256 );
OutputDebugString(szUnicodeBuffer);
}
#endif
Int3 ();
#endif /* _WIN32 */
}
IMG_VOID dPMX_ASSERT (char *szAssertText, char *szFileName, IMG_INT32 nLine, int * ask)
{
IMG_CHAR *pszLeafName;
pszLeafName = (char *)strrchr (szFileName, '\\');
if (pszLeafName)
{
szFileName = pszLeafName;
}
DbgAssert( szAssertText, szFileName, nLine, ask);
}
/***********************************************************************************
Function Name : DebugInit
Inputs : i32DebugLevel
Outputs : -
Returns : -
Description : Create a debug interface
************************************************************************************/
IMG_VOID DebugInit (IMG_INT32 i32DebugLevel)
{
int k;
#if 1
for (k = 0; k < MODID_NUMMODULES; ++k)
{
ai32ModuleDebugLevels[k] = i32DebugLevel;
}
#else
FILE *tmp;
#ifdef __linux__
char filename[128];
#define MAX_PATH 128
char *buffer = "OGLDRV.INI";
#endif
#if defined(_WIN32)
char buffer[MAX_PATH+16];
/* Get the current working directory: */
if( getcwd( buffer, MAX_PATH ) == NULL )
{
OutputDebugString ("_getcwd error\n");
}
else
{
strcat(buffer,"\\OGLDRV.INI");
}
#endif
InitialiseAsserts();
#ifdef __linux__
strcpy(filename, getenv("HOME"));
strcat(filename,"/");
strcat(filename, buffer);
PVRREGOpenSpecificRegistry(filename);
#endif
DebugLevel = (int) ReadAppHintInt("GlobalDebugLevel", DebugLevel);
DebugLevel = (int) SglReadPrivateProfileInt2 ("DEBUG", "GlobalLevel", DebugLevel, buffer);
for (k = 0; k < MODID_NUMMODULES; ++k)
{
ai32ModuleDebugLevels[k] = (int) ReadAppHintInt(Modules[k], ai32ModuleDebugLevels[k]);
}
tmp = fopen(buffer, "r");
if(tmp)
{
fclose(tmp);
for (k = 0; k < NUM_ITEMS_IN_MODULES_ARRAY; ++k)
{
ai32ModuleDebugLevels[k] = (int) ReadPrivateProfileInt2 ("ModuleDebugLevels",
Modules[k],
#ifdef __linux__
DebugLevel,
#else
ai32ModuleDebugLevels[k],
#endif
buffer);
}
}
#endif
}
/***********************************************************************************
Function Name : DebugDeInit
Inputs : -
Outputs : -
Returns : -
Description : Shut down debug interface
************************************************************************************/
IMG_VOID DebugDeinit (IMG_VOID)
{
}
#endif /* DEBUG || TIMING */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -