dect
/
libnl
Archived
13
0
Fork 0

nl: Print file:line:func in debugging messages and provide --disable-debug to disable debugging

Compiling libnl with --disable-debug will result in the ignorance
of the 'NLDBG' environment variable.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
Thomas Graf 2013-04-02 11:39:30 +02:00
parent f9241d57fe
commit ff567100d6
5 changed files with 32 additions and 10 deletions

View File

@ -92,6 +92,11 @@ AC_ARG_ENABLE([pthreads],
[enable_pthreads="$enableval"], [enable_pthreads="yes"])
AM_CONDITIONAL([DISABLE_PTHREADS], [test "$enable_pthreads" = "no"])
AC_ARG_ENABLE([debug],
AS_HELP_STRING([--disable-debug], [Do not include debugging statements]),
[enable_debug="$enableval"], [enable_debug="yes"])
AM_CONDITIONAL([ENABLE_DEBUG], [test "$enable_debug" = "no" ])
AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required]))
if test "x$enable_pthreads" = "xno"; then
@ -100,6 +105,10 @@ else
AC_CHECK_LIB([pthread], [pthread_mutex_lock], [], AC_MSG_ERROR([libpthread is required]))
fi
if test "x$enable_debug" = "xyes"; then
AC_DEFINE([NL_DEBUG], [1], [Define to 1 to enable debugging])
fi
AC_CONFIG_SUBDIRS([doc])
AC_CONFIG_FILES([

View File

@ -80,24 +80,29 @@ struct trans_list {
struct nl_list_head list;
};
#define NL_DEBUG 1
#define NL_DBG(LVL,FMT,ARG...) \
do { \
if (LVL <= nl_debug) \
fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
#ifdef NL_DEBUG
#define NL_DBG(LVL,FMT,ARG...) \
do { \
if (LVL <= nl_debug) \
fprintf(stderr, \
"DBG<" #LVL ">%20s:%-4u %s: " FMT, \
__FILE__, __LINE__, \
__PRETTY_FUNCTION__, ##ARG); \
} while (0)
#else /* NL_DEBUG */
#define NL_DBG(LVL,FMT,ARG...) do { } while(0)
#endif /* NL_DEBUG */
#define BUG() \
do { \
NL_DBG(1, "BUG: %s:%d\n", \
__FILE__, __LINE__); \
fprintf(stderr, "BUG at file position %s:%d:%s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
assert(0); \
} while (0)
#define APPBUG(msg) \
do { \
NL_DBG(1, "APPLICATION BUG: %s:%d:%s: %s\n", \
fprintf(stderr, "APPLICATION BUG: %s:%d:%s: %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__, msg); \
assert(0); \
} while(0)

View File

@ -211,7 +211,9 @@ static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
uint32_t n_ifindex;
char n_addr[0];
} __attribute__((packed)) *nkey;
#ifdef NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
if (neigh->n_family == AF_BRIDGE) {
if (neigh->n_lladdr)

View File

@ -307,7 +307,9 @@ static void route_keygen(struct nl_object *obj, uint32_t *hashkey,
uint32_t rt_prio;
char rt_addr[0];
} __attribute__((packed)) *rkey;
#ifdef NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
if (route->rt_dst)
addr = route->rt_dst;
@ -449,8 +451,10 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
struct rtnl_route *new_route = (struct rtnl_route *) new_obj;
struct rtnl_route *old_route = (struct rtnl_route *) old_obj;
struct rtnl_nexthop *new_nh;
char buf[INET6_ADDRSTRLEN+5];
int action = new_obj->ce_msgtype;
#ifdef NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
/*
* ipv6 ECMP route notifications from the kernel come as

View File

@ -49,6 +49,7 @@
int nl_debug = 0;
/** @cond SKIP */
#ifdef NL_DEBUG
struct nl_dump_params nl_debug_dp = {
.dp_type = NL_DUMP_DETAILS,
};
@ -65,6 +66,7 @@ static void __init nl_debug_init(void)
nl_debug_dp.dp_fd = stderr;
}
#endif
int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
{