Changeset 63 in libcf for trunk


Ignore:
Timestamp:
04/09/13 11:20:55 (11 years ago)
Author:
cheese
Message:

#1 add interface to print callstack

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_debug.h

    r62 r63  
    7979
    8080/**
    81  * 함수에서 종료
     81 * 함수에서 리턴
    8282 *
    8383 * @see CF_Debug_LeaveFunction
     
    8585# define CF_DEBUG_END_FUNCTION                                      \
    8686    CF_Debug_LeaveFunction ()
     87
     88/**
     89 * 콜스택 을 지정된 파일 포인터로 출력
     90 *
     91 * @see CF_Debug_PrintCallStack
     92 */
     93# define CF_DEBUG_PRINT_CALLSTACK(__fp)                             \
     94    CF_Debug_PrintCallStack (__fp)
    8795
    8896#else // #ifdef _DEBUG
     
    93101# define CF_DEBUG_BEGIN_FUNCTION
    94102# define CF_DEBUG_END_FUNCTION
     103# define CF_DEBUG_PRINT_CALLSTACK(__fp)
    95104#endif // #ifdef _DEBUG
    96105
  • trunk/src/cf_debug.c

    r62 r63  
    414414
    415415/**
     416 * 함수 진입을 명시 (글로벌 컨텍스트)
     417 *
     418 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     419 *
     420 * @param file  파일 경로
     421 * @param func  함수 이름
     422 * @param line  라인 넘버
     423 *
     424 * @see CF_Debug_LeaveFunction
     425 */
     426int
     427CF_Debug_EnterFunction (const char  * file,
     428                        const char  * func,
     429                        const int   line)
     430{
     431    CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
     432
     433    ASSERT_CTX (ctx);
     434
     435    CF_Mutex_Lock (&ctx->mutex);
     436    CF_Debug_CallStackPush (gDebugSingleCtx, file, func, line);
     437    CF_Mutex_Unlock (&ctx->mutex);
     438
     439    return CF_OK;
     440}
     441
     442/**
     443 * 함수 종료를 명시 (글로벌 컨텍스트)
     444 *
     445 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     446 *
     447 * @see CF_Debug_EnterFunction
     448 */
     449int
     450CF_Debug_LeaveFunction (void)
     451{
     452    CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
     453
     454    ASSERT_CTX (ctx);
     455
     456    CF_Mutex_Lock (&ctx->mutex);
     457    CF_Debug_CallStackPop (gDebugSingleCtx, NULL);
     458    CF_Mutex_Unlock (&ctx->mutex);
     459
     460    return CF_OK;
     461}
     462
     463/**
    416464 * 현재 콜스택을 출력 (글로벌 컨텍스트)
    417465 *
     
    428476    CF_DEBUG_CALLSTACK  * callstack = NULL;
    429477
    430     if (ctx == NULL)
    431         return CF_ERROR_DEBUG_INVALID_CTX;
     478    ASSERT_CTX (ctx);
    432479
    433480    for ( callstack = ctx->callstack.caller
     
    435482        ; callstack = callstack->caller)
    436483    {
    437         fprintf (fp, "#%-4d %s <%s:%d>\n",
    438                      iter++,
    439                      callstack->func,
    440                      callstack->file,
    441                      callstack->line);
    442     }
    443 
    444     return CF_OK;
    445 }
    446 
    447 /**
    448  * 함수 진입을 명시 (글로벌 컨텍스트)
    449  *
    450  * @return 성공 시, CF_OK; 실패 시, 오류 코드
    451  *
    452  * @param file  파일 경로
    453  * @param func  함수 이름
    454  * @param line  라인 넘버
    455  *
    456  * @see CF_Debug_LeaveFunction
    457  */
    458 int
    459 CF_Debug_EnterFunction (const char  * file,
    460                         const char  * func,
    461                         const int   line)
    462 {
    463     CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
    464 
    465     ASSERT_CTX (ctx);
    466 
    467     CF_Mutex_Lock (&ctx->mutex);
    468     CF_Debug_CallStackPush (gDebugSingleCtx, file, func, line);
    469     CF_Mutex_Unlock (&ctx->mutex);
    470 
    471     return CF_OK;
    472 }
    473 
    474 /**
    475  * 함수 종료를 명시 (글로벌 컨텍스트)
    476  *
    477  * @return 성공 시, CF_OK; 실패 시, 오류 코드
    478  *
    479  * @see CF_Debug_EnterFunction
    480  */
    481 int
    482 CF_Debug_LeaveFunction (void)
    483 {
    484     CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
    485 
    486     ASSERT_CTX (ctx);
    487 
    488     CF_Mutex_Lock (&ctx->mutex);
    489     CF_Debug_CallStackPop (gDebugSingleCtx, NULL);
    490     CF_Mutex_Unlock (&ctx->mutex);
    491 
    492     return CF_OK;
    493 }
     484        fprintf (fp == NULL ? stderr : fp,
     485                 "#%-4d %s <%s:%d>\n",
     486                 iter++,
     487                 callstack->func,
     488                 callstack->file,
     489                 callstack->line);
     490    }
     491
     492    return CF_OK;
     493}
  • trunk/test/debug.c

    r62 r63  
    1212    CF_DEBUG_BEGIN_FUNCTION;
    1313
    14     CF_Debug_PrintCallStack (stdout);
     14    CF_DEBUG_PRINT_CALLSTACK (stdout);
    1515
    1616    CF_DEBUG_END_FUNCTION;
  • trunk/test/test.c

    r62 r63  
    2929const char * file = "./log.txt";
    3030
     31int     test_log_mt         (void * arg);
     32void    test_log            (const char * message);
     33void    test_file           (const char * message);
     34void    test_callstack3     (void);
     35void    test_callstack2     (void);
     36void    test_callstack1     (void);
     37int     socket_echo_server  (void * arg);
     38int     socket_echo_client  (void * arg);
     39void    test_socket         (void);
     40
     41int main (int argc, char ** argv)
     42{
     43    CF_DEBUG_INITIALIZE;
     44    CF_DEBUG_BEGIN_FUNCTION;
     45
     46    // 1
     47    CF_DEBUG_PRINT (stderr, " == LOG TEST ==\n");
     48    test_log ("LOG_TEST");
     49
     50    // 2
     51    CF_DEBUG_PRINT (stderr, " == FILE READ TEST ==\n");
     52    test_file ("FILE_READ_TEST");
     53
     54    // 3
     55    CF_DEBUG_PRINT (stderr, " == CALLSTACK TEST ==\n");
     56    test_callstack1 ();
     57
     58    // 4
     59    CF_DEBUG_PRINT (stderr, " == MULTI-THREADED SOCKET TEST ==\n");
     60    test_socket ();
     61
     62    CF_DEBUG_PRINT (stderr, " == END OF TEST ==\n");
     63
     64    CF_DEBUG_END_FUNCTION;
     65    CF_DEBUG_FINALIZE;
     66
     67    return 0;
     68}
     69
    3170int test_log_mt (void * arg)
    3271{
     
    157196{
    158197    CF_DEBUG_BEGIN_FUNCTION;
    159     CF_Debug_PrintCallStack (stdout);
     198    CF_DEBUG_PRINT_CALLSTACK (stdout);
    160199    CF_DEBUG_END_FUNCTION;
    161200}
     
    331370}
    332371
    333 int main (int argc, char ** argv)
    334 {
    335     CF_DEBUG_INITIALIZE;
    336     CF_DEBUG_BEGIN_FUNCTION;
    337 
    338     // 1
    339     CF_DEBUG_PRINT (stderr, " == LOG TEST ==\n");
    340     test_log ("LOG_TEST");
    341 
    342     // 2
    343     CF_DEBUG_PRINT (stderr, " == FILE READ TEST ==\n");
    344     test_file ("FILE_READ_TEST");
    345 
    346     // 3
    347     CF_DEBUG_PRINT (stderr, " == CALLSTACK TEST ==\n");
    348     test_callstack1 ();
    349 
    350     // 4
    351     CF_DEBUG_PRINT (stderr, " == MULTI-THREADED SOCKET TEST ==\n");
    352     test_socket ();
    353 
    354     CF_DEBUG_PRINT (stderr, " == END OF TEST ==\n");
    355 
    356     CF_DEBUG_END_FUNCTION;
    357     CF_DEBUG_FINALIZE;
    358 
    359     return 0;
    360 }
    361 
Note: See TracChangeset for help on using the changeset viewer.