From e3403072dbc8f31817f6492dea70ebdf5128fcb2 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 8 Jun 2008 15:20:25 +0200 Subject: [PATCH] added watches and status line --- DbgTerminal.py | 12 ++++- GdbTerminal.py | 22 +++++--- MainControlWindow.py | 7 +-- StatusWindow.py | 49 ++++++++++++++++++ WatchesFrame.py | 118 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 11 deletions(-) create mode 100644 StatusWindow.py create mode 100644 WatchesFrame.py diff --git a/DbgTerminal.py b/DbgTerminal.py index 69fa833..c8b079f 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -17,6 +17,7 @@ import ClientIOTerminal class DbgTerminal (vte.Terminal): + isactive = True lastrow = 0 history = [] @@ -116,6 +117,15 @@ class DbgTerminal (vte.Terminal): def getExpression(self, expr): raise NotImplementedError() + def waitForActivation(self, his): + raise NotImplementedError() + + def setActive(self, isactive): + self.isactive = isactive + + def isActive(self): + return self.isactive + def getLastLine(self): if len(self.history) == 0: return None @@ -125,7 +135,7 @@ class DbgTerminal (vte.Terminal): def feed_dbg(self, text): self.feed_child(text) - + diff --git a/GdbTerminal.py b/GdbTerminal.py index 12256c1..bcd857a 100755 --- a/GdbTerminal.py +++ b/GdbTerminal.py @@ -32,23 +32,23 @@ class GdbTerminal (DbgTerminal.DbgTerminal): his = self.getHistoryLen() argv = string.join(string.split(self.clientCmd)[1:]) self.feed_dbg("run " + argv + "\n") - return self.waitForPosition(his) + return self.waitForActivation(his) def setContinue(self): his = self.getHistoryLen() self.feed_dbg("cont\n"); - return self.waitForPosition(his) + return self.waitForActivation(his) def setStepover(self): his = self.getHistoryLen() self.feed_dbg("next\n"); - return self.waitForPosition(his) + return self.waitForActivation(his) def setStepin(self): his = self.getHistoryLen() self.feed_dbg("step\n"); - return self.waitForPosition(his) + return self.waitForActivation(his) def setQuit(self): self.feed_dbg("quit\n") @@ -63,16 +63,24 @@ class GdbTerminal (DbgTerminal.DbgTerminal): his = self.getHistoryLen() self.feed_dbg("print " + expr + "\n") - rx = re.compile("^\$[1-9][0-9]* = .*$") + rx = re.compile("^\(gdb\) $") his, response = self.waitForRx(rx, his) - split = string.split(response, "=") + answer = self.history[his-1] + + if len(string.split(answer, "=")) == 1: + return answer.strip() + + split = string.split(answer, "=") return string.join(split[1:], "=").strip() - def waitForPosition(self, his): + def waitForActivation(self, his): + + self.setActive(False) rx = re.compile("^\(gdb\) $") his, reponse = self.waitForRx(rx,his) + self.setActive(True) if self.history[his-1][0:2]=="\x1a\x1a": tuples = string.split(self.history[his-1][2:], ":") diff --git a/MainControlWindow.py b/MainControlWindow.py index d82baaf..55bff28 100755 --- a/MainControlWindow.py +++ b/MainControlWindow.py @@ -132,15 +132,16 @@ class MainControlWindow (gtk.Window): if __name__ == "__main__": - def newpos(pos): - print "new pos: ", pos + + import StatusWindow clientCmd = string.join(sys.argv[1:]) dbgterm = GdbTerminal.GdbTerminal(clientCmd) mainCtrlWnd = MainControlWindow(dbgterm) - mainCtrlWnd.newPosCbs += [newpos] + statusWnd = StatusWindow.StatusWindow(mainCtrlWnd, dbgterm) + mainCtrlWnd.newPosCbs += [statusWnd.updateValues] gtk.main() diff --git a/StatusWindow.py b/StatusWindow.py new file mode 100644 index 0000000..a97e625 --- /dev/null +++ b/StatusWindow.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +#shuber, 2008-06-04 + +__author__ = "shuber" + + +import gtk +import vte + +import WatchesFrame + + +class StatusWindow (gtk.Window): + + def __init__(self, parent, debugger): + + gtk.Window.__init__(self) + self.set_screen(parent.get_screen()) + + self.set_border_width(5) + self.set_title("Status") + self.set_default_size(400,400) + + + vbox = gtk.VBox(False, 5) + self.add(vbox) + + self.status = gtk.Label("Not Running") + vbox.pack_start(self.status, False, False) + vpaned = gtk.VPaned() + vbox.add(vpaned) + + self.watchesFrame = WatchesFrame.WatchesFrame(debugger) + vpaned.add1(self.watchesFrame) + + self.show_all() + + + def updateValues(self, pos): + + if pos == None: + self.status.set_text("Exited") + else: + file, lineno = pos + self.status.set_text("%s:%s" % (file, lineno)) + + self.watchesFrame.updateValues() + + diff --git a/WatchesFrame.py b/WatchesFrame.py new file mode 100644 index 0000000..823f79f --- /dev/null +++ b/WatchesFrame.py @@ -0,0 +1,118 @@ +#!/usr/bin/python +#shuber, 2008-06-04 + +__author__ = "shuber" + + +import gobject +import gtk +import vte + +import DbgTerminal + + +class WatchesFrame (gtk.Frame): + + + def __init__(self, debugger): + + gtk.Frame.__init__(self, "Watches") + self.debugger = debugger + + vbox = gtk.VBox(False, 5) + self.add(vbox) + + hbox = gtk.HButtonBox() + vbox.pack_start(hbox, False, False) + + self.addBtn = gtk.Button(stock=gtk.STOCK_ADD) + self.delBtn = gtk.Button(stock=gtk.STOCK_REMOVE) + hbox.add(self.addBtn) + hbox.add(self.delBtn) + hbox.set_layout(gtk.BUTTONBOX_SPREAD) + + 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) + + + + def __createModel(self): + + model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, \ + gobject.TYPE_BOOLEAN) + + return model + + + def __addColumns(self, tv): + + model = tv.get_model() + + renderer = gtk.CellRendererText() + renderer.connect("edited", self.onExprEdited, model) + renderer.set_data("column", 0) + col = gtk.TreeViewColumn("Expr", renderer, text=0, editable=2) + col.set_resizable(True) + tv.append_column(col) + + + renderer = gtk.CellRendererText() + renderer.set_data("column", 1) + col = gtk.TreeViewColumn("Result", renderer, text=1) + col.set_resizable(True) + tv.append_column(col) + + + def onExprEdited(self, cell, pathStr, expr, model): + iter = model.get_iter_from_string(pathStr) + path = model.get_path(iter)[0] + col = cell.get_data("column") + + model.set(iter, 0, expr) + + if self.debugger.isActive(): + res = self.debugger.getExpression(expr) + model.set(iter, 1, res) + + + + + def addBtnClicked(self, btn): + iter = self.model.append() + self.model.set(iter, 0, "0", 1, "0", 2, True) + + + def delBtnClicked(self, btn): + selection = self.tv.get_selection() + model, paths = selection.get_selected_rows() + + for path in paths: + iter = model.get_iter(path) + model.remove(iter) + + + def updateValues(self): + + iter = self.model.get_iter_first() + + while iter != None: + + expr, = self.model.get(iter, 0) + res = self.debugger.getExpression(expr) + self.model.set(iter, 1, res) + + iter = self.model.iter_next(iter) + -- 2.39.5