23 self
.currfile
, self
.currlineno
= None, 0
26 def load(self
, filename
):
32 f
= file(filename
, "r")
33 for line
in f
.readlines():
37 cmd
= string
.split(line
)[0]
38 tail
= string
.join(string
.split(line
)[1:])
46 elif cmd
== "currpos":
47 self
.parseCurrpos(tail
)
50 print "Unkown command", cmd
58 def store(self
, filename
):
60 f
= file(filename
, "w")
62 for b
in self
.breakpoints
:
63 self
.__writeBreak
(f
, b
)
65 for w
in self
.watches
:
66 self
.__writeWatch
(f
, w
)
71 if self
.isCurrposSet():
72 self
.__writeCurrpos
(f
)
82 def parseBreak(self
, tail
):
85 rx
= re
.compile("^[\w/\._\-]+:\d+(\s+if\s+\S+.*)?$")
87 if not rx
.search(tail
):
88 print "Wrong breakpoint format:", tail
91 preif
= string
.split(tail
, "if")[0].strip()
92 postif
= string
.join( string
.split(tail
, "if")[1:], "if").strip()
94 [file,lineno
] = string
.split(preif
, ":")
101 self
.addBreak(file, lineno
, cond
)
103 def parseInt(self
, tail
):
105 rx
= re
.compile("^[\w_\-]+\s+\d+$")
107 if not rx
.search(tail
):
108 print "Wrong size format:", tail
111 [name
,val
] = string
.split(tail
)
113 self
.addInt(name
, val
)
115 def parseWatch(self
, tail
):
118 def parseCurrpos(self
, tail
):
121 rx
= re
.compile("^[\w/\._\-]+:\d+$")
123 if not rx
.search(tail
):
124 print "Wrong current position format:", tail
127 [file,lineno
] = string
.split(tail
, ":")
130 self
.setCurrpos(file, lineno
)
133 def __writeBreak(self
, f
, b
):
134 if b
["cond"] != None:
135 f
.write("break %(file)s:%(lineno)d if %(cond)s\n" % b
)
137 f
.write("break %(file)s:%(lineno)d\n" % b
)
139 def __writeInt(self
, f
, s
):
140 f
.write("int %(name)s %(val)d\n" % s
)
142 def __writeWatch(self
, f
, w
):
143 f
.write("watch %(expr)s\n" % w
)
145 def __writeCurrpos(self
, f
):
146 f
.write("currpos %s:%d\n" % (self
.currfile
, self
.currlineno
))
149 def addBreak(self
, file, lineno
, cond
=None):
150 bp
= {"file" : file, "lineno" : lineno
, "cond" : cond
}
151 if not bp
in self
.breakpoints
:
152 self
.breakpoints
+= [bp
]
154 def addInt(self
, name
, val
):
155 i
= {"name": name
, "val": val
}
156 if not i
in self
.ints
:
159 def addWatch(self
, expr
):
160 w
= {"expr" : expr
.strip() }
161 if not w
in self
.watches
:
164 def setCurrpos(self
, file, lineno
):
165 self
.currfile
, self
.currlineno
= file, lineno
167 def isCurrposSet(self
):
168 return self
.currfile
!=None
171 def findInt(self
, name
):
173 if i
["name"] == name
:
179 return "breakpoints=" + str(self
.breakpoints
) + \
180 ", watches=" + str(self
.watches
) + \
181 ", ints=" + str(self
.ints
) + \
182 ", currpos=" + str((self
.currfile
, self
.currlineno
))