- stopping gdb in any case...
 
 
 import gtk
+import os
 import pango
 import pty
 import string
        isactive = True
        lastrow = 0
        history = []
+       childpid = None
 
 
-       def __init__(self, clientCmd):
+       def __init__(self, clientCmd, exitcb=None):
 
                vte.Terminal.__init__(self)
 
+               def onChildExited():
+                       self.childpid = None
+                       if exitcb != None:
+                               exitcb()
+
                #Start debugger
                self.clientCmd = clientCmd
                #Open pseudo-terminal where to-be-debugged process reads/writes to
 
                #Set up terminal window and initialize debugger
                self.connect("cursor-moved", self.contents_changed)
-               self.connect("child-exited", lambda *w: gtk.main_quit())
+               self.connect("child-exited", lambda *w: onChildExited())
 
                #font description
                fontdesc = pango.FontDescription("monospace 9")
 
 
        def initialize(self):
-               self.fork_command( self.getCommand(), self.getArgv())
+               self.childpid = self.fork_command( self.getCommand(), self.getArgv())
                self.setPty(self.client_ptyslave)
                self.waitForActivation()
 
+       def stopDbg(self):
+
+               if self.childpid != None:
+                       os.kill(self.childpid, 15);
+                       self.childpid = None
+
+
 
        def contents_changed(self, term):
                c,r = term.get_cursor_position()
 
 class GdbTerminal (DbgTerminal.DbgTerminal):
 
 
-       def __init__(self, clientCmd):
-               DbgTerminal.DbgTerminal.__init__(self, clientCmd)
+       def __init__(self, clientCmd, exitcb=None):
+               DbgTerminal.DbgTerminal.__init__(self, clientCmd, exitcb)
 
        def getArgv(self):
                return ["gdb", "--fullname", string.split(self.clientCmd)[0]]
 
        #Callbacks for new positions
        newPosCbs = []
 
-       def __init__(self, dbgterm, quitonclose=True):
+       def __init__(self, dbgterm, closecb=None):
 
                #Set up GTK stuff
                gtk.Window.__init__(self)
-               if quitonclose:
-                       self.connect("destroy", lambda *w: gtk.main_quit() )
+
+               if closecb!=None:
+                       self.connect("destroy", lambda *w: closecb() )
 
                #Set terminals
                self.dbgterm = dbgterm
 
 
 class StatusWindow (gtk.Window):
 
-       def __init__(self, mainctrlwnd, debugger, quitonclose=True):
+       def __init__(self, mainctrlwnd, debugger, closecb=None):
 
                gtk.Window.__init__(self)
                self.set_screen(mainctrlwnd.get_screen())
                self.set_title("Status")
                self.set_default_size(400,600)
 
-               if quitonclose:
-                       self.connect("destroy", lambda *w: gtk.main_quit())
+               if closecb!=None:
+                       self.connect("destroy", lambda *w: closecb())
 
 
                #Register callback function for new positions
 
 __author__ = "shuber"
 
 import gtk
+import os
 import string
 import sys
 
 import StatusWindow
 
 
-def launchDebugger(clientCmd):
+def launchDebugger(clientCmd, quitonclose=True):
+
+       
+
+       def hideWindows():
+               #Kill the debugger
+               dbgterm.stopDbg()
+
+               mainCtrlWnd.destroy()
+               statusWnd.destroy()
+               gtk.main_quit()
+
+       
+
+       #Determine the closing callback func
+       if quitonclose:
+               destroycb = gtk.main_quit
+       else:
+               destroycb = hideWindows
+
        #Create Terminal
-       dbgterm = GdbTerminal.GdbTerminal(clientCmd)
+       dbgterm = GdbTerminal.GdbTerminal(clientCmd, destroycb)
 
        #Create windows
-       mainCtrlWnd = MainControlWindow.MainControlWindow(dbgterm)
-       statusWnd = StatusWindow.StatusWindow(mainCtrlWnd, dbgterm)
+       mainCtrlWnd = MainControlWindow.MainControlWindow(dbgterm, destroycb)
+       statusWnd = StatusWindow.StatusWindow(mainCtrlWnd, dbgterm, destroycb)
        dbgterm.initialize()
 
-       gtk.main()
+       return dbgterm, mainCtrlWnd, statusWnd
 
 
 
        #Create the terminals
        clientCmd = string.join(sys.argv[1:])
        launchDebugger(clientCmd)
+       gtk.main()
 
 
 
 #Do not use a ~ for home directory
 sys.path.append("/home/shuber/projekte/pygdb/")
 
+import pygdb
 import GdbTerminal
 import MainControlWindow
 import StatusWindow
        if gdbterm == None:
 
                clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
-               gdbterm = GdbTerminal.GdbTerminal(clientcmd)
-               mainctrlwnd = MainControlWindow.MainControlWindow(gdbterm, quitonclose=False)
-               statuswnd = StatusWindow.StatusWindow(mainctrlwnd, gdbterm, quitonclose=False)
-               gdbterm.initialize()
 
+               gdbterm, mainctrlwnd, statuswnd = pygdb.launchDebugger(clientcmd, False)
 
                for bp in gdbBps:
                        statuswnd.breakpointsFrame.addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
 
                gtk.main()
-               gtk.main()
-               print "hello"
-               #mainctrlwnd.hide()
-               #statuswnd.hide()
+               gdbterm = None  
 
 
 def gdbToggleBreakpoint(lineno=None, file=None):