~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to src/debug.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman, Bhavani Shankar, Scott Kitterman
  • Date: 2008-12-31 02:39:33 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081231023933-zi5r2w9vf7fdz0x9
Tags: 1.1.8-1ubuntu1
[ Bhavani Shankar ]
* Merge from debian unstable, remaining changes: LP: #311666
  - debian/rules: enable tests

[ Scott Kitterman ]
* Re-enable testsuite on armel since it's no longer a first build 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* debug.h - interface to debugging functions
 
2
   Copyright (C) 2002, 2004, 2005, 2007 g10 Code GmbH
 
3
 
 
4
   This file is part of GPGME.
 
5
 
 
6
   GPGME is free software; you can redistribute it and/or modify it
 
7
   under the terms of the GNU Lesser General Public License as
 
8
   published by the Free Software Foundation; either version 2.1 of
 
9
   the License, or (at your option) any later version.
 
10
   
 
11
   GPGME is distributed in the hope that it will be useful, but
 
12
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Lesser General Public License for more details.
 
15
   
 
16
   You should have received a copy of the GNU Lesser General Public
 
17
   License along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
   02111-1307, USA.  */
 
20
 
 
21
#ifndef DEBUG_H
 
22
#define DEBUG_H
 
23
 
 
24
#include <string.h>
 
25
 
 
26
/* Indirect stringification, requires __STDC__ to work.  */
 
27
#define STRINGIFY(v) #v
 
28
#define XSTRINGIFY(v) STRINGIFY(v)
 
29
 
 
30
 
 
31
/* The debug levels.  */
 
32
 
 
33
#define DEBUG_INIT      1
 
34
#define DEBUG_CTX       2
 
35
#define DEBUG_ENGINE    3
 
36
#define DEBUG_DATA      4
 
37
#define DEBUG_ASSUAN    5
 
38
#define DEBUG_SYSIO     6
 
39
 
 
40
 
 
41
/* Remove path components from filenames (i.e. __FILE__) for cleaner
 
42
   logs. */
 
43
static inline const char *_gpgme_debug_srcname (const char *file)
 
44
                                                GPGME_GCC_A_PURE;
 
45
 
 
46
static inline const char *
 
47
_gpgme_debug_srcname (const char *file)
 
48
{
 
49
  const char *s = strrchr (file, '/');
 
50
  return s? s+1:file;
 
51
}
 
52
 
 
53
/* Called early to initialize the logging.  */
 
54
void _gpgme_debug_subsystem_init (void);
 
55
 
 
56
/* Log the formatted string FORMAT at debug level LEVEL or higher.  */
 
57
void _gpgme_debug (int level, const char *format, ...);
 
58
 
 
59
/* Start a new debug line in *LINE, logged at level LEVEL or higher,
 
60
   and starting with the formatted string FORMAT.  */
 
61
void _gpgme_debug_begin (void **helper, int level, const char *format, ...);
 
62
 
 
63
/* Add the formatted string FORMAT to the debug line *LINE.  */
 
64
void _gpgme_debug_add (void **helper, const char *format, ...);
 
65
 
 
66
/* Finish construction of *LINE and send it to the debug output
 
67
   stream.  */
 
68
void _gpgme_debug_end (void **helper);
 
69
 
 
70
void _gpgme_debug_buffer (int lvl, const char *const fmt,
 
71
                          const char *const func, const char *const tagname,
 
72
                          void *tag, const char *const buffer, size_t len);
 
73
 
 
74
 
 
75
/* Trace support.  */
 
76
 
 
77
/* FIXME: For now.  */
 
78
#define _gpgme_debug_trace() 1
 
79
 
 
80
#define _TRACE(lvl, name, tag)                                  \
 
81
  int _gpgme_trace_level = lvl;                                 \
 
82
  const char *const _gpgme_trace_func = name;                   \
 
83
  const char *const _gpgme_trace_tagname = STRINGIFY (tag);     \
 
84
  void *_gpgme_trace_tag = (void *) tag
 
85
 
 
86
#define TRACE_BEG(lvl, name, tag)                          \
 
87
  _TRACE (lvl, name, tag);                                 \
 
88
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter\n", \
 
89
                _gpgme_trace_func, _gpgme_trace_tagname,   \
 
90
                _gpgme_trace_tag), 0
 
91
#define TRACE_BEG0(lvl, name, tag, fmt)                                 \
 
92
  _TRACE (lvl, name, tag);                                              \
 
93
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter: " fmt "\n",   \
 
94
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
95
                _gpgme_trace_tag), 0
 
96
#define TRACE_BEG1(lvl, name, tag, fmt, arg1)                           \
 
97
  _TRACE (lvl, name, tag);                                              \
 
98
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter: " fmt "\n",   \
 
99
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
100
                _gpgme_trace_tag, arg1), 0
 
101
#define TRACE_BEG2(lvl, name, tag, fmt, arg1, arg2)                 \
 
102
  _TRACE (lvl, name, tag);                                          \
 
103
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
 
104
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
105
                _gpgme_trace_tag, arg1, arg2), 0
 
106
#define TRACE_BEG3(lvl, name, tag, fmt, arg1, arg2, arg3)           \
 
107
  _TRACE (lvl, name, tag);                                          \
 
108
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
 
109
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
110
                _gpgme_trace_tag, arg1, arg2, arg3), 0
 
111
#define TRACE_BEG4(lvl, name, tag, fmt, arg1, arg2, arg3, arg4)     \
 
112
  _TRACE (lvl, name, tag);                                          \
 
113
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): enter: " fmt "\n", \
 
114
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
115
                _gpgme_trace_tag, arg1, arg2, arg3, arg4), 0
 
116
 
 
117
#define TRACE(lvl, name, tag)                                           \
 
118
  _gpgme_debug (lvl, "%s (%s=0x%x): call\n",                            \
 
119
                name, STRINGIFY (tag), (void *) tag), 0
 
120
#define TRACE0(lvl, name, tag, fmt)                                     \
 
121
  _gpgme_debug (lvl, "%s (%s=0x%x): call: " fmt "\n",                   \
 
122
                name, STRINGIFY (tag), (void *) tag), 0
 
123
#define TRACE1(lvl, name, tag, fmt, arg1)                              \
 
124
  _gpgme_debug (lvl, "%s (%s=0x%x): call: " fmt "\n",                  \
 
125
                name, STRINGIFY (tag), (void *) tag, arg1), 0
 
126
#define TRACE2(lvl, name, tag, fmt, arg1, arg2)                        \
 
127
  _gpgme_debug (lvl, "%s (%s=0x%x): call: " fmt "\n",                  \
 
128
                name, STRINGIFY (tag), (void *) tag, arg1, arg2), 0
 
129
#define TRACE3(lvl, name, tag, fmt, arg1, arg2, arg3)                  \
 
130
  _gpgme_debug (lvl, "%s (%s=0x%x): call: " fmt "\n",                  \
 
131
                name, STRINGIFY (tag), (void *) tag, arg1, arg2,       \
 
132
                arg3), 0
 
133
#define TRACE6(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
 
134
  _gpgme_debug (lvl, "%s (%s=0x%x): call: " fmt "\n",                   \
 
135
                name, STRINGIFY (tag), (void *) tag, arg1, arg2, arg3,  \
 
136
                arg4, arg5, arg6), 0
 
137
 
 
138
#define TRACE_ERR(err)                                                  \
 
139
  err == 0 ? (TRACE_SUC ()) :                                           \
 
140
    (_gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): error: %s <%s>\n",        \
 
141
                   _gpgme_trace_func, _gpgme_trace_tagname,             \
 
142
                   _gpgme_trace_tag, gpgme_strerror (err),              \
 
143
                   gpgme_strsource (err)), (err))
 
144
/* The cast to void suppresses GCC warnings.  */
 
145
#define TRACE_SYSRES(res)                                               \
 
146
  res >= 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) :          \
 
147
    (_gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): error: %s\n",     \
 
148
                   _gpgme_trace_func, _gpgme_trace_tagname,             \
 
149
                   _gpgme_trace_tag, strerror (errno)), (res))
 
150
#define TRACE_SYSERR(res)                                               \
 
151
  res == 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) :          \
 
152
    (_gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): error: %s\n",     \
 
153
                   _gpgme_trace_func, _gpgme_trace_tagname,             \
 
154
                   _gpgme_trace_tag, strerror (res)), (res))
 
155
 
 
156
#define TRACE_SUC()                                              \
 
157
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): leave\n",       \
 
158
                _gpgme_trace_func, _gpgme_trace_tagname,         \
 
159
                _gpgme_trace_tag), 0
 
160
#define TRACE_SUC0(fmt)                                                 \
 
161
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): leave: " fmt "\n",   \
 
162
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
163
                _gpgme_trace_tag), 0
 
164
#define TRACE_SUC1(fmt, arg1)                                           \
 
165
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): leave: " fmt "\n",   \
 
166
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
167
                _gpgme_trace_tag, arg1), 0
 
168
#define TRACE_SUC2(fmt, arg1, arg2)                                     \
 
169
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): leave: " fmt "\n",   \
 
170
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
171
                _gpgme_trace_tag, arg1, arg2), 0
 
172
#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5)                   \
 
173
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): leave: " fmt "\n",   \
 
174
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
175
                _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
 
176
 
 
177
#define TRACE_LOG(fmt)                                                  \
 
178
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n",   \
 
179
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
180
                _gpgme_trace_tag), 0
 
181
#define TRACE_LOG1(fmt, arg1)                                           \
 
182
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n",   \
 
183
                _gpgme_trace_func, _gpgme_trace_tagname,                \
 
184
                _gpgme_trace_tag, arg1), 0
 
185
#define TRACE_LOG2(fmt, arg1, arg2)                                 \
 
186
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
 
187
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
188
                _gpgme_trace_tag, arg1, arg2), 0
 
189
#define TRACE_LOG3(fmt, arg1, arg2, arg3)                           \
 
190
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
 
191
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
192
                _gpgme_trace_tag, arg1, arg2, arg3), 0
 
193
#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4)                     \
 
194
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
 
195
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
196
                _gpgme_trace_tag, arg1, arg2, arg3, arg4), 0
 
197
#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6)         \
 
198
  _gpgme_debug (_gpgme_trace_level, "%s (%s=0x%x): check: " fmt "\n", \
 
199
                _gpgme_trace_func, _gpgme_trace_tagname,            \
 
200
                _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5,     \
 
201
                arg6), 0
 
202
 
 
203
#define TRACE_LOGBUF(buf, len)                                          \
 
204
  _gpgme_debug_buffer (_gpgme_trace_level, "%s (%s=0x%x): check: %s",   \
 
205
                       _gpgme_trace_func, _gpgme_trace_tagname,         \
 
206
                       _gpgme_trace_tag, buf, len)
 
207
 
 
208
#define TRACE_SEQ(hlp,fmt)                                              \
 
209
  _gpgme_debug_begin (&(hlp), _gpgme_trace_level,                       \
 
210
                      "%s (%s=0x%x): check: " fmt,                      \
 
211
                      _gpgme_trace_func, _gpgme_trace_tagname,          \
 
212
                      _gpgme_trace_tag)
 
213
#define TRACE_ADD0(hlp,fmt) \
 
214
  _gpgme_debug_add (&(hlp), fmt)
 
215
#define TRACE_ADD1(hlp,fmt,a) \
 
216
  _gpgme_debug_add (&(hlp), fmt, (a))
 
217
#define TRACE_ADD2(hlp,fmt,a,b) \
 
218
  _gpgme_debug_add (&(hlp), fmt, (a), (b))
 
219
#define TRACE_ADD3(hlp,fmt,a,b,c) \
 
220
  _gpgme_debug_add (&(hlp), fmt, (a), (b), (c))
 
221
#define TRACE_END(hlp,fmt) \
 
222
  _gpgme_debug_add (&(hlp), fmt); \
 
223
  _gpgme_debug_end (&(hlp))
 
224
#define TRACE_ENABLED(hlp) (!!(hlp))
 
225
 
 
226
#endif  /* DEBUG_H */