- moving pygdb path to .gvimrc
[pygdb.git] / DbgTerminal.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gtk
8 import os
9 import pango
10 import pty
11 import string
12 import sys
13 import time
14 import threading
15 import vte
16
17 import ClientIOTerminal
18
19
20
21 class DbgTerminal (vte.Terminal):
22
23 def __init__(self, clientCmd):
24
25 vte.Terminal.__init__(self)
26
27 #Set members
28 self.childpid = None
29 self.history = []
30 self.isactive = True
31
32 #Start debugger
33 self.clientCmd = clientCmd
34 #Open pseudo-terminal where to-be-debugged process reads/writes to
35 self.client_ptymaster, self.client_ptyslave = pty.openpty()
36
37 #Set up terminal window and initialize debugger
38 self.connect("cursor-moved", self.contents_changed)
39 self.connect("child-exited", quitHandler)
40
41 #font description
42 fontdesc = pango.FontDescription("monospace 9")
43 self.set_font(fontdesc)
44
45
46 def initialize(self):
47 self.childpid = self.fork_command( self.getCommand(), self.getArgv())
48 self.waitForActivation(0)
49 self.setPty(self.client_ptyslave)
50
51 def stopDbg(self):
52
53 if self.childpid != None:
54 #9=KILL, 15=TERM
55 os.kill(self.childpid, 15);
56 self.childpid = None
57
58
59
60 def contents_changed(self, term):
61 c,r = term.get_cursor_position()
62 text = self.get_text_range(self.getHistoryLen()-1,0,r,-1,lambda *w:True)
63
64 #Remove annoying \n at the end
65 assert(text[-1] == "\n")
66 text = text[:-1]
67
68 #Remove the incomplete line
69 if self.getHistoryLen()>0 and self.history[-1]!='\n':
70 del self.history[-1]
71
72 #Get the lines and remove empty lines
73 lines = string.split(text, "\n")
74
75 #Add lines to history. The last line contains no "\n" at the end!
76 self.history += [l+"\n" for l in lines[:-1]]
77 self.history += [lines[-1]]
78
79
80 def waitForNewline(self):
81 l = self.getHistoryLen()
82 while not self.getHistoryLen() > l:
83 gtk.main_iteration()
84
85 def getHistoryLen(self):
86 return len(self.history)
87
88 def waitForRx(self, rx, start):
89
90 curr = start
91
92 while True:
93 for no in range(max(curr-1,start), self.getHistoryLen()):
94 line = self.history[no]
95 if rx.search(line):
96 return no, line
97
98 curr = max(start,self.getHistoryLen())
99 gtk.main_iteration()
100
101
102 def getCommand(self):
103 return self.getArgv()[0];
104
105 def getArgv(self):
106 raise NotImplementedError()
107
108 def setPty(self, pty):
109 raise NotImplementedError()
110
111 def setRun(self):
112 raise NotImplementedError()
113
114 def setContinue(self):
115 raise NotImplementedError()
116
117 def setStepover(self):
118 raise NotImplementedError()
119
120 def setStepin(self):
121 raise NotImplementedError()
122
123 def setQuit(self):
124 raise NotImplementedError()
125
126 def setBreakpoint(self, file, lineno, condition=False):
127 raise NotImplementedError()
128
129 def delBreakpoint(self, breakpoint):
130 raise NotImplementedError()
131
132 def getExpression(self, expr):
133 raise NotImplementedError()
134
135 def waitForActivation(self, his):
136 raise NotImplementedError()
137
138 def setActive(self, isactive):
139 self.isactive = isactive
140
141 def isActive(self):
142 return self.isactive
143
144
145
146 def quitHandler(*w):
147 try:
148 gtk.main_quit()
149 except:
150 pass
151 sys.exit(0)
152
153
154
155 class DbgWindow (gtk.Window):
156
157 clientIOWnd = None
158
159
160 def __init__(self, terminal):
161
162 #Set up some members
163 self.terminal = terminal
164
165 #Set up GTK stuff
166 gtk.Window.__init__(self)
167 self.connect("destroy", quitHandler)
168
169 #Set title and add terminal
170 self.set_title("Debugger I/O")
171 self.terminal.history = []
172 self.terminal.history_length = 5
173 self.add(self.terminal)
174
175 #Show the window
176 self.show_all()
177
178 def toggleClientIOWindow(self):
179 if not self.clientIOWnd:
180 self.clientIOWnd = ClientIOTerminal.ClientIOWindow(self, \
181 self.terminal.client_ptymaster)
182 else:
183 self.clientIOWnd.destroy()
184 self.clientIOWnd = None
185
186 def isClientIOWindowExisting(self):
187 return self.clientIOWnd != None
188
189
190