Changeset 62 in libcf for trunk/src/cf_debug.c
- Timestamp:
- 04/08/13 11:03:03 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_debug.c
r55 r62 26 26 return CF_ERROR_DEBUG_INVALID_CTX 27 27 28 #define GET_CTX_OSTREAM(__ctx) \29 ((((CF_DEBUG_CTX *)__ctx)->fp == NULL) \30 ? stderr \31 : ((CF_DEBUG_CTX *)__ctx)->fp)32 33 28 /** 34 29 * 디버그 컨텍스트 … … 66 61 int line; 67 62 68 FILE * fp;69 63 CF_Mutex mutex; 70 64 … … 135 129 } 136 130 fprintf (fp, "\n"); 137 }138 139 return CF_OK;140 }141 142 /**143 * 디버그 컨텍스트를 해제144 *145 * @return 성공 시, CF_OK; 실패 시, 오류 코드146 *147 * @param ctx 디버그 컨텍스트148 *149 * @see CF_DEBUG_DESTROY_CTX150 */151 static int152 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx)153 {154 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx;155 CF_DEBUG_CALLSTACK * pop = NULL;156 CF_DEBUG_CALLSTACK * next = NULL;157 158 ASSERT_CTX (ctx);159 160 if (context->fp != NULL)161 fclose (context->fp);162 163 for (pop = next = context->callstack.caller ; pop ; pop = next)164 {165 next = next->caller;166 free (pop);167 }168 169 if (context->mutex)170 CF_Mutex_Destory (&context->mutex);171 172 free (context);173 174 return CF_OK;175 }176 177 /**178 * 디버그 컨텍스트를 생성179 *180 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL181 * @see CF_DEBUG_CREATE_CTX182 */183 static int184 CF_Debug_CreateCtx (CF_Debug_Ctx * ctx)185 {186 int result = 0;187 CF_DEBUG_CTX * context = NULL;188 189 TRY190 {191 context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1);192 if (context == NULL)193 {194 result = CF_ERROR_DEBUG_ALLOCATE_CTX;195 TRY_BREAK;196 }197 198 result = CF_Mutex_Create (&context->mutex);199 if (result < 0)200 {201 TRY_BREAK;202 }203 204 *ctx = (CF_Debug_Ctx) context;205 }206 CATCH_IF (result < 0)207 {208 CF_Debug_DestroyCtx (context);209 131 } 210 132 … … 395 317 396 318 /** 397 * 현재 콜스택을 출력 319 * 디버그 컨텍스트를 해제 320 * 321 * @return 성공 시, CF_OK; 실패 시, 오류 코드 322 * 323 * @param ctx 디버그 컨텍스트 324 * 325 * @see CF_DEBUG_DESTROY_CTX 326 */ 327 static int 328 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx) 329 { 330 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 331 332 ASSERT_CTX (ctx); 333 334 while (context->callstack.caller) 335 CF_Debug_CallStackPop (ctx, NULL); 336 337 if (context->mutex) 338 CF_Mutex_Destory (&context->mutex); 339 340 free (context); 341 342 return CF_OK; 343 } 344 345 /** 346 * 디버그 컨텍스트를 생성 347 * 348 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL 349 * @see CF_DEBUG_CREATE_CTX 350 */ 351 static int 352 CF_Debug_CreateCtx (CF_Debug_Ctx * ctx) 353 { 354 int result = 0; 355 CF_DEBUG_CTX * context = NULL; 356 357 TRY 358 { 359 context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1); 360 if (context == NULL) 361 { 362 result = CF_ERROR_DEBUG_ALLOCATE_CTX; 363 TRY_BREAK; 364 } 365 366 result = CF_Mutex_Create (&context->mutex); 367 if (result < 0) 368 { 369 TRY_BREAK; 370 } 371 372 *ctx = (CF_Debug_Ctx) context; 373 } 374 CATCH_IF (result < 0) 375 { 376 CF_Debug_DestroyCtx (context); 377 } 378 379 return CF_OK; 380 } 381 382 /** 383 * 콜스택 매니저 초기화 (글로벌 컨텍스트) 384 * 385 * @return 성공 시, CF_OK; 실패 시, 오류 코드 386 * 387 * @see CF_Debug_Finalize 388 */ 389 int 390 CF_Debug_Initialize (void) 391 { 392 int result = 0; 393 394 if (gDebugSingleCtx == NULL) 395 { 396 result = CF_Debug_CreateCtx (&gDebugSingleCtx); 397 if (result != CF_OK) 398 return result; 399 } 400 401 return CF_OK; 402 } 403 404 /** 405 * 콜스택 매니저 해제 (글로벌 컨텍스트) 406 * 407 * @return 성공 시, CF_OK; 실패 시, 오류 코드 408 */ 409 int 410 CF_Debug_Finalize (void) 411 { 412 return CF_Debug_DestroyCtx (gDebugSingleCtx); 413 } 414 415 /** 416 * 현재 콜스택을 출력 (글로벌 컨텍스트) 398 417 * 399 418 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 427 446 428 447 /** 429 * 함수 진입을 명시 448 * 함수 진입을 명시 (글로벌 컨텍스트) 430 449 * 431 450 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 442 461 const int line) 443 462 { 444 int result = 0; 445 CF_DEBUG_CTX * ctx = NULL; 446 447 if (gDebugSingleCtx == NULL) 448 { 449 result = CF_Debug_CreateCtx (&gDebugSingleCtx); 450 if (result != CF_OK) 451 return result; 452 } 453 ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 463 CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 464 465 ASSERT_CTX (ctx); 454 466 455 467 CF_Mutex_Lock (&ctx->mutex); … … 461 473 462 474 /** 463 * 함수 종료를 명시 475 * 함수 종료를 명시 (글로벌 컨텍스트) 464 476 * 465 477 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 472 484 CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 473 485 474 if (ctx == NULL) 475 return CF_ERROR_DEBUG_INVALID_CTX; 486 ASSERT_CTX (ctx); 476 487 477 488 CF_Mutex_Lock (&ctx->mutex);
Note:
See TracChangeset
for help on using the changeset viewer.