import os
import pango
import pty
+import re
import string
import sys
import time
def initialize(self):
self.childpid = self.fork_command( self.getCommand(), self.getArgv())
- self.waitForActivation(0)
+ self.waitForPrompt(0)
self.setPty(self.client_ptyslave)
def stopDbg(self):
os.kill(self.childpid, 15);
self.childpid = None
+ def getClientExecuteable(self):
+ return string.split(self.clientCmd)[0]
+
+
+ def toAbsPath(self, path):
+ """convert path to an absolute path relative to the client
+ executable we debug."""
+
+ #Current working dir
+ pwd = os.getcwd() + "/"
+
+ #executeable path
+ client = self.getClientExecuteable()
+ client = relToAbsPath(pwd, client)
+
+ return relToAbsPath(client, path)
+
+
def checkActivityChanged(self):
try:
status, param = res
if self.isActive():
+ print "got active: ", res
for cb in self.gotActiveCallback:
cb(status, param)
else:
+ print "got inactive: ", res
for cb in self.gotInactiveCallback:
cb(status, param)
- except:
- pass
+ except Exception, e:
+ print e
return True
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)
+ text = self.get_text_range(self.lastr,0,r,c,lambda *w:True)
self.lastc, self.lastr = c,r
#Remove annoying \n at the end
assert(text[-1] == "\n")
text = text[:-1]
+
#Get the lines and remove empty lines
lines = string.split(text, "\n")
#Remove the incomplete line
- len = max(0,self.getHistoryLen()-1)
- self.history[-1] += lines[0]
+ len = max(0,self.getHistoryLen())
+ self.history[-1] = lines[0]
self.history += lines[1:]
#Check if activity status has been changed
for i in range(len, self.getHistoryLen()):
line = self.history[i]
+
+ res = self.testForInactivity(i)
+ if res != None:
+ while self.activityChanged != None:
+ print "wait for pending activity"
+ gtk.main_iteration()
+
+ self.setActive(False)
+ self.activityChanged = res
res = self.testForActivity(i)
- if res != None and not self.isActive():
+ if res != None:
+ while self.activityChanged != None:
+ print "wait for pending activity"
+ gtk.main_iteration()
+
self.setActive(True)
self.activityChanged = res
-
- res = self.testForInactivity(i)
- if res != None and self.isActive():
- self.setActive(False)
- self.activityChanged = res
+
def getHistoryLen(self):
return len(self.history)
- def waitForRx(self, rx, start):
+ def waitForRx(self, pat, start):
+
+ rx = re.compile(pat)
curr = start
while True:
assert( curr>=start )
#Do not forget the last line
curr = max(start,self.getHistoryLen()-1)
- gtk.main_iteration()
+ lr, lc = self.lastr, self.lastc
+
+ while (self.lastr, self.lastc) == (lr,lc):
+ gtk.main_iteration()
def getCommand(self):
def setStepin(self):
raise NotImplementedError()
+ def setStepout(self):
+ raise NotImplementedError()
+
def setQuit(self):
raise NotImplementedError()
def getExpression(self, expr):
raise NotImplementedError()
- def waitForActivation(self, his):
+ def listCodeSnippet(self):
+ raise NotImplementedError()
+
+ def getBacktrace(self):
+ raise NotImplementedError()
+
+ def waitForPrompt(self, his):
raise NotImplementedError()
def testForActivity(self, his):
pass
+def updateVim():
+ os.system('gvim --servername pygdb --remote-send "<ESC> :GDBLoadConfig<CR>"')
+
+
+def relToAbsPath(absfile, relfile):
+ """When an absfile is given and a relfile is given by
+ relative paths relative to absfile, determine the abs
+ path of relfile"""
+
+ #Get directories except for "." parts
+ relsplit = filter(lambda x: x!=".", string.split(relfile, os.sep))
+ #Get the directories of absfile withouth the trailing filename
+ abssplit = string.split(absfile, os.sep)[:-1]
+
+ #Determine number of ".." and remove them
+ up=0
+ while relsplit[0] == "..":
+ up += 1
+ del relsplit[0]
+ del abssplit[-1]
+
+ return string.join(abssplit + relsplit, os.sep)
+
class DbgWindow (gtk.Window):