X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=Configuration.py;h=1aeb258a48320eeeb1b27d190fa6aeb6310cd068;hb=c90feb4c530cdb4e5abbfac044fea74d88975775;hp=7dcd2908aca58e6f9013a752c3e8af982ce85908;hpb=f2698c930f26434a100e0b4c1e4f39291b55b4f9;p=pygdb.git diff --git a/Configuration.py b/Configuration.py index 7dcd290..1aeb258 100755 --- a/Configuration.py +++ b/Configuration.py @@ -15,13 +15,15 @@ class Configuration: def __init__(self): self.breakpoints = [] self.watches = [] + self.ints = [] def load(self, filename): try: cnt = 0 #Parse all lines - for line in file(filename).readlines(): + f = file(filename, "r") + for line in f.readlines(): cnt += 1 #Get command and tail @@ -32,28 +34,43 @@ class Configuration: self.parseBreak(tail) elif cmd == "watch": self.parseWatch(tail) + elif cmd == "int": + self.parseInt(tail) else: cnt -= 1 print "Unkown command", cmd + f.close() return cnt + except IOError: return None + def store(self, filename): + try: + f = file(filename, "w") + + for b in self.breakpoints: + self.__writeBreak(f, b) - f = file(filename, "w") + for w in self.watches: + self.__writeWatch(f, w) - for b in self.breakpoints: - self.__writeBreak(f, b) + for s in self.ints: + self.__writeInt(f, s) + + f.close() + return True + + except IOError: + return False - for w in self.watches: - self.__writeWatch(f, w) def parseBreak(self, tail): tail = tail.strip() - rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$") + rx = re.compile("^[\w/\._\-]+:\d+(\s+if\s+\S+.*)?$") if not rx.search(tail): print "Wrong breakpoint format:", tail @@ -71,6 +88,17 @@ class Configuration: self.addBreak(file, lineno, cond) + def parseInt(self, tail): + tail.strip() + rx = re.compile("^[\w_\-]+\s+\d+$") + + if not rx.search(tail): + print "Wrong size format:", tail + return + + [name,val] = string.split(tail) + val = int(val) + self.addInt(name, val) def parseWatch(self, tail): self.addWatch(tail) @@ -82,18 +110,40 @@ class Configuration: else: f.write("break %(file)s:%(lineno)d\n" % b) + def __writeInt(self, f, s): + f.write("int %(name)s %(val)d\n" % s) + def __writeWatch(self, f, w): f.write("watch %(expr)s\n" % w) - def addBreak(self, file, lineno, cond=None): - self.breakpoints += [ {"file" : file, "lineno" : lineno, "cond" : cond} ] + def addBreak(self, file, lineno, cond=None): + bp = {"file" : file, "lineno" : lineno, "cond" : cond} + if not bp in self.breakpoints: + self.breakpoints += [bp] + + def addInt(self, name, val): + i = {"name": name, "val": val} + if not i in self.ints: + self.ints += [i] def addWatch(self, expr): - self.watches += [ {"expr" : expr.strip() } ] + w = {"expr" : expr.strip() } + if not w in self.watches: + self.watches += [w] + + + def findInt(self, name): + for i in self.ints: + if i["name"] == name: + return i["val"] + return None + def __str__(self): - return "breakpoints=" + str(self.breakpoints) + ", watches=" + str(self.watches) + return "breakpoints=" + str(self.breakpoints) + \ + ", watches=" + str(self.watches) + \ + ", ints=" + str(self.ints)