Changeset 9 in libcf


Ignore:
Timestamp:
01/30/13 17:39:07 (11 years ago)
Author:
cheese
Message:

#1 add more omitted code and enhance stability

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_debug.h

    r8 r9  
    99#define CF_ERROR_DEBUG_INVALID_CTX          CF_ERROR_DEBUG - 1
    1010#define CF_ERROR_DEBUG_SET_OUTPUT_FD        CF_ERROR_DEBUG - 2
    11 #define CF_ERROR_DEBUG_INVALID_ARGS         CF_ERROR_DEBUG - 3
    12 #define CF_ERROR_DEBUG_PUSH_CALLSTACK       CF_ERROR_DEBUG - 4
    13 #define CF_ERROR_DEBUG_POP_CALLSTACK        CF_ERROR_DEBUG - 5
     11#define CF_ERROR_DEBUG_PUSH_CALLSTACK       CF_ERROR_DEBUG - 3
     12#define CF_ERROR_DEBUG_POP_CALLSTACK        CF_ERROR_DEBUG - 4
    1413
    1514#ifdef _WIN32
     
    2322    CF_Debug_Trace (__ctx,__bin,__len,__fmt,##__VA_ARGS__)
    2423# define CF_DEBUG_CALLSTACK_PUSH(__ctx)                             \
    25     CF_Debug_CallstackPush (__ctx,__func__,__LINE__)
     24    CF_Debug_CallstackPush (__ctx,__FILE__,__func__,__LINE__)
    2625# define CF_DEBUG_CALLSTACK_POP                                     \
    2726    CF_Debug_CallstackPop
     
    6766CF_EXPORT int
    6867CF_Debug_CallStackPush  (CF_Debug_Ctx   ctx,
     68                         const char     * file,
    6969                         const char     * func,
    7070                         const int      line);
  • trunk/src/cf_debug.c

    r8 r9  
    99#include <ctype.h>
    1010#include <stdarg.h>
     11#include <string.h>
    1112
    1213#ifdef _WIN32
     
    2829typedef struct __cf_debug_callstack__
    2930{
     31    char    file[NAME_LENGTH + 1];
    3032    char    func[NAME_LENGTH + 1];
    3133    int     line;
     
    187189int
    188190CF_Debug_CallStackPush (CF_Debug_Ctx    ctx,
     191                        const char      * file,
    189192                        const char      * func,
    190193                        const int       line)
     
    199202        return CF_ERROR_DEBUG_PUSH_CALLSTACK;
    200203
     204    /* push to callstack */
     205    sprintf (push->file, "%s", file);
    201206    sprintf (push->func, "%s", func);
    202207    push->line = line;
    203208    push->caller = context->callstack.caller;
    204 
    205209    context->callstack.caller = push;
     210
     211    /* set current context */
     212    sprintf (context->file, "%s", file);
     213    sprintf (context->func, "%s", func);
     214    context->line = line;
    206215
    207216    return CF_OK;
     
    216225
    217226    CHECK_INVALID_CTX (ctx);
    218 
    219     if (callstack == NULL)
    220         return CF_ERROR_DEBUG_INVALID_ARGS;
    221227
    222228    pop = context->callstack.caller;
     
    224230        return CF_ERROR_DEBUG_POP_CALLSTACK;
    225231
    226     sprintf (callstack->function, "%s", pop->func);
    227     callstack->line = pop->line;
    228 
    229     context->callstack.caller = pop->caller;
     232    if (callstack != NULL)
     233    {
     234        sprintf (callstack->function, "%s", pop->func);
     235        callstack->line = pop->line;
     236    }
     237
     238    memset (context->file, 0x00, sizeof (context->file));
     239    memset (context->func, 0x00, sizeof (context->func));
     240    context->line = 0;
     241
     242    /* restore current context */
     243    if (pop->caller != NULL)
     244    {
     245        sprintf (context->file, "%s", pop->caller->file);
     246        sprintf (context->func, "%s", pop->caller->func);
     247        context->line = pop->caller->line;
     248        context->callstack.caller = pop->caller;
     249    }
     250
    230251    free (pop);
    231252
Note: See TracChangeset for help on using the changeset viewer.