]> git.sthu.org Git - pygdb.git/commitdiff
- pygdb saves current executed line
authorStefan Huber <shuber2@gmail.com>
Wed, 11 Jun 2008 16:05:21 +0000 (18:05 +0200)
committerStefan Huber <shuber2@gmail.com>
Wed, 11 Jun 2008 16:05:21 +0000 (18:05 +0200)
- vim loads current executed line
- changed colors of highlited lines in vim

Configuration.py
DbgTerminal.py
PositionFrame.py
StatusWindow.py
pygdb.vim

index 1aeb258a48320eeeb1b27d190fa6aeb6310cd068..6f08a20b442bb2ab9073adc5e243fdecf5b583a6 100755 (executable)
@@ -13,13 +13,20 @@ import StatusWindow
 class Configuration:
 
        def __init__(self):
+               self.clear()
+
+
+       def clear(self):
                self.breakpoints = []
                self.watches = []
                self.ints = []
+               self.currfile, self.currlineno = None, 0
 
 
        def load(self, filename):
                try:
+                       self.clear()
+
                        cnt = 0
                        #Parse all lines
                        f = file(filename, "r")
@@ -36,6 +43,8 @@ class Configuration:
                                        self.parseWatch(tail)
                                elif cmd == "int":
                                        self.parseInt(tail)
+                               elif cmd == "currpos":
+                                       self.parseCurrpos(tail)
                                else:
                                        cnt -= 1
                                        print "Unkown command", cmd
@@ -59,6 +68,9 @@ class Configuration:
                        for s in self.ints:
                                self.__writeInt(f, s)
 
+                       if self.isCurrposSet():
+                               self.__writeCurrpos(f)
+
                        f.close()
                        return True
 
@@ -103,6 +115,20 @@ class Configuration:
        def parseWatch(self, tail):
                self.addWatch(tail)
 
+       def parseCurrpos(self, tail):
+
+               tail = tail.strip()
+               rx = re.compile("^[\w/\._\-]+:\d+$")
+
+               if not rx.search(tail):
+                       print "Wrong current position format:", tail
+                       return
+
+               [file,lineno] = string.split(tail, ":")
+               lineno = int(lineno)
+
+               self.setCurrpos(file, lineno)
+
 
        def __writeBreak(self, f, b):
                if b["cond"] != None:
@@ -116,6 +142,9 @@ class Configuration:
        def __writeWatch(self, f, w):
                f.write("watch %(expr)s\n" % w)
 
+       def __writeCurrpos(self, f):
+               f.write("currpos %s:%d\n" % (self.currfile, self.currlineno))
+
 
        def addBreak(self, file, lineno, cond=None):
                bp = {"file" : file, "lineno" : lineno, "cond" : cond}
@@ -132,6 +161,12 @@ class Configuration:
                if not w in self.watches:
                        self.watches += [w]
 
+       def setCurrpos(self, file, lineno):
+               self.currfile, self.currlineno = file, lineno
+
+       def isCurrposSet(self):
+               return self.currfile!=None
+
 
        def findInt(self, name):
                for i in self.ints:
@@ -143,7 +178,8 @@ class Configuration:
        def __str__(self):
                return "breakpoints=" + str(self.breakpoints) + \
                                ", watches=" + str(self.watches) + \
-                               ", ints=" + str(self.ints)
+                               ", ints=" + str(self.ints) + \
+                               ", currpos=" + str((self.currfile, self.currlineno))
 
 
 
index f69d8036fc8e5c3785903acb21f081a823ce268d..c854bbaab2a449e344fcdbc7c5615e14a207b558 100644 (file)
@@ -81,8 +81,8 @@ class DbgTerminal (vte.Terminal):
                                        print "got inactive: ", res
                                        for cb in self.gotInactiveCallback:
                                                cb(status, param)
-               except:
-                       pass
+               except Exception, e:
+                       print e
 
                return True
 
index 29bd6a70bece55c67c4dd698f7b83886d3ac850d..ce82619bc1ed37e1906e6cdbdeec05116fe94e88 100644 (file)
@@ -74,7 +74,7 @@ class PositionFrame (StatusFrame.StatusFrame):
                        self.file, self.lineno = param
                        self.positionLabel.set_label("%s:%d" % (self.file, self.lineno))
                else:
-                       self.file, self.lineno = None, 0
+                       self.file, self.lineno = None, None
 
                        if status == "exited":
                                self.positionLabel.set_label("Exited with code %d." % param)
@@ -90,5 +90,5 @@ class PositionFrame (StatusFrame.StatusFrame):
                pass
 
        def fillConfiguration(self, conf):
-               pass
+               conf.setCurrpos(self.file, self.lineno)
 
index 3209fed5b94e69141518965cfc87363c7dc938e1..3d77dea2d21b939efcf72968e87bd0a184183182 100644 (file)
@@ -10,6 +10,7 @@ import string
 import os
 import vte
 
+import Configuration
 import DbgTerminal
 import BreakpointsFrame
 import PositionFrame
@@ -23,6 +24,7 @@ class StatusWindow (gtk.Window):
                gtk.Window.__init__(self)
 
                self.debugger = debugger
+               self.debugger.gotActiveCallback += [self.updateValues]
                
                self.set_border_width(5)
                self.set_title("Status")
@@ -41,6 +43,8 @@ class StatusWindow (gtk.Window):
                                WatchesFrame.WatchesFrame(debugger), \
                                BreakpointsFrame.BreakpointsFrame(debugger) ]
 
+               #Register callback after frames!
+               self.debugger.gotActiveCallback += [self.updateValues]
 
                #First paned window
                self.paned1 = gtk.VPaned()
@@ -88,3 +92,10 @@ class StatusWindow (gtk.Window):
                for f in self.frames:
                        f.fillConfiguration(conf)
 
+
+       def updateValues(self, status, param):
+
+               conf = Configuration.Configuration()
+               self.fillConfiguration(conf)
+               conf.store(".pygdb.conf")
+
index fc03b84404d48cf050f4f1116db99c5aeec2c6f2..e505b0aca7c938994a9725403cbce21efa63526f 100644 (file)
--- a/pygdb.vim
+++ b/pygdb.vim
@@ -24,6 +24,7 @@ import Configuration
 gdbBps = []
 signnum = 0
 clientcmd = ""
+execsign = None
 
 def gdbLaunch():
        global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
@@ -62,8 +63,42 @@ def gdbToggleBreakpoint(lineno=None, file=None):
                addBreakpoint(file, lineno)
 
 
+def setExecutionLine(file, lineno):
+       global execsign
+
+
+       #Open that file!
+       if file != getCurrentFile():
+               try:
+                       os.stat(file)
+                       vim.command(":e %s" % file)
+               except OSError:
+                       print "Warning: file '%s' does not exist! (Wrong client command?)" % file
+                       return
+
+       #Jump to line
+       vim.command(":%d" % lineno)
+
+       #Remove old execsign
+       if execsign != None:
+               delExecutionLine()
+
+       #Set the sign
+       execsign = gdbNewSignnum()
+       vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
+
+
+def delExecutionLine():
+       global execsign
+
+       #Remove old execsign
+       if execsign != None:
+               vim.command("sign unplace %d" % execsign)
+               execsign = None
+
+
 def addBreakpoint(file, lineno, cond=None):
-       global gdbBps
+       global gdbBps, cmdset
 
        #If file is not open, open it
        if not file in [b.name for b in vim.buffers]:
@@ -72,6 +107,7 @@ def addBreakpoint(file, lineno, cond=None):
                        vim.command(":e %s" % file)
                except OSError:
                        print "Warning: file '%s' does not exist! (Wrong client command?)" % file
+                       cmdset = False
                        return
 
 
@@ -171,9 +207,32 @@ def getAbsPath(absfile, relfile):
        return string.join(abssplit + relsplit, os.sep)
 
 
+#Change to absolute path
+def toAbsPath(path):
+       global clientcmd, cmdset
+
+       #Not a absolute path --> make one
+       if path[0] != os.sep:
+
+               #We need the client command to expand the paths...
+               while clientcmd == "" or not cmdset:
+                       clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
+                       cmdset = True
+
+               #Get the dirs where executeable is in
+               relcmd = string.split(clientcmd)[0]
+               abscmd = getAbsPath(getCurrentFile(), relcmd)
+               path = getAbsPath(abscmd, path)
+
+               assert(path[0] == "/")
+
+       return path
+
 
 def gdbLoadConfig():
-       global clientcmd, gdbBps
+       global clientcmd, gdbBps, cmdset
+
+
 
 
        #Load configuration
@@ -185,38 +244,26 @@ def gdbLoadConfig():
                removeBreakpoint(0)
 
        #Add breakpoints from configuration
-       cmdset = False
        for bp in conf.breakpoints:
-
-               file = bp["file"]
-
-               #Not a absolute path --> make one
-               if file[0] != os.sep:
-
-                       #We need the client command to expand the paths...
-                       while clientcmd == "" or not cmdset:
-                               clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
-                               cmdset = True
-
-                       #Get the dirs where executeable is in
-                       relcmd = string.split(clientcmd)[0]
-                       abscmd = getAbsPath(getCurrentFile(), relcmd)
-                       bp["file"] = file = getAbsPath(abscmd, file)
-
-                       assert(file[0] == "/")
-
+               bp["file"] = toAbsPath( bp["file"] )
                addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
-
+       
+       #Set current execution line
+       if conf.isCurrposSet():
+               file = toAbsPath(conf.currfile)
+               setExecutionLine(file, conf.currlineno)
+       else:
+               delExecutionLine()
 >>
 
+highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
+highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
 
-highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
-
+sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
 
 
-
 command! GDBLaunch :python gdbLaunch()
 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
 command! GDBBreakpointCond :python gdbBreakpointCond()