]> git.sthu.org Git - pygdb.git/commitdiff
- moving pygdb path to .gvimrc
authorStefan Huber <shuber2@gmail.com>
Tue, 10 Jun 2008 10:25:54 +0000 (11:25 +0100)
committerStefan Huber <shuber2@gmail.com>
Tue, 10 Jun 2008 10:25:54 +0000 (11:25 +0100)
- introducing a quit-handler to not call gtk.main_quit multiple times
  --> crash on rapfen.cosy...
- fixed synchronization problems: sometimes lines have been missing
  + row away DbgTerminal.lastrow

DbgTerminal.py
GdbTerminal.py
MainControlWindow.py
StatusWindow.py
pygdb.vim

index 8beec4652f97750b6a553710185b6c92b5295e37..11eaf5c35ee2cdf4a7f2629716b69fe5f2394e85 100644 (file)
@@ -9,6 +9,7 @@ import os
 import pango
 import pty
 import string
+import sys
 import time
 import threading
 import vte
@@ -26,7 +27,6 @@ class DbgTerminal (vte.Terminal):
                #Set members
                self.childpid = None
                self.history = []
-               self.lastrow = 0
                self.isactive = True
 
                #Start debugger
@@ -36,7 +36,7 @@ class DbgTerminal (vte.Terminal):
 
                #Set up terminal window and initialize debugger
                self.connect("cursor-moved", self.contents_changed)
-               self.connect("child-exited", lambda *w: gtk.main_quit())
+               self.connect("child-exited", quitHandler)
 
                #font description
                fontdesc = pango.FontDescription("monospace 9")
@@ -45,8 +45,8 @@ class DbgTerminal (vte.Terminal):
 
        def initialize(self):
                self.childpid = self.fork_command( self.getCommand(), self.getArgv())
+               self.waitForActivation(0)
                self.setPty(self.client_ptyslave)
-               self.waitForActivation()
 
        def stopDbg(self):
 
@@ -59,49 +59,43 @@ class DbgTerminal (vte.Terminal):
 
        def contents_changed(self, term):
                c,r = term.get_cursor_position()
+               text = self.get_text_range(self.getHistoryLen()-1,0,r,-1,lambda *w:True)
 
-               if self.lastrow <= r:
-                       text = self.get_text_range(self.lastrow,0,r,-1,lambda *w:True)
+               #Remove annoying \n at the end
+               assert(text[-1] == "\n")
+               text = text[:-1]
 
-                       #Remove the incomplete line
-                       if self.getHistoryLen()>0 and (len(self.history[-1])==0 or self.history[-1]!='\n') :
-                               del self.history[-1]
+               #Remove the incomplete line
+               if self.getHistoryLen()>0 and self.history[-1]!='\n':
+                       del self.history[-1]
 
-                       #Get the lines and remove empty lines
-                       lines = string.split(text, "\n")
+               #Get the lines and remove empty lines
+               lines = string.split(text, "\n")
 
-                       #Remove last empty line...
-                       if lines[-1] == "":
-                               del lines[-1]
-
-                       #Add lines to history
-                       self.history += [l+"\n" for l in lines[:-1]]
-                       self.history += [lines[-1]]
-                       self.lastrow = r
+               #Add lines to history. The last line contains no "\n" at the end!
+               self.history += [l+"\n" for l in lines[:-1]]
+               self.history += [lines[-1]]
 
 
        def waitForNewline(self):
-               r = self.lastrow
-               while not self.lastrow > r:
+               l = self.getHistoryLen()
+               while not self.getHistoryLen() > l:
                        gtk.main_iteration()
 
        def getHistoryLen(self):
                return len(self.history)
 
-       def waitForRx(self, rx, start=None):    
+       def waitForRx(self, rx, start): 
 
-               if start == None:
-                       start = self.getHistoryLen()
-               if start < 0:
-                       start = 0
+               curr = start
 
                while True:
-                       for no in range(start, self.getHistoryLen()):
+                       for no in range(max(curr-1,start), self.getHistoryLen()):
                                line = self.history[no]
                                if rx.search(line):
                                        return no, line
 
-                       start = self.getHistoryLen()
+                       curr = max(start,self.getHistoryLen())
                        gtk.main_iteration()
 
 
@@ -148,7 +142,13 @@ class DbgTerminal (vte.Terminal):
                return self.isactive
 
        
-       
+
+def quitHandler(*w):
+       try:
+               gtk.main_quit()
+       except:
+               pass
+       sys.exit(0)
 
 
 
@@ -164,7 +164,7 @@ class DbgWindow (gtk.Window):
 
                #Set up GTK stuff
                gtk.Window.__init__(self)
-               self.connect("destroy", lambda *w: gtk.main_quit())
+               self.connect("destroy", quitHandler)
 
                #Set title and add terminal
                self.set_title("Debugger I/O")
index 7341cae049379a2f9342e887f482f43acef56fdf..7c282360501232a26a97acedbceeec10b286e50e 100755 (executable)
@@ -25,7 +25,9 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
 
        def setPty(self, pty):
                ttyname = os.ttyname(pty)
+               his = self.getHistoryLen()
                self.feed_child("set inferior-tty %s\n" % (ttyname,))
+               self.waitForActivation(his)
 
        def setRun(self):
 
@@ -65,18 +67,19 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
                rx = re.compile("^Breakpoint |^No |^\(gdb\) ")
                his, response = self.waitForRx(rx, his)
 
-               if response[0:10] == "Breakpoint":
-                       return string.split(response)[1].strip()
+               answer = None
 
+               if response[0:10] == "Breakpoint":
+                       answer = string.split(response)[1].strip()
+               
+               #Wants an answer: "No"
                if response[0:14] == "No source file":
                        self.feed_child("n\n");
-                       return None
 
-               #Wait again for gdb
-               if response[0:5] != "(gdb)":
-                       his, response = self.waitForRx(rx,his)
+               #Wait again for (gdb)...
+               self.waitForActivation(his)
 
-               return None
+               return answer
 
 
        def delBreakpoint(self, breakpoint):
@@ -136,7 +139,7 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
                his = self.getHistoryLen()
                self.feed_child("print " + expr + "\n")
 
-               rx = re.compile("^\(gdb\) $")
+               rx = re.compile("^\(gdb\)")
                his, response = self.waitForRx(rx, his)
 
                answer = self.history[his-1]
@@ -148,14 +151,11 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
                return string.join(split[1:], "=").strip()
 
 
-       def waitForActivation(self, starthis=None):
-
-               if starthis == None:
-                       starthis = self.getHistoryLen()
+       def waitForActivation(self, starthis):
 
                self.setActive(False)
-               rx = re.compile("^\(gdb\) $")
-               endhis, reponse = self.waitForRx(rx,starthis)
+               rx = re.compile("^\(gdb\)")
+               endhis, response = self.waitForRx(rx,starthis)
                self.setActive(True)
 
                for his in reversed(range(starthis+1,endhis)):
index d8235c07283941187fa6cc937ca1042cf9778004..5ea0fb8f4cb38e7f77081a52159d614fff2ace32 100644 (file)
@@ -10,7 +10,7 @@ import sys
 import vte
 
 
-import GdbTerminal
+import DbgTerminal
 import ClientIOTerminal
 
 
@@ -20,7 +20,7 @@ class MainControlWindow (gtk.Window):
 
                #Set up GTK stuff
                gtk.Window.__init__(self)
-               self.connect("destroy", lambda *w: gtk.main_quit() )
+               self.connect("destroy", DbgTerminal.quitHandler )
 
                #Callbacks for new positions
                self.newPosCbs = []
index 72ee3caf712294439fcbd0eae4030a6e20035840..e021fed1a18b2f4c1b26d901ffbca4ac5e1786d2 100644 (file)
@@ -10,6 +10,7 @@ import string
 import os
 import vte
 
+import DbgTerminal
 import BreakpointsFrame
 import WatchesFrame
 
@@ -25,7 +26,7 @@ class StatusWindow (gtk.Window):
                self.set_border_width(5)
                self.set_title("Status")
                self.set_default_size(400,600)
-               self.connect("destroy", lambda *w: gtk.main_quit())
+               self.connect("destroy", DbgTerminal.quitHandler)
 
                vbox = gtk.VBox(False, 5)
                self.add(vbox)
index 872db2374769ecc3019122d3190e73eebacf6117..fe0626ff04f12b9359f87dbcef63393babe3cb17 100644 (file)
--- a/pygdb.vim
+++ b/pygdb.vim
@@ -13,13 +13,8 @@ import os
 import string
 import sys
 import threading
-
 import vim
 
-#Do not use a ~ for home directory
-pygdbdir = "/home/shuber/projekte/pygdb" 
-sys.path.append(pygdbdir)
-
 import Configuration