2023-03-26 16:09:05 +02:00
|
|
|
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
2022-05-25 14:18:29 +02:00
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//
|
2023-03-26 16:09:05 +02:00
|
|
|
//===========================================================================//
|
2022-05-25 14:18:29 +02:00
|
|
|
#ifndef DBG_H
|
|
|
|
#define DBG_H
|
2022-07-08 00:55:01 +02:00
|
|
|
#define AssertDbg assert
|
2023-03-17 00:04:08 +01:00
|
|
|
#define Verify( _exp ) ( _exp )
|
2022-05-25 14:18:29 +02:00
|
|
|
#include "tier0/dbgflag.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "tier0/platform.h"
|
|
|
|
|
|
|
|
// Used for the 'Error' function, this tells the function to only log, not quit.
|
|
|
|
//#define NO_ERROR 0
|
2022-05-25 14:18:29 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
enum class eDLL_T : int
|
|
|
|
{
|
2023-03-26 16:09:05 +02:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Script enumerants
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
SCRIPT_SERVER = -3,
|
|
|
|
SCRIPT_CLIENT = -2,
|
|
|
|
SCRIPT_UI = -1,
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Native enumerants
|
|
|
|
//-------------------------------------------------------------------------
|
2022-11-27 10:19:23 +01:00
|
|
|
SERVER = 0, // server.dll (GameDLL)
|
|
|
|
CLIENT = 1, // client.dll (GameDLL)
|
|
|
|
UI = 2, // ui.dll (GameDLL)
|
|
|
|
ENGINE = 3, // engine.dll (Wrapper)
|
|
|
|
FS = 4, // filesystem_stdio.dll (FileSystem API)
|
|
|
|
RTECH = 5, // rtech_game.dll (RTech API)
|
|
|
|
MS = 6, // materialsystem_dx11.dll (MaterialSystem API)
|
|
|
|
AUDIO = 7, // binkawin64/mileswin64.dll (AudioSystem API)
|
|
|
|
VIDEO = 8, // bink2w64 (VideoSystem API)
|
|
|
|
NETCON = 9, // netconsole impl (RCON wire)
|
2022-05-25 14:18:29 +02:00
|
|
|
|
2023-03-26 16:09:05 +02:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Common enumerants
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
COMMON = 10, // general (No specific subsystem)
|
|
|
|
SYSTEM_WARNING = 11, // general warning (No specific subsystem)
|
|
|
|
SYSTEM_ERROR = 12, // general error (No specific subsystem)
|
|
|
|
NONE = 13 // no context
|
|
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-25 21:27:49 +01:00
|
|
|
enum class LogType_t
|
|
|
|
{
|
|
|
|
LOG_INFO = 0,
|
|
|
|
LOG_NET,
|
|
|
|
LOG_WARNING,
|
2023-03-26 16:09:05 +02:00
|
|
|
LOG_ERROR,
|
|
|
|
SQ_INFO,
|
|
|
|
SQ_WARNING
|
2023-03-25 21:27:49 +01:00
|
|
|
};
|
2023-03-26 16:09:05 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
enum class LogLevel_t
|
|
|
|
{
|
|
|
|
LEVEL_DISK_ONLY = 0,
|
|
|
|
LEVEL_CONSOLE, // Emit to console panels
|
|
|
|
LEVEL_NOTIFY // Emit to in-game mini console
|
|
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-07-01 01:20:47 +02:00
|
|
|
constexpr const char s_CommonAnsiColor[] = "\033[38;2;255;204;153m";
|
|
|
|
constexpr const char s_WarningAnsiColor[] = "\033[38;2;255;255;000m";
|
|
|
|
constexpr const char s_ErrorAnsiColor[] = "\033[38;2;255;000;000m";
|
|
|
|
constexpr const char s_DefaultAnsiColor[] = "\033[38;2;204;204;204m";
|
|
|
|
constexpr const char* s_DllAnsiColor[14] =
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
"\033[38;2;059;120;218mNative(S):",
|
|
|
|
"\033[38;2;118;118;118mNative(C):",
|
|
|
|
"\033[38;2;151;090;118mNative(U):",
|
|
|
|
"\033[38;2;204;204;204mNative(E):",
|
|
|
|
"\033[38;2;097;214;214mNative(F):",
|
|
|
|
"\033[38;2;092;181;089mNative(R):",
|
2022-11-27 10:19:23 +01:00
|
|
|
"\033[38;2;192;077;173mNative(M):",
|
2022-11-28 23:13:18 +01:00
|
|
|
"\033[38;2;238;108;030mNative(A):",
|
2022-11-27 10:19:23 +01:00
|
|
|
"\033[38;2;185;000;235mNative(V):",
|
2022-05-25 14:18:29 +02:00
|
|
|
"\033[38;2;204;204;204mNetcon(X):",
|
2023-06-30 22:00:54 +02:00
|
|
|
s_CommonAnsiColor,
|
2023-07-01 01:20:47 +02:00
|
|
|
s_WarningAnsiColor,
|
|
|
|
s_ErrorAnsiColor,
|
2023-03-25 21:27:49 +01:00
|
|
|
s_DefaultAnsiColor
|
2022-05-25 14:18:29 +02:00
|
|
|
};
|
2023-03-26 16:09:05 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
constexpr const char* s_ScriptAnsiColor[4] =
|
|
|
|
{
|
|
|
|
"\033[38;2;151;149;187mScript(S):",
|
|
|
|
"\033[38;2;151;149;163mScript(C):",
|
|
|
|
"\033[38;2;151;123;136mScript(U):",
|
|
|
|
"\033[38;2;151;149;163mScript(X):"
|
|
|
|
};
|
2022-10-30 10:08:14 +01:00
|
|
|
|
|
|
|
extern std::mutex g_LogMutex;
|
2022-05-25 14:18:29 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Legacy Logging System
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-26 16:09:05 +02:00
|
|
|
void CoreMsgV(LogType_t logType, LogLevel_t logLevel, eDLL_T context, const char* pszLogger,
|
2023-03-27 02:01:48 +02:00
|
|
|
const char* pszFormat, va_list args, const UINT exitCode = NO_ERROR, const char* pszUptimeOverride = nullptr);
|
2023-03-26 16:09:05 +02:00
|
|
|
void CoreMsg(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
|
|
|
|
const UINT exitCode, const char* pszLogger, const char* pszFormat, ...);
|
|
|
|
|
2022-05-25 14:18:29 +02:00
|
|
|
// These functions do not return.
|
2023-08-21 19:12:29 +02:00
|
|
|
PLATFORM_INTERFACE void Msg(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3);
|
2023-03-27 02:01:48 +02:00
|
|
|
PLATFORM_INTERFACE void NetMsg(LogType_t logType, eDLL_T context, const char* uptime, const char* fmt, ...) FMTFUNCTION(4, 5);
|
2022-10-30 10:08:14 +01:00
|
|
|
PLATFORM_INTERFACE void Warning(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3);
|
|
|
|
PLATFORM_INTERFACE void Error(eDLL_T context, const UINT code, const char* fmt, ...) FMTFUNCTION(3, 4);
|
2022-05-25 14:18:29 +02:00
|
|
|
|
2024-04-05 17:42:05 +02:00
|
|
|
// TODO[ AMOS ]: export to DLL?
|
|
|
|
void Plat_FatalError(eDLL_T context, const char* fmt, ...);
|
|
|
|
|
2023-08-21 19:12:29 +02:00
|
|
|
#if defined DBGFLAG_STRINGS_STRIP
|
|
|
|
#define DevMsg( ... ) ((void)0)
|
|
|
|
#define DevWarning( ... ) ((void)0)
|
|
|
|
#else // DBGFLAG_STRINGS_STRIP
|
|
|
|
PLATFORM_INTERFACE void DevMsg(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3);
|
|
|
|
PLATFORM_INTERFACE void DevWarning(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3);
|
|
|
|
#endif
|
|
|
|
|
2022-05-25 14:18:29 +02:00
|
|
|
// You can use this macro like a runtime assert macro.
|
|
|
|
// If the condition fails, then Error is called with the message. This macro is called
|
|
|
|
// like AssertMsg, where msg must be enclosed in parenthesis:
|
|
|
|
//
|
|
|
|
// ErrorIfNot( bCondition, ("a b c %d %d %d", 1, 2, 3) );
|
|
|
|
#define ErrorIfNot( condition, msg ) \
|
|
|
|
if ( (condition) ) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
Error msg; \
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Templates to assist in validating pointers:
|
|
|
|
|
|
|
|
// Have to use these stubs so we don't have to include windows.h here.
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidReadPtr(void* ptr, int count = 1);
|
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidWritePtr(void* ptr, int count = 1);
|
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidReadWritePtr(void* ptr, int count = 1);
|
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidStringPtr(const TCHAR* ptr, int maxchar);
|
2022-05-25 14:18:29 +02:00
|
|
|
|
|
|
|
#ifdef DBGFLAG_ASSERT
|
|
|
|
inline void AssertValidStringPtr(const TCHAR* ptr, int maxchar = 0xFFFFFF) { _AssertValidStringPtr(ptr, maxchar); }
|
|
|
|
template<class T> inline void AssertValidReadPtr(T* ptr, int count = 1) { _AssertValidReadPtr((void*)ptr, count); }
|
|
|
|
template<class T> inline void AssertValidWritePtr(T* ptr, int count = 1) { _AssertValidWritePtr((void*)ptr, count); }
|
|
|
|
template<class T> inline void AssertValidReadWritePtr(T* ptr, int count = 1) { _AssertValidReadWritePtr((void*)ptr, count); }
|
|
|
|
#define AssertValidThis() AssertValidReadWritePtr(this,sizeof(*this))
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
inline void AssertValidStringPtr(const TCHAR* /*ptr*/, int maxchar = 0xFFFFFF) { NOTE_UNUSED(maxchar); }
|
|
|
|
template<class T> inline void AssertValidReadPtr(T* /*ptr*/, int count = 1) { NOTE_UNUSED(count); }
|
|
|
|
template<class T> inline void AssertValidWritePtr(T* /*ptr*/, int count = 1) { NOTE_UNUSED(count); }
|
|
|
|
template<class T> inline void AssertValidReadWritePtr(T* /*ptr*/, int count = 1) { NOTE_UNUSED(count); }
|
2022-05-25 14:18:29 +02:00
|
|
|
#define AssertValidThis()
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
|
2024-04-03 18:55:27 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Macro to protect functions that are not reentrant
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
class CReentryGuard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CReentryGuard(int* pSemaphore)
|
|
|
|
: m_pSemaphore(pSemaphore)
|
|
|
|
{
|
|
|
|
++(*m_pSemaphore);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CReentryGuard()
|
|
|
|
{
|
|
|
|
--(*m_pSemaphore);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int* m_pSemaphore;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ASSERT_NO_REENTRY() \
|
|
|
|
static int fSemaphore##__LINE__; \
|
|
|
|
Assert( !fSemaphore##__LINE__ ); \
|
|
|
|
CReentryGuard ReentryGuard##__LINE__( &fSemaphore##__LINE__ )
|
|
|
|
#else
|
|
|
|
#define ASSERT_NO_REENTRY()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define AssertMsg(condition, ...) assert(condition)
|
|
|
|
|
2023-05-10 00:05:38 +02:00
|
|
|
typedef void (*CoreMsgVCallbackSink_t)(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
|
|
|
|
const char* pszLogger, const char* pszFormat, va_list args, const UINT exitCode, const char* pszUptimeOverride);
|
|
|
|
|
|
|
|
extern CoreMsgVCallbackSink_t g_CoreMsgVCallback;
|
|
|
|
|
2022-05-25 14:18:29 +02:00
|
|
|
#endif /* DBG_H */
|