summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-04-10 21:18:14 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-04-10 21:18:14 +0000
commit2abb2c66f6dc075f79d46d30f59a27ed8cc2dc3e (patch)
tree45a1120fab5fa701d4d8f8a137681aa72d716a8c
parentc9d690f1dc5a0e8cfd4aba5f51a363d6b6722a39 (diff)
downloadnavit-svn-2abb2c66f6dc075f79d46d30f59a27ed8cc2dc3e.tar.gz
Add:Core:Call gdb on segfault, beginning of modularized event loop, better debug output in case of failed object creation
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/src@999 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--Makefile.am2
-rw-r--r--debug.c41
-rw-r--r--debug.h2
-rw-r--r--event.c19
-rw-r--r--event.h2
-rw-r--r--main.c33
-rw-r--r--speech.c2
-rw-r--r--xmlconfig.c8
8 files changed, 57 insertions, 52 deletions
diff --git a/Makefile.am b/Makefile.am
index 43148dcf..3ec369f1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/debug.c b/debug.c
index 7c6dc5e5..472695c0 100644
--- a/debug.c
+++ b/debug.c
@@ -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
diff --git a/debug.h b/debug.h
index 95269641..7e897129 100644
--- a/debug.h
+++ b/debug.h
@@ -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/event.c b/event.c
new file mode 100644
index 00000000..8fe59490
--- /dev/null
+++ b/event.c
@@ -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/event.h b/event.h
new file mode 100644
index 00000000..23c07ebf
--- /dev/null
+++ b/event.h
@@ -0,0 +1,2 @@
+void event_main_loop_run(void);
+void event_main_loop_quit(void);
diff --git a/main.c b/main.c
index 697edfef..f320ae67 100644
--- a/main.c
+++ b/main.c
@@ -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;
}
diff --git a/speech.c b/speech.c
index e6935868..0e49cd75 100644
--- a/speech.c
+++ b/speech.c
@@ -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) {
diff --git a/xmlconfig.c b/xmlconfig.c
index 864d7308..49df7671 100644
--- a/xmlconfig.c
+++ b/xmlconfig.c
@@ -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;
}