seed r277 - in trunk: . libseed src



Author: hortont
Date: Fri Nov 21 17:32:46 2008
New Revision: 277
URL: http://svn.gnome.org/viewvc/seed?rev=277&view=rev

Log:
Add debugging framework; don't segfault if given a nonexistant file.


Added:
   trunk/libseed/seed-debug.h
Modified:
   trunk/configure.ac
   trunk/libseed/Makefile.am
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-private.h
   trunk/src/main.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Fri Nov 21 17:32:46 2008
@@ -66,6 +66,25 @@
     AC_DEFINE(HAVE_LIBREADLINE, 1, [have readline]),
     AC_MSG_ERROR([readline not found]))
 
+m4_define([debug_default], "yes")
+
+AC_ARG_ENABLE(debug,
+              AC_HELP_STRING([--enable-debug=@<:@no/yes@:>@],
+                             [build debugging code. This does not actually enable debugging, it only builds the code in. Pass --seed-debug=(misc/finalization/initialization/signal/all) to enable debugging. @<:@default=debug_default@:>@]),
+,
+              enable_debug=debug_default)
+
+if test "x$enable_debug" = "xyes"; then
+  test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
+  SEED_DEBUG_CFLAGS="-DSEED_ENABLE_DEBUG"
+else
+  if test "x$enable_debug" = "xno"; then
+    SEED_DEBUG_CFLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS -DG_DISABLE_CAST_CHECKS"
+  fi
+fi
+
+AC_SUBST(SEED_DEBUG_CFLAGS)
+
 PKG_CHECK_MODULES(SEED, gobject-introspection-1.0 webkit-1.0)
 PKG_CHECK_MODULES(LIBSEED, gobject-introspection-1.0 webkit-1.0)
 

Modified: trunk/libseed/Makefile.am
==============================================================================
--- trunk/libseed/Makefile.am	(original)
+++ trunk/libseed/Makefile.am	Fri Nov 21 17:32:46 2008
@@ -36,7 +36,7 @@
 EXTRA_DIST = \
 	$(seedheaders_HEADERS)
 
-LIBSEED_CFLAGS+=-Werror
+LIBSEED_CFLAGS+=-Werror $(SEED_DEBUG_CFLAGS)
 
 ## File created by the gnome-build tools
 

Added: trunk/libseed/seed-debug.h
==============================================================================
--- (empty file)
+++ trunk/libseed/seed-debug.h	Fri Nov 21 17:32:46 2008
@@ -0,0 +1,42 @@
+#ifndef _SEED_DEBUG_H
+#define _SEED_DEBUG_H
+
+// Borrowed from Clutter, more or less.
+
+#include <glib.h>
+
+typedef enum
+{
+	SEED_DEBUG_ALL = 1 << 0,
+	SEED_DEBUG_MISC = 1 << 1,
+	SEED_DEBUG_FINALIZATION = 1 << 2,
+	SEED_DEBUG_INITIALIZATION = 1 << 3,
+	SEED_DEBUG_SIGNAL = 1 << 4
+} SeedDebugFlag;
+
+#ifdef SEED_ENABLE_DEBUG
+
+#define SEED_NOTE(type,...)  G_STMT_START {                 \
+    if ((seed_debug_flags & SEED_DEBUG_##type) ||           \
+        seed_debug_flags & SEED_DEBUG_ALL)                  \
+    {                                                       \
+        gchar * _fmt = g_strdup_printf (__VA_ARGS__);       \
+        g_message ("[" #type "] " G_STRLOC ": %s",_fmt);    \
+        g_free (_fmt);                                      \
+    }                                                       \
+} G_STMT_END
+
+#define SEED_MARK()      SEED_NOTE(MISC, "== mark ==")
+#define SEED_DBG(x) { a }
+
+#else /* !SEED_ENABLE_DEBUG */
+
+#define SEED_NOTE(type,...)
+#define SEED_MARK()
+#define SEED_DBG(x)
+
+#endif /* SEED_ENABLE_DEBUG */
+
+extern guint seed_debug_flags;
+
+#endif

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Fri Nov 21 17:32:46 2008
@@ -32,6 +32,17 @@
 
 gchar *glib_message = 0;
 
+guint seed_debug_flags = 0;  /* global seed debug flag */
+
+#ifdef SEED_ENABLE_DEBUG
+static const GDebugKey seed_debug_keys[] = {
+  { "misc", SEED_DEBUG_MISC },
+  { "finalization", SEED_DEBUG_FINALIZATION },
+  { "initialization", SEED_DEBUG_INITIALIZATION },
+  { "signal", SEED_DEBUG_SIGNAL }
+};
+#endif /* SEED_ENABLE_DEBUG */
+
 static JSObjectRef
 seed_gobject_constructor_invoked(JSContextRef ctx,
 				 JSObjectRef constructor,
@@ -970,6 +981,89 @@
     glib_message = g_strdup(message);
 }
 
+#ifdef SEED_ENABLE_DEBUG
+static gboolean
+seed_arg_debug_cb (const char *key,
+                   const char *value,
+                   gpointer    user_data)
+{
+    seed_debug_flags |=
+        g_parse_debug_string (value,
+                              seed_debug_keys,
+                              G_N_ELEMENTS (seed_debug_keys));
+    return TRUE;
+}
+
+static gboolean
+seed_arg_no_debug_cb (const char *key,
+                      const char *value,
+                      gpointer    user_data)
+{
+    seed_debug_flags &=
+        ~g_parse_debug_string (value,
+                               seed_debug_keys,
+                               G_N_ELEMENTS (seed_debug_keys));
+    return TRUE;
+}
+#endif /* SEED_ENABLE_DEBUG */
+
+static GOptionEntry seed_args[] = {
+#ifdef SEED_ENABLE_DEBUG
+  { "seed-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_debug_cb,
+    "Seed debugging flags to set", "FLAGS" },
+  { "seed-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_no_debug_cb,
+    "Seed debugging flags to unset", "FLAGS" },
+#endif /* SEED_ENABLE_DEBUG */
+  { NULL, },
+};
+
+GOptionGroup * seed_get_option_group (void)
+{
+    GOptionGroup *group;
+
+    group = g_option_group_new ("seed",
+                              "Seed Options",
+                              "Show Seed Options",
+                              NULL,
+                              NULL);
+
+    g_option_group_add_entries (group, seed_args);
+
+    return group;
+}
+
+static gboolean seed_parse_args(int * argc, char *** argv)
+{
+    GOptionContext *option_context;
+    GOptionGroup   *seed_group;
+    GError         *error = NULL;
+    gboolean        ret = TRUE;
+
+    option_context = g_option_context_new (NULL);
+    g_option_context_set_ignore_unknown_options (option_context, TRUE);
+    g_option_context_set_help_enabled (option_context, FALSE);
+
+    /* Initiate any command line options from the backend */
+
+    seed_group = seed_get_option_group ();
+    g_option_context_set_main_group (option_context, seed_group);
+
+    if (!g_option_context_parse (option_context, argc, argv, &error))
+    {
+        if (error)
+        {
+            g_warning ("%s", error->message);
+            g_error_free (error);
+        }
+
+        ret = FALSE;
+    }
+
+    g_option_context_free (option_context);
+
+    return ret;
+}
+
 gboolean seed_init(gint * argc, gchar *** argv)
 {
     JSObjectRef seed_obj_ref;
@@ -978,6 +1072,16 @@
     g_type_init();
     g_log_set_handler("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler, 0);
 
+    if (seed_parse_args (argc, argv) == FALSE)
+    {
+        SEED_NOTE(MISC, "failed to parse arguments.");
+        return false;
+    }
+    
+    
+	SEED_NOTE(MISC, "== mark ==");
+
+
     qname = g_quark_from_static_string("js-type");
     qprototype = g_quark_from_static_string("js-prototype");
 
@@ -1018,7 +1122,6 @@
     JSStringRelease(defaults_script);
 
     return TRUE;
-
 }
 
 SeedScript *seed_make_script(const gchar * js, const gchar * source_url,
@@ -1030,7 +1133,7 @@
 
     if (source_url)
     {
-	ret->source_url = JSStringCreateWithUTF8CString(source_url);
+	    ret->source_url = JSStringCreateWithUTF8CString(source_url);
     }
     ret->line_number = line_number;
 

Modified: trunk/libseed/seed-private.h
==============================================================================
--- trunk/libseed/seed-private.h	(original)
+++ trunk/libseed/seed-private.h	Fri Nov 21 17:32:46 2008
@@ -37,6 +37,7 @@
     JSObjectRef global;
 };
 
+#include "seed-debug.h"
 #include "seed-engine.h"
 #include "seed-types.h"
 #include "seed-signals.h"

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Fri Nov 21 17:32:46 2008
@@ -22,6 +22,7 @@
 #include <glib-object.h>
 #include <stdio.h>
 #include "../libseed/seed.h"
+#include "../libseed/seed-debug.h"
 #include <readline/readline.h>
 #include <stdlib.h>
 #include <girepository.h>
@@ -45,8 +46,13 @@
 	SeedException e;
 	gchar * buffer;
 
-	g_file_get_contents(argv[1], 
-	&buffer, 0, 0);
+	g_file_get_contents(argv[1], &buffer, 0, 0);
+
+	if(!buffer)
+	{
+		g_critical("File %s not found!", argv[1]);
+		exit(1);
+	}
 
 	if (*buffer == '#')
 	{
@@ -55,7 +61,7 @@
 		buffer++;
 	}
 	script = seed_make_script(buffer, argv[1], 1);
-	if (e =seed_script_exception(script))
+	if (e = seed_script_exception(script))
 	{
 		g_critical("%s. %s in %s at line %d",
 			   seed_exception_get_name(e),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]