Пример #1
0
/**
 * egg_debug_print_line:
 **/
static void
egg_debug_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
{
	gchar *str_time;
	gchar *header;
	time_t the_time;

	time (&the_time);
	str_time = g_new0 (gchar, 255);
	strftime (str_time, 254, "%H:%M:%S", localtime (&the_time));

	/* generate header text */
	header = g_strdup_printf ("TI:%s\tFI:%s\tFN:%s,%d", str_time, file, func, line);
	g_free (str_time);

	/* always in light green */
	egg_debug_set_console_mode (CONSOLE_GREEN);
	printf ("%s\n", header);

	/* different colors according to the severity */
	egg_debug_set_console_mode (color);
	printf (" - %s\n", buffer);
	egg_debug_set_console_mode (CONSOLE_RESET);

	/* log to a file */
	if (_log_filename != NULL) {
		egg_debug_log_line (header);
		egg_debug_log_line (buffer);
	}

	/* flush this output, as we need to debug */
	fflush (stdout);

	g_free (header);
}
Пример #2
0
/**
 * egg_debug_backtrace:
 **/
void
egg_debug_backtrace (void)
{
#ifdef HAVE_EXECINFO_H
	void *call_stack[512];
	int  call_stack_size;
	char **symbols;
	int i = 1;

	call_stack_size = backtrace (call_stack, G_N_ELEMENTS (call_stack));
	symbols = backtrace_symbols (call_stack, call_stack_size);
	if (symbols != NULL) {
		egg_debug_set_console_mode (CONSOLE_RED);
		g_print ("Traceback:\n");
		while (i < call_stack_size) {
			g_print ("\t%s\n", symbols[i]);
			i++;
		}
		egg_debug_set_console_mode (CONSOLE_RESET);
		free (symbols);
	}
#endif
}