nautilus-3.6.3/eel/eel-debug.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
  2 
  3    eel-debug.c: Eel debugging aids.
  4  
  5    Copyright (C) 2000, 2001 Eazel, Inc.
  6   
  7    This program is free software; you can redistribute it and/or
  8    modify it under the terms of the GNU Library General Public License as
  9    published by the Free Software Foundation; either version 2 of the
 10    License, or (at your option) any later version.
 11   
 12    This program is distributed in the hope that it will be useful,
 13    but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15    Library General Public License for more details.
 16   
 17    You should have received a copy of the GNU Library General Public
 18    License along with this program; if not, write to the
 19    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 20    Boston, MA 02111-1307, USA.
 21   
 22    Author: Darin Adler <darin@eazel.com>
 23 */
 24 
 25 #include <config.h>
 26 #include "eel-debug.h"
 27 
 28 #include <glib.h>
 29 #include <signal.h>
 30 #include <stdio.h>
 31 
 32 typedef struct {
 33 	gpointer data;
 34 	GFreeFunc function;
 35 } ShutdownFunction;
 36 
 37 static GList *shutdown_functions;
 38 
 39 /* Raise a SIGINT signal to get the attention of the debugger.
 40  * When not running under the debugger, we don't want to stop,
 41  * so we ignore the signal for just the moment that we raise it.
 42  */
 43 static void
 44 eel_stop_in_debugger (void)
 45 {
 46 	void (* saved_handler) (int);
 47 
 48 	saved_handler = signal (SIGINT, SIG_IGN);
 49 	raise (SIGINT);
 50 	signal (SIGINT, saved_handler);
 51 }
 52 
 53 /* Stop in the debugger after running the default log handler.
 54  * This makes certain kinds of messages stop in the debugger
 55  * without making them fatal (you can continue).
 56  */
 57 static void
 58 log_handler (const char *domain,
 59 	     GLogLevelFlags level,
 60 	     const char *message,
 61 	     gpointer data)
 62 {
 63 	g_log_default_handler (domain, level, message, data);
 64 	if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0) {
 65 		eel_stop_in_debugger ();
 66 	}
 67 }
 68 
 69 void
 70 eel_make_warnings_and_criticals_stop_in_debugger (void)
 71 {
 72 	g_log_set_default_handler (log_handler, NULL);
 73 }
 74 
 75 void
 76 eel_debug_shut_down (void)
 77 {
 78 	ShutdownFunction *f;
 79 
 80 	while (shutdown_functions != NULL) {
 81 		f = shutdown_functions->data;
 82 		shutdown_functions = g_list_remove (shutdown_functions, f);
 83 		
 84 		f->function (f->data);
 85 		g_free (f);
 86 	}
 87 }
 88 
 89 void
 90 eel_debug_call_at_shutdown (EelFunction function)
 91 {
 92 	eel_debug_call_at_shutdown_with_data ((GFreeFunc) function, NULL);
 93 }
 94 
 95 void
 96 eel_debug_call_at_shutdown_with_data (GFreeFunc function, gpointer data)
 97 {
 98 	ShutdownFunction *f;
 99 
100 	f = g_new (ShutdownFunction, 1);
101 	f->data = data;
102 	f->function = function;
103 	shutdown_functions = g_list_prepend (shutdown_functions, f);
104 }