New header containing GTK_DEBUG-style debugging support for GLib.
authorMatthias Clasen <matthiasc@src.gnome.org>
Thu, 21 Feb 2002 23:07:34 +0000 (23:07 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 21 Feb 2002 23:07:34 +0000 (23:07 +0000)
* glib/gdebug.h: New header containing GTK_DEBUG-style debugging
support for GLib. Currently only the fatal_warnings debug option exists.

* glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
for parsing G_MESSAGES_PREFIXED.
(_g_debug_init): New one-shot function for parsing G_DEBUG.
(g_log_write_prefix): Use g_log_msg_prefix_init().
(g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().

* glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.

* glib/Makefile.am (IGNORE_HFILES): Add gdebug.h.

* glib/running.sgml: Document the G_DEBUG environment variable.

* glib/tmpl/threads.sgml: Replace g_thread_wait() by
g_thread_join() in two places.

15 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/glib/Makefile.am
docs/reference/glib/running.sgml
docs/reference/glib/tmpl/threads.sgml
glib/Makefile.am
glib/gdebug.h [new file with mode: 0644]
glib/gmessages.c

index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 0365c98135954ce18083c210a818f194efc996fe..c9ee6af3678f4cea325708b0ef4648f9f7a4b589 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gdebug.h: New header containing GTK_DEBUG-style debugging
+       support for GLib. Currently only the fatal_warnings debug option exists. 
+
+       * glib/gmessages.c (g_log_msg_prefix_init): New one-shot function
+       for parsing G_MESSAGES_PREFIXED.
+       (_g_debug_init): New one-shot function for parsing G_DEBUG.
+       (g_log_write_prefix): Use g_log_msg_prefix_init().
+       (g_messages_init): Use g_log_msg_prefix_init() and _g_debug_init().
+
+       * glib/Makefile.am (libglib_1_3_la_SOURCES): Add gdebug.h.
+
 Wed Feb 20 22:35:42 2002  Owen Taylor  <otaylor@redhat.com>
 
        Fixes from Miroslaw Dobrzanski-Neumann (#71963)
index 5aacdf36067b6b1a8dde01136621fed014f321f8..f99549a84ce50bdf848aa3942bce312800f79360 100644 (file)
@@ -1,3 +1,12 @@
+2002-02-21  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/Makefile.am (IGNORE_HFILES): Add gdebug.h.
+
+       * glib/running.sgml: Document the G_DEBUG environment variable.
+
+       * glib/tmpl/threads.sgml: Replace g_thread_wait() by
+       g_thread_join() in two places.
+
 2002-02-20  Sven Neumann  <sven@gimp.org>
 
        * gobject/gobject-sections.txt
index fcce6f5b452e7f1921b1106338f0f234749c16ab..e44a3c2660a74b20d14a9eb136a703e820fe6537 100644 (file)
@@ -34,7 +34,8 @@ IGNORE_HFILES=                        \
        gunicomp.h              \
        gunidecomp.h            \
        gunichartables.h        \
-       glibconfig-sysdefs.h
+       glibconfig-sysdefs.h    \
+       gdebug.h
 
 # Extra files to add when scanning
 EXTRA_HFILES=
index c1cfac84fb7e1de5729e91828027418edfb63de4..94d55120647eddb9cbb4ccdf89f09928a2b76005 100644 (file)
@@ -38,7 +38,27 @@ variables like <envar>LANG</envar>, <envar>PATH</envar> or <envar>HOME</envar>.
   <para>
     A list of log levels for which messages should be prefixed by the 
     program name and PID of the application. The default is to prefix
-    everything except %G_LOG_LEVEL_MESSAGE and %G_LOG_LEVEL_INFO. 
+    everything except <literal>G_LOG_LEVEL_MESSAGE</literal> and <literal>G_LOG_LEVEL_INFO</literal>. 
+  </para>
+</formalpara>
+
+<formalpara>
+  <title><envar>G_DEBUG</envar></title>
+
+  <para>
+    If GLib has been configured with <option>--enable-debug=yes</option>,
+    this variable can be set to a list of debug options, which cause GLib
+    to print out different types of debugging information.
+    <variablelist>
+      <varlistentry>
+        <term>fatal_warnings</term>
+        <listitem><para>Causes GLib to abort the program at the first call
+           to <link linkend="g-warning">g_warning</link>(). This option is 
+           special in that it doesn't require GLib to be configured with 
+           debugging support.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
   </para>
 </formalpara>
 
@@ -61,9 +81,9 @@ static volatile gulong g_trap_free_size;
 static volatile gulong g_trap_realloc_size;
 static volatile gulong g_trap_malloc_size;
 </programlisting>
-If set to a size > 0, <link linkend="g-free">g_free()</link>
-<link linkend="g-realloc">g_realloc()</link> and 
-<link linkend="g-malloc">g_malloc()</link> will be intercepted if the size 
+If set to a size > 0, <link linkend="g-free">g_free</link>()
+<link linkend="g-realloc">g_realloc</link>() and 
+<link linkend="g-malloc">g_malloc</link>() will be intercepted if the size 
 matches the size of the corresponding memory block. This will only work with 
 <literal>g_mem_set_vtable (glib_mem_profiler_table)</literal> upon startup 
 though, because memory profiling is required to match on the memory block sizes.
index 36b13d136f7c02ebf51425a2db4250edaeb682e3..76ac5c207b73b5befe93e69350bcc8c0926b08e1 100644 (file)
@@ -274,7 +274,7 @@ This function creates a new thread with the priority @priority.
 
 <para>
 If @joinable is %TRUE, you can wait for this threads termination
-calling g_thread_wait(). Otherwise the thread will just disappear, when
+calling g_thread_join(). Otherwise the thread will just disappear, when
 ready. 
 </para>
 
@@ -304,7 +304,7 @@ platform, if @stack_size is 0.
 
 <para>
 If @joinable is %TRUE, you can wait for this threads termination
-calling g_thread_wait(). Otherwise the thread will just disappear, when
+calling g_thread_join(). Otherwise the thread will just disappear, when
 ready. If @bound is %TRUE, this thread will be scheduled in the system
 scope, otherwise the implementation is free to do scheduling in the
 process scope. The first variant is more expensive resource-wise, but
index b9b772ebff144ad2eef41654492b20792cd681cd..10cf8531115e03bedc317f685f7387dd60954064 100644 (file)
@@ -81,7 +81,8 @@ libglib_1_3_la_SOURCES =      \
        gunicomp.h              \
        gunidecomp.h            \
        gunidecomp.c            \
-       gutils.c
+       gutils.c                \
+       gdebug.h
 
 EXTRA_libglib_1_3_la_SOURCES = \
        giounix.c       \
diff --git a/glib/gdebug.h b/glib/gdebug.h
new file mode 100644 (file)
index 0000000..a4dc06d
--- /dev/null
@@ -0,0 +1,63 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#ifndef __G_DEBUG_H__
+#define __G_DEBUG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef enum {
+  G_DEBUG_FATAL_WARNINGS = 1 << 0,
+} GDebugFlag;
+
+
+#ifdef G_ENABLE_DEBUG
+
+#define G_NOTE(type, action)            G_STMT_START { \
+    if (!_g_debug_initialized)                         \
+       { _g_debug_init (); }                           \
+    if (_g_debug_flags & G_DEBUG_##type)               \
+       { action; };                         } G_STMT_END
+
+#else /* !G_ENABLE_DEBUG */
+
+#define G_NOTE(type, action)
+      
+#endif /* G_ENABLE_DEBUG */
+
+GLIB_VAR gboolean _g_debug_initialized;
+GLIB_VAR guint _g_debug_flags;
+
+void _g_debug_init ();
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __G_DEBUG_H__ */
index 3dbd90151ccde2f6e4874451273c6f4787be7785..691c12dccab8fb0b0fd4a1b9c461c8e1c2a5af03 100644 (file)
@@ -43,6 +43,7 @@
 #include <signal.h>
 #include <locale.h>
 #include <errno.h>
+#include "gdebug.h"
 
 #ifdef G_OS_WIN32
 typedef FILE* GFileDescriptor;
@@ -206,38 +207,40 @@ write_string (GFileDescriptor fd,
   write (fd, string, strlen (string));
 }
 
+static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG;
+
+static inline void
+g_log_msg_prefix_init ()
+{
+  static gboolean initialized = FALSE;
+  const gchar *val;
+
+  if (!initialized) {
+
+    initialized = TRUE;
+    val = g_getenv ("G_MESSAGES_PREFIXED");
+
+    if (val)
+      {
+       static const GDebugKey keys[] = {
+         { "error", G_LOG_LEVEL_ERROR },
+         { "critical", G_LOG_LEVEL_CRITICAL },
+         { "warning", G_LOG_LEVEL_WARNING },
+         { "message", G_LOG_LEVEL_MESSAGE },
+         { "info", G_LOG_LEVEL_INFO },
+         { "debug", G_LOG_LEVEL_DEBUG }
+       };
+       
+       g_log_msg_prefix = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
+      }
+  }
+}
+
 static void
 g_log_write_prefix (GFileDescriptor fd,
                     GLogLevelFlags mask)
 {
-  static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG;
-  static gboolean initialized = FALSE;
-  
-  g_mutex_lock (g_messages_lock);
-
-  if (!initialized)
-    {
-      const gchar *val;
-      initialized = TRUE;
-
-      val = g_getenv ("G_MESSAGES_PREFIXED");
-      
-      if (val)
-        {
-          static const GDebugKey keys[] = {
-            { "error", G_LOG_LEVEL_ERROR },
-            { "critical", G_LOG_LEVEL_CRITICAL },
-            { "warning", G_LOG_LEVEL_WARNING },
-            { "message", G_LOG_LEVEL_MESSAGE },
-            { "info", G_LOG_LEVEL_INFO },
-            { "debug", G_LOG_LEVEL_DEBUG }
-          };
-          
-          g_log_msg_prefix = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
-        }
-    }
-  
-  g_mutex_unlock (g_messages_lock);
+  g_log_msg_prefix_init ();
   
   if ((g_log_msg_prefix & mask) == mask)
     {
@@ -504,6 +507,9 @@ g_logv (const gchar   *log_domain,
   va_end (args2);
 #endif /* !HAVE_VSNPRINTF */
   
+  if (!_g_debug_initialized) 
+    _g_debug_init ();
+
   for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
     {
       register GLogLevelFlags test_level;
@@ -1186,6 +1192,37 @@ g_printf_string_upper_bound (const gchar *format,
 void
 g_messages_init (void)
 {
-  g_messages_lock = g_mutex_new();
-  g_log_depth = g_private_new(NULL);
+  g_messages_lock = g_mutex_new ();
+  g_log_depth = g_private_new (NULL);
+  g_log_msg_prefix_init ();
+  _g_debug_init ();
+}
+
+gboolean _g_debug_initialized = FALSE;
+guint _g_debug_flags = 0;
+
+void _g_debug_init () 
+{
+  const gchar *val;
+  
+  _g_debug_initialized = TRUE;
+
+  val = g_getenv ("G_DEBUG");
+  if (val != NULL)
+    {
+      static const GDebugKey keys[] = {
+       {"fatal_warnings", G_DEBUG_FATAL_WARNINGS}
+      };
+
+      _g_debug_flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
+    }
+
+  if (_g_debug_flags & G_DEBUG_FATAL_WARNINGS) 
+    {
+      GLogLevelFlags fatal_mask;
+      
+      fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+      fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+      g_log_set_always_fatal (fatal_mask);
+    }
 }