--- /dev/null
+#!/usr/bin/python
+#shuber, 2008-06-04
+
+__author__ = "shuber"
+
+
+import gobject
+import gtk
+import re
+import string
+import vte
+
+import DbgTerminal
+
+
+class BreakpointsFrame (gtk.Frame):
+
+
+ def __init__(self, debugger):
+
+ gtk.Frame.__init__(self, "Breakpoints")
+ self.debugger = debugger
+
+ vbox = gtk.VBox(False, 5)
+ self.add(vbox)
+
+ hbox = gtk.HBox()
+ vbox.pack_start(hbox, False, False)
+ self.bpEntry = gtk.Entry()
+ hbox.add(self.bpEntry)
+
+
+ hbox = gtk.HBox()
+ vbox.pack_start(hbox, False, False)
+ self.addBtn = gtk.Button(stock=gtk.STOCK_ADD)
+ self.delBtn = gtk.Button(stock=gtk.STOCK_REMOVE)
+ self.updBtn = gtk.Button("Update")
+ hbox.add(self.addBtn)
+ hbox.add(self.delBtn)
+ hbox.add(self.updBtn)
+
+ sw = gtk.ScrolledWindow()
+ sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+ sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ vbox.add(sw)
+
+ self.model = self.__createModel()
+ self.tv = gtk.TreeView(self.model)
+ self.tv.set_rules_hint(True)
+ self.tv.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
+
+ self.__addColumns(self.tv)
+ sw.add(self.tv)
+
+ self.addBtn.connect("clicked", self.addBtnClicked)
+ self.delBtn.connect("clicked", self.delBtnClicked)
+ self.updBtn.connect("clicked", self.updBtnClicked)
+
+
+
+ def __createModel(self):
+ #Breakpoint number, position and a boolean flag indicating whether BP has been set
+ #at debugger yet
+ model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
+
+ return model
+
+
+ def __addColumns(self, tv):
+
+ model = tv.get_model()
+
+ renderer = gtk.CellRendererText()
+ renderer.set_data("column", 0)
+ col = gtk.TreeViewColumn("No", renderer, text=0)
+ col.set_resizable(True)
+ tv.append_column(col)
+
+
+ renderer = gtk.CellRendererText()
+ renderer.set_data("column", 1)
+ col = gtk.TreeViewColumn("Specification", renderer, text=1)
+ col.set_resizable(True)
+ tv.append_column(col)
+
+
+
+ def addBtnClicked(self, btn):
+
+ if not self.debugger.isActive():
+ return
+
+
+ bpspec = self.bpEntry.get_text()
+ rx = re.compile("^[\w\._\-]+:\d+\s*(\sif\s+\S+.*)?$")
+
+ #Check if format is correct
+ if not rx.search(bpspec):
+ dialog = gtk.MessageDialog(None, \
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
+ gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \
+ "Invalid format!")
+ dialog.run()
+ dialog.destroy()
+ return
+
+
+ ifsplit = string.split(bpspec, "if")
+
+ if len(ifsplit)>1:
+ cond = ifsplit[1].strip()
+ else:
+ cond = None
+
+ pos = ifsplit[0].strip()
+ [file,lineno] = string.split(pos, ":")
+
+ pos = self.debugger.setBreakpoint(file, lineno, cond)
+
+ if pos!=None:
+ iter = self.model.append()
+ self.model.set(iter, 0, pos)
+ self.model.set(iter, 1, bpspec)
+ else:
+ dialog = gtk.MessageDialog(None, \
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
+ gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \
+ "Invalid specification!")
+ dialog.run()
+ dialog.destroy()
+ return
+
+
+
+
+ def delBtnClicked(self, btn):
+
+ if not self.debugger.isActive():
+ return
+
+ selection = self.tv.get_selection()
+ model, paths = selection.get_selected_rows()
+
+ for path in paths:
+ iter = model.get_iter(path)
+ bpno, = self.model.get(iter, 0)
+ self.debugger.delBreakpoint(bpno)
+ model.remove(iter)
+
+
+ def updBtnClicked(self, btn):
+
+ if not self.debugger.isActive():
+ return
+
+ self.updateValues()
+
+
+ def updateValues(self):
+
+ bpnts = self.debugger.getBreakpoints()
+
+ #Remove them all
+ iter = self.model.get_iter_first()
+ while iter != None:
+ newiter = self.model.iter_next(iter)
+ self.model.remove(iter)
+ iter = newiter
+
+ for bp in bpnts:
+ [no, file, lineno, cond] = bp
+ iter = self.model.append()
+ self.model.set(iter, 0, no)
+
+ if cond==None:
+ self.model.set(iter, 1, "%s:%s" % (file, lineno))
+ else:
+ self.model.set(iter, 1, "%s:%s if %s" % (file, lineno, cond))
+
+
+
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):