aboutsummaryrefslogtreecommitdiffstats
path: root/src/debug.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2009-11-04 18:13:44 +0000
committerMarcus Brinkmann <[email protected]>2009-11-04 18:13:44 +0000
commit49693e8e45ec9233f779e8f1d8a30f54b683c6ff (patch)
tree0492f347800597011ed17cbf9e478bd476e7cfbe /src/debug.c
parentAdjust for changed assuan_register_command. (diff)
downloadgpgme-49693e8e45ec9233f779e8f1d8a30f54b683c6ff.tar.gz
gpgme-49693e8e45ec9233f779e8f1d8a30f54b683c6ff.zip
2009-11-04 Marcus Brinkmann <[email protected]>
* ath.h (ath_self): New prototype. Include <stdint.h> * ath.c, ath-pth.c, ath-pthread.c (ath_self): New function. * debug.h: Rewrite most macros to beautify debug output. (_gpgme_debug_buffer): Remove tagname and tag argument. (_gpgme_debug_frame_begin, _gpgme_debug_frame_end): New prototypes. * debug.c: Include <time.h>. Don't include assuan.h. (frame_nr, FRAME_NR): New thread-specific variable and macro. (debug_init): Do not initialize assuan. Call _gpgme_debug after initialization instead using printf directly. (_gpgme_debug): Do not call debug_init (we now ensure proper initialization by user). Add timestamp and thread/process ID. (_gpgme_debug_buffer): Do not take tagname and tag argument. (_gpgme_debug_frame_begin, _gpgme_debug_frame_end): New functions. * version.c (gpgme_check_version_internal, gpgme_check_version): Fix debug string. Do not initialize assuan. * posix-io.c (get_max_fds): Use 0 not NULL (nicer debug output).
Diffstat (limited to '')
-rw-r--r--src/debug.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/src/debug.c b/src/debug.c
index c0e61551..d3fce779 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
+#include <time.h>
#ifndef HAVE_DOSISH_SYSTEM
# include <sys/types.h>
# include <sys/stat.h>
@@ -36,11 +37,8 @@
#endif
#include <assert.h>
-#ifdef HAVE_ASSUAN_H
-#include "assuan.h"
-#endif
-
#include "util.h"
+#include "ath.h"
#include "sema.h"
#include "debug.h"
@@ -57,6 +55,28 @@ static int debug_level;
static FILE *errfp;
+#ifdef __GNUC__
+#define FRAME_NR
+static __thread int frame_nr = 0;
+#endif
+
+void
+_gpgme_debug_frame_begin (void)
+{
+#ifdef FRAME_NR
+ frame_nr++;
+#endif
+}
+
+void _gpgme_debug_frame_end (void)
+{
+#ifdef FRAME_NR
+ frame_nr--;
+#endif
+}
+
+
+
/* Remove leading and trailing white spaces. */
static char *
trim_spaces (char *str)
@@ -140,15 +160,11 @@ debug_init (void)
}
free (e);
}
-
- if (debug_level > 0)
- fprintf (errfp, "gpgme_debug: level=%d\n", debug_level);
-#ifdef HAVE_ASSUAN_H
- assuan_set_assuan_log_prefix ("gpgme-assuan");
- assuan_set_assuan_log_stream (debug_level > 0 ? errfp : NULL);
-#endif /* HAVE_ASSUAN_H*/
}
UNLOCK (debug_lock);
+
+ if (debug_level > 0)
+ _gpgme_debug (DEBUG_INIT, "gpgme_debug: level=%d\n", debug_level);
}
@@ -173,13 +189,37 @@ _gpgme_debug (int level, const char *format, ...)
int saved_errno;
saved_errno = errno;
-
- debug_init ();
if (debug_level < level)
return;
va_start (arg_ptr, format);
LOCK (debug_lock);
+ {
+ struct tm *tp;
+ time_t atime = time (NULL);
+
+ tp = localtime (&atime);
+ fprintf (errfp, "GPGME %04d-%02d-%02d %02d:%02d:%02d <0x%04llx> ",
+ 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday,
+ tp->tm_hour, tp->tm_min, tp->tm_sec,
+ (unsigned long long) ath_self ());
+ }
+#ifdef FRAME_NR
+ {
+ char spaces[] = " ";
+ int nr_spaces = sizeof (spaces) - 1;
+ int nr_columns;
+
+ nr_columns = 2 * (frame_nr - 1);
+ if (nr_columns > nr_spaces)
+ nr_columns = nr_spaces;
+ if (nr_columns < 0)
+ nr_columns = 0;
+ spaces[nr_columns] = '\0';
+ fprintf (errfp, "%s", spaces);
+ }
+#endif
+
vfprintf (errfp, format, arg_ptr);
va_end (arg_ptr);
if(format && *format && format[strlen (format) - 1] != '\n')
@@ -199,7 +239,6 @@ _gpgme_debug_begin (void **line, int level, const char *format, ...)
va_list arg_ptr;
int res;
- debug_init ();
if (debug_level < level)
{
/* Disable logging of this line. */
@@ -265,8 +304,7 @@ _gpgme_debug_end (void **line)
void
_gpgme_debug_buffer (int lvl, const char *const fmt,
- const char *const func, const char *const tagname,
- const void *const tag, const char *const buffer,
+ const char *const func, const char *const buffer,
size_t len)
{
int idx = 0;
@@ -302,6 +340,6 @@ _gpgme_debug_buffer (int lvl, const char *const fmt,
*(strp++) = ' ';
*(strp2) = '\0';
- _gpgme_debug (lvl, fmt, func, tagname, tag, str);
+ _gpgme_debug (lvl, fmt, func, str);
}
}