Add:Core:Call gdb on segfault, beginning of modularized event loop, better debug...
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 10 Apr 2008 21:18:14 +0000 (21:18 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 10 Apr 2008 21:18:14 +0000 (21:18 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@999 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/Makefile.am
navit/src/debug.c
navit/src/debug.h
navit/src/event.c [new file with mode: 0644]
navit/src/event.h [new file with mode: 0644]
navit/src/main.c
navit/src/speech.c
navit/src/xmlconfig.c

index 43148dc..3ec369f 100644 (file)
@@ -14,7 +14,7 @@ pkgdata_DATA = navit.xml
 EXTRA_DIST = navit.xml 
 
 navit_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_window.c debug.c \
-       file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
+       event.c file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
        mapset.c maptype.c menu.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
        profile.c projection.c route.c search.c speech.c transform.c track.c \
        util.c vehicle.c xmlconfig.c attr.h attr_def.h callback.h color.h compass.h coord.h country.h \
index 7c6dc5e..472695c 100644 (file)
@@ -9,33 +9,26 @@
 #include "debug.h"
 
 
-int debug_level=0;
+int debug_level=0,segv_level=0;
 static GHashTable *debug_hash;
+static char *gdb_program;
 
-#if 0
 static void sigsegv(int sig)
 {
-       FILE *f;
-       time_t t;
-       printf("segmentation fault received\n");
-       f=fopen("crash.txt","a");
-       setvbuf(f, NULL, _IONBF, 0);
-       fprintf(f,"segmentation fault received\n");
-       t=time(NULL);
-       fprintf(f,"Time: %s", ctime(&t));
-       file_unmap_all();
-       fprintf(f,"dumping core\n");
-       fclose(f);      
-       abort();
+       char buffer[256];
+       if (segv_level > 1)
+               sprintf(buffer, "gdb -ex bt %s %d", gdb_program, getpid());
+       else
+               sprintf(buffer, "gdb -ex bt -ex detach -ex quit %s %d", gdb_program, getpid());
+       system(buffer);
+       exit(1);
 }
-#endif
 
 void
-debug_init(void)
+debug_init(const char *program_name)
 {
-#if 0
+       gdb_program=program_name;
        signal(SIGSEGV, sigsegv);
-#endif
        debug_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 }
 
@@ -51,8 +44,16 @@ void
 debug_level_set(const char *name, int level)
 {
        debug_level=0;
-       g_hash_table_insert(debug_hash, g_strdup(name), (gpointer) level);
-       g_hash_table_foreach(debug_hash, debug_update_level, NULL);     
+       if (strcmp(name,"segv")) {
+               g_hash_table_insert(debug_hash, g_strdup(name), (gpointer) level);
+               g_hash_table_foreach(debug_hash, debug_update_level, NULL);     
+       } else {
+               segv_level=level;
+               if (segv_level)
+                       signal(SIGSEGV, sigsegv);
+               else
+                       signal(SIGSEGV, NULL);
+       }
 }
 
 int
index 9526964..7e89712 100644 (file)
@@ -13,7 +13,7 @@ extern int debug_level;
 #define dbg(level,fmt...) ({ if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,fmt); })
 
 /* prototypes */
-void debug_init(void);
+void debug_init(const char *program_name);
 void debug_level_set(const char *name, int level);
 int debug_level_get(const char *name);
 void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
diff --git a/navit/src/event.c b/navit/src/event.c
new file mode 100644 (file)
index 0000000..8fe5949
--- /dev/null
@@ -0,0 +1,19 @@
+#include <glib.h>
+#include "event.h"
+
+static GMainLoop *loop;
+
+void event_main_loop_run(void)
+{
+       loop = g_main_loop_new (NULL, TRUE);
+        if (g_main_loop_is_running (loop))
+        {
+               g_main_loop_run (loop);
+       }
+}
+
+void event_main_loop_quit(void)
+{
+       if (loop)
+               g_main_loop_quit(loop);
+} 
diff --git a/navit/src/event.h b/navit/src/event.h
new file mode 100644 (file)
index 0000000..23c07eb
--- /dev/null
@@ -0,0 +1,2 @@
+void event_main_loop_run(void);
+void event_main_loop_quit(void);
index 697edfe..f320ae6 100644 (file)
@@ -13,9 +13,6 @@
 
 #include <unistd.h>
 #include <libintl.h>
-#ifdef USE_GTK_MAIN_LOOP
-#include <gtk/gtk.h>
-#endif
 #include "config.h"
 #include "file.h"
 #include "debug.h"
@@ -27,6 +24,7 @@
 #include "coord.h"
 #include "route.h"
 #include "navigation.h"
+#include "event.h"
 
 #define _(STRING)    gettext(STRING)
 
@@ -63,9 +61,6 @@ static gchar *get_home_directory(void)
 }
 
 static GList *navit;
-#ifndef USE_GTK_MAIN_LOOP
-static GMainLoop *loop;
-#endif
 
 struct iter {
        GList *list;
@@ -112,14 +107,8 @@ void
 main_remove_navit(struct navit *nav)
 {
        navit=g_list_remove(navit, nav);
-       if (! navit) {
-#ifdef USE_GTK_MAIN_LOOP
-               gtk_main_quit();
-#else
-               if (loop)
-                       g_main_loop_quit(loop);
-#endif
-       }
+       if (! navit) 
+               event_main_loop_quit();
 }
 
 int main(int argc, char **argv)
@@ -137,7 +126,6 @@ int main(int argc, char **argv)
        setenv("LC_NUMERIC","C",1);
        setlocale(LC_ALL,"");
        setlocale(LC_NUMERIC,"C");
-
        if (file_exists("navit.c") || file_exists("navit.o")) {
                char buffer[PATH_MAX];
                printf(_("Running from source directory\n"));
@@ -184,7 +172,7 @@ int main(int argc, char **argv)
        bind_textdomain_codeset (PACKAGE, "UTF-8");
        textdomain(PACKAGE);
 
-       debug_init();
+       debug_init(argv[0]);
        if (getenv("LC_ALL")) 
                dbg(0,"Warning: LC_ALL is set, this might lead to problems\n");
 #ifndef USE_PLUGINS
@@ -251,17 +239,8 @@ int main(int argc, char **argv)
        }
        if (main_loop_gui) {
                gui_run_main_loop(main_loop_gui);
-       } else {
-#ifdef USE_GTK_MAIN_LOOP
-               gtk_main();
-#else
-               loop = g_main_loop_new (NULL, TRUE);
-               if (g_main_loop_is_running (loop))
-               {
-                       g_main_loop_run (loop);
-               }
-#endif
-       }
+       } else 
+               event_main_loop_run();
 
        return 0;
 }
index e693586..0e49cd7 100644 (file)
@@ -15,7 +15,7 @@ speech_new(const char *type, const char *data)
        struct speech *this_;
        struct speech_priv *(*speech_new)(const char *data, struct speech_methods *meth);
 
-       dbg("enter type=%s data=%s\n", type, data);
+       dbg(1,"enter type=%s data=%s\n", type, data);
         speech_new=plugin_get_speech_type(type);
        dbg(1,"new=%p\n", speech_new);
         if (! speech_new) {
index 864d730..49df767 100644 (file)
@@ -241,8 +241,10 @@ xmlconfig_graphics(struct xmlstate *state)
                return 0;
        attrs=convert_to_attrs(state);
        state->element_object = graphics_new(type, attrs);
-       if (! state->element_object)
+       if (! state->element_object) {
+               dbg(0,"Failed to create graphics '%s'\n", type);
                return 0;
+       }
        navit_set_graphics(state->parent->element_object, state->element_object, type);
        return 1;
 }
@@ -256,8 +258,10 @@ xmlconfig_gui(struct xmlstate *state)
                return 0;
        attrs=convert_to_attrs(state);
        state->element_object = gui_new(state->parent->element_object, type, attrs);
-       if (! state->element_object)
+       if (! state->element_object) {
+               dbg(0,"Failed to create gui '%s'\n", type);
                return 0;
+       }
        navit_set_gui(state->parent->element_object, state->element_object, type);
        return 1;
 }