# HG changeset patch # User Sebastien Decugis # Date 1265966948 -32400 # Node ID ff9ade3520765efdab2c57a1b6d30d6e17c12bb2 # Parent 2465698b9f31b48b777bafca89459e9e9e0841c9 Simplified use of --dbg_file option diff -r 2465698b9f31 -r ff9ade352076 freeDiameter/main.c --- a/freeDiameter/main.c Fri Feb 12 16:12:54 2010 +0900 +++ b/freeDiameter/main.c Fri Feb 12 18:29:08 2010 +0900 @@ -233,11 +233,21 @@ break; case 'f': /* Full debug for the function with this name. */ + #ifdef DEBUG fd_debug_one_function = optarg; + #else /* DEBUG */ + TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature"); + return EINVAL; + #endif /* DEBUG */ break; case 'F': /* Full debug for the file with this name. */ - fd_debug_one_file = optarg; + #ifdef DEBUG + fd_debug_one_file = basename(optarg); + #else /* DEBUG */ + TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature"); + return EINVAL; + #endif /* DEBUG */ break; case 'q': /* Decrease verbosity then remove debug messages. */ diff -r 2465698b9f31 -r ff9ade352076 include/freeDiameter/libfreeDiameter.h --- a/include/freeDiameter/libfreeDiameter.h Fri Feb 12 16:12:54 2010 +0900 +++ b/include/freeDiameter/libfreeDiameter.h Fri Feb 12 18:29:08 2010 +0900 @@ -70,6 +70,10 @@ #include #include +#ifdef DEBUG +#include /* for basename if --dbg_file is specified */ +#endif /* DEBUG */ + /*============================================================*/ /* DEBUG */ /*============================================================*/ @@ -166,10 +170,18 @@ #define __PRETTY_FUNCTION__ __func__ #endif /* __PRETTY_FUNCTION__ */ +/* A version of __FILE__ without the full path */ +static char * file_bname = NULL; +#define __STRIPPED_FILE__ (file_bname ?: (file_bname = basename(__FILE__))) + /* Boolean for tracing at a certain level */ +#ifdef DEBUG #define TRACE_BOOL(_level_) ( ((_level_) <= local_debug_level + fd_g_debug_lvl) \ || (fd_debug_one_function && !strcmp(fd_debug_one_function, __PRETTY_FUNCTION__)) \ - || (fd_debug_one_file && !strcmp(fd_debug_one_file, __FILE__) ) ) + || (fd_debug_one_file && !strcmp(fd_debug_one_file, __STRIPPED_FILE__) ) ) +#else /* DEBUG */ +#define TRACE_BOOL(_level_) ((_level_) <= local_debug_level + fd_g_debug_lvl) +#endif /* DEBUG */ /* The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) */ #define TRACE_DEBUG(level,format,args... ) { \