glade-debug.c 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2003 Joaquin Cuenca Abela
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 18 19 20 21
 *
 * Authors:
 *   Joaquin Cuenca Abela <e98cuenc@yahoo.com>
 */

Christian Persch's avatar
Christian Persch committed
22 23
#include "config.h"

24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "glade.h"
#include "glade-debug.h"

#ifdef G_OS_UNIX
#include <signal.h>
#endif

#ifndef RETSIGTYPE
#define RETSIGTYPE void
#endif


static void
glade_log_handler (const char *domain,
38
                   GLogLevelFlags level, const char *message, gpointer data)
39
{
40
  static volatile int want_breakpoint = 0;
41

42 43 44 45
  /* Ignore this message */
  if (g_strcmp0 ("gdk_window_set_composited called but compositing is not supported", message) != 0)
    g_log_default_handler (domain, level, message, data);

46 47 48
  if (want_breakpoint &&
      ((level & (G_LOG_LEVEL_CRITICAL /* | G_LOG_LEVEL_WARNING */ )) != 0))
    G_BREAKPOINT ();
49 50 51 52 53
}

static void
glade_set_log_handler (const char *domain)
{
54
  g_log_set_handler (domain, G_LOG_LEVEL_MASK, glade_log_handler, NULL);
55 56
}

57 58 59 60 61 62
/**
 * glade_setup_log_handlers:
 *
 * Sets up a log handler to manage all %G_LOG_LEVEL_MASK errors of domain:
 * GLib, GLib-GObject, Gtk, Gdk, and domainless.
 */
63 64 65
void
glade_setup_log_handlers ()
{
66 67 68 69 70
  glade_set_log_handler ("");
  glade_set_log_handler ("GLib");
  glade_set_log_handler ("GLib-GObject");
  glade_set_log_handler ("Gtk");
  glade_set_log_handler ("Gdk");
71
}
72 73 74 75

static GladeDebugFlag glade_debug_flags = 0;

static const GDebugKey glade_debug_keys[] = {
76 77 78 79
  { "ref-counts",    GLADE_DEBUG_REF_COUNTS },
  { "widget-events", GLADE_DEBUG_WIDGET_EVENTS },
  { "commands",      GLADE_DEBUG_COMMANDS },
  { "properties",    GLADE_DEBUG_PROPERTIES },
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  { "verify",        GLADE_DEBUG_VERIFY }
};

guint
glade_get_debug_flags (void)
{
  return glade_debug_flags;
}

void
glade_init_debug_flags (void)
{
  static gboolean initialized = FALSE;

  if (G_UNLIKELY (!initialized))
    {
      const gchar *env_string;

      initialized = TRUE;

      env_string = g_getenv ("GLADE_DEBUG");
      if (env_string != NULL)
	glade_debug_flags = 
	  g_parse_debug_string (env_string,
				glade_debug_keys,
				G_N_ELEMENTS (glade_debug_keys));
    }
}