home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WDEBUG.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-12
|
11KB
|
391 lines
/**********************************************************************
*
* WDebug -- Debugging utilties.
*
**********************************************************************/
#ifndef _WDEBUG_HPP_INCLUDED
#define _WDEBUG_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WDEF_HPP_INCLUDED
# include "wdef.hpp"
#endif
#ifndef _WLLIST_HPP_INCLUDED
# include "wllist.hpp"
#endif
//
// WDBG macro -- Use like: WDBG(( "This is number %d", i ));
//
#ifdef _DEBUG
#define WDBG(x) WDebug::Printf x
#else
#define WDBG(x)
#endif
//
// WAssert macro -- Use to check that a given condition is true.
//
#define WVerify(__x)\
(((int)(__x))? (void)0 \
: WDebug::Assert( NULL, __WTEXT(#__x), NULL, \
__WTEXT(__FUNCTION__), \
__WTEXT(__FILE__), __LINE__ ))
#define WVerifyEx(__x,__msg)\
(((int)(__x))? (void)0 \
: WDebug::Assert( NULL, __WTEXT(#__x), __WTEXT(__msg),\
__WTEXT(__FUNCTION__), \
__WTEXT(__FILE__), __LINE__ ))
#ifdef _DEBUG
#define WAssert(__x)\
(((int)(__x))? (void)0 \
: WDebug::Assert( NULL, __WTEXT(#__x), NULL, \
__WTEXT(__FUNCTION__), \
__WTEXT(__FILE__), __LINE__ ))
#define WAssertEx(__x,__msg)\
(((int)(__x))? (void)0 \
: WDebug::Assert( NULL, __WTEXT(#__x), __WTEXT(__msg),\
__WTEXT(__FUNCTION__), \
__WTEXT(__FILE__), __LINE__ ))
#define WWarning(__msg)\
WDebug::Assert( __WTEXT("Warning"),__WTEXT(__msg),NULL,\
__WTEXT(__FUNCTION__),\
__WTEXT(__FILE__), __LINE__ )
#else
#define WAssert(__x)
#define WAssertEx(__x,__msg)
#define WWarning(__msg)
#endif
#define WVERIFY(__x) WVerify(__x)
#define WVERIFYEX(__x,__msg) WVerifyEx(__x,__msg)
#define WASSERT(__x) WAssert(__x)
#define WASSERTEX(__x,__msg) WAssertEx(__x,__msg)
#define WWARNING(__msg) WWarning(__msg)
#define WInternalError(__msg) WDebug::InternalError( __msg,\
__WTEXT(__FUNCTION__),\
__WTEXT(__FILE__),__LINE__)
#ifndef _DEBUG
#define __NO_WCM_TRACING__
#endif
//
// WTraceMember macro -- Declare at beginning of a WObject member function.
//
#ifndef __NO_WCM_TRACING__
#define WTraceMember() static WTraceMarker __marker(__WTEXT(__FUNCTION__),\
__WTEXT(__FILE__),\
__LINE__);\
WTrace __trace( __marker );\
WValidateObject(this);
#else
#define WTraceMember()
#endif
//
// WTraceFunction macro -- Declare at beginning of a non-member function
// or of a non-WObject member.
//
#ifndef __NO_WCM_TRACING__
#define WTraceFunction() static WTraceMarker __marker(__WTEXT(__FUNCTION__),\
__WTEXT(__FILE__),\
__LINE__);\
WTrace __trace( __marker );
#else
#define WTraceFunction()
#endif
//
// WValidateObject macro -- Use to check if object is valid or not.
//
#ifdef __BUILDING_WCM__
#define WGETOBJECTFLAGS WDebug::ObjectFlags
#define WGETCHECKGDIHANDLES WDebug::CheckGDIHandles
#define WGETCHECKSTRINGS WDebug::CheckStrings
#define WGETMEMORYTRACKING WDebug::MemoryTracking
#else
#define WGETOBJECTFLAGS WDebug::GetObjectFlags()
#define WGETCHECKGDIHANDLES WDebug::GetCheckGDIHandles()
#define WGETCHECKSTRINGS WDebug::GetCheckStrings()
#define WGETMEMORYTRACKING WDebug::GetMemoryTracking()
#endif
#ifdef _DEBUG
#pragma warning 549 9
#define WValidateObject(__x) \
((WGETOBJECTFLAGS == 0) ? (void)0 : \
WDebug::ValidateObject( (WObject*)__x,\
(((__x)!=NULL)?sizeof(*__x):0),\
__WTEXT(__FUNCTION__), \
__WTEXT(__FILE__),__LINE__))
#else
#define WValidateObject(__x)
#endif
#define WVALIDATEWOBJECT(__x) WValidateObject(__x)
#define WVALIDATETHIS() WValidateObject(this)
class WObject;
//
// WNoDefault macro -- Use to catch unexpected switch values.
//
#ifdef _DEBUG
#define WNoDefault() WDebug::NoDefault(__WTEXT(__FUNCTION__),\
__WTEXT(__FILE__),__LINE__ )
#else
#define WNoDefault()
#endif
#define WNODEFAULT WNoDefault()
#ifdef _DEBUG
#define CHECKGDI(__x) (WGETCHECKGDIHANDLES?WASSERT(__x):(void)0)
#else
#define CHECKGDI(__x)
#endif
//
// System error checking
//
#if defined( _DEBUG ) && defined( __BUILDING_WCM__ )
#define WUPDATEERRORLOGFILE() if( WDebug::CheckErrors ) \
WDebug::CheckErrorCode( __WTEXT(__FUNCTION__),\
__WTEXT(__FILE__), __LINE__ )
#elif defined( _DEBUG )
#define WUPDATEERRORLOGFILE() WDebug::CheckErrorCode( __WTEXT(__FUNCTION__),\
__WTEXT(__FILE__), __LINE__ )
#else
#define WUPDATEERRORLOGFILE() ((void)0)
#endif
#define WUPDATESYSTEMERRORLOGFILE() WUPDATEERRORLOGFILE()
//
// Tracing facilities
//
// Declare a WTraceMarker statically at the beginning of a function.
// Then declare a WTrace on the stack, passing in the address of the
// trace marker.
//
class WCMCLASS WTraceMarker {
public:
struct WTraceMarkerEntry {
wllist_link link;
const WChar *name;
const WChar *fileName;
WULong line;
};
public:
WTraceMarker( const WChar *name, const WChar *fileName,
WULong line );
// ~WTraceMarker(); no destructor is needed....
//
// Data
//
WTraceMarkerEntry _markerInfo;
};
class WCMCLASS WTrace {
public:
typedef WTraceMarker::WTraceMarkerEntry wtm_entry;
struct WTraceEntry {
wllist_link link;
wtm_entry *marker;
};
public:
WTrace( WTraceMarker & marker );
~WTrace();
WTraceEntry _traceInfo;
};
//
// Debugging control
//
// Used to turn on/off debugging options.
//
class WCMCLASS WDebug {
public:
struct WDebugEntry {
wllist_link link;
WULong memoryFlags;
WBool checkGDI;
WBool checkStrings;
};
public:
WDebug();
~WDebug();
/**************************************************************
* Properties
**************************************************************/
// CheckErrors
static WBool GetCheckErrors();
static WBool SetCheckErrors( WBool check );
// CheckGDIHandles
static WBool GetCheckGDIHandles();
static WBool SetCheckGDIHandles( WBool check );
// CheckStrings
static WBool GetCheckStrings();
static WBool SetCheckStrings( WBool check );
// MemoryTracking
static WULong GetMemoryTracking();
static WBool SetMemoryTracking( WULong trackFlags );
// ObjectFlags
static WULong GetObjectFlags();
static WBool SetObjectFlags( WULong flags );
/**************************************************************
* Methods
**************************************************************/
//
// Assert
//
static void Assert( const WChar *line1, const WChar *line2,
const WChar *line3, const WChar *name,
const WChar *fileName, WULong lineNumber );
// BreakIntoDebugger
//
// Enter the debugger if it is present. Returns FALSE
// if the debugger was not entered. The parameter
// is a message to display (it can be NULL). Only works
// in debugging version.
static WBool BreakIntoDebugger( const WAnsiChar *message,
WBool startWDW );
// CheckErrorCode
//
// Used for debugging. Checks to see if the last error
// code is non-zero, and if so prints a debugging message.
// It then calls ::SetErrorCode( 0 ) to reset the error.
// Returns the error code that was detected. Fails without
// checking the error code if GetCheckErrors() is FALSE.
static WDWord CheckErrorCode( const WChar *functionName,
const WChar *fileName,
WULong line );
//
// InternalError
//
static void InternalError( const WChar *text, const WChar *name,
const WChar *fileName, WULong line );
//
// IsDebuggerPresent
//
static WBool IsDebuggerPresent();
//
// NoDefault
//
static void NoDefault( const WChar *name,
const WChar *fileName, WULong lineNumber );
//
// Printf
//
static void Printf( const WChar *format, ... );
//
// ValidateObject
//
static void ValidateObject( WObject *ptr, WULong len,
const WChar *name,
const WChar *fileName, WULong line );
/**************************************************************
* Data
**************************************************************/
#ifdef __BUILDING_WCM__
public:
#else
private:
#endif
WDebugEntry _debugInfo;
static WBool CheckStrings;
static WBool CheckGDIHandles;
static WULong MemoryTracking;
static WULong ObjectFlags;
static WBool CheckErrors;
};
#define WDEBUG_CHECK_OBJECT_FLAGS 0x01
#define WDEBUG_CHECK_OBJECT_WRITE 0x02
#define WDEBUG_CHECK_OBJECT_READ 0x04
#define WDEBUG_CHECK_OBJECT_NONE 0x00
#define WDEBUG_CHECK_OBJECT_ALL 0xFF
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WDEBUG_HPP_INCLUDED