Mercurial > hg > freeDiameter
changeset 205:ff9ade352076
Simplified use of --dbg_file option
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 12 Feb 2010 18:29:08 +0900 |
parents | 2465698b9f31 |
children | 8eda7c917fc6 |
files | freeDiameter/main.c include/freeDiameter/libfreeDiameter.h |
diffstat | 2 files changed, 24 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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. */
--- 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 <stdlib.h> #include <unistd.h> +#ifdef DEBUG +#include <libgen.h> /* 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... ) { \