- fixing problem of destroying windows -> segfault
authorStefan Huber <shuber2@gmail.com>
Mon, 9 Jun 2008 12:54:43 +0000 (14:54 +0200)
committerStefan Huber <shuber2@gmail.com>
Mon, 9 Jun 2008 12:54:43 +0000 (14:54 +0200)
- stopping gdb in any case...

DbgTerminal.py
GdbTerminal.py
MainControlWindow.py
StatusWindow.py
pygdb.py
pygdb.vim

index 89659d035628a9fe7a450bffc9e603ff905eceb7..21aa1c42d790f4b1bc230be0e51c54715b627466 100644 (file)
@@ -5,6 +5,7 @@ __author__ = "shuber"
 
 
 import gtk
+import os
 import pango
 import pty
 import string
@@ -21,12 +22,18 @@ class DbgTerminal (vte.Terminal):
        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
@@ -34,7 +41,7 @@ class DbgTerminal (vte.Terminal):
 
                #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")
@@ -42,10 +49,17 @@ class DbgTerminal (vte.Terminal):
 
 
        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()
index bc5d1e7285935a934ccd4dea16c985241f12055b..3656701e5619e383a8e1a2d776ca4a2854235a4e 100755 (executable)
@@ -17,8 +17,8 @@ import DbgTerminal
 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]]
index 4866134766793687c48d1df1fcc6483c88990d01..6dbbf2e101b5698ae01e4a35bc5e8350773c746c 100644 (file)
@@ -19,12 +19,13 @@ class MainControlWindow (gtk.Window):
        #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
index e1f4db9a956d963fdb50024a537683a6f2ca485f..84811c2c7248d610d54b7f6534f047c31d7b14d2 100644 (file)
@@ -13,7 +13,7 @@ import BreakpointsFrame
 
 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())
@@ -22,8 +22,8 @@ class StatusWindow (gtk.Window):
                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
index 66fe63452f8f355adab3298b07b26b4c0455ea83..077bc1cb55adad060071a03e1f658b9d9a00af62 100755 (executable)
--- a/pygdb.py
+++ b/pygdb.py
@@ -4,6 +4,7 @@
 __author__ = "shuber"
 
 import gtk
+import os
 import string
 import sys
 
@@ -12,16 +13,35 @@ import MainControlWindow
 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
 
 
 
@@ -35,5 +55,6 @@ if __name__ == "__main__":
        #Create the terminals
        clientCmd = string.join(sys.argv[1:])
        launchDebugger(clientCmd)
+       gtk.main()
 
 
index b38a173115aca00226ac05589e4039b49f6ac3d9..1926f3e60b5406859a794c3719884c46dbc109db 100644 (file)
--- a/pygdb.vim
+++ b/pygdb.vim
@@ -18,6 +18,7 @@ import vim
 #Do not use a ~ for home directory
 sys.path.append("/home/shuber/projekte/pygdb/")
 
+import pygdb
 import GdbTerminal
 import MainControlWindow
 import StatusWindow
@@ -41,20 +42,14 @@ def gdbLaunch():
        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):