X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=DbgTerminal.py;h=6b09426a0698313742ed85402b441cdf4b715c67;hb=505db8dd1b2862d460c7442e98c0c14ac776a4db;hp=7c494458000fb40005486ea9f8b85f64849ec4ee;hpb=9a8e5a643a533e00a2c8fdd6f03ea7b7a5e5d649;p=pygdb.git diff --git a/DbgTerminal.py b/DbgTerminal.py index 7c49445..6b09426 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -5,8 +5,11 @@ __author__ = "shuber" import gtk +import os +import pango import pty import string +import sys import time import threading import vte @@ -17,73 +20,82 @@ import ClientIOTerminal class DbgTerminal (vte.Terminal): - isactive = True - lastrow = 0 - history = [] - - def __init__(self, clientCmd): vte.Terminal.__init__(self) + #Set members + self.childpid = None + self.history = [""] + self.isactive = True + self.lastc, self.lastr = 0,0 + #Start debugger self.clientCmd = clientCmd - self.fork_command( self.getCommand(), self.getArgv()) - #Open pseudo-terminal where to-be-debugged process reads/writes to self.client_ptymaster, self.client_ptyslave = pty.openpty() - self.setPty(self.client_ptyslave) #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", quitHandler) + #font description + fontdesc = pango.FontDescription("monospace 9") + self.set_font(fontdesc) - 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,lambda *w:True) + def initialize(self): + self.childpid = self.fork_command( self.getCommand(), self.getArgv()) + self.waitForActivation(0) + self.setPty(self.client_ptyslave) - #Remove the incomplete line - if self.getHistoryLen()>0 and (len(self.history[-1])==0 or self.history[-1]!='\n') : - del self.history[-1] + def stopDbg(self): + + if self.childpid != None: + #9=KILL, 15=TERM + os.kill(self.childpid, 15); + self.childpid = None + + + + def contents_changed(self, term): + assert( self.getHistoryLen()>0 ) + + c,r = term.get_cursor_position() + text = self.get_text_range(self.lastr,self.lastc,r,c-1,lambda *w:True) + self.lastc, self.lastr = c,r - #Get the lines and remove empty lines - lines = string.split(text, "\n") + #Remove annoying \n at the end + assert(text[-1] == "\n") + text = text[:-1] - #Remove last empty line... - if lines[-1] == "": - del lines[-1] + #Get the lines and remove empty lines + lines = string.split(text, "\n") - #Add lines to history - self.history += [l+"\n" for l in lines[:-1]] - self.history += [lines[-1]] - self.lastrow = r + #Remove the incomplete line + self.history[-1] += lines[0] + self.history += lines[1:] def waitForNewline(self): - r = self.lastrow - while not self.lastrow > r: + l = self.getHistoryLen() + while not self.getHistoryLen() > l: gtk.main_iteration() def getHistoryLen(self): return len(self.history) - def waitForRx(self, rx, start=None): - - if start == None: - start = self.getHistoryLen() - if start < 0: - start = 0 - + def waitForRx(self, rx, start): + curr = start while True: - for no in range(start, self.getHistoryLen()): + assert( curr>=start ) + for no in range(curr, self.getHistoryLen()): line = self.history[no] if rx.search(line): return no, line - start = self.getHistoryLen() + #Do not forget the last line + curr = max(start,self.getHistoryLen()-1) gtk.main_iteration() @@ -129,18 +141,14 @@ class DbgTerminal (vte.Terminal): def isActive(self): return self.isactive - def getLastLine(self): - if len(self.history) == 0: - return None - - return self.history[-1] - - def feed_dbg(self, text): - self.feed_child(text) - - +def quitHandler(*w): + try: + gtk.main_quit() + except: + pass + class DbgWindow (gtk.Window): @@ -155,7 +163,7 @@ class DbgWindow (gtk.Window): #Set up GTK stuff gtk.Window.__init__(self) - self.connect("destroy", lambda *w: gtk.main_quit()) + self.connect("destroy", quitHandler) #Set title and add terminal self.set_title("Debugger I/O") @@ -179,17 +187,3 @@ class DbgWindow (gtk.Window): - -def launchDebugger(wnd, term): - - wnd.toggleClientIOWindow() - - term.setBreakpoint("main.cpp", 15) - term.setRun() - res = term.getExpression("a") - print "Result = ", res - - term.setQuit() - - -