From 5c48ca6a99597f2a2bfa1f9718eabb6e3f8678fa Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 8 Jun 2008 10:49:24 +0200 Subject: [PATCH] new exciting GTK Main Control Window --- ClientIOWindow.py => ClientIOTerminal.py | 14 +- DbgTerminal.py | 160 +++++++++++++++++++++++ DbgWindow.py | 126 +----------------- GdbWindow.py => GdbTerminal.py | 16 ++- 4 files changed, 179 insertions(+), 137 deletions(-) rename ClientIOWindow.py => ClientIOTerminal.py (68%) create mode 100755 DbgTerminal.py rename GdbWindow.py => GdbTerminal.py (74%) diff --git a/ClientIOWindow.py b/ClientIOTerminal.py similarity index 68% rename from ClientIOWindow.py rename to ClientIOTerminal.py index 87f045e..6cb1753 100755 --- a/ClientIOWindow.py +++ b/ClientIOTerminal.py @@ -16,17 +16,21 @@ class ClientIOWindow (gtk.Window): #Set up GTK stuff gtk.Window.__init__(self) self.set_screen(parent.get_screen()) - self.connect("destroy", lambda *w: gtk.main_quit()) #Set title and add terminal self.set_title("Client I/O") - self.terminal = vte.Terminal() + self.terminal = ClientIOTerminal(pty_master) self.add(self.terminal) - #Set the pty to client - self.terminal.set_pty(pty_master) - #Show the window self.show_all() + + +class ClientIOTerminal(vte.Terminal): + + def __init__(self, pty_master): + vte.Terminal.__init__(self) + self.set_pty(pty_master) + diff --git a/DbgTerminal.py b/DbgTerminal.py new file mode 100755 index 0000000..51d6ce1 --- /dev/null +++ b/DbgTerminal.py @@ -0,0 +1,160 @@ +#!/usr/bin/python +#shuber, 2008-06-04 + +__author__ = "shuber" + + +import gtk +import pty +import string +import time +import threading +import vte + +import ClientIOTerminal + + + +class DbgTerminal (vte.Terminal): + + lastrow = 0 + history = [] + + + def __init__(self, clientCmd): + + vte.Terminal.__init__(self) + + #Start debugger + self.clientCmd = clientCmd + self.fork_command( self.getDbgCommand(), self.getDbgArgv()) + + #Open pseudo-terminal where to-be-debugged process reads/writes to + self.client_ptymaster, self.client_ptyslave = pty.openpty() + self.setDbgPty(self.client_ptyslave) + + #Set up terminal window and initialize debugger + self.connect("cursor-moved", self.contents_changed) + self.connect("eof", lambda *w: gtk.main_quit()) + + + def contents_changed(self, term): + c,r = term.get_cursor_position() + + if self.lastrow < r: + text = self.get_text_range(self.lastrow,0,r-1,-1,lambda *w:True) + self.history += string.split(text, "\n") + self.lastrow = r + + def waitForDbgNewline(self): + r = self.lastrow + while not self.lastrow > r: + gtk.main_iteration() + + def getHistoryLen(self): + return len(self.history) + + def waitForDbgRx(self, rx, start=None): + + if start == None: + start = self.getHistoryLen() + if start < 0: + start = 0 + + while True: + for no in range(start, self.getHistoryLen()): + line = self.history[no] + if rx.search(line): + return no, line + + start = self.getHistoryLen() + self.waitForDbgNewline() + + + def getDbgCommand(self): + return self.getDbgArgv()[0]; + + def getDbgArgv(self): + raise NotImplementedError() + + def setDbgPty(self, pty): + raise NotImplementedError() + + def setDbgRun(self): + raise NotImplementedError() + + def setDbgQuit(self): + raise NotImplementedError() + + def setDbgContinue(self): + raise NotImplementedError() + + def setDbgBreakpoint(self, file, lineno): + raise NotImplementedError() + + def getDbgExpression(self, expr): + raise NotImplementedError() + + def getDbgLastLine(self): + if len(self.history) == 0: + return None + + return self.history[-1] + + def feed_dbg(self, text): + self.feed_child(text) + + + + + + +class DbgWindow (gtk.Window): + + clientIOWnd = None + + + def __init__(self, terminal): + + #Set up some members + self.terminal = terminal + + #Set up GTK stuff + gtk.Window.__init__(self) + self.connect("destroy", lambda *w: gtk.main_quit()) + + #Set title and add terminal + self.set_title("Debugger I/O") + self.terminal.history = [] + self.terminal.history_length = 5 + self.add(self.terminal) + + #Show the window + self.show_all() + + def toggleClientIOWindow(self): + if not self.clientIOWnd: + self.clientIOWnd = ClientIOTerminal.ClientIOWindow(self, self.terminal.client_ptymaster) + else: + self.clientIOWnd.destroy() + self.clientIOWnd = None + + def isClientIOWindowExisting(self): + return self.clientIOWnd != None + + + + +def launchDebugger(wnd, term): + + wnd.toggleClientIOWindow() + + term.setDbgBreakpoint("main.cpp", 15) + term.setDbgRun() + res = term.getDbgExpression("a") + print "Result = ", res + + term.setDbgQuit() + + + diff --git a/DbgWindow.py b/DbgWindow.py index 6f46c6c..aa073ff 100755 --- a/DbgWindow.py +++ b/DbgWindow.py @@ -11,130 +11,6 @@ import time import threading import vte -import ClientIOWindow - - -class DbgWindow (gtk.Window): - - clientIOWnd = None - lastrow = 0 - history = [] - - - - def __init__(self, clientCmd): - - #Set up some members - self.clientCmd = clientCmd - - #Set up GTK stuff - gtk.Window.__init__(self) - self.connect("destroy", lambda *w: gtk.main_quit()) - - #Set title and add terminal - self.set_title("Debugger I/O") - self.terminal = vte.Terminal() - self.terminal.history = [] - self.terminal.history_length = 5 - self.add(self.terminal) - - #Set up terminal window and initialize debugger - self.terminal.connect("child-exited", lambda *w: gtk.main_quit()) - self.terminal.connect("cursor-moved", self.contents_changed) - self._initializeDbg() - - #Show the window - self.show_all() - - - def _initializeDbg(self): - - #Start debugger - self.terminal.fork_command( self.getDbgCommand(), self.getDbgArgv()) - - #Open pseudo-terminal where to-be-debugged process reads/writes to - self.client_ptymaster, self.client_ptyslave = pty.openpty() - self.setDbgPty(self.client_ptyslave) - - - def contents_changed(self, term): - c,r = term.get_cursor_position() - - if self.lastrow < r: - text = self.terminal.get_text_range(self.lastrow,0,r-1,-1,lambda *w:True) - self.history += string.split(text, "\n") - self.lastrow = r - - def waitForDbgNewline(self): - r = self.lastrow - while not self.lastrow > r: - gtk.main_iteration() - - def waitForDbgRx(self, rx): - while True: - start = len(self.history) - gtk.main_iteration() - - for line in self.history[start:]: - if rx.search(line): - return line - - - def getDbgCommand(self): - return self.getDbgArgv()[0]; - - def getDbgArgv(self): - raise NotImplementedError() - - def setDbgPty(self, pty): - raise NotImplementedError() - - def setDbgRun(self): - raise NotImplementedError() - - def setDbgQuit(self): - raise NotImplementedError() - - def setDbgContinue(self): - raise NotImplementedError() - - def setDbgBreakpoint(self, file, lineno): - raise NotImplementedError() - - def getDbgExpression(self, expr): - raise NotImplementedError() - - def getDbgLastLine(self): - if len(self.history) == 0: - return None - - return self.history[-1] - - def feed_dbg(self, text): - self.terminal.feed_child(text) - - - def showClientIOWindow(self): - if not self.clientIOWnd: - self.clientIOWnd = ClientIOWindow.ClientIOWindow(self, self.client_ptymaster) - - - - -def launchDebugger(wnd): - - wnd.showClientIOWindow() - - wnd.setDbgBreakpoint("main.cpp", 15) - wnd.setDbgRun() - res = wnd.getDbgExpression("a") - print "Result = ", res - - wnd.setDbgQuit() - - gtk.main() - - - +import DbgTerminal diff --git a/GdbWindow.py b/GdbTerminal.py similarity index 74% rename from GdbWindow.py rename to GdbTerminal.py index a5baaa8..79daf70 100755 --- a/GdbWindow.py +++ b/GdbTerminal.py @@ -11,14 +11,14 @@ import string import sys import time -import DbgWindow +import DbgTerminal -class GdbWindow (DbgWindow.DbgWindow): +class GdbTerminal (DbgTerminal.DbgTerminal): def __init__(self, clientCmd): - DbgWindow.DbgWindow.__init__(self, clientCmd) + DbgTerminal.DbgTerminal.__init__(self, clientCmd) def getDbgArgv(self): return ["gdb", "--fullname", string.split(self.clientCmd)[0]] @@ -44,11 +44,11 @@ class GdbWindow (DbgWindow.DbgWindow): def getDbgExpression(self, expr): - self.waitForDbgNewline() + his = self.getHistoryLen() self.feed_dbg("print " + expr + "\n") rx = re.compile("^\$[1-9][0-9]* = .*$") - response = self.waitForDbgRx(rx) + his, response = self.waitForDbgRx(rx, his) split = string.split(response, "=") return string.join(split[1:], "=").strip() @@ -58,8 +58,10 @@ class GdbWindow (DbgWindow.DbgWindow): if __name__ == "__main__": - gdbwnd = GdbWindow(string.join(sys.argv[1:])) - DbgWindow.launchDebugger(gdbwnd) + dbgterm = GdbTerminal(string.join(sys.argv[1:])) + dbgwnd = DbgTerminal.DbgWindow(dbgterm) + + DbgTerminal.launchDebugger(dbgwnd, dbgterm) -- 2.39.5