adding updating of breakpoint list
[pygdb.git] / GdbTerminal.py
index bcd857ac5ef5428fdc0fc435a57a0cba5d8b7047..77d21e2f6e3fbffab0c3143214bca2ff1dd8db31 100755 (executable)
@@ -55,8 +55,75 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
                self.waitForNewline()
                self.feed_dbg("y\n");
 
-       def setBreakpoint(self, file, lineno):
-               self.feed_dbg("break %s:%d\n" % (file, lineno))
+       def setBreakpoint(self, file, lineno, condition=None):
+               his = self.getHistoryLen()
+               if condition==None:
+                       self.feed_dbg("break %s:%s\n" % (file, str(lineno)))
+               else:
+                       self.feed_dbg("break %s:%s if %s\n" % \
+                                       (file, str(lineno), condition))
+
+               rx = re.compile("^Breakpoint |^No|^\(gdb\) ")
+               his, response = self.waitForRx(rx, his)
+
+
+               if response[0:10] == "Breakpoint":
+                       return string.split(response)[1].strip()
+               if response[0:5] == "(gdb)":
+                       return None
+               if response[0:14] == "No source file":
+                       self.feed_dbg("n\n");
+                       return None
+               if response[0:3] == "No ":
+                       return None
+                       
+               return NotImplementedError()
+
+       def delBreakpoint(self, breakpoint):
+               self.feed_dbg("del breakpoint %s\n" % (breakpoint,))
+
+       def getBreakpoints(self):
+               starthis = self.getHistoryLen()
+               self.feed_dbg("info breakpoints\n")
+
+               rx = re.compile("^\(gdb\) ")
+               endhis, response = self.waitForRx(rx, starthis)
+
+
+               rxbp1 = re.compile("^\d+\s+breakpoint")
+               rxbp2 = re.compile("^\tstop only if")
+
+               bpnts = []
+               bplines = self.history[starthis+1:endhis]
+               i = 0
+
+               #Parse the resulting lines
+               while i<len(bplines):
+                       line = bplines[i]
+
+                       if not rxbp1.search(line):
+                               print "Warning GdbTerminal.getBreakpoints at line", line
+                               i += 1
+                               continue
+
+                       splits = string.split(line)
+                       no = splits[0]
+                       pos = splits[-1]
+                       [file,lineno] = string.split(pos,":")
+                       cond = None
+
+                       if i+1<len(bplines) and rxbp2.search(bplines[i+1]):
+                               i +=1
+                               line = bplines[i]
+                               pre,cond = string.split(line,"if")
+                               cond = cond.strip()
+
+                       bpnts += [[no, file, lineno, cond]]
+                       i += 1
+
+               return bpnts
+               
+
 
        def getExpression(self, expr):