X-Git-Url: https://git.sthu.org/?p=pygdb.git;a=blobdiff_plain;f=Configuration.py;h=778afb2334a15469d08b4c1548a0fbc35256a99f;hp=1aeb258a48320eeeb1b27d190fa6aeb6310cd068;hb=HEAD;hpb=8a09be35138b09a6871dfc323a9e6e3a825a286b diff --git a/Configuration.py b/Configuration.py old mode 100755 new mode 100644 index 1aeb258..778afb2 --- a/Configuration.py +++ b/Configuration.py @@ -13,13 +13,21 @@ import StatusWindow class Configuration: def __init__(self): + self.clear() + + + def clear(self): self.breakpoints = [] self.watches = [] self.ints = [] + self.currfile, self.currlineno = None, 0 + self.command = None def load(self, filename): try: + self.clear() + cnt = 0 #Parse all lines f = file(filename, "r") @@ -36,6 +44,10 @@ class Configuration: self.parseWatch(tail) elif cmd == "int": self.parseInt(tail) + elif cmd == "currpos": + self.parseCurrpos(tail) + elif cmd == "cmd": + self.parseCommand(tail) else: cnt -= 1 print "Unkown command", cmd @@ -59,6 +71,12 @@ class Configuration: for s in self.ints: self.__writeInt(f, s) + if self.isCurrposSet(): + self.__writeCurrpos(f) + + if self.getCommand() != None: + self.__writeCommand(f) + f.close() return True @@ -76,8 +94,8 @@ class Configuration: print "Wrong breakpoint format:", tail return - preif = string.split(tail, "if")[0].strip() - postif = string.join( string.split(tail, "if")[1:], "if").strip() + preif = string.split(tail, " if ")[0].strip() + postif = string.join( string.split(tail, " if ")[1:], " if ").strip() [file,lineno] = string.split(preif, ":") lineno = int(lineno) @@ -103,6 +121,23 @@ class Configuration: def parseWatch(self, tail): self.addWatch(tail) + def parseCurrpos(self, tail): + + tail = tail.strip() + rx = re.compile("^[\w/\._\-]+:\d+$") + + if not rx.search(tail): + print "Wrong current position format:", tail + return + + [file,lineno] = string.split(tail, ":") + lineno = int(lineno) + + self.setCurrpos(file, lineno) + + def parseCommand(self, tail): + self.command = tail + def __writeBreak(self, f, b): if b["cond"] != None: @@ -116,6 +151,12 @@ class Configuration: def __writeWatch(self, f, w): f.write("watch %(expr)s\n" % w) + def __writeCurrpos(self, f): + f.write("currpos %s:%d\n" % (self.currfile, self.currlineno)) + + def __writeCommand(self, f): + f.write("cmd %s\n" % self.command) + def addBreak(self, file, lineno, cond=None): bp = {"file" : file, "lineno" : lineno, "cond" : cond} @@ -132,6 +173,21 @@ class Configuration: if not w in self.watches: self.watches += [w] + def setCurrpos(self, file, lineno): + self.currfile, self.currlineno = file, lineno + + def isCurrposSet(self): + return self.currfile!=None + + + def delCurrpos(self): + self.currfile = None + + def setCommand(self,cmd): + self.command = cmd + + def getCommand(self): + return self.command def findInt(self, name): for i in self.ints: @@ -143,7 +199,8 @@ class Configuration: def __str__(self): return "breakpoints=" + str(self.breakpoints) + \ ", watches=" + str(self.watches) + \ - ", ints=" + str(self.ints) + ", ints=" + str(self.ints) + \ + ", currpos=" + str((self.currfile, self.currlineno))