Index: /trunk/src/lib/network/network_socket.cc
===================================================================
--- /trunk/src/lib/network/network_socket.cc	(revision 7439)
+++ /trunk/src/lib/network/network_socket.cc	(revision 7440)
@@ -120,4 +120,8 @@
 void NetworkSocket::connectToServer(IPaddress ip)
 {
+  //HACK this will cause segfault
+#warning remove this
+  int * a;
+  *a = 99;
   //check if not already connected or listening
   if (tcpSocket)
Index: /trunk/src/orxonox.cc
===================================================================
--- /trunk/src/orxonox.cc	(revision 7439)
+++ /trunk/src/orxonox.cc	(revision 7440)
@@ -34,4 +34,5 @@
 #include "parser/ini_parser/ini_parser.h"
 #include "util/loading/game_loader.h"
+#include "util/signal_handler.h"
 
 //ENGINES
@@ -84,4 +85,9 @@
 REGISTER_ARG_ARG(  _, music_volume, "audio", "Music-Volume", "Sets music volume", "vol" );
 REGISTER_ARG_ARG(  _, effects_volume, "audio", "Effects-Volume", "Sets effects volume", "vol" );
+
+#ifndef __WIN32__
+REGISTER_ARG_FLAG( _, start_gdb_on_signal, "misc", "start-gdb", "Start gdb on signal", "1");
+REGISTER_ARG_FLAG( _, write_bt_to_file, "misc", "bt-to-file", "Write backtrace to file", "1");
+#endif
 
 /**
@@ -429,4 +435,13 @@
   }
 
+  if ( Preferences::getInstance()->getString("misc", "start-gdb", "0") == "1" )
+  {
+    SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_IN_FOREGROUND );
+  }
+  else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
+  {      SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE );
+    
+  }
+  
   if( Preferences::getInstance()->getString("game", "showGui", "") == "1" )
     showGui = true;
Index: /trunk/src/util/Makefile.am
===================================================================
--- /trunk/src/util/Makefile.am	(revision 7439)
+++ /trunk/src/util/Makefile.am	(revision 7440)
@@ -12,4 +12,5 @@
 			multiplayer_team_deathmatch.cc \
 			singleplayer_shootemup.cc \
+			signal_handler.cc \
 			\
 			animation/animation3d.cc \
@@ -30,4 +31,5 @@
 			multiplayer_team_deathmatch.h \
 			singleplayer_shootemup.h \
+			signal_handler.h \
 			\
 			animation/animation3d.h \
Index: /trunk/src/util/signal_handler.cc
===================================================================
--- /trunk/src/util/signal_handler.cc	(revision 7440)
+++ /trunk/src/util/signal_handler.cc	(revision 7440)
@@ -0,0 +1,113 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Christoph Renner
+   co-programmer: ...
+*/
+
+#include "signal_handler.h"
+
+#ifndef __WIN32__
+
+SignalHandler * SignalHandler::singletonRef = NULL;
+
+SignalHandler::SignalHandler()
+{
+}
+
+void SignalHandler::doCatch( std::string appName, GdbRunType type )
+{
+  this->type = type;
+  this->appName = appName;
+  
+  catchSignal( SIGSEGV );
+  catchSignal( SIGABRT );
+}
+
+void SignalHandler::dontCatch()
+{
+  for ( SignalRecList::iterator it = sigRecList.begin(); it != sigRecList.end(); it++ )
+  {
+    signal( it->signal, it->handler );
+  }
+
+  sigRecList.clear();
+}
+
+void SignalHandler::catchSignal( int sig )
+{
+  sighandler_t handler = signal( sig, SignalHandler::sigHandler );
+
+  assert( handler != SIG_ERR );
+
+  SignalRec rec;
+  rec.signal = sig;
+  rec.handler = handler;
+
+  sigRecList.push_front( rec );
+}
+
+void SignalHandler::sigHandler( int sig )
+{
+  std::string sigName = "UNKNOWN";
+
+  switch ( sig )
+  {
+    case SIGSEGV:
+      sigName = "SIGSEGV";
+      break;
+    case SIGABRT:
+      sigName = "SIGABRT";
+      break;
+  }
+
+  printf( "recieved signal %s\ntry to write backtrace to file orxonox.backtrace\n", sigName.c_str() );
+
+  int fd[2];
+
+  assert( pipe(fd) != -1 );
+  
+  int pid = fork();
+
+  assert( pid != -1 );
+
+  if ( pid == 0 )
+  {
+    getInstance()->dontCatch();
+
+    sleep(2);
+
+    
+    return;
+  }
+  else
+  {
+    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE && fork() == 0 )
+    {
+      sleep(1);
+      write( fd[1], "c\nbt\nq\n", 7 );
+
+      exit(0);
+    }
+    
+    char command[256];
+    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE )
+    {
+      dup2( fd[0], STDIN_FILENO );
+      snprintf( command, 255, "gdb -p %d %s 1>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );
+    }
+    else
+      snprintf( command, 255, "gdb -p %d %s", pid, getInstance()->appName.c_str() );
+    execlp( "sh", "sh", "-c", command, (void*)NULL);
+  }
+}
+
+#endif /* __WIN32__ */
Index: /trunk/src/util/signal_handler.h
===================================================================
--- /trunk/src/util/signal_handler.h	(revision 7440)
+++ /trunk/src/util/signal_handler.h	(revision 7440)
@@ -0,0 +1,67 @@
+/*!
+ * @file signalhandler.h
+ * Defines game rules for this game
+ */
+
+#ifndef _SIGNAL_HANDLER_H
+#define _SIGNAL_HANDLER_H
+
+#include <list>
+#include <string>
+
+#define GDB_BT_FILE "orxonox.backtrace"
+
+enum GdbRunType{
+  GDB_RUN_WRITE_TO_FILE = 1,
+  GDB_RUN_IN_FOREGROUND
+};
+
+
+#ifndef __WIN32__
+#include <signal.h>
+
+struct SignalRec
+{
+  int signal;
+  sighandler_t handler;
+};
+
+
+typedef std::list<SignalRec> SignalRecList;
+
+class SignalHandler
+{
+  private:
+    SignalHandler();
+  public:
+    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler();
+      return SignalHandler::singletonRef; }
+
+    void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE );
+    void dontCatch();
+
+  private:
+    static void sigHandler( int sig );
+
+    void catchSignal( int sig );
+    SignalRecList sigRecList;
+
+    static SignalHandler * singletonRef;
+
+    GdbRunType type;
+
+    std::string appName;
+};
+
+#else /* if defined __WIN32__ */
+class SignalHandler
+{
+ public:
+  inline static SignalHandler* getInstance() {};
+  void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE ) {};
+  void dontCatch() {};
+};
+#endif
+
+#endif /* _SIGNAL_HANDLER_H */
+
