diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2016-05-10 16:51:25 +0200 |
---|---|---|
committer | sanghyeok.oh <sanghyeok.oh@samsung.com> | 2019-02-01 10:20:01 +0900 |
commit | 65e5748e56976da5eb37436738625bbfb619e2a2 (patch) | |
tree | 410658b4e41d77f3af792b8de84e1263e9d044c1 | |
parent | 6a3e4d836b45b68be0bb07fc0fd1d80f9db5a444 (diff) | |
download | dbus-65e5748e56976da5eb37436738625bbfb619e2a2.tar.gz dbus-65e5748e56976da5eb37436738625bbfb619e2a2.tar.bz2 dbus-65e5748e56976da5eb37436738625bbfb619e2a2.zip |
Display thread id in _dbus_verbose to be able to see threading issues.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95191
Change-Id: I16b39c8c3123436d54655a67f9d00aa090933aba
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r-- | dbus/dbus-internals.c | 12 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-pthread.c | 18 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-thread-win.c | 8 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-win.c | 1 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.h | 4 |
5 files changed, 31 insertions, 12 deletions
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 30a5fa73..3f10c0c3 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -281,12 +281,6 @@ _dbus_warn_check_failed(const char *format, static dbus_bool_t verbose_initted = FALSE; static dbus_bool_t verbose = TRUE; -/** Whether to show the current thread in verbose messages */ -#define PTHREAD_IN_VERBOSE 0 -#if PTHREAD_IN_VERBOSE -#include <pthread.h> -#endif - #ifdef DBUS_USE_OUTPUT_DEBUG_STRING static char module_name[1024]; #endif @@ -406,11 +400,7 @@ _dbus_verbose_real ( /* Print out pid before the line */ if (need_pid) { -#if PTHREAD_IN_VERBOSE - fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ()); -#else - fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); -#endif + _dbus_print_thread (); } #endif diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c index 1300ec35..bc0b2c35 100644 --- a/dbus/dbus-sysdeps-pthread.c +++ b/dbus/dbus-sysdeps-pthread.c @@ -28,6 +28,7 @@ #include <sys/time.h> #include <pthread.h> +#include <stdio.h> #include <string.h> #ifdef HAVE_ERRNO_H @@ -300,3 +301,20 @@ _dbus_threads_unlock_platform_specific (void) { pthread_mutex_unlock (&init_mutex); } + +#ifdef DBUS_ENABLE_VERBOSE_MODE +/* + * If we can identify the current process and/or thread, print them to stderr followed by a colon. + */ +void +_dbus_print_thread (void) +{ +#ifdef __linux__ + /* we know a pthread_t is numeric on Linux */ + fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), (unsigned long) pthread_self ()); +#else + /* in principle pthread_t isn't required to be printable */ + fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); +#endif +} +#endif diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c index 0887a549..d006cb8b 100644 --- a/dbus/dbus-sysdeps-thread-win.c +++ b/dbus/dbus-sysdeps-thread-win.c @@ -300,3 +300,11 @@ _dbus_threads_unlock_platform_specific (void) _dbus_assert (global_init_done); LeaveCriticalSection (&init_lock); } + +#ifdef DBUS_ENABLE_VERBOSE_MODE +void +_dbus_print_thread (void) +{ + fprintf (stderr, "%lu: 0x%04lx: ", _dbus_pid_for_log (), GetCurrentThreadId ()); +} +#endif diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index d19267e6..f535d9a1 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3706,4 +3706,3 @@ _dbus_restore_socket_errno (int saved_errno) /** @} end of sysdeps-win */ /* tests in dbus-sysdeps-util.c */ - diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 2f493b09..fc3818f9 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -491,6 +491,10 @@ DBUS_PRIVATE_EXPORT int _dbus_printf_string_upper_bound (const char *format, va_list args); +#ifdef DBUS_ENABLE_VERBOSE_MODE +DBUS_PRIVATE_EXPORT +void _dbus_print_thread (void); +#endif /** * Portable struct with stat() results |