From 054679cd2c3372717bf7982407e2453428193581 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 9 Jun 2008 14:54:43 +0200 Subject: [PATCH] - fixing problem of destroying windows -> segfault - stopping gdb in any case... --- DbgTerminal.py | 20 +++++++++++++++++--- GdbTerminal.py | 4 ++-- MainControlWindow.py | 7 ++++--- StatusWindow.py | 6 +++--- pygdb.py | 31 ++++++++++++++++++++++++++----- pygdb.vim | 11 +++-------- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/DbgTerminal.py b/DbgTerminal.py index 89659d0..21aa1c4 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -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() diff --git a/GdbTerminal.py b/GdbTerminal.py index bc5d1e7..3656701 100755 --- a/GdbTerminal.py +++ b/GdbTerminal.py @@ -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]] diff --git a/MainControlWindow.py b/MainControlWindow.py index 4866134..6dbbf2e 100644 --- a/MainControlWindow.py +++ b/MainControlWindow.py @@ -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 diff --git a/StatusWindow.py b/StatusWindow.py index e1f4db9..84811c2 100644 --- a/StatusWindow.py +++ b/StatusWindow.py @@ -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 diff --git a/pygdb.py b/pygdb.py index 66fe634..077bc1c 100755 --- 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() diff --git a/pygdb.vim b/pygdb.vim index b38a173..1926f3e 100644 --- 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): -- 2.39.5