]>
git.sthu.org Git - pygdb.git/blob - Configuration.py
23 self
.currfile
, self
.currlineno
= None, 0
27 def load(self
, filename
):
33 f
= file(filename
, "r")
34 for line
in f
.readlines():
38 cmd
= string
.split(line
)[0]
39 tail
= string
.join(string
.split(line
)[1:])
47 elif cmd
== "currpos":
48 self
.parseCurrpos(tail
)
50 self
.parseCommand(tail
)
53 print "Unkown command", cmd
61 def store(self
, filename
):
63 f
= file(filename
, "w")
65 for b
in self
.breakpoints
:
66 self
.__writeBreak
(f
, b
)
68 for w
in self
.watches
:
69 self
.__writeWatch
(f
, w
)
74 if self
.isCurrposSet():
75 self
.__writeCurrpos
(f
)
77 if self
.getCommand() != None:
78 self
.__writeCommand
(f
)
88 def parseBreak(self
, tail
):
91 rx
= re
.compile("^[\w/\._\-]+:\d+(\s+if\s+\S+.*)?$")
93 if not rx
.search(tail
):
94 print "Wrong breakpoint format:", tail
97 preif
= string
.split(tail
, " if ")[0].strip()
98 postif
= string
.join( string
.split(tail
, " if ")[1:], " if ").strip()
100 [file,lineno
] = string
.split(preif
, ":")
107 self
.addBreak(file, lineno
, cond
)
109 def parseInt(self
, tail
):
111 rx
= re
.compile("^[\w_\-]+\s+\d+$")
113 if not rx
.search(tail
):
114 print "Wrong size format:", tail
117 [name
,val
] = string
.split(tail
)
119 self
.addInt(name
, val
)
121 def parseWatch(self
, tail
):
124 def parseCurrpos(self
, tail
):
127 rx
= re
.compile("^[\w/\._\-]+:\d+$")
129 if not rx
.search(tail
):
130 print "Wrong current position format:", tail
133 [file,lineno
] = string
.split(tail
, ":")
136 self
.setCurrpos(file, lineno
)
138 def parseCommand(self
, tail
):
142 def __writeBreak(self
, f
, b
):
143 if b
["cond"] != None:
144 f
.write("break %(file)s:%(lineno)d if %(cond)s\n" % b
)
146 f
.write("break %(file)s:%(lineno)d\n" % b
)
148 def __writeInt(self
, f
, s
):
149 f
.write("int %(name)s %(val)d\n" % s
)
151 def __writeWatch(self
, f
, w
):
152 f
.write("watch %(expr)s\n" % w
)
154 def __writeCurrpos(self
, f
):
155 f
.write("currpos %s:%d\n" % (self
.currfile
, self
.currlineno
))
157 def __writeCommand(self
, f
):
158 f
.write("cmd %s\n" % self
.command
)
161 def addBreak(self
, file, lineno
, cond
=None):
162 bp
= {"file" : file, "lineno" : lineno
, "cond" : cond
}
163 if not bp
in self
.breakpoints
:
164 self
.breakpoints
+= [bp
]
166 def addInt(self
, name
, val
):
167 i
= {"name": name
, "val": val
}
168 if not i
in self
.ints
:
171 def addWatch(self
, expr
):
172 w
= {"expr" : expr
.strip() }
173 if not w
in self
.watches
:
176 def setCurrpos(self
, file, lineno
):
177 self
.currfile
, self
.currlineno
= file, lineno
179 def isCurrposSet(self
):
180 return self
.currfile
!=None
183 def delCurrpos(self
):
186 def setCommand(self
,cmd
):
189 def getCommand(self
):
192 def findInt(self
, name
):
194 if i
["name"] == name
:
200 return "breakpoints=" + str(self
.breakpoints
) + \
201 ", watches=" + str(self
.watches
) + \
202 ", ints=" + str(self
.ints
) + \
203 ", currpos=" + str((self
.currfile
, self
.currlineno
))