From 9a8e5a643a533e00a2c8fdd6f03ea7b7a5e5d649 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 8 Jun 2008 18:19:25 +0200 Subject: [PATCH] adding updating of breakpoint list --- BreakpointsFrame.py | 181 ++++++++++++++++++++++++++++++++++++++++++++ DbgTerminal.py | 5 +- GdbTerminal.py | 71 ++++++++++++++++- StatusWindow.py | 8 +- WatchesFrame.py | 3 +- 5 files changed, 262 insertions(+), 6 deletions(-) create mode 100644 BreakpointsFrame.py diff --git a/BreakpointsFrame.py b/BreakpointsFrame.py new file mode 100644 index 0000000..3216de6 --- /dev/null +++ b/BreakpointsFrame.py @@ -0,0 +1,181 @@ +#!/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)) + + + diff --git a/DbgTerminal.py b/DbgTerminal.py index c8b079f..7c49445 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -111,7 +111,10 @@ class DbgTerminal (vte.Terminal): def setQuit(self): raise NotImplementedError() - def setBreakpoint(self, file, lineno): + def setBreakpoint(self, file, lineno, condition=False): + raise NotImplementedError() + + def delBreakpoint(self, breakpoint): raise NotImplementedError() def getExpression(self, expr): diff --git a/GdbTerminal.py b/GdbTerminal.py index bcd857a..77d21e2 100755 --- a/GdbTerminal.py +++ b/GdbTerminal.py @@ -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