- fixing problem of destroying windows -> segfault
[pygdb.git] / DbgTerminal.py
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()