diff options
author | Nick Schermer <nick@xfce.org> | 2010-07-14 22:40:48 +0200 |
---|---|---|
committer | Nick Schermer <nick@xfce.org> | 2010-07-14 22:45:59 +0200 |
commit | dc8625abcd28f218694b736e7c560652bbab5117 (patch) | |
tree | e2fa5eee577e485644fdb40924a23fff6701cc53 /common | |
parent | b09727368607c0e943ff24f977eff67bd842f9a5 (diff) | |
download | xfce4-panel-dc8625abcd28f218694b736e7c560652bbab5117.tar.gz |
Add debug mode to run plugins in gdb.
With PANEL_DEBUG=gdb plugin will be started in gdb
and log files (with backtrace and register dump) are
automatically stored in /tmp.
Some functionality will not be available, like
automatically restart the plugins.
Also cleanup the debug level handling a bit, so it is
easier to extend and make struts debugging work again.
Diffstat (limited to 'common')
-rw-r--r-- | common/panel-debug.c | 54 | ||||
-rw-r--r-- | common/panel-debug.h | 9 |
2 files changed, 46 insertions, 17 deletions
diff --git a/common/panel-debug.c b/common/panel-debug.c index 31a62f29..b99e8cbf 100644 --- a/common/panel-debug.c +++ b/common/panel-debug.c @@ -28,16 +28,17 @@ #include <common/panel-debug.h> #include <common/panel-private.h> -enum -{ - DEBUG_LEVEL_UNKNOWN = 0, - DEBUG_LEVEL_NONE, - DEBUG_LEVEL_ENABLED -}; +PanelDebugFlag panel_debug_flags = 0; -gboolean panel_debug_enabled = FALSE; + + +/* additional debug levels */ +static const GDebugKey panel_debug_keys[] = +{ + { "gdb", PANEL_DEBUG_GDB } +}; @@ -46,10 +47,9 @@ panel_debug (const gchar *domain, const gchar *message, ...) { - static volatile gsize level__volatile = DEBUG_LEVEL_UNKNOWN; - gsize level; + static volatile gsize level__volatile = 0; const gchar *value; - gchar *string; + gchar *string, *path; va_list args; panel_return_if_fail (domain != NULL); @@ -60,15 +60,37 @@ panel_debug (const gchar *domain, { value = g_getenv ("PANEL_DEBUG"); if (G_UNLIKELY (value != NULL)) - level = DEBUG_LEVEL_ENABLED; - else - level = DEBUG_LEVEL_NONE; - - g_once_init_leave (&level__volatile, level); + { + panel_debug_flags = g_parse_debug_string (value, panel_debug_keys, + G_N_ELEMENTS (panel_debug_keys)); + + /* always enable debug logging */ + PANEL_SET_FLAG (panel_debug_flags, PANEL_DEBUG_YES); + + /* TODO: only print this in the main application */ + if (PANEL_HAS_FLAG (panel_debug_flags, PANEL_DEBUG_GDB)) + { + path = g_find_program_in_path ("gdb"); + if (G_LIKELY (path != NULL)) + { + g_printerr (PACKAGE_NAME "(debug): running plugins with %s; " + "log files stored in '%s'\n", path, g_get_tmp_dir ()); + g_free (path); + } + else + { + PANEL_UNSET_FLAG (panel_debug_flags, PANEL_DEBUG_GDB); + + g_printerr (PACKAGE_NAME "(debug): gdb not found in PATH; mode disabled\n"); + } + } + } + + g_once_init_leave (&level__volatile, 1); } /* leave when debug is disabled */ - if (level__volatile == DEBUG_LEVEL_NONE) + if (panel_debug_flags == 0) return; va_start (args, message); diff --git a/common/panel-debug.h b/common/panel-debug.h index 74990c5b..200758f3 100644 --- a/common/panel-debug.h +++ b/common/panel-debug.h @@ -30,7 +30,14 @@ #define PANEL_DEBUG_BOOL(bool) ((bool) ? "true" : "false") -extern gboolean panel_debug_enabled; +typedef enum +{ + PANEL_DEBUG_YES = 1 << 0, /* always enabled if PANEL_DEBUG is not %NULL */ + PANEL_DEBUG_GDB = 1 << 1 /* run plugin through gdb */ +} +PanelDebugFlag; + +extern PanelDebugFlag panel_debug_flags; void panel_debug (const gchar *domain, const gchar *message, |