import gtk
+import os
+import pango
import pty
import string
import time
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
- 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())
+ self.connect("child-exited", lambda *w: onChildExited())
+
+ #font description
+ fontdesc = pango.FontDescription("monospace 9")
+ self.set_font(fontdesc)
+
+
+ def initialize(self):
+ 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()
- if self.lastrow < r:
- text = self.get_text_range(self.lastrow,0,r-1,-1,lambda *w:True)
- self.history += string.split(text, "\n")
+ if self.lastrow <= r:
+ text = self.get_text_range(self.lastrow,0,r,-1,lambda *w:True)
+
+ #Remove the incomplete line
+ if self.getHistoryLen()>0 and (len(self.history[-1])==0 or self.history[-1]!='\n') :
+ del self.history[-1]
+
+ #Get the lines and remove empty lines
+ lines = string.split(text, "\n")
+
+ #Remove last empty line...
+ if lines[-1] == "":
+ del lines[-1]
+
+ #Add lines to history
+ self.history += [l+"\n" for l in lines[:-1]]
+ self.history += [lines[-1]]
self.lastrow = r
- def waitForDbgNewline(self):
+
+ def waitForNewline(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):
+ def waitForRx(self, rx, start=None):
if start == None:
start = self.getHistoryLen()
return no, line
start = self.getHistoryLen()
- self.waitForDbgNewline()
+ gtk.main_iteration()
- def getDbgCommand(self):
- return self.getDbgArgv()[0];
+ def getCommand(self):
+ return self.getArgv()[0];
- def getDbgArgv(self):
+ def getArgv(self):
raise NotImplementedError()
- def setDbgPty(self, pty):
+ def setPty(self, pty):
raise NotImplementedError()
- def setDbgRun(self):
+ def setRun(self):
raise NotImplementedError()
- def setDbgQuit(self):
+ def setContinue(self):
raise NotImplementedError()
- def setDbgContinue(self):
+ def setStepover(self):
raise NotImplementedError()
- def setDbgBreakpoint(self, file, lineno):
+ def setStepin(self):
raise NotImplementedError()
- def getDbgExpression(self, expr):
+ def setQuit(self):
raise NotImplementedError()
- def getDbgLastLine(self):
- if len(self.history) == 0:
- return None
+ def setBreakpoint(self, file, lineno, condition=False):
+ raise NotImplementedError()
- return self.history[-1]
+ def delBreakpoint(self, breakpoint):
+ raise NotImplementedError()
- def feed_dbg(self, text):
- self.feed_child(text)
+ def getExpression(self, expr):
+ raise NotImplementedError()
+ def waitForActivation(self, his):
+ raise NotImplementedError()
+ def setActive(self, isactive):
+ self.isactive = isactive
+
+ def isActive(self):
+ return self.isactive
+
+
def toggleClientIOWindow(self):
if not self.clientIOWnd:
- self.clientIOWnd = ClientIOTerminal.ClientIOWindow(self, self.terminal.client_ptymaster)
+ self.clientIOWnd = ClientIOTerminal.ClientIOWindow(self, \
+ self.terminal.client_ptymaster)
else:
self.clientIOWnd.destroy()
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()
-
-
-