]> git.sthu.org Git - pygdb.git/commitdiff
adding updating of breakpoint list
authorStefan Huber <shuber2@gmail.com>
Sun, 8 Jun 2008 16:19:25 +0000 (18:19 +0200)
committerStefan Huber <shuber2@gmail.com>
Sun, 8 Jun 2008 16:19:25 +0000 (18:19 +0200)
BreakpointsFrame.py [new file with mode: 0644]
DbgTerminal.py
GdbTerminal.py
StatusWindow.py
WatchesFrame.py

diff --git a/BreakpointsFrame.py b/BreakpointsFrame.py
new file mode 100644 (file)
index 0000000..3216de6
--- /dev/null
@@ -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))
+
+
+       
index c8b079fe18491567865c0d86c4c2ca9e39902e6b..7c494458000fb40005486ea9f8b85f64849ec4ee 100644 (file)
@@ -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):
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):
 
index a97e62588233bac642ac2eaac983c29afad22152..1eb486251471aa9d540a27b5108b67607f5d02fd 100644 (file)
@@ -8,6 +8,7 @@ import gtk
 import vte
 
 import WatchesFrame
+import BreakpointsFrame
 
 
 class StatusWindow (gtk.Window):
@@ -19,7 +20,8 @@ class StatusWindow (gtk.Window):
 
                self.set_border_width(5)
                self.set_title("Status")
-               self.set_default_size(400,400)
+               self.set_default_size(400,600)
+               self.connect("destroy", lambda *w: gtk.main_quit())
 
 
                vbox = gtk.VBox(False, 5)
@@ -33,6 +35,9 @@ class StatusWindow (gtk.Window):
                self.watchesFrame = WatchesFrame.WatchesFrame(debugger)
                vpaned.add1(self.watchesFrame)
 
+               self.breakpointsFrame = BreakpointsFrame.BreakpointsFrame(debugger)
+               vpaned.add2(self.breakpointsFrame)
+
                self.show_all()
 
 
@@ -45,5 +50,6 @@ class StatusWindow (gtk.Window):
                        self.status.set_text("%s:%s" % (file, lineno))
 
                self.watchesFrame.updateValues()
+               self.breakpointsFrame.updateValues()
 
 
index 823f79f8bf5161553f83452ee3f678ccad1d8f10..a792501b956ef26f5efff9c686ddcd7e064a9fc2 100644 (file)
@@ -22,14 +22,13 @@ class WatchesFrame (gtk.Frame):
                vbox = gtk.VBox(False, 5)
                self.add(vbox)
 
-               hbox = gtk.HButtonBox()
+               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)
                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)