[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] RFC: Full stacktrace on glib/gtk errors and warnings
From: |
Mark Wielaard |
Subject: |
[cp-patches] RFC: Full stacktrace on glib/gtk errors and warnings |
Date: |
Sat, 25 Jun 2005 15:51:20 +0200 |
Hi,
While working with the native gtk+ awt peers I often need to find out
where precisely a warning or error message is comming from. The
following patch installs a default log handler that dumps a stacktrace
whenever we encounter such a situation. It is careful about only
installing it when gtk+ (> 2.4) supports it and that it isn't swallowing
any pending exceptions.
2005-06-25 Mark Wielaard <address@hidden>
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
(glog_func): New static function.
(Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit): Install glog_func as
default log handler.
* native/jni/gtk-peer/Makefile.am (libgtkpeer_la_LIBADD): Add jcl.
This generates things like:
java.lang.InternalError: GdkPixbuf: gdk_pixbuf_loader_close: assertion
`priv->closed == FALSE' failed
at gnu.java.awt.peer.gtk.GdkPixbufDecoder.finish (Native Method)
at gnu.java.awt.peer.gtk.GdkPixbufDecoder.finalize
(GdkPixbufDecoder.java:182)
(Which indeed is a bug that I recently introduces, sorry. We should be
more careful in the finalizer manipulating the native state.)
The stack trace generation is only conditional on it being something
that already generates output on stderr by default. Since I think that
none of these error/warning messages should ever occur in our code (it
means we are feeding the native side bogus data from java-'user-space')
I think this is the right thing to do. And it really helps with
debugging.
Comments?
Cheers,
Mark
Index: native/jni/gtk-peer/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/Makefile.am,v
retrieving revision 1.23
diff -u -r1.23 Makefile.am
--- native/jni/gtk-peer/Makefile.am 2 Jun 2005 13:18:10 -0000 1.23
+++ native/jni/gtk-peer/Makefile.am 25 Jun 2005 13:24:51 -0000
@@ -51,7 +51,8 @@
gtkcairopeer.h \
gtkpeer.h
-libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/native_state.lo
+libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/native_state.lo \
+ $(top_builddir)/native/jni/classpath/jcl.lo
AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @CAIRO_LIBS@ @PANGOFT2_LIBS@
@X_LIBS@ -lXtst
AM_CPPFLAGS = @CLASSPATH_INCLUDES@
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,v
retrieving revision 1.14
diff -u -r1.14 gnu_java_awt_peer_gtk_GtkToolkit.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c 3 May 2005
23:57:49 -0000 1.14
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c 25 Jun 2005
13:24:51 -0000
@@ -39,6 +39,7 @@
#include "gtkpeer.h"
#include "gnu_java_awt_peer_gtk_GtkToolkit.h"
#include "gthread-jni.h"
+#include "jcl.h"
#include <sys/time.h>
@@ -102,6 +103,14 @@
static void dpi_changed_cb (GtkSettings *settings,
GParamSpec *pspec);
+#if GTK_MINOR_VERSION > 4
+static GLogFunc old_glog_func;
+static void glog_func (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data);
+#endif
+
/*
* Call gtk_init. It is very important that this happen before any other
* gtk calls.
@@ -177,6 +186,11 @@
g_free (argv[0]);
g_free (argv);
+ /* On errors or warning print a whole stacktrace. */
+#if GTK_MINOR_VERSION > 4
+ old_glog_func = g_log_set_default_handler (&glog_func, NULL);
+#endif
+
/* setup cached IDs for posting GTK events to Java */
window = (*env)->FindClass (env, "java/awt/Window");
@@ -362,6 +376,31 @@
return milliseconds_elapsed < 100;
}
+#if GTK_MINOR_VERSION > 4
+static void
+glog_func (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ old_glog_func (log_domain, log_level, message, user_data);
+ if (log_level & (G_LOG_LEVEL_ERROR
+ | G_LOG_LEVEL_CRITICAL
+ | G_LOG_LEVEL_WARNING))
+ {
+ JNIEnv *env = gdk_env ();
+ jthrowable *exc = (*env)->ExceptionOccurred(env);
+ gchar *detail = g_strconcat (log_domain, ": ", message, NULL);
+ JCL_ThrowException (env, "java/lang/InternalError", detail);
+ g_free (detail);
+ (*env)->ExceptionDescribe (env);
+ if (exc != NULL)
+ (*env)->Throw (env, exc);
+ else
+ (*env)->ExceptionClear (env);
+ }
+}
+#endif
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkToolkit_iterateNativeQueue
signature.asc
Description: This is a digitally signed message part
- [cp-patches] RFC: Full stacktrace on glib/gtk errors and warnings,
Mark Wielaard <=