projects
/
pygdb.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
- moving pygdb path to .gvimrc
[pygdb.git]
/
DbgTerminal.py
diff --git
a/DbgTerminal.py
b/DbgTerminal.py
index 89659d035628a9fe7a450bffc9e603ff905eceb7..11eaf5c35ee2cdf4a7f2629716b69fe5f2394e85 100644
(file)
--- a/
DbgTerminal.py
+++ b/
DbgTerminal.py
@@
-5,9
+5,11
@@
__author__ = "shuber"
import gtk
import gtk
+import os
import pango
import pty
import string
import pango
import pty
import string
+import sys
import time
import threading
import vte
import time
import threading
import vte
@@
-18,15
+20,15
@@
import ClientIOTerminal
class DbgTerminal (vte.Terminal):
class DbgTerminal (vte.Terminal):
- isactive = True
- lastrow = 0
- history = []
-
-
def __init__(self, clientCmd):
vte.Terminal.__init__(self)
def __init__(self, clientCmd):
vte.Terminal.__init__(self)
+ #Set members
+ self.childpid = None
+ self.history = []
+ self.isactive = True
+
#Start debugger
self.clientCmd = clientCmd
#Open pseudo-terminal where to-be-debugged process reads/writes to
#Start debugger
self.clientCmd = clientCmd
#Open pseudo-terminal where to-be-debugged process reads/writes to
@@
-34,7
+36,7
@@
class DbgTerminal (vte.Terminal):
#Set up terminal window and initialize debugger
self.connect("cursor-moved", self.contents_changed)
#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")
#font description
fontdesc = pango.FontDescription("monospace 9")
@@
-42,56
+44,58
@@
class DbgTerminal (vte.Terminal):
def initialize(self):
def initialize(self):
- self.fork_command( self.getCommand(), self.getArgv())
+ self.childpid = self.fork_command( self.getCommand(), self.getArgv())
+ self.waitForActivation(0)
self.setPty(self.client_ptyslave)
self.setPty(self.client_ptyslave)
- self.waitForActivation()
+
+ def stopDbg(self):
+
+ if self.childpid != None:
+ #9=KILL, 15=TERM
+ os.kill(self.childpid, 15);
+ self.childpid = None
+
def contents_changed(self, term):
c,r = term.get_cursor_position()
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 the incomplete line
- if self.getHistoryLen()>0 and (len(self.history[-1])==0 or self.history[-1]!='\n') :
- del self.history[-1]
+ #Remove annoying \n at the end
+ assert(text[-1] == "\n")
+ text = text[:-1]
- #Get the lines and remove empty lines
- lines = string.split(text, "\n")
+ #Remove the incomplete line
+ if self.getHistoryLen()>0 and self.history[-1]!='\n':
+ del self.history[-1]
- #Remove last empty line...
- if lines[-1] == "":
- del lines[-1]
+ #Get the lines and remove empty lines
+ lines = string.split(text, "\n")
- #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):
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)
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:
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
line = self.history[no]
if rx.search(line):
return no, line
-
start = self.getHistoryLen(
)
+
curr = max(start,self.getHistoryLen()
)
gtk.main_iteration()
gtk.main_iteration()
@@
-138,7
+142,13
@@
class DbgTerminal (vte.Terminal):
return self.isactive
return self.isactive
-
+
+def quitHandler(*w):
+ try:
+ gtk.main_quit()
+ except:
+ pass
+ sys.exit(0)
@@
-154,7
+164,7
@@
class DbgWindow (gtk.Window):
#Set up GTK stuff
gtk.Window.__init__(self)
#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")
#Set title and add terminal
self.set_title("Debugger I/O")