[gitg/gtk3] Improved debugging
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/gtk3] Improved debugging
- Date: Fri, 25 Mar 2011 08:41:51 +0000 (UTC)
commit 9a98434dc2ca7e055bb2ab109e9c8f182a1e7171
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Thu Mar 24 12:44:24 2011 +0100
Improved debugging
configure.ac | 11 +++++++++
libgitg/gitg-debug.c | 37 ++++++++++++++++++++++++++++---
libgitg/gitg-debug.h | 22 ++++++++++++++++++-
libgitg/gitg-line-parser.c | 3 ++
libgitg/gitg-runner.c | 7 +++--
libgitg/gitg-smart-charset-converter.c | 19 +++++++++++++---
6 files changed, 87 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4d06480..cda16cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,6 +100,17 @@ fi
PACKAGE_LIBS="$PACKAGE_LIBS -lm"
+
+AC_ARG_ENABLE(debug,
+ [AS_HELP_STRING([--disable-debug],
+ [disable debug information [default=yes]])],
+ [enable_debug=$enableval], [enable_debug=yes])
+
+if test "$enable_debug" = "yes"; then
+ PACKAGE_CFLAGS="$PACKAGE_CFLAGS -g"
+ AC_DEFINE([ENABLE_DEBUG],[1],[Whether debugging support is enabled])
+fi
+
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
diff --git a/libgitg/gitg-debug.c b/libgitg/gitg-debug.c
index 175d035..fb4c45c 100644
--- a/libgitg/gitg-debug.c
+++ b/libgitg/gitg-debug.c
@@ -22,19 +22,24 @@
#include "gitg-debug.h"
#include <glib.h>
+#include <stdio.h>
static guint debug_enabled = GITG_DEBUG_NONE;
#define DEBUG_FROM_ENV(name) \
- { \
- if (g_getenv(#name)) \
- debug_enabled |= name; \
+ { \
+ if (g_getenv(#name)) \
+ { \
+ debug_enabled |= name; \
+ } \
}
void
gitg_debug_init (void)
{
- DEBUG_FROM_ENV(GITG_DEBUG_RUNNER);
+ DEBUG_FROM_ENV (GITG_DEBUG_SHELL);
+ DEBUG_FROM_ENV (GITG_DEBUG_SHELL_OUTPUT);
+ DEBUG_FROM_ENV (GITG_DEBUG_CHARSET_CONVERSION);
}
gboolean
@@ -42,3 +47,27 @@ gitg_debug_enabled (guint debug)
{
return debug_enabled & debug;
}
+
+void
+gitg_debug_message (guint level,
+ gchar const *file,
+ gint line,
+ gchar const *function,
+ gchar const *format,
+ ...)
+{
+ if (G_UNLIKELY (debug_enabled & level))
+ {
+ va_list ap;
+ gchar *msg;
+
+ va_start (ap, format);
+ msg = g_strdup_vprintf (format, ap);
+ va_end (ap);
+
+ g_print ("%s:%d (%s) %s\n", file, line, function, msg);
+ fflush (stdout);
+
+ g_free (msg);
+ }
+}
diff --git a/libgitg/gitg-debug.h b/libgitg/gitg-debug.h
index 5c5a493..e2ff3c6 100644
--- a/libgitg/gitg-debug.h
+++ b/libgitg/gitg-debug.h
@@ -24,15 +24,35 @@
#define __GITG_DEBUG_H__
#include <glib.h>
+#include <config.h>
enum
{
GITG_DEBUG_NONE = 0,
- GITG_DEBUG_RUNNER = 1 << 0
+ GITG_DEBUG_SHELL = 1 << 0,
+ GITG_DEBUG_SHELL_OUTPUT = 1 << 1,
+ GITG_DEBUG_CHARSET_CONVERSION = 1 << 2
};
+#if ENABLE_DEBUG
void gitg_debug_init (void);
gboolean gitg_debug_enabled (guint debug);
+void gitg_debug_message (guint level,
+ gchar const *file,
+ gint line,
+ gchar const *function,
+ gchar const *format,
+ ...);
+
+#define gitg_debug(level,format,args...) gitg_debug_message (level, __FILE__, __LINE__, G_STRFUNC, format, args)
+#else
+
+#define gitg_debug_init ;
+#define gitg_debug_enabled(x) FALSE
+#define gitg_debug(level,format,args...) ;
+
+#endif
+
#endif /* __GITG_DEBUG_H__ */
diff --git a/libgitg/gitg-line-parser.c b/libgitg/gitg-line-parser.c
index 5526ce1..889aeda 100644
--- a/libgitg/gitg-line-parser.c
+++ b/libgitg/gitg-line-parser.c
@@ -21,6 +21,7 @@
*/
#include "gitg-line-parser.h"
+#include <libgitg/gitg-debug.h>
#define GITG_LINE_PARSER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GITG_TYPE_LINE_PARSER, GitgLineParserPrivate))
@@ -212,6 +213,8 @@ parse_lines (GitgLineParser *stream,
stream->priv->lines[i++] = g_strndup (ptr, newline - ptr);
}
+ gitg_debug (GITG_DEBUG_SHELL_OUTPUT, "%s", stream->priv->lines[i - 1]);
+
ptr = line_end;
if (i == stream->priv->buffer_size)
diff --git a/libgitg/gitg-runner.c b/libgitg/gitg-runner.c
index 80450c6..6bd2b76 100644
--- a/libgitg/gitg-runner.c
+++ b/libgitg/gitg-runner.c
@@ -446,7 +446,7 @@ gitg_runner_run (GitgRunner *runner)
(gchar **)gitg_command_get_arguments (runner->priv->command),
(gchar **)gitg_command_get_environment (runner->priv->command),
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD |
- (gitg_debug_enabled (GITG_DEBUG_RUNNER) ? 0 : G_SPAWN_STDERR_TO_DEV_NULL),
+ (gitg_debug_enabled (GITG_DEBUG_SHELL) ? 0 : G_SPAWN_STDERR_TO_DEV_NULL),
NULL,
NULL,
&(runner->priv->pid),
@@ -476,8 +476,9 @@ gitg_runner_run (GitgRunner *runner)
runner->priv->cancellable = g_cancellable_new ();
- runner->priv->stdin = G_OUTPUT_STREAM (g_unix_output_stream_new (stdinf,
- TRUE));
+ runner->priv->stdin =
+ G_OUTPUT_STREAM (g_unix_output_stream_new (stdinf,
+ TRUE));
data = async_data_new (runner);
diff --git a/libgitg/gitg-smart-charset-converter.c b/libgitg/gitg-smart-charset-converter.c
index 29cbad2..6f98fed 100644
--- a/libgitg/gitg-smart-charset-converter.c
+++ b/libgitg/gitg-smart-charset-converter.c
@@ -21,6 +21,7 @@
*/
#include "gitg-smart-charset-converter.h"
+#include "gitg-debug.h"
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -278,10 +279,18 @@ guess_encoding (GitgSmartCharsetConverter *smart,
/* Try to convert */
if (try_convert (conv, inbuf, inbuf_size))
{
+ gitg_debug (GITG_DEBUG_CHARSET_CONVERSION,
+ "Guessed %s conversion",
+ gitg_encoding_get_charset (enc));
break;
}
}
+ if (smart->priv->is_utf8)
+ {
+ gitg_debug (GITG_DEBUG_CHARSET_CONVERSION, "%s", "Guessed UTF8 conversion");
+ }
+
if (conv != NULL)
{
g_converter_reset (G_CONVERTER (conv));
@@ -307,15 +316,13 @@ gitg_smart_charset_converter_convert (GConverter *converter,
GitgSmartCharsetConverter *smart = GITG_SMART_CHARSET_CONVERTER (converter);
/* Guess the encoding if we didn't make it yet */
- if (smart->priv->charset_conv == NULL &&
- !smart->priv->is_utf8)
+ if (smart->priv->charset_conv == NULL && !smart->priv->is_utf8)
{
smart->priv->charset_conv = guess_encoding (smart, inbuf, inbuf_size);
/* If we still have the previous case is that we didn't guess
anything */
- if (smart->priv->charset_conv == NULL &&
- !smart->priv->is_utf8)
+ if (smart->priv->charset_conv == NULL && !smart->priv->is_utf8)
{
g_set_error_literal (error, GITG_CHARSET_CONVERSION_ERROR,
GITG_CHARSET_CONVERSION_ERROR_ENCODING_AUTO_DETECTION_FAILED,
@@ -340,9 +347,13 @@ gitg_smart_charset_converter_convert (GConverter *converter,
ret = G_CONVERTER_CONVERTED;
if (flags & G_CONVERTER_INPUT_AT_END)
+ {
ret = G_CONVERTER_FINISHED;
+ }
else if (flags & G_CONVERTER_FLUSH)
+ {
ret = G_CONVERTER_FLUSHED;
+ }
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]