📄 debug.hpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#pragma once
#ifndef __DEBUG_HPP__
#define __DEBUG_HPP__
#include <windows.h>
#include "MemTrace.hpp"
// Module name.
extern const WCHAR __g_ModuleName[];
#define MODULE_NAME(module) const WCHAR __g_ModuleName[] = module;
#ifdef DEBUG
//the debug zones
#define ZONE_COMMON_ERROR DEBUGZONE(0) //an error has occurred
#define ZONE_COMMON_CTOR DEBUGZONE(1) //constructor/destructor/initialization calls (tracing)
//internal debugger object
class DebugTracer_t
{
public:
DebugTracer_t(
int zone,
__in const WCHAR* pZoneName,
__in const char* pFnName
)
{
StringCchCopyA(m_FnName, _countof(m_FnName), pFnName);
StringCchCopyW(m_ZoneName, _countof(m_ZoneName), pZoneName);
m_Zone = zone;
DEBUGMSG(m_Zone, (L"%s: %s tracing+++ %S Entering\r\n", __g_ModuleName, m_ZoneName, m_FnName));
}
~DebugTracer_t()
{
DEBUGMSG(m_Zone, (L"%s: %s tracing--- %S Exiting\r\n", __g_ModuleName, m_ZoneName, m_FnName));
}
private:
char m_FnName[100];
WCHAR m_ZoneName[50];
int m_Zone;
};
//tracing macro
#define TRACE(zone) DebugTracer_t __tracer(zone, L#zone, __FUNCTION__)
//overloaded debugmsg
static const CHAR* __s_pFunctionName = NULL;
static const WCHAR* __s_pZoneName = NULL;
inline
void
__common_debugset(
const WCHAR* pZoneName,
const CHAR* pFunctionName
)
{
__s_pFunctionName = pFunctionName;
__s_pZoneName = pZoneName;
}
inline
void
__common_debugmsg(
const WCHAR* FormatString,
...
)
{
WCHAR ArgBuffer[MAX_PATH] = L"";
va_list List;
va_start(List, FormatString);
StringCchVPrintfW(
ArgBuffer,
_countof(ArgBuffer),
FormatString,
List
);
va_end(List);
DEBUGMSG(1, (L"%s %s %S - %s", __g_ModuleName, __s_pZoneName, __s_pFunctionName, ArgBuffer));
}
#define COMMON_DEBUGMSG(zone, out) if (zone) { __common_debugset(L#zone, __FUNCTION__); (__common_debugmsg out); }
#define COMMON_RETAILMSG(zone, out) COMMON_DEBUGMSG(zone, out)
#else //! defined DEBUG
//do nothing in retail...
#define ZONE_COMMON_ERROR
#define ZONE_COMMON_CTOR
inline
void
__common_retailmsg(
const WCHAR* FormatString,
...
)
{
WCHAR ArgBuffer[MAX_PATH] = L"";
va_list List;
va_start(List, FormatString);
StringCchVPrintfW(
ArgBuffer,
_countof(ArgBuffer),
FormatString,
List
);
va_end(List);
RETAILMSG(1, (L"%s %s", __g_ModuleName, ArgBuffer));
}
#define TRACE(zone)
#define COMMON_DEBUGMSG(zone, out)
void __common_retailmsg(__in const WCHAR *c_wszFmt, ...);
#define COMMON_RETAILMSG(zone, out) (__common_retailmsg out)
#endif //defined DEBUG
// Automation
#ifdef AUTOMATION
#define STRING_DELIMITER L'$'
#endif
#endif /* __DEBUG_HPP__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -