Last active
May 24, 2018 07:42
-
-
Save justinc1/dbc685c7a5798e7003ec79b75bdf3f9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------------------------------------------------------------------*/ | |
#define LOG_FUNCION_ENTER 1 | |
static int call_depth = 0; | |
static FILE *dbg_outlog = NULL; | |
void dbg_open_log(void); | |
void dbg_open_log(void) { | |
if (dbg_outlog == NULL) { | |
dbg_outlog = stdout; | |
//outlog = fopen("outlog", "a+"); | |
fprintf(dbg_outlog, "/*----------------------------------------*/\n"); | |
} | |
} | |
#define ENTER() if (LOG_FUNCION_ENTER) { dbg_open_log(); fprintf(dbg_outlog, "ENTER (%d) %s\n", call_depth++, __FUNCTION__); fflush(dbg_outlog); } | |
#define LEAVE() if (LOG_FUNCION_ENTER) { dbg_open_log(); fprintf(dbg_outlog, "LEAVE (%d) %s\n", --call_depth, __FUNCTION__); fflush(dbg_outlog); } | |
#ifdef ENABLE_FPRINTF_POS | |
# undef ENABLE_FPRINTF_POS | |
#endif | |
#define ENABLE_FPRINTF_POS 1 | |
const char* dbg_short_file(const char* path); | |
const char* dbg_short_file(const char* path) | |
{ | |
const char* p1 = path; | |
const char* p2 = path; | |
while(*p1 != '\0') { | |
if(*p1 == '/') { | |
p2 = p1+1; | |
} | |
p1++; | |
} | |
assert(*p2 != '\0'); | |
assert(*p2 != '/'); | |
assert(((size_t)(p2 - path)) < strlen(path)); | |
return p2; | |
} | |
//define fprintf_pos(ff, fmt, ...) { if(ENABLE_FPRINTF_POS) { fprintf(ff, "DBG-PP tid=% 5d %s:%d %s " fmt, my_gettid(), dbg_short_file(__FILE__), __LINE__, __FUNCTION__, __VA_ARGS__ ); } } | |
#define fprintf_pos(ff, fmt, ...) { if(ENABLE_FPRINTF_POS) { fprintf(ff, "DBG %s:%d %s " fmt, dbg_short_file(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__ ); fflush(dbg_outlog); } } | |
#define printf_pos(fmt, ...) { dbg_open_log(); fprintf_pos(dbg_outlog, fmt, ##__VA_ARGS__ ); fflush(dbg_outlog); } | |
/*----------------------------------------------------------------------------*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment