From 51e6cf89edbcdb4dd39e83f467da695ebdecb228 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 8 May 2002 04:04:12 +0000 Subject: [PATCH] 2002-05-08 Marcus Brinkmann * debug.h: New file. * Makefile.am (libgpgme_la_SOURCES): Add debug.h. * util.h: Removed all prototypes and declarations related to debugging. Include "debug.h". * debug.c (debug_level): Comment variable and remove superfluous zero initializer. (errfp): Likewise. (_gpgme_debug_enabled): Function removed. (struct debug_control_s): Definition removed. (_gpgme_debug_level): Function removed. (_gpgme_debug_begin): Rewritten to use vasprintf. Accept a pritnf-style format specification and a variable number of arguments. (_gpgme_debug_add): Rewritten using vasprintf. Expect that format starts out with "%s" for simplicity. (_gpgme_debug_end): Rewritten using vasprintf. Do not accept a TEXT argument anymore. * posix-io.c (_gpgme_io_select): Use new level argument for DEBUG_BEGIN instead explicit if construct. * debug.c (debug_init): Remove superfluous zero initializer, remove volatile flag of INITIALIZED. Do not use the double-checked locking algorithm, it is fundamentally flawed and will empty your fridge (on a more serious note, despite the volatile flag it doesn't give you the guarantee you would expect, for example on a DEC Alpha or an SMP machine. The volatile only serializes accesses to the volatile variable, but not to the other variables). --- gpgme/debug.h | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 gpgme/debug.h diff --git a/gpgme/debug.h b/gpgme/debug.h new file mode 100644 index 0000000..bdeaebc --- /dev/null +++ b/gpgme/debug.h @@ -0,0 +1,110 @@ +/* debug.h - interface to debugging functions + * Copyright (C) 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 + +/* Log the formatted string FORMAT at debug level LEVEL or higher. */ +void _gpgme_debug (int level, const char *format, ...); + +/* Start a new debug line in *LINE, logged at level LEVEL or higher, + and starting with the formatted string FORMAT. */ +void _gpgme_debug_begin (void **helper, int level, const char *format, ...); + +/* Add the formatted string FORMAT to the debug line *LINE. */ +void _gpgme_debug_add (void **helper, const char *format, ...); + +/* Finish construction of *LINE and send it to the debug output + stream. */ +void _gpgme_debug_end (void **helper); + +/* Indirect stringification, requires __STDC__ to work. */ +#define STRINGIFY(v) #v +#define XSTRINGIFY(v) STRINGIFY(v) + +#if 0 +/* Only works in GNU. */ +#define DEBUG(fmt, arg...) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__) , ##arg) +#define DEBUG_BEGIN(hlp, lvl, fmt, arg...) \ + _gpgme_debug_begin (&(hlp), lvl, "%s:%s: " fmt, __FILE__, \ + XSTRINGIFY (__LINE__) , ##arg) +#define DEBUG_ADD(hlp, fmt, arg...) \ + _gpgme_debug_add (&(hlp), fmt , ##arg) +#define DEBUG_END(hlp, fmt, arg...) \ + _gpgme_debug_add (&(hlp), fmt , ##arg); \ + _gpgme_debug_end (&(hlp)) +#elsif 0 +/* Only works in C99. */ +#define DEBUG0(fmt) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__)) +#define DEBUG(fmt, ...) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), __VA_ARGS__) +#define DEBUG_BEGIN(hlp, lvl, fmt) \ + _gpgme_debug_begin (&(hlp), lvl, "%s:%s: " fmt, __FILE__, \ + XSTRINGIFY (__LINE__)) +#define DEBUG_BEGINX(hlp, lvl, fmt, ...) \ + _gpgme_debug_begin (&(hlp), lvl, "%s:%s: " fmt, __FILE__, \ + XSTRINGIFY (__LINE__), __VA_ARGS__) +#define DEBUG_ADD0(hlp, fmt) \ + _gpgme_debug_add (&(hlp), fmt) +#define DEBUG_ADD(hlp, fmt, ...) \ + _gpgme_debug_add (&(hlp), fmt, __VA_ARGS__) +#define DEBUG_END(hlp, fmt) \ + _gpgme_debug_add (&(hlp), fmt); \ + _gpgme_debug_end (&(hlp)) +#define DEBUG_ENDX(hlp, fmt, ...) \ + _gpgme_debug_add (&(hlp), fmt, __VA_ARGS__); \ + _gpgme_debug_end (&(hlp)) +#else +/* This finally works everywhere, horror. */ +#define DEBUG0(fmt) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__)) +#define DEBUG1(fmt,a) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), (a)) +#define DEBUG2(fmt,a,b) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), (a), (b)) +#define DEBUG3(fmt,a,b,c) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), (a), (b), \ + (c)) +#define DEBUG4(fmt,a,b,c,d) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), (a), (b), \ + (c), (d)) +#define DEBUG5(fmt,a,b,c,d,e) \ + _gpgme_debug (1, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__), (a), (b), \ + (c), (d), (e)) +#define DEBUG_BEGIN(hlp,lvl,fmt) \ + _gpgme_debug_begin (&(hlp), lvl, "%s:%s: " fmt, __FILE__, XSTRINGIFY (__LINE__)) +#define DEBUG_ADD0(hlp,fmt) \ + _gpgme_debug_add (&(hlp), fmt) +#define DEBUG_ADD1(hlp,fmt,a) \ + _gpgme_debug_add (&(hlp), fmt, (a)) +#define DEBUG_ADD2(hlp,fmt,a,b) \ + _gpgme_debug_add (&(hlp), fmt, (a), (b)) +#define DEBUG_ADD3(hlp,fmt,a,b,c) \ + _gpgme_debug_add (&(hlp), fmt, (a), (b), (c)) +#define DEBUG_END(hlp,fmt) \ + _gpgme_debug_add (&(hlp), fmt); \ + _gpgme_debug_end (&(hlp)) +#endif + +#define DEBUG_ENABLED(hlp) (!!(hlp)) + +#endif /* DEBUG_H */ -- 2.26.2