202 lines
5.5 KiB
C
202 lines
5.5 KiB
C
/*
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
* SCR_Dbg.h
|
|
*
|
|
* Contains macro for debugging capabilities.
|
|
*
|
|
* SCR_DM_ProtectedVersion must be define in project makefile for assertion macros.
|
|
* _DEBUG must be define in project makefile for other macros.
|
|
*
|
|
* Scripts, Beaudet Christophe
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
*
|
|
*/
|
|
|
|
#ifndef __SCR_Dbg_h__Types
|
|
#define __SCR_Dbg_h__Types
|
|
|
|
#ifndef __Only_Types__
|
|
#define __SCR_Dbg_h__Undef
|
|
#define __Only_Types__
|
|
#endif /* !__Only_Types__ */
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Includes.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
#include "SCR_Err.h"
|
|
|
|
#ifdef __SCR_Dbg_h__Undef
|
|
#undef __Only_Types__
|
|
#undef __SCR_Dbg_h__Undef
|
|
#endif /* __SCR_Dbg_h__Undef */
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Constants.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
/*
|
|
* To export code.
|
|
*/
|
|
#undef CPA_EXPORT
|
|
#if defined(CPA_WANTS_IMPORT)
|
|
#define CPA_EXPORT __declspec(dllimport)
|
|
#elif defined(CPA_WANTS_EXPORT)
|
|
#define CPA_EXPORT __declspec(dllexport)
|
|
#else /* CPA_WANTS_IMPORT */
|
|
#define CPA_EXPORT
|
|
#endif /* CPA_WANTS_IMPORT */
|
|
|
|
#endif /* !__SCR_Dbg_h__Types */
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Macros.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
#if !defined(__SCR_Dbg_h__Macros) && !defined(__Only_Types__)
|
|
#define __SCR_Dbg_h__Macros
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Macros if _DEBUG.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifdef _DEBUG
|
|
|
|
/*
|
|
* A break point.
|
|
*/
|
|
#ifndef WATCOM
|
|
#define SCR_M_Dbg_BreakForDebug() {__asm {int 3h}}
|
|
#else /* !WATCOM */
|
|
#pragma aux SCR_M_Dbg_BreakForDebug = "int 0x03" value [eax] modify [eax];
|
|
#endif /* !WATCOM */
|
|
|
|
#else /* _DEBUG */
|
|
|
|
#define SCR_M_Dbg_BreakForDebug()
|
|
|
|
#endif /* _DEBUG */
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Macros if SCR_DM_ProtectedVersion.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifdef SCR_DM_ProtectedVersion
|
|
|
|
/*
|
|
* A normal assertion.
|
|
*/
|
|
#define SCR_M_Dbg_Assert_P(_Expression)\
|
|
{\
|
|
if(!(_Expression))\
|
|
{\
|
|
sprintf(g_st_Err_GlobalError.a_szBufferTmp1, "Incorrect expression is \""#_Expression"\".\n");\
|
|
*g_st_Err_GlobalError.a_szBufferTmp2 = '\0';\
|
|
SCR_M_Err_RaiseError(SCR_EI_Err_AssertionFailed);\
|
|
}\
|
|
}
|
|
|
|
/*
|
|
* A normal assertion but expression is always kept.
|
|
*/
|
|
#define SCR_M_Dbg_Verify_P(_Expression)\
|
|
{\
|
|
if(!(_Expression))\
|
|
{\
|
|
sprintf(g_st_Err_GlobalError.a_szBufferTmp1, "Incorrect expression is \""#_Expression"\".\n");\
|
|
*g_st_Err_GlobalError.a_szBufferTmp2 = '\0';\
|
|
SCR_M_Err_RaiseError(SCR_EI_Err_AssertionFailed);\
|
|
}\
|
|
}
|
|
|
|
/*
|
|
* To check validity of a structure.
|
|
*/
|
|
#define SCR_M_Dbg_AssertStruct_P(_Cast, _Pointer)\
|
|
{\
|
|
SCR_M_Dbg_Assert_P((_Pointer) != NULL);\
|
|
SCR_M_Dbg_Assert_P(((_Cast *) (_Pointer))->stHeader.uiSizeOf == sizeof(_Cast));\
|
|
}
|
|
|
|
/*
|
|
* Update uiSizeOf field of a structure.
|
|
*/
|
|
#define SCR_M_Dbg_UpdateSizeOf_P(_Cast, _Pointer)\
|
|
{\
|
|
(_Pointer)->stHeader.uiSizeOf = sizeof(_Cast);\
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Macros if not SCR_DM_ProtectedVersion.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#else /* SCR_DM_ProtectedVersion */
|
|
|
|
#define SCR_M_Dbg_Assert_P(_Expression)
|
|
#define SCR_M_Dbg_Verify_P(_Expression) _Expression
|
|
#define SCR_M_Dbg_AssertStruct_P(_Cast, _Pointer)
|
|
#define SCR_M_Dbg_UpdateSizeOf_P(_Cast, _Pointer)
|
|
|
|
#endif /* SCR_DM_ProtectedVersion */
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Macros if _DEBUG.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifdef _DEBUG
|
|
|
|
/*
|
|
* A normal assertion.
|
|
*/
|
|
#define SCR_M_Dbg_Assert_D(_Expression)\
|
|
{\
|
|
if(!(_Expression))\
|
|
{\
|
|
strcpy(g_st_Err_GlobalError.a_szBufferTmp1, "Expression is \""#_Expression"\".\n");\
|
|
*g_st_Err_GlobalError.a_szBufferTmp2 = '\0';\
|
|
SCR_M_Err_RaiseError(SCR_EI_Err_AssertionFailed);\
|
|
}\
|
|
}
|
|
|
|
/*
|
|
* A normal assertion but expression is always kept.
|
|
*/
|
|
#define SCR_M_Dbg_Verify_D(_Expression)\
|
|
{\
|
|
if(!(_Expression))\
|
|
{\
|
|
sprintf(g_st_Err_GlobalError.a_szBufferTmp1, "Incorrect expression is \""#_Expression"\".\n");\
|
|
*g_st_Err_GlobalError.a_szBufferTmp2 = '\0';\
|
|
SCR_M_Err_RaiseError(SCR_EI_Err_AssertionFailed);\
|
|
}\
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Macros if not _DEBUG.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#else /* _DEBUG */
|
|
|
|
#define SCR_M_Dbg_Assert_D(_Expression)
|
|
#define SCR_M_Dbg_Verify_D(_Expression) _Expression
|
|
|
|
#endif /* _DEBUG */
|
|
|
|
#endif /* !__SCR_Dbg_h__Macros && !__Only_Types__ */
|