From 8cd91d18de8ada1cc1284a6e9dcad6f78b018b97 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 14 Aug 2011 14:56:20 -0700 Subject: [PATCH] plugin: Add debug support for exteranl plugins --- src/log.c | 19 +++++++++++++++---- src/log.h | 3 +++ src/plugin.c | 2 ++ src/plugin.h | 9 ++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/log.c b/src/log.c index 2c492e9ef..4a50117b3 100644 --- a/src/log.c +++ b/src/log.c @@ -86,6 +86,20 @@ static gboolean is_enabled(struct btd_debug_desc *desc) return 0; } +void __btd_enable_debug(struct btd_debug_desc *start, + struct btd_debug_desc *stop) +{ + struct btd_debug_desc *desc; + + if (start == NULL || stop == NULL) + return; + + for (desc = start; desc < stop; desc++) { + if (is_enabled(desc)) + desc->flags |= BTD_DEBUG_FLAG_PRINT; + } +} + void __btd_toggle_debug(void) { struct btd_debug_desc *desc; @@ -97,14 +111,11 @@ void __btd_toggle_debug(void) void __btd_log_init(const char *debug, int detach) { int option = LOG_NDELAY | LOG_PID; - struct btd_debug_desc *desc; if (debug != NULL) enabled = g_strsplit_set(debug, ":, ", 0); - for (desc = __start___debug; desc < __stop___debug; desc++) - if (is_enabled(desc)) - desc->flags |= BTD_DEBUG_FLAG_PRINT; + __btd_enable_debug(__start___debug, __stop___debug); if (!detach) option |= LOG_PERROR; diff --git a/src/log.h b/src/log.h index 78bbdd80f..b43b2b7ec 100644 --- a/src/log.h +++ b/src/log.h @@ -37,6 +37,9 @@ struct btd_debug_desc { unsigned int flags; } __attribute__((aligned(8))); +void __btd_enable_debug(struct btd_debug_desc *start, + struct btd_debug_desc *stop); + /** * DBG: * @fmt: format string diff --git a/src/plugin.c b/src/plugin.c index 3506553fe..2a86e6822 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -77,6 +77,8 @@ static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc) plugin->active = FALSE; plugin->desc = desc; + __btd_enable_debug(desc->debug_start, desc->debug_stop); + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); return TRUE; diff --git a/src/plugin.h b/src/plugin.h index 30bd415dc..4fbdd1daf 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -30,6 +30,8 @@ struct bluetooth_plugin_desc { int priority; int (*init) (void); void (*exit) (void); + void *debug_start; + void *debug_stop; }; #ifdef BLUETOOTH_PLUGIN_BUILTIN @@ -39,9 +41,14 @@ struct bluetooth_plugin_desc { }; #else #define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \ + extern struct btd_debug_desc __start___debug[] \ + __attribute__ ((visibility("hidden"))); \ + extern struct btd_debug_desc __stop___debug[] \ + __attribute__ ((visibility("hidden"))); \ extern struct bluetooth_plugin_desc bluetooth_plugin_desc \ __attribute__ ((visibility("default"))); \ struct bluetooth_plugin_desc bluetooth_plugin_desc = { \ - #name, version, priority, init, exit \ + #name, version, priority, init, exit, \ + __start___debug, __stop___debug \ }; #endif -- 2.47.3