[Pkg-gnupg-commit] [libgpg-error] 15/29: Add a tracing framework.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Sun Mar 5 00:41:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository libgpg-error.
commit a52f12cc1879d171ddf309b5ac461bab06c8b5e2
Author: Werner Koch <wk at gnupg.org>
Date: Mon Feb 27 00:22:26 2017 +0100
Add a tracing framework.
* src/init.c (trace_save_errno, trace_arg_module)
(trace_arg_file, trace_arg_line): New module vars.
(do_internal_trace): New.
(_gpgrt_internal_trace_printf): New.
(_gpgrt_internal_trace): New.
(_gpgrt_internal_trace_errno): New.
(_gpgrt_internal_trace_end): New.
* src/gpgrt-int.h (trace): New macro.
(trace_errno): New macro.
(trace_start): New macro.
(trace_append): New macro.
(trace_finish): New macro.
--
We want to be abale to use libgpg-error also with pre-c99 compilers
and thus we can use the __VA_ARGS__ but resort to the common macro
trick.
---
src/gpgrt-int.h | 44 +++++++++++++++++++++++++++++++++
src/init.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index 8a2dae7..e1cf50b 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -49,6 +49,50 @@ gpg_err_code_t _gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
gpg_err_code_t _gpgrt_lock_destroy (gpgrt_lock_t *lockhd);
gpg_err_code_t _gpgrt_yield (void);
+/* Trace support. */
+
+void _gpgrt_internal_trace_begin (const char *mod, const char *file, int line);
+void _gpgrt_internal_trace (const char *format,
+ ...) GPGRT_ATTR_PRINTF(1,2);
+void _gpgrt_internal_trace_errno (const char *format,
+ ...) GPGRT_ATTR_PRINTF(1,2);
+void _gpgrt_internal_trace_printf (const char *format,
+ ...) GPGRT_ATTR_PRINTF(1,2);
+void _gpgrt_internal_trace_end (void);
+
+#ifdef ENABLE_TRACING
+# define trace(X) do { \
+ _gpgrt_internal_trace_begin \
+ (ENABLE_TRACING, __func__, __LINE__); \
+ _gpgrt_internal_trace X; \
+ _gpgrt_internal_trace_end (); \
+ } while (0)
+# define trace_errno(X) do { \
+ _gpgrt_internal_trace_begin \
+ (ENABLE_TRACING, __func__, __LINE__); \
+ _gpgrt_internal_trace_errno X; \
+ _gpgrt_internal_trace_end (); \
+ } while (0)
+# define trace_start(X) do { \
+ _gpgrt_internal_trace_begin \
+ (ENABLE_TRACING, __func__, __LINE__); \
+ _gpgrt_internal_trace_printf X; \
+ } while (0)
+# define trace_append(X) do { \
+ _gpgrt_internal_trace_printf X; \
+ } while (0)
+# define trace_finish(X) do { \
+ _gpgrt_internal_trace_printf X; \
+ _gpgrt_internal_trace_end (); \
+ } while (0)
+#else
+# define trace(X) do { } while (0)
+# define trace_errno(X) do { } while (0)
+# define trace_start(X) do { } while (0)
+# define trace_append(X) do { } while (0)
+# define trace_finish(X) do { } while (0)
+#endif /*!ENABLE_TRACING*/
+
/* Local definitions for estream. */
diff --git a/src/init.c b/src/init.c
index f7207fe..e90bec5 100644
--- a/src/init.c
+++ b/src/init.c
@@ -214,6 +214,83 @@ _gpg_err_set_errno (int err)
+/* Internal tracing functions. We use flockfile and funlockfile to
+ * protect their use. */
+static int trace_save_errno;
+static const char *trace_arg_module;
+static const char *trace_arg_file;
+static int trace_arg_line;
+
+void
+_gpgrt_internal_trace_begin (const char *module, const char *file, int line)
+{
+ int save_errno = errno;
+#ifdef HAVE_FLOCKFILE
+ flockfile (stderr);
+#endif
+ trace_save_errno = save_errno;
+ trace_arg_module = module;
+ trace_arg_file = file;
+ trace_arg_line = line;
+}
+
+
+static void
+do_internal_trace (const char *format, va_list arg_ptr, int with_errno)
+{
+ fprintf (stderr, "%s:%s:%d: ",
+ trace_arg_module, trace_arg_file, trace_arg_line);
+ vfprintf (stderr, format, arg_ptr);
+ if (with_errno)
+ fprintf (stderr, " errno=%s", strerror (trace_save_errno));
+ fputc ('\n', stderr);
+}
+
+void
+_gpgrt_internal_trace_printf (const char *format, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, format) ;
+ vfprintf (stderr, format, arg_ptr);
+ va_end (arg_ptr);
+}
+
+
+void
+_gpgrt_internal_trace (const char *format, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, format) ;
+ do_internal_trace (format, arg_ptr, 0);
+ va_end (arg_ptr);
+}
+
+
+void
+_gpgrt_internal_trace_errno (const char *format, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, format) ;
+ do_internal_trace (format, arg_ptr, 1);
+ va_end (arg_ptr);
+}
+
+
+void
+_gpgrt_internal_trace_end (void)
+{
+ int save_errno = trace_save_errno;
+#ifdef HAVE_FLOCKFILE
+ funlockfile (stderr);
+#endif
+ errno = save_errno;
+}
+
+
+
#ifdef HAVE_W32_SYSTEM
/*****************************************
******** Below is only Windows code. ****
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libgpg-error.git
More information about the Pkg-gnupg-commit
mailing list