Changeset 51 in libcf
- Timestamp:
- 04/02/13 10:23:52 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_debug.h
r50 r51 27 27 28 28 #ifdef _DEBUG 29 /**30 * 디버그 컨텍스트 생성31 *32 * @see CF_Debug_CreateCtx33 */34 # define CF_DEBUG_CREATE_CTX() \35 CF_Debug_CreateCtx ()36 37 /**38 * 디버그 컨텍스트 해제39 *40 * @param __ctx 디버그 컨텍스트41 *42 * @see CF_Debug_DestroyCtx43 */44 # define CF_DEBUG_DESTROY_CTX(__ctx) \45 CF_Debug_DestroyCtx (__ctx)46 29 47 30 /** 48 31 * 디버그 메시지를 지정된 파일 포인터로 출력 49 32 * 50 * @param __fp 파일 포인터. 표준출력(stdout) 및 표준오류(stderr) 사용 가능51 33 * @param __fmt 포맷 스트링 52 34 * @param ... 가변 인자 … … 60 42 * 바이너리 데이터를 디버그 메시지와 함께 지정된 파일 포인터로 출력 61 43 * 62 * @param __fp 파일 포인터. 표준출력(stdout) 및 표준오류(stderr) 사용 가능63 44 * @param __bin 바이너리 데이터 64 45 * @param __len 바이너리 길이 … … 72 53 73 54 /** 74 * 컨텍스트를 업데이트하고 디버그 메시지를 출력55 * 함수에 진입 75 56 * 76 * @param __ctx 디버그 컨텍스트 77 * @param __fmt 포맷 스트링 78 * @param ... 가변 인자 79 * 80 * @see CF_Debug_Trace 57 * @see CF_Debug_EnterFunction 81 58 */ 82 # define CF_DEBUG_ TRACE(__ctx,__fmt,...)\83 CF_Debug_ Trace (__ctx,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)59 # define CF_DEBUG_BEGIN_FUNCTION \ 60 CF_Debug_EnterFunction (__FILE__,__func__,__LINE__) 84 61 85 62 /** 86 * 컨텍스트를 업데이트하고 바이너리 데이터를 디버그 메시지와 함께 출력63 * 함수에서 종료 87 64 * 88 * @param __ctx 디버그 컨텍스트 89 * @param __bin 바이너리 데이터 90 * @param __len 바이너리 길이 91 * @param __fmt 포맷 스트링 92 * @param ... 가변 인자 93 * 94 * @see CF_Debug_TraceBin 65 * @see CF_Debug_LeaveFunction 95 66 */ 96 # define CF_DEBUG_ TRACE_BIN(__ctx,__bin,__len,__fmt,...)\97 CF_Debug_ TraceBin (__ctx,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)67 # define CF_DEBUG_END_FUNCTION \ 68 CF_Debug_LeaveFunction () 98 69 99 /**100 * 컨텍스트에 콜스택 푸시101 *102 * @param __ctx 디버그 컨텍스트103 *104 * @see CF_Debug_CallStackPush105 */106 # define CF_DEBUG_CALLSTACK_PUSH(__ctx) \107 CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)108 109 /**110 * 컨텍스트에서 콜스택 팝111 *112 * @param __ctx 디버그 컨텍스트113 * @param __callstack 콜스택 정보를 가져올 콜스택 데이터 구조체 포인터114 *115 * @see CF_Debug_CallStackPop, CF_Debug_CallStack116 */117 # define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) \118 CF_Debug_CallStackPop (__ctx,__callstack)119 70 #else // #ifdef _DEBUG 120 # define CF_DEBUG_CREATE_CTX() NULL121 # define CF_DEBUG_DESTROY_CTX(__ctx)122 71 # define CF_DEBUG_PRINT(__fp,__fmt,...) 123 72 # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) 124 # define CF_DEBUG_TRACE(__ctx,__fmt,...) 125 # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) 126 # define CF_DEBUG_CALLSTACK_PUSH(__ctx) 127 # define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1 73 # define CF_DEBUG_BEGIN_FUNCTION 74 # define CF_DEBUG_END_FUNCTION 128 75 #endif // #ifdef _DEBUG 129 130 /** 디버그 컨텍스트 */131 typedef void * CF_Debug_Ctx;132 133 /** 콜스택 데이터 */134 typedef struct cf_debug_callStack {135 char file[NAME_LENGTH + 1]; /**< 파일 이름 */136 char function[NAME_LENGTH + 1]; /**< 함수 이름 */137 int line; /**< 라인 넘버 */138 } CF_Debug_CallStack;139 76 140 77 #ifdef __cplusplus 141 78 extern "C" { 142 79 #endif 143 144 CF_EXPORT CF_Debug_Ctx145 CF_Debug_CreateCtx (void);146 147 CF_EXPORT int148 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);149 150 CF_EXPORT int151 CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,152 int fd);153 80 154 81 CF_EXPORT int … … 169 96 170 97 CF_EXPORT int 171 CF_Debug_Trace (CF_Debug_Ctx ctx, 172 const char * file, 173 const char * func, 174 const int line, 175 const char * fmt, ...); 98 CF_Debug_PrintCallStack (FILE * fp); 176 99 177 100 CF_EXPORT int 178 CF_Debug_TraceBin (CF_Debug_Ctx ctx, 179 const char * file, 180 const char * func, 181 const int line, 182 const unsigned char * bin, 183 const int len, 184 const char * fmt, ...); 101 CF_Debug_EnterFunction (const char * file, 102 const char * func, 103 const int line); 185 104 186 105 CF_EXPORT int 187 CF_Debug_CallStackPush (CF_Debug_Ctx ctx, 188 const char * file, 189 const char * func, 190 const int line); 191 192 CF_EXPORT int 193 CF_Debug_CallStackPop (CF_Debug_Ctx ctx, 194 CF_Debug_CallStack * callstack); 106 CF_Debug_LeaveFunction (void); 195 107 196 108 #ifdef __cplusplus -
trunk/include/cf_error.h
r46 r51 62 62 /*------------------------------------------------------------*/ 63 63 #define CF_ERROR_DEBUG_INVALID_CTX CF_ERROR_DEBUG - 1 64 #define CF_ERROR_DEBUG_SET_OUTPUT_FD CF_ERROR_DEBUG - 2 65 #define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 3 66 #define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 4 64 #define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 2 65 #define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 3 66 #define CF_ERROR_DEBUG_PEEK_CALLSTACK CF_ERROR_DEBUG - 4 67 #define CF_ERROR_DEBUG_ALLOCATE_CTX CF_ERROR_DEBUG - 5 67 68 /* }}} debug */ 68 69 -
trunk/src/cf_debug.c
r50 r51 7 7 #include "cf_local.h" 8 8 #include "cf_error.h" 9 #include "cf_thread.h" 9 10 10 11 #include <stdlib.h> … … 30 31 : ((CF_DEBUG_CTX *)__ctx)->fp) 31 32 33 /** 34 * 디버그 컨텍스트 35 * 36 * @remark change from public to private 37 */ 38 typedef void * CF_Debug_Ctx; 39 40 /** 41 * 콜스택 데이터 42 * 43 * @remark change from public to private 44 */ 45 typedef struct cf_debug_callStack { 46 char file[NAME_LENGTH + 1]; /**< 파일 이름 */ 47 char function[NAME_LENGTH + 1]; /**< 함수 이름 */ 48 int line; /**< 라인 넘버 */ 49 } CF_Debug_CallStack; 50 32 51 typedef struct __cf_debug_callstack__ 33 52 { … … 36 55 int line; 37 56 57 int frameIndex; 58 38 59 struct __cf_debug_callstack__ * caller; 39 60 } S_CF_DEBUG_CALLSTACK, CF_DEBUG_CALLSTACK; … … 41 62 typedef struct __cf_debug_ctx__ 42 63 { 43 char file[NAME_LENGTH + 1]; 44 char func[NAME_LENGTH + 1]; 45 int line; 46 47 FILE * fp; 64 char file[NAME_LENGTH + 1]; 65 char func[NAME_LENGTH + 1]; 66 int line; 67 68 FILE * fp; 69 CF_Mutex mutex; 48 70 49 71 CF_DEBUG_CALLSTACK callstack; 50 72 } S_CF_DEBUG_CTX, CF_DEBUG_CTX; 73 74 CF_Debug_Ctx gDebugSingleCtx = NULL; 51 75 52 76 static int … … 117 141 118 142 /** 119 * 디버그 컨텍스트를 생성120 *121 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL122 * @see CF_DEBUG_CREATE_CTX123 */124 CF_Debug_Ctx125 CF_Debug_CreateCtx (void)126 {127 CF_DEBUG_CTX * ctx = NULL;128 129 ctx = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1);130 131 return (CF_Debug_Ctx) ctx;132 }133 134 /**135 143 * 디버그 컨텍스트를 해제 136 144 * … … 141 149 * @see CF_DEBUG_DESTROY_CTX 142 150 */ 143 int151 static int 144 152 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx) 145 153 { … … 159 167 } 160 168 169 if (context->mutex) 170 CF_Mutex_Destory (&context->mutex); 171 161 172 free (context); 162 173 … … 165 176 166 177 /** 167 * 디버그 컨텍스트에 출력할 파일 디스크립터를 설정 168 * 169 * @return 성공 시, CF_OK; 실패 시, 오류 코드 170 * 171 * @param ctx 디버그 컨텍스트 172 * @param fd 파일 디스크립터 173 * 174 * @see CF_File_Open, CF_File_Create 175 */ 176 int 177 CF_Debug_SetOutputFD (CF_Debug_Ctx ctx, 178 int fd) 179 { 180 int result = 0; 181 int dupfd = 0; 182 183 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 184 FILE * fp = NULL; 185 186 CHECK_INVALID_CTX (ctx); 178 * 디버그 컨텍스트를 생성 179 * 180 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL 181 * @see CF_DEBUG_CREATE_CTX 182 */ 183 static int 184 CF_Debug_CreateCtx (CF_Debug_Ctx * ctx) 185 { 186 int result = 0; 187 CF_DEBUG_CTX * context = NULL; 187 188 188 189 TRY 189 190 { 190 dupfd = dup (fd);191 if ( dupfd < 0)191 context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1); 192 if (context == NULL) 192 193 { 193 result = -1;194 result = CF_ERROR_DEBUG_ALLOCATE_CTX; 194 195 TRY_BREAK; 195 196 } 196 197 197 fp = fdopen (dupfd, "a");198 if ( fp == NULL)198 result = CF_Mutex_Create (&context->mutex); 199 if (result < 0) 199 200 { 200 close (dupfd);201 result = -2;202 201 TRY_BREAK; 203 202 } 204 203 205 context->fp = fp;204 *ctx = (CF_Debug_Ctx) context; 206 205 } 207 206 CATCH_IF (result < 0) 208 207 { 209 return CF_ERROR_DEBUG_SET_OUTPUT_FD;208 CF_Debug_DestroyCtx (context); 210 209 } 211 210 … … 280 279 281 280 /** 282 * 컨텍스트 를 업데이트하고 디버그 메시지를 출력283 * 284 * @return CF_OK 반환281 * 컨텍스트에 콜스택 푸시 282 * 283 * @return 성공 시, CF_OK; 실패 시, 오류 코드 285 284 * 286 285 * @param ctx 디버그 컨텍스트 … … 288 287 * @param func 함수 이름 289 288 * @param line 라인 넘버 290 * @param fmt 포맷 스트링 291 * @param ... 가변 인자 292 * 293 * @see CF_Debug_Trace 294 */ 295 int 296 CF_Debug_Trace (CF_Debug_Ctx ctx, 297 const char * file, 298 const char * func, 299 const int line, 300 const char * fmt, ...) 301 { 302 va_list valist; 303 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 304 305 CHECK_INVALID_CTX (ctx); 306 307 CF_Debug_Local_UpdateCtx (ctx, file, func, line); 308 309 va_start (valist, fmt); 310 CF_Debug_Local_Print (GET_CTX_OSTREAM (context), 311 context->file, 312 context->func, 313 context->line, 314 fmt, valist); 315 va_end (valist); 316 317 return CF_OK; 318 } 319 320 /** 321 * 컨텍스트를 업데이트하고 바이너리 데이터를 디버그 메시지와 함께 출력 322 * 323 * @return 성공 시, CF_OK; 실패 시, 오류 코드 324 * 325 * @param ctx 디버그 컨텍스트 326 * @param file 파일 경로 327 * @param func 함수 이름 328 * @param line 라인 넘버 329 * @param bin 바이너리 데이터 330 * @param len 바이너리 길이 331 * @param fmt 포맷 스트링 332 * @param ... 가변 인자 333 * 334 * @see CF_DEBUG_TRACE_BIN 335 */ 336 int 337 CF_Debug_TraceBin (CF_Debug_Ctx ctx, 338 const char * file, 339 const char * func, 340 const int line, 341 const unsigned char * bin, 342 const int len, 343 const char * fmt, ...) 344 { 345 va_list valist; 346 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 347 348 CHECK_INVALID_CTX (ctx); 349 350 CF_Debug_Local_UpdateCtx (ctx, file, func, line); 351 352 va_start (valist, fmt); 353 CF_Debug_Local_Print (GET_CTX_OSTREAM (context), 354 context->file, 355 context->func, 356 context->line, 357 fmt, valist); 358 va_end (valist); 359 360 CF_Debug_Local_PrintBin (GET_CTX_OSTREAM (context), 361 context->file, 362 context->func, 363 context->line, 364 bin, len); 365 366 return CF_OK; 367 } 368 369 /** 370 * 컨텍스트에 콜스택 푸시 371 * 372 * @return 성공 시, CF_OK; 실패 시, 오류 코드 373 * 374 * @param ctx 디버그 컨텍스트 375 * @param file 파일 경로 376 * @param func 함수 이름 377 * @param line 라인 넘버 378 * 379 * @see CF_DEBUG_CALLSTACK_PUSH 380 */ 381 int 289 */ 290 static int 382 291 CF_Debug_CallStackPush (CF_Debug_Ctx ctx, 383 292 const char * file, … … 399 308 push->line = line; 400 309 push->caller = context->callstack.caller; 310 push->frameIndex = context->callstack.frameIndex + 1; 401 311 context->callstack.caller = push; 402 312 … … 407 317 408 318 /** 409 * 컨텍스트에서 콜스택 팝319 * 컨텍스트에서 콜스택에서 TOP을 제거하지 않고 가져옴 410 320 * 411 321 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 414 324 * @param callstack 콜스택 정보를 가져올 콜스택 데이터 구조체 포인터 415 325 * 416 * @see CF_Debug_CallStackPop, CF_Debug_CallStack 417 */ 418 int 326 * @see CF_Debug_CallStack 327 */ 328 static int 329 CF_Debug_CallStackPeek (CF_Debug_Ctx ctx, 330 CF_Debug_CallStack * callstack) 331 { 332 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 333 CF_DEBUG_CALLSTACK * pop = NULL; 334 335 pop = context->callstack.caller; 336 if (pop == NULL) 337 return CF_ERROR_DEBUG_PEEK_CALLSTACK; 338 339 if (callstack != NULL) 340 { 341 sprintf (callstack->file , "%s", pop->file); 342 sprintf (callstack->function, "%s", pop->func); 343 callstack->line = pop->line; 344 } 345 346 return CF_OK; 347 } 348 349 /** 350 * 컨텍스트에서 콜스택 팝 351 * 352 * @return 성공 시, CF_OK; 실패 시, 오류 코드 353 * 354 * @param ctx 디버그 컨텍스트 355 * @param callstack 콜스택 정보를 가져올 콜스택 데이터 구조체 포인터 356 * 357 * @see CF_Debug_CallStack 358 */ 359 static int 419 360 CF_Debug_CallStackPop (CF_Debug_Ctx ctx, 420 361 CF_Debug_CallStack * callstack) … … 429 370 return CF_ERROR_DEBUG_POP_CALLSTACK; 430 371 431 if (callstack != NULL) 432 { 433 sprintf (callstack->file , "%s", pop->file); 434 sprintf (callstack->function, "%s", pop->func); 435 callstack->line = pop->line; 436 } 372 if (CF_Debug_CallStackPeek (ctx, callstack) < 0) 373 return CF_ERROR_DEBUG_PEEK_CALLSTACK; 437 374 438 375 memset (context->file, 0x00, sizeof (context->file)); … … 454 391 return CF_OK; 455 392 } 393 394 /** 395 * 현재 콜스택을 출력 396 * 397 * @return 성공 시, CF_OK; 실패 시, 오류 코드 398 * 399 * @param fp 출력 할 파일 포인터 400 */ 401 int 402 CF_Debug_PrintCallStack (FILE * fp) 403 { 404 int iter = 0; 405 406 CF_DEBUG_CTX * ctx = gDebugSingleCtx; 407 CF_DEBUG_CALLSTACK * callstack = NULL; 408 409 if (ctx == NULL) 410 return CF_ERROR_DEBUG_INVALID_CTX; 411 412 callstack = &ctx->callstack; 413 414 do 415 { 416 if (callstack == NULL) 417 break; 418 419 fprintf (fp, "#%04d %s (%s:%d)\n", 420 iter, 421 callstack->func, 422 callstack->file, 423 callstack->line); 424 425 callstack = callstack->caller; 426 } while (iter++ < ctx->callstack.frameIndex); 427 428 return CF_OK; 429 } 430 431 /** 432 * 함수 진입을 명시 433 * 434 * @return 성공 시, CF_OK; 실패 시, 오류 코드 435 * 436 * @param file 파일 경로 437 * @param func 함수 이름 438 * @param line 라인 넘버 439 * 440 * @see CF_Debug_LeaveFunction 441 */ 442 int 443 CF_Debug_EnterFunction (const char * file, 444 const char * func, 445 const int line) 446 { 447 int result = 0; 448 CF_DEBUG_CTX * ctx = NULL; 449 450 if (gDebugSingleCtx == NULL) 451 { 452 result = CF_Debug_CreateCtx (&gDebugSingleCtx); 453 if (result != CF_OK) 454 return result; 455 } 456 ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 457 458 CF_Mutex_Lock (&ctx->mutex); 459 CF_Debug_CallStackPush (gDebugSingleCtx, file, func, line); 460 CF_Mutex_Unlock (&ctx->mutex); 461 462 return CF_OK; 463 } 464 465 /** 466 * 함수 종료를 명시 467 * 468 * @return 성공 시, CF_OK; 실패 시, 오류 코드 469 * 470 * @see CF_Debug_EnterFunction 471 */ 472 int 473 CF_Debug_LeaveFunction (void) 474 { 475 CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 476 477 if (ctx == NULL) 478 return CF_ERROR_DEBUG_INVALID_CTX; 479 480 CF_Mutex_Lock (&ctx->mutex); 481 CF_Debug_CallStackPop (gDebugSingleCtx, NULL); 482 CF_Mutex_Unlock (&ctx->mutex); 483 484 return CF_OK; 485 } -
trunk/src/cf_log.c
r50 r51 30 30 #define LOCK_LOG_CTX(__ctx) CF_Mutex_Lock (&__ctx->mutex) 31 31 #define UNLOCK_LOG_CTX(__ctx) CF_Mutex_Unlock (&__ctx->mutex) 32 #define CHECK_INITIALIZED() (gLogEnvironment.ctxPool == NULL|| \ 33 gLogEnvironment.ctxSize <= 0 ) 34 #define CHECK_INVALID_MAPID(__mapid) (gLogEnvironment.ctxSize <= __mapid) 35 #define CHECK_MAPPED_ID(__mapid) (gLogEnvironment.ctxPool[__mapid] != NULL) \ 36 32 #define CHECK_INITIALIZED() (gLogArray.ctxPool == NULL|| \ 33 gLogArray.ctxSize <= 0 ) 34 #define CHECK_INVALID_MAPID(__mapid) (gLogArray.ctxSize <= __mapid) 35 #define CHECK_MAPPED_ID(__mapid) (gLogArray.ctxPool[__mapid] != NULL) 37 36 38 37 #define LOG_BUFFER_DEFAULT_SIZE 128 * 1024 39 38 40 #define LOG_DATETIME_LENGTH sizeof ("0000-00-00 00:00:00.000") - 139 #define LOG_DATETIME_LENGTH sizeof ("0000-00-00 00:00:00.000") - 1 41 40 42 41 /** … … 69 68 } S_CF_LOG_CTX, CF_LOG_CTX; 70 69 71 typedef struct __cf_log_ environment__ {70 typedef struct __cf_log_array__ { 72 71 CF_Log_Ctx * ctxPool; 73 72 int ctxSize; 74 } S_CF_LOG_ ENVIRONMENT, CF_LOG_ENVIRONMENT;75 76 static CF_LOG_ ENVIRONMENT gLogEnvironment;73 } S_CF_LOG_ARRAY, CF_LOG_ARRAY; 74 75 static CF_LOG_ARRAY gLogArray; 77 76 78 77 #if defined(_WIN32) || defined(_WIN64) … … 475 474 } 476 475 477 gLog Environment.ctxPool[mapid] = ctx;476 gLogArray.ctxPool[mapid] = ctx; 478 477 479 478 return CF_OK; … … 501 500 return CF_ERROR_LOG_NOT_MAPPED_ID; 502 501 503 CF_Log_DestroyCtx (gLog Environment.ctxPool[mapid]);504 505 free (gLog Environment.ctxPool[mapid]);506 gLog Environment.ctxPool[mapid] = NULL;502 CF_Log_DestroyCtx (gLogArray.ctxPool[mapid]); 503 504 free (gLogArray.ctxPool[mapid]); 505 gLogArray.ctxPool[mapid] = NULL; 507 506 508 507 return CF_OK; … … 528 527 return CF_ERROR_LOG_NOT_MAPPED_ID; 529 528 530 *ctx = gLog Environment.ctxPool[mapid];529 *ctx = gLogArray.ctxPool[mapid]; 531 530 532 531 return CF_OK; … … 543 542 CF_Log_Initialize (const int logPool) 544 543 { 545 memset (&gLog Environment, 0x00, sizeof (CF_LOG_ENVIRONMENT));544 memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY)); 546 545 547 546 if (logPool > 0) 548 547 { 549 gLog Environment.ctxPool =548 gLogArray.ctxPool = 550 549 (CF_Log_Ctx *) calloc ((size_t) logPool, sizeof (CF_Log_Ctx)); 551 if (gLog Environment.ctxPool == NULL)550 if (gLogArray.ctxPool == NULL) 552 551 return CF_ERROR_LOG_INITIALIZE; 553 gLog Environment.ctxSize = logPool;552 gLogArray.ctxSize = logPool; 554 553 } 555 554 … … 567 566 int mapid = 0; 568 567 569 for (mapid = 0 ; mapid < gLog Environment.ctxSize ; mapid++)568 for (mapid = 0 ; mapid < gLogArray.ctxSize ; mapid++) 570 569 { 571 570 CF_Log_UnmapCtxID (mapid); 572 571 } 573 572 574 if (gLog Environment.ctxPool != NULL)575 free (gLog Environment.ctxPool);576 577 memset (&gLog Environment, 0x00, sizeof (CF_LOG_ENVIRONMENT));573 if (gLogArray.ctxPool != NULL) 574 free (gLogArray.ctxPool); 575 576 memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY)); 578 577 579 578 return CF_OK; -
trunk/test/debug.c
r35 r51 7 7 #include "cf_debug.h" 8 8 9 CF_Debug_Ctx gDebugCtx; 9 #include <string.h> 10 10 11 11 void callee (void) { 12 CF_Debug_CallStack callstack; 13 14 CF_DEBUG_CALLSTACK_PUSH (gDebugCtx); 15 CF_DEBUG_CALLSTACK_POP (gDebugCtx, &callstack); 12 CF_DEBUG_BEGIN_FUNCTION; 13 14 CF_Debug_PrintCallStack (stdout); 15 16 CF_DEBUG_END_FUNCTION; 16 17 } 17 18 18 19 int main (void) { 19 int fd = 0; 20 gDebugCtx = CF_Debug_CreateCtx (); 20 char data[] = 21 "【 曲名 : 사랑하고 있는데 】\n" 22 "《 歌 : Kylee 》\n" 23 "『 절원의 템페스트 OP2 Theme 』\n"; 21 24 22 CF_DEBUG_ CALLSTACK_PUSH (gDebugCtx);25 CF_DEBUG_BEGIN_FUNCTION; 23 26 24 CF_DEBUG_ TRACE (gDebugCtx, "print tracemessage with context to stderr\n");27 CF_DEBUG_PRINT (stderr, "print message with context to stderr\n"); 25 28 26 fd = CF_File_Create ("debug.txt"); 27 if (fd < 0) { 28 CF_DEBUG_PRINT (stderr, "error ...\n"); 29 // error 30 } 31 CF_Debug_SetOutputFD (gDebugCtx, fd); 29 CF_DEBUG_PRINT_BIN (stdout, (unsigned char *) data, (int) sizeof (data), "hehehehe\n"); 32 30 33 CF_DEBUG_TRACE (gDebugCtx, "print trace message with context to debug.txt\n");31 callee (); 34 32 35 CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL); 36 37 CF_Debug_DestroyCtx (gDebugCtx); 33 CF_DEBUG_END_FUNCTION; 38 34 39 35 return 0; -
trunk/test/test.c
r49 r51 22 22 #define PORT 1234 23 23 24 CF_Debug_Ctx gDebugCtx;25 CF_Debug_CallStack gDebugCallstack;26 24 CF_Mutex globalMutex; 27 25 … … 63 61 CF_Thread tid[10]; 64 62 65 CF_DEBUG_ CALLSTACK_PUSH (gDebugCtx);63 CF_DEBUG_BEGIN_FUNCTION; 66 64 67 65 /* initialize */ … … 125 123 /* finalize */ 126 124 CF_Log_Finalize (); 125 126 CF_DEBUG_END_FUNCTION; 127 127 } 128 128 … … 132 132 char buffer[128] = {0x00,}; 133 133 134 CF_DEBUG_ CALLSTACK_PUSH (gDebugCtx);134 CF_DEBUG_BEGIN_FUNCTION; 135 135 136 136 fd = CF_File_Open (file, CF_FILE_RO); 137 137 if (fd < 0) 138 CF_DEBUG_ TRACE (gDebugCtx, "what the ... file open ?\n");138 CF_DEBUG_PRINT (stderr, "what the ... file open ?\n"); 139 139 140 140 if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0) 141 CF_DEBUG_ TRACE (gDebugCtx, "what the ... file read ?\n");141 CF_DEBUG_PRINT (stderr, "what the ... file read ?\n"); 142 142 else 143 CF_DEBUG_ TRACE_BIN (gDebugCtx, (unsigned char *)buffer,144 145 146 147 143 CF_DEBUG_PRINT_BIN (stdout, (unsigned char *)buffer, 144 sizeof (buffer), 145 "-- %d bytes of %d bytes\n", 146 sizeof (buffer), 147 CF_File_GetSize (fd)); 148 148 149 149 CF_File_Close (fd); 150 150 151 CF_DEBUG_ CALLSTACK_POP (gDebugCtx, NULL);151 CF_DEBUG_END_FUNCTION; 152 152 } 153 153 154 154 void test_callstack3 (void) 155 155 { 156 CF_DEBUG_CALLSTACK_PUSH (gDebugCtx); 157 while (CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack) == CF_OK) 158 { 159 CF_DEBUG_TRACE (gDebugCtx, "print callstack [file:%s line:%d func:%s]\n", 160 gDebugCallstack.file, 161 gDebugCallstack.line, 162 gDebugCallstack.function); 163 } 164 CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL); 156 CF_DEBUG_BEGIN_FUNCTION; 157 CF_Debug_PrintCallStack (stdout); 158 CF_DEBUG_END_FUNCTION; 165 159 } 166 160 void test_callstack2 (void) 167 161 { 168 CF_DEBUG_ CALLSTACK_PUSH (gDebugCtx);162 CF_DEBUG_BEGIN_FUNCTION; 169 163 test_callstack3 (); 170 CF_DEBUG_ CALLSTACK_POP (gDebugCtx, NULL);164 CF_DEBUG_END_FUNCTION; 171 165 } 172 166 void test_callstack1 (void) 173 167 { 174 CF_DEBUG_ CALLSTACK_PUSH (gDebugCtx);168 CF_DEBUG_BEGIN_FUNCTION; 175 169 test_callstack2 (); 176 CF_DEBUG_ CALLSTACK_POP (gDebugCtx, NULL);170 CF_DEBUG_END_FUNCTION; 177 171 } 178 172 … … 333 327 int main (int argc, char ** argv) 334 328 { 335 gDebugCtx = CF_Debug_CreateCtx (); 336 337 CF_DEBUG_CALLSTACK_PUSH (gDebugCtx); 329 CF_DEBUG_BEGIN_FUNCTION; 338 330 339 331 // 1 … … 353 345 test_socket (); 354 346 355 CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack);356 357 347 CF_DEBUG_PRINT (stderr, " == END OF TEST ==\n"); 358 CF_DEBUG_TRACE (gDebugCtx, "here is the end of function [file:%s line:%d func:%s]\n", 359 gDebugCallstack.file, 360 gDebugCallstack.line, 361 gDebugCallstack.function); 362 363 CF_Debug_DestroyCtx (gDebugCtx); 348 349 CF_DEBUG_END_FUNCTION; 364 350 365 351 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.