diff options
author | Pete Batard <pbatard@gmail.com> | 2010-04-06 21:12:13 +0100 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-04-06 21:12:13 +0100 |
commit | a7a96927a30094f308ad00bf2af4532e765c05e0 (patch) | |
tree | 6fd594ae992c22b8503d4329771b5daeaa982909 | |
parent | adc09459820a35ecaf407adfce4e71835d8e469a (diff) | |
download | libusb-a7a96927a30094f308ad00bf2af4532e765c05e0.tar.gz |
added toggable debug logging (core)
-rw-r--r-- | configure.ac | 14 | ||||
-rw-r--r-- | libusb/core.c | 14 | ||||
-rw-r--r-- | libusb/libusbi.h | 2 |
3 files changed, 23 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index 2aa9ee5..323c54e 100644 --- a/configure.ac +++ b/configure.ac @@ -105,11 +105,21 @@ if test "x$log_enabled" != "xno"; then fi AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log], - [enable debug logging (default n)])], + [enable non-toggable debug logging (default n)])], [debug_log_enabled=$enableval], [debug_log_enabled='no']) + +AC_ARG_ENABLE([toggable-debug], [AS_HELP_STRING([--enable-toggable-debug], + [enable toggable debug logging (default n)])], + [toggable_debug=$enableval], + [toggable_debug='no']) + if test "x$debug_log_enabled" != "xno"; then - AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging]) + AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging (non toggable)]) +else + if test "x$toggable_debug" != "xno"; then + AC_DEFINE([INCLUDE_DEBUG_LOGGING], 1, [Debug message logging (toggable)]) + fi fi # Examples build diff --git a/libusb/core.c b/libusb/core.c index af3e2fe..64b32cc 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1461,6 +1461,9 @@ API_EXPORTED int libusb_attach_kernel_driver(libusb_device_handle *dev, API_EXPORTED void libusb_set_debug(libusb_context *ctx, int level) { USBI_GET_CONTEXT(ctx); + // ctx can be NULL if called before libusb_init + if (ctx == NULL) + return; if (!ctx->debug_fixed) ctx->debug = level; } @@ -1499,6 +1502,11 @@ API_EXPORTED int libusb_init(libusb_context **context) ctx->debug_fixed = 1; } + // default context should be initialized before any call to usbi_dbg + if (!usbi_default_context) { + usbi_default_context = ctx; + } + usbi_dbg(""); usbi_mutex_init(&ctx->usb_devs_lock, NULL); @@ -1519,10 +1527,6 @@ API_EXPORTED int libusb_init(libusb_context **context) goto err; } - if (!usbi_default_context) { - usbi_dbg("created default context"); - usbi_default_context = ctx; - } usbi_mutex_static_unlock(&default_context_lock); if (context) @@ -1576,6 +1580,8 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level, #ifndef ENABLE_DEBUG_LOGGING USBI_GET_CONTEXT(ctx); + if (ctx == NULL) + return; if (!ctx->debug) return; if (level == LOG_LEVEL_WARNING && ctx->debug < 2) diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 20077b6..8a26907 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -123,7 +123,7 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level, #define _usbi_log(ctx, level, ...) #endif -#ifdef ENABLE_DEBUG_LOGGING +#if defined(ENABLE_DEBUG_LOGGING) || defined(INCLUDE_DEBUG_LOGGING) #define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__) #else #define usbi_dbg(...) |