Better debugging support
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 3 Jan 2006 20:05:42 +0000 (20:05 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 3 Jan 2006 20:05:42 +0000 (20:05 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@53 ffa7fe5e-494d-0410-b361-a75ebd5db220

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

index d0c586d..84c633a 100644 (file)
@@ -9,12 +9,12 @@ AM_CPPFLAGS = @PACKAGE_CFLAGS@
 
 bin_PROGRAMS = navit
 
-navit_SOURCES = block.c command.c compass.c coord.c country.c cursor.c data_window.c destination.c \
+navit_SOURCES = block.c command.c compass.c coord.c country.c cursor.c data_window.c debug.c destination.c \
        display.c file.c graphics.c log.c main.c map-common.c map-skelimpl.c map-skels.c map-srv.c \
        map-stubs.c map_data.c menu.c navigation.c param.c phrase.c plugin.c poly.c popup.c \
        profile.c route.c search.c speech.c street.c street_name.c town.c transform.c tree.c track.c \
        util.c vehicle.c block.h command.h compass.h config.h container.h coord.h country.h \
-       cursor.h data.h data_window.h data_window_int.h destination.h display.h draw_info.h \
+       cursor.h data.h data_window.h data_window_int.h debug.h destination.h display.h draw_info.h \
        file.h graphics.h gtkext.h log.h main.h map-share.h map.h map_data.h menu.h navigation.h \
        param.h phrase.h plugin.h point.h poly.h popup.h route.h search.h speech.h statusbar.h \
        street.h street_data.h street_name.h toolbar.h town.h transform.h tree.h track.h util.h vehicle.h
diff --git a/navit/src/debug.c b/navit/src/debug.c
new file mode 100644 (file)
index 0000000..68edf71
--- /dev/null
@@ -0,0 +1,30 @@
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "file.h"
+#include "debug.h"
+
+
+
+static int sigsegv(void)
+{
+       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_remap_readonly_all();
+       fprintf(f,"dumping core\n");
+       fclose(f);      
+       abort();
+}
+
+void
+debug_init(void)
+{
+       signal(SIGSEGV, sigsegv);
+}
diff --git a/navit/src/debug.h b/navit/src/debug.h
new file mode 100644 (file)
index 0000000..fb9abbc
--- /dev/null
@@ -0,0 +1 @@
+void debug_init(void);
index 2389d8a..eb85ea1 100644 (file)
@@ -9,25 +9,26 @@
 #include <glib.h>
 #include "file.h"
 
+static struct file *file_list;
+
 struct file *
 file_create(char *name)
 {
-        int fd;
         struct stat stat;
        struct file *file=malloc(sizeof(*file)+strlen(name)+1);
 
        if (! file)
                return file; 
-        fd=open(name, O_RDONLY);
-       if (fd < 0) {
+        file->fd=open(name, O_RDONLY);
+       if (file->fd < 0) {
                free(file);
                return NULL;
        }
-        fstat(fd, &stat);
+        fstat(file->fd, &stat);
         file->size=stat.st_size;
        file->name=(char *)file+sizeof(*file);
        strcpy(file->name, name);
-        file->begin=mmap(NULL, file->size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+        file->begin=mmap(NULL, file->size, PROT_READ|PROT_WRITE, MAP_PRIVATE, file->fd, 0);
        g_assert(file->begin != NULL);
        if (file->begin == (void *)0xffffffff) {
                perror("mmap");
@@ -35,16 +36,32 @@ file_create(char *name)
        g_assert(file->begin != (void *)0xffffffff);
         file->end=file->begin+file->size;
        file->private=NULL;
-        close(fd);
 
        g_assert(file != NULL); 
+       file->next=file_list;
+       file_list=file;
         return file;
 }
 
 void
-file_set_readonly(struct file *file)
+file_remap_readonly(struct file *f)
+{
+       void *begin;
+       munmap(f->begin, f->size);
+        begin=mmap(f->begin, f->size, PROT_READ, MAP_PRIVATE, f->fd, 0);
+       if (f->begin != begin)
+               printf("remap failed\n");
+}
+
+void
+file_remap_readonly_all(void)
 {
-       mprotect(file->begin, file->end-file->begin, PROT_READ);
+       struct file *f=file_list;
+
+       while (f) {
+               file_remap_readonly(f);
+               f=f->next;
+       }
 }
 
 void *
@@ -110,6 +127,7 @@ file_create_caseinsensitive(char *name)
 void
 file_destroy(struct file *f)
 {
+        close(f->fd);
        munmap(f->begin, f->size);
        free(f);        
 }
index 4dedb89..e8e00cc 100644 (file)
@@ -6,10 +6,13 @@ struct file {
         unsigned long size;
        char *name;
        void *private;
+       int fd;
+       struct file *next;
 };
  
 struct file *file_create(char *name);
-void file_set_readonly(struct file *file);
+void file_remap_readonly(struct file *file);
+void file_remap_readonly_all(void);
 struct file *file_create_caseinsensitive(char *name);
 int file_get_param(struct file *file, struct param_list *param, int count);
 void file_destroy(struct file *f);
index 34ab1f7..434f244 100644 (file)
@@ -19,7 +19,7 @@
 #include "compass.h"
 #include "track.h"
 #include "container.h"
-
+#include "debug.h"
 
 void *speech_handle;
 
@@ -45,6 +45,7 @@ int main(int argc, char **argv)
        setlocale(LC_NUMERIC,"C");
        gtk_set_locale();
        setlocale(LC_NUMERIC,"C");
+       debug_init();
        gtk_init(&argc, &argv);
        gdk_rgb_init();