- Fixed bug when bp is set on same addr
[pygdb.git] / Configuration.py
1 #!/usr/bin/python
2 #shuber, 2008-06-09
3
4 __author__ = "shuber"
5
6
7
8 import re
9 import string
10
11 import StatusWindow
12
13 class Configuration:
14
15 def __init__(self):
16 self.breakpoints = []
17 self.watches = []
18
19
20 def load(self, filename):
21 try:
22 cnt = 0
23 #Parse all lines
24 for line in file(filename).readlines():
25 cnt += 1
26
27 #Get command and tail
28 cmd = string.split(line)[0]
29 tail = string.join(string.split(line)[1:])
30
31 if cmd == "break":
32 self.parseBreak(tail)
33 elif cmd == "watch":
34 self.parseWatch(tail)
35 else:
36 cnt -= 1
37 print "Unkown command", cmd
38 return cnt
39 except IOError:
40 return None
41
42 def store(self, filename):
43
44 f = file(filename, "w")
45
46 for b in self.breakpoints:
47 self.__writeBreak(f, b)
48
49 for w in self.watches:
50 self.__writeWatch(f, w)
51
52
53 def parseBreak(self, tail):
54
55 tail = tail.strip()
56 rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$")
57
58 if not rx.search(tail):
59 print "Wrong breakpoint format:", tail
60 return
61
62 preif = string.split(tail, "if")[0].strip()
63 postif = string.join( string.split(tail, "if")[1:], "if").strip()
64
65 [file,lineno] = string.split(preif, ":")
66 lineno = int(lineno)
67
68 cond = None
69 if postif != "":
70 cond = postif
71
72 self.addBreak(file, lineno, cond)
73
74
75 def parseWatch(self, tail):
76 self.addWatch(tail)
77
78
79 def __writeBreak(self, f, b):
80 if b["cond"] != None:
81 f.write("break %(file)s:%(lineno)d if %(cond)s\n" % b)
82 else:
83 f.write("break %(file)s:%(lineno)d\n" % b)
84
85 def __writeWatch(self, f, w):
86 f.write("watch %(expr)s\n" % w)
87
88
89 def addBreak(self, file, lineno, cond=None):
90 self.breakpoints += [ {"file" : file, "lineno" : lineno, "cond" : cond} ]
91
92 def addWatch(self, expr):
93 self.watches += [ {"expr" : expr.strip() } ]
94
95 def __str__(self):
96 return "breakpoints=" + str(self.breakpoints) + ", watches=" + str(self.watches)
97
98
99