diff options
author | Marcus Brinkmann <mb@g10code.com> | 2009-09-21 01:08:08 +0000 |
---|---|---|
committer | Marcus Brinkmann <mb@g10code.com> | 2009-09-21 01:08:08 +0000 |
commit | cd87e56dac64c74d45f42838fc1049848f8aadcd (patch) | |
tree | ff70f9a6e8601305d06bebb55709350d3d8dbae4 /src/debug.h | |
parent | 0650eaa24a8a54dbfb1d5aea113ffd7a1536861a (diff) | |
download | libassuan-cd87e56dac64c74d45f42838fc1049848f8aadcd.tar.gz |
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* tests/fdpassing.c: Update to new API.
* configure.ac: Check for stdint.h and inttypes.h. Invoke
AC_TYPE_UINTPTR_T.
doc/
2009-09-21 Marcus Brinkmann <marcus@g10code.de>
* assuan.texi: Update to new API.
src/
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* src/libassuan.vers, src/libassuan.def: Update to new API.
* assuan.c, context.c, system.c, debug.c: New files.
* Makefile.am (common_sources): Add assuan.c, context.c, system.c
and debug.c.
* assuan.h: Include <stdarg.h>. Fix inclusion of <gpg-error.h>.
(_ASSUAN_EXT_SYM_PREFIX, _ASSUAN_PREFIX1, _ASSUAN_PREFIX2)
(_ASSUAN_PREFIX): Remove support for renaming the whole library,
now that we have a stable shared library interface that can evolve
to cover all needs (particularly those of GPGME).
(assuan_malloc_hooks, assuan_malloc_hooks_t, assuan_log_cb_t)
(assuan_io_monitor_t): New types.
(ASSUAN_LOG_INIT, ASSUAN_LOG_CTX, ASSUAN_LOG_ENGINE)
(ASSUAN_LOG_DATA, ASSUAN_LOG_SYSIO, ASSUAN_IO_FROM_PEER)
(ASSUAN_IO_TO_PEER, ASSUAN_IO_MONITOR_NOLOG)
(ASSUAN_IO_MONITOR_IGNORE): New symbols.
(assuan_set_gpg_err_source, assuan_get_gpg_err_source)
(assuan_get_malloc_hooks, assuan_set_log_cb, assuan_get_log_cb)
(assuan_new, assuan_new_ext, assuan_release): New function
prototypes.
(assuan_init_pipe_server, assuan_init_socket_server)
(assuan_init_socket_server_ext, assuan_pipe_connect)
(assuan_pipe_connect_ext, assuan_socket_connect)
(assuan_socket_connect_ext): Take a context argument instead of
pointer to context.
(assuan_deinit_server, assuan_disconnect)
(assuan_set_assuan_err_source): Remove function prototypes.
* assuan-defs.h (ASSUAN_GCC_A_PURE): Moved here from XXX
(_assuan_error): New macro.
(struct assuan_context_s): New members err_source, w32_strerror,
malloc_hooks, log_cb, log_cb_data: New members. Move confidential
into flags. New member engine.
(_assuan_log_handler, _assuan_error_default, _assuan_disconnect):
New prototypes.
(_assuan_new_context): Remove prototype.
(_assuan_malloc, _assuan_calloc, _assuan_realloc, _assuan_free):
Add context argument to prototype.
* assuan-util.c (alloc_func, realloc_func, free_func): Remove
global variables.
(assuan_set_malloc_hooks, _assuan_malloc, _assuan_realloc)
(_assuan_calloc, _assuan_free, assuan_set_pointer)
(assuan_get_pointer, assuan_begin_confidential)
(assuan_end_confidential, assuan_set_io_monitor, assuan_set_flag)
(assuan_get_flag): Move functions to ...
* assuan-client.c: Add ctx argument to all invocations of
_assuan_error.
* assuan-socket-server.c, assuan-socket-connect.c,
assuan-connect.c: Likewise.
* assuan-buffer.c: Likewise. Also update access to confidential
flag.
* assuan-uds.c: Add ctx argument to all invocations of
_assuan_malloc, _assuan_realloc, _assuan_calloc, _assuan_free and
_assuan_error.
* assuan_listen.c, assuan-inquire.c, assuan-handler.c: Likewise.
* assuan-error.c (err_source): Remove global variable.
(assuan_set_assuan_err_source): Removed function.
(_assuan_w32_strerror): Moved here from assuan-logging.c and made
thread-safe.
(_assuan_error): Removed function (is now macro).
* assuan-handler.c: Update access to confidential flag.
* assuan-socket-server.c (accept_connection_bottom): Update access
to confidential flag in context.
(assuan_init_socket_server, assuan_init_socket_server_ext): Take
ctx argument instead of pointer to ctx.
* assuan-inquire.c (init_membuf, put_membuf, get_membuf)
(free_membuf): Take context argument and change all callers.
* assuan-socket-server.c (assuan_socket_connect)
(assuan_socket_connect_ext): Take ctx argument instead of pointer
to ctx.
* assuan-pipe-connect.c (initial_handshake, pipe_connect_unix)
(socketpair_connect, assuan_pipe_connect)
(assuan_pipe_connect_ext): Likewise.
(socketpair_connect): Now that ctx is not a pointer argument
anymore, return if we are server or client in the argv argument.
* assuan-logging.c (_assuan_log_handler): New function.
(_assuan_w32_strerror): Move to assuan-error.c
* assuan-connect.c (assuan_disconnect): Renamed to ...
(_assuan_disconnect): ... this.
* assuan-pipe-server.c (_assuan_new_context): Removed function.
(assuan_init_pipe_server): Take ctx argument instead of pointer to
ctx.
(_assuan_release_context): Removed function.
(_assuan_deinit_server): Reimplement.
Diffstat (limited to 'src/debug.h')
-rw-r--r-- | src/debug.h | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..13e5419 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,260 @@ +/* debug.h - interface to debugging functions + Copyright (C) 2002, 2004, 2005, 2007 g10 Code GmbH + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#ifndef DEBUG_H +#define DEBUG_H + +#include <string.h> +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#ifdef HAVE_INTTYPES_H +#include <inttypes.h> +#endif + +#include "assuan-defs.h" + +/* Indirect stringification, requires __STDC__ to work. */ +#define STRINGIFY(v) #v +#define XSTRINGIFY(v) STRINGIFY(v) + + + +/* Remove path components from filenames (i.e. __FILE__) for cleaner + logs. */ +static inline const char *_assuan_debug_srcname (const char *file) + ASSUAN_GCC_A_PURE; + +static inline const char * +_assuan_debug_srcname (const char *file) +{ + const char *s = strrchr (file, '/'); + return s ? s + 1 : file; +} + + +/* Called early to initialize the logging. */ +void _assuan_debug_subsystem_init (void); + +/* Log the formatted string FORMAT at debug level LEVEL or higher. */ +void _assuan_debug (assuan_context_t ctx, unsigned int cat, + const char *format, ...); + +/* Start a new debug line in *LINE, logged at level LEVEL or higher, + and starting with the formatted string FORMAT. */ +void _assuan_debug_begin (assuan_context_t ctx, + void **helper, unsigned int cat, + const char *format, ...); + +/* Add the formatted string FORMAT to the debug line *LINE. */ +void _assuan_debug_add (assuan_context_t ctx, + void **helper, const char *format, ...); + +/* Finish construction of *LINE and send it to the debug output + stream. */ +void _assuan_debug_end (assuan_context_t ctx, + void **helper, unsigned int cat); + +void _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat, + const char *const fmt, + const char *const func, const char *const tagname, + void *tag, const char *const buffer, size_t len); + + +/* Trace support. */ + +#define _TRACE(ctx, lvl, name, tag) \ + assuan_context_t _assuan_trace_context = ctx; \ + int _assuan_trace_level = lvl; \ + const char *const _assuan_trace_func = name; \ + const char *const _assuan_trace_tagname = STRINGIFY (tag); \ + void *_assuan_trace_tag = (void *) (uintptr_t) tag + +#define TRACE_BEG(ctx,lvl, name, tag) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag), 0 +#define TRACE_BEG0(ctx, lvl, name, tag, fmt) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag), 0 +#define TRACE_BEG1(ctx, lvl, name, tag, fmt, arg1) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1), 0 +#define TRACE_BEG2(ctx, lvl, name, tag, fmt, arg1, arg2) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2), 0 +#define TRACE_BEG3(ctx, lvl, name, tag, fmt, arg1, arg2, arg3) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3), 0 +#define TRACE_BEG4(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3, arg4), 0 + +#define TRACE_BEG8(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \ + arg5, arg6, arg7, arg8) \ + _TRACE (ctx, lvl, name, tag); \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, "%s (%s=%p): enter: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3, arg4, \ + arg5, arg6, arg7, arg8), 0 + +#define TRACE(ctx, lvl, name, tag) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0 +#define TRACE0(ctx, lvl, name, tag, fmt) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0 +#define TRACE1(ctx, lvl, name, tag, fmt, arg1) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1), 0 +#define TRACE2(ctx, lvl, name, tag, fmt, arg1, arg2) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \ + arg2), 0 +#define TRACE3(ctx, lvl, name, tag, fmt, arg1, arg2, arg3) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \ + arg2, arg3), 0 +#define TRACE6(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \ + _assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \ + name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \ + arg2, arg3, arg4, arg5, arg6), 0 + +#define TRACE_ERR(err) \ + err == 0 ? (TRACE_SUC ()) : \ + (_assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): error: %s <%s>\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, gpg_strerror (err), \ + gpg_strsource (ctx->err_source)), \ + _assuan_error (ctx, err)) + +/* The cast to void suppresses GCC warnings. */ +#define TRACE_SYSRES(res) \ + res >= 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \ + (_assuan_debug (_assuan_trace_context, _assuan_trace_level, "%s (%s=%p): error: %s\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, strerror (errno)), (res)) +#define TRACE_SYSERR(res) \ + res == 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \ + (_assuan_debug (_assuan_trace_level, "%s (%s=%p): error: %s\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, strerror (res)), (res)) + +#define TRACE_SUC() \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): leave\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag), 0 +#define TRACE_SUC0(fmt) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): leave: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag), 0 +#define TRACE_SUC1(fmt, arg1) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): leave: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1), 0 +#define TRACE_SUC2(fmt, arg1, arg2) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): leave: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2), 0 +#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): leave: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3, arg4, arg5), 0 + +#define TRACE_LOG(fmt) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag), 0 +#define TRACE_LOG1(fmt, arg1) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1), 0 +#define TRACE_LOG2(fmt, arg1, arg2) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2), 0 +#define TRACE_LOG3(fmt, arg1, arg2, arg3) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3), 0 +#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3, arg4), 0 +#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \ + _assuan_debug (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: " fmt "\n", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, arg1, arg2, arg3, arg4, arg5, \ + arg6), 0 + +#define TRACE_LOGBUF(buf, len) \ + _assuan_debug_buffer (_assuan_trace_context, _assuan_trace_level, \ + "%s (%s=%p): check: %s", \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag, buf, len) + +#define TRACE_SEQ(hlp,fmt) \ + _assuan_debug_begin (_assuan_trace_context, &(hlp), \ + "%s (%s=%p): check: " fmt, \ + _assuan_trace_func, _assuan_trace_tagname, \ + _assuan_trace_tag) +#define TRACE_ADD0(hlp,fmt) \ + _assuan_debug_add (_assuan_trace_context, &(hlp), fmt) +#define TRACE_ADD1(hlp,fmt,a) \ + _assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a)) +#define TRACE_ADD2(hlp,fmt,a,b) \ + _assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a), (b)) +#define TRACE_ADD3(hlp,fmt,a,b,c) \ + _assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a), (b), (c)) +#define TRACE_END(hlp,fmt) \ + _assuan_debug_add (_assuan_trace_context, &(hlp), fmt); \ + _assuan_debug_end (_assuan_trace_context, &(hlp), _assuan_trace_level) +#define TRACE_ENABLED(hlp) (!!(hlp)) + +#endif /* DEBUG_H */ |