/** * @file cf_debug.h * @author myusgun * @version 0.1 * * @remark * 디버그 함수를 직접 호출하지 않고 정의된 매크로를 사용하면, * Preprocessor에 _DEBUG가 정의되어 있는 경우에 만 * 디버그 코드가 동작하도록 할 수 있음
* 디버그 메시지는 stdout 및 stderr를 이용한 파일 포인터 출력을 지원하고, * 환경에 적합하도록 사용자가 구성한 컨텍스트를 이용하여 사용할 수도 있음
* (단, 콜스택의 푸시/팝은 컨텍스트를 이용해야만 사용 가능) * * @example debug.c */ #ifndef __CF_DEBUG_H__ #define __CF_DEBUG_H__ #include "cf_base.h" #include /** Windows 함수 이름 매크로 재정의 */ #if defined(_WIN32) || defined(_WIN64) # define __func__ __FUNCTION__ #endif #ifdef _DEBUG /** * 디버그 메시지를 지정된 파일 포인터로 출력 * * @param __fmt 포맷 스트링 * @param ... 가변 인자 * * @see CF_Debug_Print */ # define CF_DEBUG_PRINT(__fp,__fmt,...) \ CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__) /** * 바이너리 데이터를 디버그 메시지와 함께 지정된 파일 포인터로 출력 * * @param __bin 바이너리 데이터 * @param __len 바이너리 길이 * @param __fmt 포맷 스트링 * @param ... 가변 인자 * * @see CF_Debug_PrintBin */ # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \ CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__) /** * 함수에 진입 * * @see CF_Debug_EnterFunction */ # define CF_DEBUG_BEGIN_FUNCTION \ CF_Debug_EnterFunction (__FILE__,__func__,__LINE__) /** * 함수에서 종료 * * @see CF_Debug_LeaveFunction */ # define CF_DEBUG_END_FUNCTION \ CF_Debug_LeaveFunction () #else // #ifdef _DEBUG # define CF_DEBUG_PRINT(__fp,__fmt,...) # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) # define CF_DEBUG_BEGIN_FUNCTION # define CF_DEBUG_END_FUNCTION #endif // #ifdef _DEBUG #ifdef __cplusplus extern "C" { #endif CF_EXPORT int CF_Debug_Print (FILE * fp, const char * file, const char * func, const int line, const char * fmt, ...); CF_EXPORT int CF_Debug_PrintBin (FILE * fp, const char * file, const char * func, const int line, const unsigned char * bin, const int len, const char * fmt, ...); CF_EXPORT int CF_Debug_PrintCallStack (FILE * fp); CF_EXPORT int CF_Debug_EnterFunction (const char * file, const char * func, const int line); CF_EXPORT int CF_Debug_LeaveFunction (void); #ifdef __cplusplus } #endif #endif // #ifndef __CF_DEBUG_H__