📄 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"
#include "CommonFunctions.hpp"
//constant to be prepended to all the messages
#define MODULE_NAME L"[PhoneApp]"
#ifdef DEBUG
//the debug zones
#define ZONE_PHONEAPP_ERROR DEBUGZONE(0) //an error has occurred
#define ZONE_PHONEAPP_CTOR DEBUGZONE(1) //constructor/destructor/initialization calls (tracing)
#define ZONE_PHONEAPP_ALLOCS DEBUGZONE(2) //memory allocation
#define ZONE_PHONEAPP_REFCOUNT DEBUGZONE(3) //Ref count
#define ZONE_PHONEAPP_FUNCTION DEBUGZONE(4) //Function
#define ZONE_PHONEAPP_EVENT DEBUGZONE(5) //RTC Event
#define ZONE_PHONEAPP_DIALRULES DEBUGZONE(6) //Dialing Rules
#define ZONE_PHONEAPP_DIALPLAN DEBUGZONE(7) //Dila Plan
#define ZONE_PHONEAPP_STATE DEBUGZONE(8) //Phone state
//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", MODULE_NAME, m_ZoneName, m_FnName));
}
~DebugTracer_t()
{
DEBUGMSG(m_Zone, (L"%s: %s tracing--- %S Exiting\r\n", MODULE_NAME, m_ZoneName, m_FnName));
}
private:
char m_FnName[100];
WCHAR m_ZoneName[50];
int m_Zone;
};
//overloaded debugmsg that spits out module name + debug zone
static WCHAR* __s_dbg_wszZone = NULL;
static CHAR* __s_dbg_szFn = NULL;
//tracing macro
#define TRACE(zone) DebugTracer_t __tracer(zone, L#zone, __FUNCTION__)
//overloaded debugmsg
void __phoneapp_debugset(__in const WCHAR*, __in const CHAR*);
void __phoneapp_debugmsg(__in const WCHAR *c_wszFmt, ...);
#define PHONEAPP_DEBUGMSG(zone, out) if (zone) { __phoneapp_debugset(L#zone, __FUNCTION__); (__phoneapp_debugmsg out); }
#define PHONEAPP_RETAILMSG(zone, out) PHONEAPP_DEBUGMSG(zone, out)
#else //! defined DEBUG
//do nothing in retail...
#define ZONE_PHONEAPP_ERROR
#define ZONE_PHONEAPP_CTOR
#define ZONE_PHONEAPP_ALLOCS
#define ZONE_PHONEAPP_REFCOUNT
#define ZONE_PHONEAPP_FUNCTION
#define ZONE_PHONEAPP_EVENT
#define ZONE_PHONEAPP_DIALRULES
#define ZONE_PHONEAPP_DIALPLAN
#define ZONE_PHONEAPP_STATE
#define TRACE(zone)
#define PHONEAPP_DEBUGMSG(zone, out)
void __phoneapp_retailmsg(__in const WCHAR *c_wszFmt, ...);
#define PHONEAPP_RETAILMSG(zone, out) (__phoneapp_retailmsg out)
#endif //defined DEBUG
#define TRACE_FAILEDHR() PHONEAPP_DEBUGMSG(FAILED(hr) && ZONE_PHONEAPP_ERROR, (L"Routine failed with HRESULT = 0x%08x\r\n", hr))
inline void TraceDialPlanElement(
__in const WCHAR *pFormatString,
__in_ecount(NameLength) const WCHAR *pName,
int NameLength
)
{
#ifdef DEBUG
WCHAR Name[MAX_PATH];
StringCchCopyNEx(
Name,
ARRAYSIZE(Name),
pName,
NameLength,
NULL,
NULL,
STRSAFE_IGNORE_NULLS
);
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_DIALPLAN, (pFormatString, Name));
#endif
}
inline void TraceDialingRuleAttribute(
__in const WCHAR *pFormatString,
__in_ecount(NameLength) const WCHAR *pName,
int NameLength,
__in_ecount(ValueLength) const WCHAR *pValue,
int ValueLength
)
{
#ifdef DEBUG
WCHAR Name[MAX_PATH];
WCHAR Value[MAX_PATH];
StringCchCopyNEx(
Name,
ARRAYSIZE(Name),
pName,
NameLength,
NULL,
NULL,
STRSAFE_IGNORE_NULLS
);
StringCchCopyNEx(
Value,
ARRAYSIZE(Value),
pValue,
ValueLength,
NULL,
NULL,
STRSAFE_IGNORE_NULLS
);
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_DIALPLAN, (pFormatString, Name, Value));
#endif
}
#endif /* __DEBUG_HPP__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -